diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2016-06-18 23:45:19 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2016-06-18 23:45:19 +0200 |
commit | 0e5d59f77586134da457ed7a3c57fc99649be590 (patch) | |
tree | 214318f8ed6a75e71ab8c3af5e806849a0407f12 /helpers/action.py | |
parent | be27763f8be0f647cbe17ecee8c782901ce2cede (diff) | |
download | MusicSampler-0e5d59f77586134da457ed7a3c57fc99649be590.tar.gz MusicSampler-0e5d59f77586134da457ed7a3c57fc99649be590.tar.zst MusicSampler-0e5d59f77586134da457ed7a3c57fc99649be590.zip |
Add some actions
Diffstat (limited to 'helpers/action.py')
-rw-r--r-- | helpers/action.py | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/helpers/action.py b/helpers/action.py index a68de90..8a69fae 100644 --- a/helpers/action.py +++ b/helpers/action.py | |||
@@ -43,23 +43,37 @@ class Action: | |||
43 | def play(self, music = None, fade_in = 0, start_at = 0, | 43 | def play(self, music = None, fade_in = 0, start_at = 0, |
44 | restart_if_running = False, volume = 100, **kwargs): | 44 | restart_if_running = False, volume = 100, **kwargs): |
45 | if music is not None: | 45 | if music is not None: |
46 | music.play() | 46 | if restart_if_running: |
47 | if music.is_playing(): | ||
48 | music.stop() | ||
49 | music.play(volume = volume, fade_in = fade_in, start_at = start_at) | ||
50 | else: | ||
51 | if not music.is_playing(): | ||
52 | music.play(volume = volume, fade_in = fade_in, start_at = start_at) | ||
47 | else: | 53 | else: |
48 | pygame.mixer.unpause() | 54 | pygame.mixer.unpause() |
49 | 55 | ||
50 | def stop(self, music = None, fade_out = 0, **kwargs): | 56 | def stop(self, music = None, fade_out = 0, **kwargs): |
51 | if music is not None: | 57 | if music is not None: |
52 | music.stop() | 58 | music.stop(fade_out = fade_out) |
53 | else: | 59 | else: |
54 | pygame.mixer.stop() | 60 | if fade_out > 0: |
61 | pygame.fadeout(fade_out * 1000) | ||
62 | else: | ||
63 | pygame.mixer.stop() | ||
55 | 64 | ||
56 | def stop_all_actions(self, **kwargs): | 65 | def stop_all_actions(self, **kwargs): |
57 | self.key.mapping.stop_all_running() | 66 | self.key.mapping.stop_all_running() |
58 | 67 | ||
59 | def volume(self, music = None, value = 100, **kwargs): | 68 | def volume(self, music = None, value = 100, **kwargs): |
60 | pass | 69 | if music is not None: |
70 | music.set_volume(value) | ||
71 | else: | ||
72 | pass | ||
61 | 73 | ||
62 | def wait(self, duration = 0, **kwargs): | 74 | def wait(self, duration = 0, **kwargs): |
75 | # FIXME: Make it stoppable | ||
76 | # http://stackoverflow.com/questions/29082268/python-time-sleep-vs-event-wait | ||
63 | time.sleep(duration) | 77 | time.sleep(duration) |
64 | 78 | ||
65 | def command_print(self, command = "", **kwargs): | 79 | def command_print(self, command = "", **kwargs): |
@@ -104,10 +118,10 @@ class Action: | |||
104 | else: | 118 | else: |
105 | return "stopping all musics with {}s fadeout".format(fade_out) | 119 | return "stopping all musics with {}s fadeout".format(fade_out) |
106 | 120 | ||
107 | def stop_all_actions_print(self): | 121 | def stop_all_actions_print(self, **kwargs): |
108 | return "stopping all actions" | 122 | return "stopping all actions" |
109 | 123 | ||
110 | def volume_print(self, music = None, value = 100, *kwargs): | 124 | def volume_print(self, music = None, value = 100, **kwargs): |
111 | if music is not None: | 125 | if music is not None: |
112 | return "setting volume of {} to {}%".format(music.filename, value) | 126 | return "setting volume of {} to {}%".format(music.filename, value) |
113 | else: | 127 | else: |