aboutsummaryrefslogtreecommitdiff
path: root/music_sampler
diff options
context:
space:
mode:
Diffstat (limited to 'music_sampler')
-rw-r--r--music_sampler/action.py18
-rw-r--r--music_sampler/actions/__init__.py3
-rw-r--r--music_sampler/actions/pause_wait.py8
-rw-r--r--music_sampler/actions/reset_wait.py8
-rw-r--r--music_sampler/actions/unpause_wait.py8
-rw-r--r--music_sampler/actions/wait.py54
-rw-r--r--music_sampler/locales/fr/LC_MESSAGES/music_sampler.po24
-rw-r--r--music_sampler/mapping.py33
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 @@
1from . import interrupt_wait 1from . import interrupt_wait
2from . import pause 2from . import pause
3from . import pause_wait
3from . import play 4from . import play
5from . import reset_wait
4from . import run_command 6from . import run_command
5from . import seek 7from . import seek
6from . import stop 8from . import stop
7from . import stop_all_actions 9from . import stop_all_actions
8from . import unpause 10from . import unpause
11from . import unpause_wait
9from . import volume 12from . import volume
10from . import wait 13from . 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 @@
1def run(action, wait_id=None, **kwargs):
2 action.mapping.pause_wait(wait_id)
3
4def 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 @@
1def run(action, wait_id=None, **kwargs):
2 action.mapping.reset_wait(wait_id)
3
4def 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 @@
1def run(action, wait_id=None, **kwargs):
2 action.mapping.unpause_wait(wait_id)
3
4def 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 @@
1import threading 1import threading
2import time
2 3
3def run(action, duration=0, music=None, set_wait_id=None, **kwargs): 4def 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
17def description(action, duration=0, music=None, set_wait_id=None, **kwargs): 25def 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
45def 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
61def 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
74def 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
37def interrupt(action, duration=0, music=None, **kwargs): 89def 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 « {} »"
103msgid "pausing all musics" 103msgid "pausing all musics"
104msgstr "mise en pause des musiques" 104msgstr "mise en pause des musiques"
105 105
106#: music_sampler/actions/pause_wait.py:5
107msgid "pause wait with id {}"
108msgstr "Mettre en pause l'attente d'identifiant {}"
109
110#: music_sampler/actions/pause_wait.py:5
111msgid "pause all waits"
112msgstr "Mettre en pause toutes les attentes"
113
106#: music_sampler/actions/play.py:50 114#: music_sampler/actions/play.py:50
107msgid "starting « {} » at volume {}%" 115msgid "starting « {} » at volume {}%"
108msgstr "lance « {} » au volume {}%" 116msgstr "lance « {} » au volume {}%"
@@ -295,6 +303,14 @@ msgstr "lance « {} » à {}s avec un fondu de {}s au volume {}% en boucle (re
295msgid "starting all musics at {}s with {}s fade_in at volume {}% in loop (restarting if already running)" 303msgid "starting all musics at {}s with {}s fade_in at volume {}% in loop (restarting if already running)"
296msgstr "lance toutes les musiques à {}s avec un fondu de {}s au volume {}% en boucle (redémarre si déjà lancée)" 304msgstr "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
307msgid "reset wait with id {}"
308msgstr "Réinitialise l'attente d'identifiant {}"
309
310#: music_sampler/actions/reset_wait.py:5
311msgid "reset all waits"
312msgstr "Réinitialise toutes les attentes"
313
298#: music_sampler/actions/run_command.py:15 314#: music_sampler/actions/run_command.py:15
299msgid "running command {}" 315msgid "running command {}"
300msgstr "lance la commande {}" 316msgstr "lance la commande {}"
@@ -367,6 +383,14 @@ msgstr "reprend « {} »"
367msgid "unpausing all musics" 383msgid "unpausing all musics"
368msgstr "reprend toutes les musiques" 384msgstr "reprend toutes les musiques"
369 385
386#: music_sampler/actions/unpause_wait.py:5
387msgid "unpause wait with id {}"
388msgstr "Reprendre l'attente d'identifiant {}"
389
390#: music_sampler/actions/unpause_wait.py:5
391msgid "unpause all waits"
392msgstr "Reprendre toutes les attentes"
393
370#: music_sampler/actions/volume.py:32 394#: music_sampler/actions/volume.py:32
371msgid "{:+d}% to volume of « {} »" 395msgid "{:+d}% to volume of « {} »"
372msgstr "{:+d}% sur le volume de « {} »" 396msgstr "{:+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))