aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-21 09:26:20 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-21 09:26:20 +0200
commita8340c5d43bcfc3d78c2e00ab26c0596d7ffe85e (patch)
tree0142753a5c6f8ce25ec2c456309b96c6e721d485
parent9925ce3b588fc449a3e0f5a6506a2d29207928d3 (diff)
downloadMusicSampler-a8340c5d43bcfc3d78c2e00ab26c0596d7ffe85e.tar.gz
MusicSampler-a8340c5d43bcfc3d78c2e00ab26c0596d7ffe85e.tar.zst
MusicSampler-a8340c5d43bcfc3d78c2e00ab26c0596d7ffe85e.zip
Handle fade for master volume
-rw-r--r--helpers/action.py4
-rw-r--r--helpers/mapping.py14
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:
106 if music is not None: 106 if music is not None:
107 music.set_volume(value, delta=delta, fade=fade) 107 music.set_volume(value, delta=delta, fade=fade)
108 else: 108 else:
109 self.mapping.set_master_volume(value, delta=delta) 109 self.mapping.set_master_volume(value, delta=delta, fade=fade)
110 110
111 def wait(self, duration=0, music=None, **kwargs): 111 def wait(self, duration=0, music=None, **kwargs):
112 self.sleep_event = threading.Event() 112 self.sleep_event = threading.Event()
@@ -210,7 +210,7 @@ class Action:
210 message += "setting volume to {}%" \ 210 message += "setting volume to {}%" \
211 .format(value) 211 .format(value)
212 212
213 if music is not None and fade > 0: 213 if fade > 0:
214 message += " with {}s fade".format(fade) 214 message += " with {}s fade".format(fade)
215 215
216 return message 216 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
10from .music_file import * 10from .music_file import *
11from .mixer import Mixer 11from .mixer import Mixer
12from . import Config, gain, error_print 12from . import Config, gain, error_print
13from .music_effect import GainEffect
13 14
14class Mapping(RelativeLayout): 15class Mapping(RelativeLayout):
15 expected_keys = NumericProperty(0) 16 expected_keys = NumericProperty(0)
@@ -32,13 +33,22 @@ class Mapping(RelativeLayout):
32 def master_gain(self): 33 def master_gain(self):
33 return gain(self.master_volume) 34 return gain(self.master_volume)
34 35
35 def set_master_volume(self, value, delta=False): 36 def set_master_volume(self, value, delta=False, fade=0):
36 [db_gain, self.master_volume] = gain( 37 [db_gain, self.master_volume] = gain(
37 value + int(delta) * self.master_volume, 38 value + int(delta) * self.master_volume,
38 self.master_volume) 39 self.master_volume)
39 40
40 for music in self.open_files.values(): 41 for music in self.open_files.values():
41 music.set_gain(db_gain) 42 if fade > 0:
43 music.gain_effects.append(GainEffect(
44 "fade",
45 music.current_audio_segment,
46 music.current_loop,
47 music.sound_position,
48 music.sound_position + fade,
49 gain=db_gain))
50 else:
51 music.set_gain(db_gain)
42 52
43 def _keyboard_closed(self): 53 def _keyboard_closed(self):
44 self._keyboard.unbind(on_key_down=self._on_keyboard_down) 54 self._keyboard.unbind(on_key_down=self._on_keyboard_down)