Skip to content

Commit

Permalink
Merge pull request #459 from avanwinkle/audio-track-volume-control
Browse files Browse the repository at this point in the history
Audio track volume control and SoundPlayer ducking
  • Loading branch information
avanwinkle authored Feb 4, 2024
2 parents 69aa78b + 2639f2b commit 7c7c058
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
6 changes: 6 additions & 0 deletions mpfmc/assets/sound.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,12 @@ def has_ducking(self):
"""Return whether or not this sound has ducking"""
return self._ducking is not None

def set_ducking(self, ducking_settings=None):
if not ducking_settings:
self._ducking = None
return
self._ducking = DuckingSettings(self.machine, ducking_settings)

@property
def key(self):
"""Return the unique key value for this sound"""
Expand Down
2 changes: 1 addition & 1 deletion mpfmc/config_players/slide_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def play(self, settings, context, calling_context, priority=0, **kwargs):
instance_dict = self._get_instance_dict(context)
full_context = self._get_full_context(context)

self.machine.log.info("SlidePlayer: Play called with settings=%s", settings)
self.machine.log.debug("SlidePlayer: Play called with settings=%s", settings)

settings = settings.get('slides', settings)

Expand Down
15 changes: 13 additions & 2 deletions mpfmc/config_players/sound_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,16 @@ def play(self, settings, context, calling_context, priority=0, **kwargs): # noq
action:
priority:
volume:
ducking:
loops:
max_queue_time:
block:
Notes:
Ducking settings and markers cannot currently be specified/overridden in the
sound_player (they must be specified in the sounds section of a config file).
- Ducking settings only apply to sound assets without ducking config
(i.e. sound asset ducking overrides sound_player ducking)
- Markers cannot currently be specified/overridden in the sound_player
(they must be specified in the sounds section of a config file).
"""
settings = deepcopy(settings)
Expand Down Expand Up @@ -135,7 +138,15 @@ def play(self, settings, context, calling_context, priority=0, **kwargs): # noq

# Determine action to perform
if action == 'play':
temp_ducking = None
if s.get('ducking') and not sound.has_ducking:
sound.set_ducking(s['ducking'])
temp_ducking = True

track.play_sound(sound, context, s)
# Remove the temporary ducking
if temp_ducking:
sound.set_ducking()

elif action == 'stop':
if 'fade_out' in s:
Expand Down
11 changes: 10 additions & 1 deletion mpfmc/core/audio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,18 @@ def __init__(self, mc):

self.mc.events.add_handler("shutdown", self.shutdown)
self.mc.events.add_handler("machine_var_master_volume", self._set_volume)
for track in self.tracks.keys():
self.mc.events.add_handler(f"machine_var_{track}_volume", self._set_volume, track=track)

def _set_volume(self, **kwargs):
self.master_volume = kwargs['value']
track = kwargs.get("track")
if not track:
self.master_volume = kwargs['value']
return
elif not track in self.tracks:
raise AttributeError(f"Track {track} not found in sound system.")

self.tracks[track].set_volume(kwargs['value'])

def shutdown(self, **kwargs):
"""Shuts down the audio interface"""
Expand Down
7 changes: 5 additions & 2 deletions mpfmc/tests/test_Display.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from kivy.metrics import dp
from mpfmc.uix.display import Display, DisplayOutput
from mpfmc.tests.MpfMcTestCase import MpfMcTestCase

Expand All @@ -11,12 +12,14 @@ def get_config_file(self):

def test_display(self):
# Make sure nested multiple displays are loaded properly and are centered
self.assertEqual(self.mc.root_window.size, (800, 600))
self.assertEqual(self.mc.root_window.system_size, [800, 600])
self.assertIn('window', self.mc.displays)
self.assertTrue(isinstance(self.mc.displays['window'], Display))
self.assertEqual(self.mc.displays['window'].size, [600, 200])
self.assertIsInstance(self.mc.displays['window'].parent, DisplayOutput)
self.assertEqual(self.mc.displays['window'].parent.pos, (0, 167))
self.assertEqual(self.mc.displays['window'].parent.pos[0], 0)
# Rounding DPI can cause single pixel offset, so accept within 1px
self.assertAlmostEqual(self.mc.displays['window'].parent.pos[1], dp(167), delta=1)

self.assertIn('dmd', self.mc.displays)
self.assertTrue(isinstance(self.mc.displays['dmd'], Display))
Expand Down

0 comments on commit 7c7c058

Please sign in to comment.