X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=helpers%2Faction.py;h=28afceeb6e66c3cc193428e88c28e06959cca29d;hb=1b4b78f5b6df7182ac066fcc26a7b4f0e8586a47;hp=91456299ee25c6bf072c8cdba1ac796f2c99cbcd;hpb=71715c049145a074b0f2b8d90c8c8c47830323c3;p=perso%2FImmae%2FProjets%2FPython%2FMusicSampler.git 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: raise Exception("Unknown action {}".format(action)) self.key = key + self.mapping = key.parent self.arguments = kwargs self.sleep_event = None @@ -49,7 +50,7 @@ class Action: if music is not None: return [music] else: - return self.key.parent.open_files.values() + return self.mapping.open_files.values() def pause(self, music = None, **kwargs): for music in self.music_list(music): @@ -72,20 +73,25 @@ class Action: if not music.is_not_stopped(): music.play(volume = volume, fade_in = fade_in, start_at = start_at) - def stop(self, music = None, fade_out = 0, **kwargs): + def stop(self, music = None, fade_out = 0, wait = False, **kwargs): + previous = None for music in self.music_list(music): if music.is_loaded_paused() or music.is_loaded_playing(): - music.stop(fade_out = fade_out) + if previous is not None: + previous.stop(fade_out = fade_out) + previous = music + + if previous is not None: + previous.stop(fade_out = fade_out, wait = wait) def stop_all_actions(self, **kwargs): - self.key.parent.stop_all_running() + self.mapping.stop_all_running() - def volume(self, music = None, value = 100, **kwargs): + def volume(self, music = None, value = 100, add = False, **kwargs): if music is not None: - music.set_volume(value) + music.set_volume(value, add = add) else: - # FIXME: todo - pass + self.mapping.set_master_volume(value, add = add) def wait(self, duration = 0, music = None, **kwargs): self.sleep_event = threading.Event() @@ -133,26 +139,34 @@ class Action: return message - def stop_print(self, music = None, fade_out = 0, **kwargs): + def stop_print(self, music = None, fade_out = 0, wait = False, **kwargs): + message = "stopping " if music is not None: - if fade_out == 0: - return "stopping music « {} »".format(music.name) - else: - return "stopping music « {} » with {}s fadeout".format(music.name, fade_out) + message += "music « {} »".format(music.name) else: - if fade_out == 0: - return "stopping all musics" - else: - return "stopping all musics with {}s fadeout".format(fade_out) + message += "all musics" + + if fade_out > 0: + message += " with {}s fadeout".format(fade_out) + if wait: + message += " (waiting the end of fadeout)" + + return message def stop_all_actions_print(self, **kwargs): return "stopping all actions" - def volume_print(self, music = None, value = 100, **kwargs): - if music is not None: - return "setting volume of « {} » to {}%".format(music.name, value) + def volume_print(self, music = None, value = 100, add = False, **kwargs): + if add: + if music is not None: + return "{:+d}% to volume of « {} »".format(value, music.name) + else: + return "{:+d}% to volume".format(value) else: - return "setting volume to {}%".format(value) + if music is not None: + return "setting volume of « {} » to {}%".format(music.name, value) + else: + return "setting volume to {}%".format(value) def wait_print(self, duration = 0, music = None, **kwargs): if music is None: