From a8340c5d43bcfc3d78c2e00ab26c0596d7ffe85e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Isma=C3=ABl=20Bouya?= Date: Thu, 21 Jul 2016 09:26:20 +0200 Subject: [PATCH] Handle fade for master volume --- helpers/action.py | 4 ++-- helpers/mapping.py | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/helpers/action.py b/helpers/action.py index b8e44e6..247e0a9 100644 --- a/helpers/action.py +++ b/helpers/action.py @@ -106,7 +106,7 @@ class Action: if music is not None: music.set_volume(value, delta=delta, fade=fade) else: - self.mapping.set_master_volume(value, delta=delta) + self.mapping.set_master_volume(value, delta=delta, fade=fade) def wait(self, duration=0, music=None, **kwargs): self.sleep_event = threading.Event() @@ -210,7 +210,7 @@ class Action: message += "setting volume to {}%" \ .format(value) - if music is not None and fade > 0: + if fade > 0: message += " with {}s fade".format(fade) return message diff --git a/helpers/mapping.py b/helpers/mapping.py index 9420acf..3622f9d 100644 --- a/helpers/mapping.py +++ b/helpers/mapping.py @@ -10,6 +10,7 @@ import sys from .music_file import * from .mixer import Mixer from . import Config, gain, error_print +from .music_effect import GainEffect class Mapping(RelativeLayout): expected_keys = NumericProperty(0) @@ -32,13 +33,22 @@ class Mapping(RelativeLayout): def master_gain(self): return gain(self.master_volume) - def set_master_volume(self, value, delta=False): + def set_master_volume(self, value, delta=False, fade=0): [db_gain, self.master_volume] = gain( value + int(delta) * self.master_volume, self.master_volume) for music in self.open_files.values(): - music.set_gain(db_gain) + if fade > 0: + music.gain_effects.append(GainEffect( + "fade", + music.current_audio_segment, + music.current_loop, + music.sound_position, + music.sound_position + fade, + gain=db_gain)) + else: + music.set_gain(db_gain) def _keyboard_closed(self): self._keyboard.unbind(on_key_down=self._on_keyboard_down) -- 2.41.0