aboutsummaryrefslogtreecommitdiff
path: root/helpers/action.py
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-14 22:18:51 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-14 22:18:51 +0200
commit1b4b78f5b6df7182ac066fcc26a7b4f0e8586a47 (patch)
treeef2bddec7b9f09c614012ac6ee2588cd732242ee /helpers/action.py
parent71715c049145a074b0f2b8d90c8c8c47830323c3 (diff)
downloadMusicSampler-1b4b78f5b6df7182ac066fcc26a7b4f0e8586a47.tar.gz
MusicSampler-1b4b78f5b6df7182ac066fcc26a7b4f0e8586a47.tar.zst
MusicSampler-1b4b78f5b6df7182ac066fcc26a7b4f0e8586a47.zip
Some new features:
- gain function moved to helpers/__init__ - cleanup some unused functions - stop can now wait for fade_out to finish before returning - volume can be incremented - master volume
Diffstat (limited to 'helpers/action.py')
-rw-r--r--helpers/action.py56
1 files changed, 35 insertions, 21 deletions
diff --git a/helpers/action.py b/helpers/action.py
index 9145629..28afcee 100644
--- a/helpers/action.py
+++ b/helpers/action.py
@@ -20,6 +20,7 @@ class Action:
20 raise Exception("Unknown action {}".format(action)) 20 raise Exception("Unknown action {}".format(action))
21 21
22 self.key = key 22 self.key = key
23 self.mapping = key.parent
23 self.arguments = kwargs 24 self.arguments = kwargs
24 self.sleep_event = None 25 self.sleep_event = None
25 26
@@ -49,7 +50,7 @@ class Action:
49 if music is not None: 50 if music is not None:
50 return [music] 51 return [music]
51 else: 52 else:
52 return self.key.parent.open_files.values() 53 return self.mapping.open_files.values()
53 54
54 def pause(self, music = None, **kwargs): 55 def pause(self, music = None, **kwargs):
55 for music in self.music_list(music): 56 for music in self.music_list(music):
@@ -72,20 +73,25 @@ class Action:
72 if not music.is_not_stopped(): 73 if not music.is_not_stopped():
73 music.play(volume = volume, fade_in = fade_in, start_at = start_at) 74 music.play(volume = volume, fade_in = fade_in, start_at = start_at)
74 75
75 def stop(self, music = None, fade_out = 0, **kwargs): 76 def stop(self, music = None, fade_out = 0, wait = False, **kwargs):
77 previous = None
76 for music in self.music_list(music): 78 for music in self.music_list(music):
77 if music.is_loaded_paused() or music.is_loaded_playing(): 79 if music.is_loaded_paused() or music.is_loaded_playing():
78 music.stop(fade_out = fade_out) 80 if previous is not None:
81 previous.stop(fade_out = fade_out)
82 previous = music
83
84 if previous is not None:
85 previous.stop(fade_out = fade_out, wait = wait)
79 86
80 def stop_all_actions(self, **kwargs): 87 def stop_all_actions(self, **kwargs):
81 self.key.parent.stop_all_running() 88 self.mapping.stop_all_running()
82 89
83 def volume(self, music = None, value = 100, **kwargs): 90 def volume(self, music = None, value = 100, add = False, **kwargs):
84 if music is not None: 91 if music is not None:
85 music.set_volume(value) 92 music.set_volume(value, add = add)
86 else: 93 else:
87 # FIXME: todo 94 self.mapping.set_master_volume(value, add = add)
88 pass
89 95
90 def wait(self, duration = 0, music = None, **kwargs): 96 def wait(self, duration = 0, music = None, **kwargs):
91 self.sleep_event = threading.Event() 97 self.sleep_event = threading.Event()
@@ -133,26 +139,34 @@ class Action:
133 139
134 return message 140 return message
135 141
136 def stop_print(self, music = None, fade_out = 0, **kwargs): 142 def stop_print(self, music = None, fade_out = 0, wait = False, **kwargs):
143 message = "stopping "
137 if music is not None: 144 if music is not None:
138 if fade_out == 0: 145 message += "music « {} »".format(music.name)
139 return "stopping music « {} »".format(music.name)
140 else:
141 return "stopping music « {} » with {}s fadeout".format(music.name, fade_out)
142 else: 146 else:
143 if fade_out == 0: 147 message += "all musics"
144 return "stopping all musics" 148
145 else: 149 if fade_out > 0:
146 return "stopping all musics with {}s fadeout".format(fade_out) 150 message += " with {}s fadeout".format(fade_out)
151 if wait:
152 message += " (waiting the end of fadeout)"
153
154 return message
147 155
148 def stop_all_actions_print(self, **kwargs): 156 def stop_all_actions_print(self, **kwargs):
149 return "stopping all actions" 157 return "stopping all actions"
150 158
151 def volume_print(self, music = None, value = 100, **kwargs): 159 def volume_print(self, music = None, value = 100, add = False, **kwargs):
152 if music is not None: 160 if add:
153 return "setting volume of « {} » to {}%".format(music.name, value) 161 if music is not None:
162 return "{:+d}% to volume of « {} »".format(value, music.name)
163 else:
164 return "{:+d}% to volume".format(value)
154 else: 165 else:
155 return "setting volume to {}%".format(value) 166 if music is not None:
167 return "setting volume of « {} » to {}%".format(music.name, value)
168 else:
169 return "setting volume to {}%".format(value)
156 170
157 def wait_print(self, duration = 0, music = None, **kwargs): 171 def wait_print(self, duration = 0, music = None, **kwargs):
158 if music is None: 172 if music is None: