aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2016-08-12 14:51:32 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2016-08-12 14:51:32 +0200
commit21ffec315b8fa8a6b46351021da915236148a7b1 (patch)
tree52951646c8f9d1ea453c58aa37c92e64ff0dd9a1
parent4094ae4ebff7997e8c5e0fd84a1434b1b86632b1 (diff)
downloadMusicSampler-21ffec315b8fa8a6b46351021da915236148a7b1.tar.gz
MusicSampler-21ffec315b8fa8a6b46351021da915236148a7b1.tar.zst
MusicSampler-21ffec315b8fa8a6b46351021da915236148a7b1.zip
Make 'interrupt_wait' able to interrupt all waits
If 'wait_id' is not specified, interrupt_wait will now stop all wait events. This fixes https://git.immae.eu/mantisbt/view.php?id=4
-rw-r--r--documentation_en.md6
-rw-r--r--documentation_fr.md7
-rw-r--r--music_sampler/actions/interrupt_wait.py5
-rw-r--r--music_sampler/actions/wait.py3
-rw-r--r--music_sampler/locales/fr/LC_MESSAGES/music_sampler.po4
-rw-r--r--music_sampler/mapping.py35
-rw-r--r--music_sampler/music_file.py3
7 files changed, 40 insertions, 23 deletions
diff --git a/documentation_en.md b/documentation_en.md
index d65e7ad..899ef1a 100644
--- a/documentation_en.md
+++ b/documentation_en.md
@@ -386,9 +386,9 @@ actions.
386 action. When false, it is thus useless to add actions after that one. 386 action. When false, it is thus useless to add actions after that one.
387- `interrupt_wait`: stop a wait event (normal `wait` or fade out wait). The keys 387- `interrupt_wait`: stop a wait event (normal `wait` or fade out wait). The keys
388 that were waiting will move to the next actions. Parameters: 388 that were waiting will move to the next actions. Parameters:
389 * `wait_id: name` : gives the id of the `wait` to interrupt (defined with 389 * `wait_id: name` (optional) gives the id of the `wait` to interrupt (defined with
390 `set_wait_id`, see actions `wait` and `stop`). To interrupt several waits, 390 `set_wait_id`, see actions `wait` and `stop`). If not given, interrupts
391 use the same action several times. 391 all wait events.
392- `run_command` : Run a command. Parameters: 392- `run_command` : Run a command. Parameters:
393 * `command: my_command` : Gives the command to run. 393 * `command: my_command` : Gives the command to run.
394 * `wait: true/false` (optional, default false) if true, waits for the 394 * `wait: true/false` (optional, default false) if true, waits for the
diff --git a/documentation_fr.md b/documentation_fr.md
index 64e3a4f..ff3cfe8 100644
--- a/documentation_fr.md
+++ b/documentation_fr.md
@@ -432,10 +432,9 @@ successivement mais sans attendre (donc presque simultanément) : ne pas hésite
432 suite de celle-ci puisqu'elles seront systématiquement interrompues. 432 suite de celle-ci puisqu'elles seront systématiquement interrompues.
433- `interrupt_wait`: interrompt l'attente (de `wait` ou fin d'un fondu avec 433- `interrupt_wait`: interrompt l'attente (de `wait` ou fin d'un fondu avec
434 attente) et passe directement à l'action suivante. Paramètre : 434 attente) et passe directement à l'action suivante. Paramètre :
435 * `wait_id: name` : précise l'identifiant du `wait` à stopper (défini par 435 * `wait_id: name` (facultatif) précise l'identifiant du `wait` à stopper
436 `set_wait_id`, voir les actions `wait` et `stop`). Pour interrompre 436 (défini par `set_wait_id`, voir les actions `wait` et `stop`). Si absent,
437 plusieurs `wait` d'un seul coup, il faut mettre plusieurs 437 interrompt toutes les attentes.
438 `interrupt_wait`.
439- `run_command` : lance une commande. Paramètres : 438- `run_command` : lance une commande. Paramètres :
440 * `command: my_command` : précise la commande à lancer. 439 * `command: my_command` : précise la commande à lancer.
441 * `wait: true/false` (facultatif, défaut : false) : si `wait` est true, 440 * `wait: true/false` (facultatif, défaut : false) : si `wait` est true,
diff --git a/music_sampler/actions/interrupt_wait.py b/music_sampler/actions/interrupt_wait.py
index f85a3c4..b367628 100644
--- a/music_sampler/actions/interrupt_wait.py
+++ b/music_sampler/actions/interrupt_wait.py
@@ -2,4 +2,7 @@ def run(action, wait_id=None, **kwargs):
2 action.mapping.interrupt_wait(wait_id) 2 action.mapping.interrupt_wait(wait_id)
3 3
4def description(action, wait_id=None, **kwargs): 4def description(action, wait_id=None, **kwargs):
5 return _("interrupt wait with id {}").format(wait_id) 5 if wait_id is None:
6 return _("interrupt all waits")
7 else:
8 return _("interrupt wait with id {}").format(wait_id)
diff --git a/music_sampler/actions/wait.py b/music_sampler/actions/wait.py
index e6d07f2..bcee649 100644
--- a/music_sampler/actions/wait.py
+++ b/music_sampler/actions/wait.py
@@ -1,8 +1,7 @@
1import threading 1import threading
2 2
3def run(action, duration=0, music=None, set_wait_id=None, **kwargs): 3def run(action, duration=0, music=None, set_wait_id=None, **kwargs):
4 if set_wait_id is not None: 4 action.mapping.add_wait(action, wait_id=set_wait_id)
5 action.mapping.add_wait_id(set_wait_id, action)
6 5
7 action.sleep_event = threading.Event() 6 action.sleep_event = threading.Event()
8 action.sleep_event_timer = threading.Timer( 7 action.sleep_event_timer = threading.Timer(
diff --git a/music_sampler/locales/fr/LC_MESSAGES/music_sampler.po b/music_sampler/locales/fr/LC_MESSAGES/music_sampler.po
index f603a3d..888d7a5 100644
--- a/music_sampler/locales/fr/LC_MESSAGES/music_sampler.po
+++ b/music_sampler/locales/fr/LC_MESSAGES/music_sampler.po
@@ -91,6 +91,10 @@ msgstr "L'argument '-V' ne peut être utilisé que dans la version compilée"
91msgid "interrupt wait with id {}" 91msgid "interrupt wait with id {}"
92msgstr "Interrompre l'attente d'identifiant {}" 92msgstr "Interrompre l'attente d'identifiant {}"
93 93
94#: music_sampler/actions/interrupt_wait.py:5
95msgid "interrupt all waits"
96msgstr "Interrompre toutes les attentes"
97
94#: music_sampler/actions/pause.py:8 98#: music_sampler/actions/pause.py:8
95msgid "pausing « {} »" 99msgid "pausing « {} »"
96msgstr "mise en pause de « {} »" 100msgstr "mise en pause de « {} »"
diff --git a/music_sampler/mapping.py b/music_sampler/mapping.py
index 50b68a9..a04c2f6 100644
--- a/music_sampler/mapping.py
+++ b/music_sampler/mapping.py
@@ -197,17 +197,30 @@ class Mapping(RelativeLayout):
197 music.set_gain_with_effect(db_gain, fade=fade) 197 music.set_gain_with_effect(db_gain, fade=fade)
198 198
199 # Wait handler methods 199 # Wait handler methods
200 def add_wait_id(self, wait_id, action_or_wait): 200 def add_wait(self, action_or_wait, wait_id=None):
201 self.wait_ids[wait_id] = action_or_wait 201 if wait_id is not None:
202 202 self.wait_ids[wait_id] = [action_or_wait]
203 def interrupt_wait(self, wait_id): 203 else:
204 if wait_id in self.wait_ids: 204 if None not in self.wait_ids:
205 action_or_wait = self.wait_ids[wait_id] 205 self.wait_ids[None] = []
206 del(self.wait_ids[wait_id]) 206 self.wait_ids[None].append(action_or_wait)
207 if isinstance(action_or_wait, Action): 207
208 action_or_wait.interrupt() 208 def interrupt_wait(self, wait_id=None):
209 else: 209 if wait_id is None:
210 action_or_wait.set() 210 ids_to_interrupt = list(self.wait_ids.keys())
211 elif wait_id in self.wait_ids:
212 ids_to_interrupt = [wait_id]
213 else:
214 ids_to_interrupt = []
215
216 for _wait_id in ids_to_interrupt:
217 action_or_waits = self.wait_ids[_wait_id]
218 del(self.wait_ids[_wait_id])
219 for action_or_wait in action_or_waits:
220 if isinstance(action_or_wait, Action):
221 action_or_wait.interrupt()
222 else:
223 action_or_wait.set()
211 224
212 # Methods to control running keys 225 # Methods to control running keys
213 def start_running(self, key, start_time): 226 def start_running(self, key, start_time):
diff --git a/music_sampler/music_file.py b/music_sampler/music_file.py
index fa6293d..4ba65e3 100644
--- a/music_sampler/music_file.py
+++ b/music_sampler/music_file.py
@@ -241,8 +241,7 @@ class MusicFile:
241 self.current_audio_segment = new_audio_segment 241 self.current_audio_segment = new_audio_segment
242 self.stop_playing() 242 self.stop_playing()
243 if wait: 243 if wait:
244 if set_wait_id is not None: 244 self.mapping.add_wait(self.wait_event, wait_id=set_wait_id)
245 self.mapping.add_wait_id(set_wait_id, self.wait_event)
246 self.wait_end() 245 self.wait_end()
247 else: 246 else:
248 self.stopped() 247 self.stopped()