diff options
Diffstat (limited to 'music_sampler')
-rw-r--r-- | music_sampler/action.py | 18 | ||||
-rw-r--r-- | music_sampler/actions/__init__.py | 3 | ||||
-rw-r--r-- | music_sampler/actions/pause_wait.py | 8 | ||||
-rw-r--r-- | music_sampler/actions/reset_wait.py | 8 | ||||
-rw-r--r-- | music_sampler/actions/unpause_wait.py | 8 | ||||
-rw-r--r-- | music_sampler/actions/wait.py | 54 | ||||
-rw-r--r-- | music_sampler/locales/fr/LC_MESSAGES/music_sampler.po | 24 | ||||
-rw-r--r-- | music_sampler/mapping.py | 33 |
8 files changed, 150 insertions, 6 deletions
diff --git a/music_sampler/action.py b/music_sampler/action.py index d269d0e..22a2bdc 100644 --- a/music_sampler/action.py +++ b/music_sampler/action.py | |||
@@ -98,6 +98,24 @@ class Action: | |||
98 | return getattr(getattr(actions, self.action), 'interrupt')( | 98 | return getattr(getattr(actions, self.action), 'interrupt')( |
99 | self, **self.arguments) | 99 | self, **self.arguments) |
100 | 100 | ||
101 | def pause(self): | ||
102 | if getattr(actions, self.action, None) and\ | ||
103 | hasattr(getattr(actions, self.action), 'pause'): | ||
104 | return getattr(getattr(actions, self.action), 'pause')( | ||
105 | self, **self.arguments) | ||
106 | |||
107 | def unpause(self): | ||
108 | if getattr(actions, self.action, None) and\ | ||
109 | hasattr(getattr(actions, self.action), 'unpause'): | ||
110 | return getattr(getattr(actions, self.action), 'unpause')( | ||
111 | self, **self.arguments) | ||
112 | |||
113 | def reset(self): | ||
114 | if getattr(actions, self.action, None) and\ | ||
115 | hasattr(getattr(actions, self.action), 'reset'): | ||
116 | return getattr(getattr(actions, self.action), 'reset')( | ||
117 | self, **self.arguments) | ||
118 | |||
101 | # Helpers | 119 | # Helpers |
102 | def music_list(self, music): | 120 | def music_list(self, music): |
103 | if music is not None: | 121 | if music is not None: |
diff --git a/music_sampler/actions/__init__.py b/music_sampler/actions/__init__.py index 658cef0..7c812cb 100644 --- a/music_sampler/actions/__init__.py +++ b/music_sampler/actions/__init__.py | |||
@@ -1,10 +1,13 @@ | |||
1 | from . import interrupt_wait | 1 | from . import interrupt_wait |
2 | from . import pause | 2 | from . import pause |
3 | from . import pause_wait | ||
3 | from . import play | 4 | from . import play |
5 | from . import reset_wait | ||
4 | from . import run_command | 6 | from . import run_command |
5 | from . import seek | 7 | from . import seek |
6 | from . import stop | 8 | from . import stop |
7 | from . import stop_all_actions | 9 | from . import stop_all_actions |
8 | from . import unpause | 10 | from . import unpause |
11 | from . import unpause_wait | ||
9 | from . import volume | 12 | from . import volume |
10 | from . import wait | 13 | from . import wait |
diff --git a/music_sampler/actions/pause_wait.py b/music_sampler/actions/pause_wait.py new file mode 100644 index 0000000..e4ab6ea --- /dev/null +++ b/music_sampler/actions/pause_wait.py | |||
@@ -0,0 +1,8 @@ | |||
1 | def run(action, wait_id=None, **kwargs): | ||
2 | action.mapping.pause_wait(wait_id) | ||
3 | |||
4 | def description(action, wait_id=None, **kwargs): | ||
5 | if wait_id is None: | ||
6 | return _("pause all waits") | ||
7 | else: | ||
8 | return _("pause wait with id {}").format(wait_id) | ||
diff --git a/music_sampler/actions/reset_wait.py b/music_sampler/actions/reset_wait.py new file mode 100644 index 0000000..500bcca --- /dev/null +++ b/music_sampler/actions/reset_wait.py | |||
@@ -0,0 +1,8 @@ | |||
1 | def run(action, wait_id=None, **kwargs): | ||
2 | action.mapping.reset_wait(wait_id) | ||
3 | |||
4 | def description(action, wait_id=None, **kwargs): | ||
5 | if wait_id is None: | ||
6 | return _("reset all waits") | ||
7 | else: | ||
8 | return _("reset wait with id {}").format(wait_id) | ||
diff --git a/music_sampler/actions/unpause_wait.py b/music_sampler/actions/unpause_wait.py new file mode 100644 index 0000000..25e9a11 --- /dev/null +++ b/music_sampler/actions/unpause_wait.py | |||
@@ -0,0 +1,8 @@ | |||
1 | def run(action, wait_id=None, **kwargs): | ||
2 | action.mapping.unpause_wait(wait_id) | ||
3 | |||
4 | def description(action, wait_id=None, **kwargs): | ||
5 | if wait_id is None: | ||
6 | return _("unpause all waits") | ||
7 | else: | ||
8 | return _("unpause wait with id {}").format(wait_id) | ||
diff --git a/music_sampler/actions/wait.py b/music_sampler/actions/wait.py index bcee649..31439b8 100644 --- a/music_sampler/actions/wait.py +++ b/music_sampler/actions/wait.py | |||
@@ -1,4 +1,5 @@ | |||
1 | import threading | 1 | import threading |
2 | import time | ||
2 | 3 | ||
3 | def run(action, duration=0, music=None, set_wait_id=None, **kwargs): | 4 | def run(action, duration=0, music=None, set_wait_id=None, **kwargs): |
4 | action.mapping.add_wait(action, wait_id=set_wait_id) | 5 | action.mapping.add_wait(action, wait_id=set_wait_id) |
@@ -8,10 +9,17 @@ def run(action, duration=0, music=None, set_wait_id=None, **kwargs): | |||
8 | duration, | 9 | duration, |
9 | action.sleep_event.set) | 10 | action.sleep_event.set) |
10 | 11 | ||
12 | action.sleep_event_initial_duration = duration | ||
13 | action.sleep_event_paused = False | ||
14 | action.sleep_event_left_time = duration | ||
15 | |||
11 | if music is not None: | 16 | if music is not None: |
12 | music.wait_end() | 17 | music.wait_end() |
13 | 18 | ||
14 | action.sleep_event_timer.start() | 19 | if duration <= 0 or not action.sleep_event_paused: |
20 | action.sleep_event_timer.start() | ||
21 | action.sleep_event_started_time = time.time() | ||
22 | |||
15 | action.sleep_event.wait() | 23 | action.sleep_event.wait() |
16 | 24 | ||
17 | def description(action, duration=0, music=None, set_wait_id=None, **kwargs): | 25 | def description(action, duration=0, music=None, set_wait_id=None, **kwargs): |
@@ -34,6 +42,50 @@ def description(action, duration=0, music=None, set_wait_id=None, **kwargs): | |||
34 | 42 | ||
35 | return _(message).format(*formats) | 43 | return _(message).format(*formats) |
36 | 44 | ||
45 | def pause(action, **kwargs): | ||
46 | if action.sleep_event_paused: | ||
47 | return | ||
48 | |||
49 | action.sleep_event_paused = True | ||
50 | |||
51 | if not action.sleep_event_timer.is_alive(): | ||
52 | return | ||
53 | |||
54 | action.sleep_event_timer.cancel() | ||
55 | |||
56 | action.sleep_event_left_time = action.sleep_event_left_time\ | ||
57 | - (time.time() - action.sleep_event_started_time) | ||
58 | if action.sleep_event_left_time < 0: | ||
59 | action.sleep_event.set() | ||
60 | |||
61 | def unpause(action, **kwargs): | ||
62 | if not action.sleep_event_paused: | ||
63 | return | ||
64 | |||
65 | action.sleep_event_paused = False | ||
66 | |||
67 | action.sleep_event_timer = threading.Timer( | ||
68 | action.sleep_event_left_time, | ||
69 | action.sleep_event.set) | ||
70 | |||
71 | action.sleep_event_timer.start() | ||
72 | action.sleep_event_started_time = time.time() | ||
73 | |||
74 | def reset(action, **kwargs): | ||
75 | action.sleep_event_timer.cancel() | ||
76 | |||
77 | action.sleep_event_left_time = action.sleep_event_initial_duration | ||
78 | |||
79 | if action.sleep_event_paused: | ||
80 | return | ||
81 | |||
82 | action.sleep_event_timer = threading.Timer( | ||
83 | action.sleep_event_left_time, | ||
84 | action.sleep_event.set) | ||
85 | |||
86 | action.sleep_event_timer.start() | ||
87 | action.sleep_event_started_time = time.time() | ||
88 | |||
37 | def interrupt(action, duration=0, music=None, **kwargs): | 89 | def interrupt(action, duration=0, music=None, **kwargs): |
38 | if action.sleep_event is not None: | 90 | if action.sleep_event is not None: |
39 | action.sleep_event.set() | 91 | action.sleep_event.set() |
diff --git a/music_sampler/locales/fr/LC_MESSAGES/music_sampler.po b/music_sampler/locales/fr/LC_MESSAGES/music_sampler.po index 888d7a5..af27ca9 100644 --- a/music_sampler/locales/fr/LC_MESSAGES/music_sampler.po +++ b/music_sampler/locales/fr/LC_MESSAGES/music_sampler.po | |||
@@ -103,6 +103,14 @@ msgstr "mise en pause de « {} »" | |||
103 | msgid "pausing all musics" | 103 | msgid "pausing all musics" |
104 | msgstr "mise en pause des musiques" | 104 | msgstr "mise en pause des musiques" |
105 | 105 | ||
106 | #: music_sampler/actions/pause_wait.py:5 | ||
107 | msgid "pause wait with id {}" | ||
108 | msgstr "Mettre en pause l'attente d'identifiant {}" | ||
109 | |||
110 | #: music_sampler/actions/pause_wait.py:5 | ||
111 | msgid "pause all waits" | ||
112 | msgstr "Mettre en pause toutes les attentes" | ||
113 | |||
106 | #: music_sampler/actions/play.py:50 | 114 | #: music_sampler/actions/play.py:50 |
107 | msgid "starting « {} » at volume {}%" | 115 | msgid "starting « {} » at volume {}%" |
108 | msgstr "lance « {} » au volume {}%" | 116 | msgstr "lance « {} » au volume {}%" |
@@ -295,6 +303,14 @@ msgstr "lance « {} » à {}s avec un fondu de {}s au volume {}% en boucle (re | |||
295 | msgid "starting all musics at {}s with {}s fade_in at volume {}% in loop (restarting if already running)" | 303 | msgid "starting all musics at {}s with {}s fade_in at volume {}% in loop (restarting if already running)" |
296 | msgstr "lance toutes les musiques à {}s avec un fondu de {}s au volume {}% en boucle (redémarre si déjà lancée)" | 304 | msgstr "lance toutes les musiques à {}s avec un fondu de {}s au volume {}% en boucle (redémarre si déjà lancée)" |
297 | 305 | ||
306 | #: music_sampler/actions/reset_wait.py:5 | ||
307 | msgid "reset wait with id {}" | ||
308 | msgstr "Réinitialise l'attente d'identifiant {}" | ||
309 | |||
310 | #: music_sampler/actions/reset_wait.py:5 | ||
311 | msgid "reset all waits" | ||
312 | msgstr "Réinitialise toutes les attentes" | ||
313 | |||
298 | #: music_sampler/actions/run_command.py:15 | 314 | #: music_sampler/actions/run_command.py:15 |
299 | msgid "running command {}" | 315 | msgid "running command {}" |
300 | msgstr "lance la commande {}" | 316 | msgstr "lance la commande {}" |
@@ -367,6 +383,14 @@ msgstr "reprend « {} »" | |||
367 | msgid "unpausing all musics" | 383 | msgid "unpausing all musics" |
368 | msgstr "reprend toutes les musiques" | 384 | msgstr "reprend toutes les musiques" |
369 | 385 | ||
386 | #: music_sampler/actions/unpause_wait.py:5 | ||
387 | msgid "unpause wait with id {}" | ||
388 | msgstr "Reprendre l'attente d'identifiant {}" | ||
389 | |||
390 | #: music_sampler/actions/unpause_wait.py:5 | ||
391 | msgid "unpause all waits" | ||
392 | msgstr "Reprendre toutes les attentes" | ||
393 | |||
370 | #: music_sampler/actions/volume.py:32 | 394 | #: music_sampler/actions/volume.py:32 |
371 | msgid "{:+d}% to volume of « {} »" | 395 | msgid "{:+d}% to volume of « {} »" |
372 | msgstr "{:+d}% sur le volume de « {} »" | 396 | msgstr "{:+d}% sur le volume de « {} »" |
diff --git a/music_sampler/mapping.py b/music_sampler/mapping.py index 99c9977..9e40d40 100644 --- a/music_sampler/mapping.py +++ b/music_sampler/mapping.py | |||
@@ -206,15 +206,17 @@ class Mapping(RelativeLayout): | |||
206 | self.wait_ids[None] = [] | 206 | self.wait_ids[None] = [] |
207 | self.wait_ids[None].append(action_or_wait) | 207 | self.wait_ids[None].append(action_or_wait) |
208 | 208 | ||
209 | def interrupt_wait(self, wait_id=None): | 209 | def matching_wait_ids(self, wait_id=None): |
210 | if wait_id is None: | 210 | if wait_id is None: |
211 | ids_to_interrupt = list(self.wait_ids.keys()) | 211 | matching_ids = list(self.wait_ids.keys()) |
212 | elif wait_id in self.wait_ids: | 212 | elif wait_id in self.wait_ids: |
213 | ids_to_interrupt = [wait_id] | 213 | matching_ids = [wait_id] |
214 | else: | 214 | else: |
215 | ids_to_interrupt = [] | 215 | matching_ids = [] |
216 | return matching_ids | ||
216 | 217 | ||
217 | for _wait_id in ids_to_interrupt: | 218 | def interrupt_wait(self, wait_id=None): |
219 | for _wait_id in self.matching_wait_ids(wait_id=wait_id): | ||
218 | action_or_waits = self.wait_ids[_wait_id] | 220 | action_or_waits = self.wait_ids[_wait_id] |
219 | del(self.wait_ids[_wait_id]) | 221 | del(self.wait_ids[_wait_id]) |
220 | for action_or_wait in action_or_waits: | 222 | for action_or_wait in action_or_waits: |
@@ -223,6 +225,27 @@ class Mapping(RelativeLayout): | |||
223 | else: | 225 | else: |
224 | action_or_wait.set() | 226 | action_or_wait.set() |
225 | 227 | ||
228 | def pause_wait(self, wait_id=None): | ||
229 | for _wait_id in self.matching_wait_ids(wait_id=wait_id): | ||
230 | action_or_waits = self.wait_ids[_wait_id] | ||
231 | for action_or_wait in action_or_waits: | ||
232 | if isinstance(action_or_wait, Action): | ||
233 | action_or_wait.pause() | ||
234 | |||
235 | def unpause_wait(self, wait_id=None): | ||
236 | for _wait_id in self.matching_wait_ids(wait_id=wait_id): | ||
237 | action_or_waits = self.wait_ids[_wait_id] | ||
238 | for action_or_wait in action_or_waits: | ||
239 | if isinstance(action_or_wait, Action): | ||
240 | action_or_wait.unpause() | ||
241 | |||
242 | def reset_wait(self, wait_id=None): | ||
243 | for _wait_id in self.matching_wait_ids(wait_id=wait_id): | ||
244 | action_or_waits = self.wait_ids[_wait_id] | ||
245 | for action_or_wait in action_or_waits: | ||
246 | if isinstance(action_or_wait, Action): | ||
247 | action_or_wait.reset() | ||
248 | |||
226 | # Methods to control running keys | 249 | # Methods to control running keys |
227 | def start_running(self, key, start_time): | 250 | def start_running(self, key, start_time): |
228 | self.running.append((key, start_time)) | 251 | self.running.append((key, start_time)) |