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
action. When false, it is thus useless to add actions after that one.
- `interrupt_wait`: stop a wait event (normal `wait` or fade out wait). The keys
that were waiting will move to the next actions. Parameters:
- * `wait_id: name` : gives the id of the `wait` to interrupt (defined with
- `set_wait_id`, see actions `wait` and `stop`). To interrupt several waits,
- use the same action several times.
+ * `wait_id: name` (optional) gives the id of the `wait` to interrupt (defined with
+ `set_wait_id`, see actions `wait` and `stop`). If not given, interrupts
+ all wait events.
- `run_command` : Run a command. Parameters:
* `command: my_command` : Gives the command to run.
* `wait: true/false` (optional, default false) if true, waits for the
suite de celle-ci puisqu'elles seront systématiquement interrompues.
- `interrupt_wait`: interrompt l'attente (de `wait` ou fin d'un fondu avec
attente) et passe directement à l'action suivante. Paramètre :
- * `wait_id: name` : précise l'identifiant du `wait` à stopper (défini par
- `set_wait_id`, voir les actions `wait` et `stop`). Pour interrompre
- plusieurs `wait` d'un seul coup, il faut mettre plusieurs
- `interrupt_wait`.
+ * `wait_id: name` (facultatif) précise l'identifiant du `wait` à stopper
+ (défini par `set_wait_id`, voir les actions `wait` et `stop`). Si absent,
+ interrompt toutes les attentes.
- `run_command` : lance une commande. Paramètres :
* `command: my_command` : précise la commande à lancer.
* `wait: true/false` (facultatif, défaut : false) : si `wait` est true,
action.mapping.interrupt_wait(wait_id)
def description(action, wait_id=None, **kwargs):
- return _("interrupt wait with id {}").format(wait_id)
+ if wait_id is None:
+ return _("interrupt all waits")
+ else:
+ return _("interrupt wait with id {}").format(wait_id)
import threading
def run(action, duration=0, music=None, set_wait_id=None, **kwargs):
- if set_wait_id is not None:
- action.mapping.add_wait_id(set_wait_id, action)
+ action.mapping.add_wait(action, wait_id=set_wait_id)
action.sleep_event = threading.Event()
action.sleep_event_timer = threading.Timer(
msgid "interrupt wait with id {}"
msgstr "Interrompre l'attente d'identifiant {}"
+#: music_sampler/actions/interrupt_wait.py:5
+msgid "interrupt all waits"
+msgstr "Interrompre toutes les attentes"
+
#: music_sampler/actions/pause.py:8
msgid "pausing « {} »"
msgstr "mise en pause de « {} »"
music.set_gain_with_effect(db_gain, fade=fade)
# Wait handler methods
- def add_wait_id(self, wait_id, action_or_wait):
- self.wait_ids[wait_id] = action_or_wait
-
- def interrupt_wait(self, wait_id):
- if wait_id in self.wait_ids:
- action_or_wait = self.wait_ids[wait_id]
- del(self.wait_ids[wait_id])
- if isinstance(action_or_wait, Action):
- action_or_wait.interrupt()
- else:
- action_or_wait.set()
+ def add_wait(self, action_or_wait, wait_id=None):
+ if wait_id is not None:
+ self.wait_ids[wait_id] = [action_or_wait]
+ else:
+ if None not in self.wait_ids:
+ self.wait_ids[None] = []
+ self.wait_ids[None].append(action_or_wait)
+
+ def interrupt_wait(self, wait_id=None):
+ if wait_id is None:
+ ids_to_interrupt = list(self.wait_ids.keys())
+ elif wait_id in self.wait_ids:
+ ids_to_interrupt = [wait_id]
+ else:
+ ids_to_interrupt = []
+
+ for _wait_id in ids_to_interrupt:
+ action_or_waits = self.wait_ids[_wait_id]
+ del(self.wait_ids[_wait_id])
+ for action_or_wait in action_or_waits:
+ if isinstance(action_or_wait, Action):
+ action_or_wait.interrupt()
+ else:
+ action_or_wait.set()
# Methods to control running keys
def start_running(self, key, start_time):
self.current_audio_segment = new_audio_segment
self.stop_playing()
if wait:
- if set_wait_id is not None:
- self.mapping.add_wait_id(set_wait_id, self.wait_event)
+ self.mapping.add_wait(self.wait_event, wait_id=set_wait_id)
self.wait_end()
else:
self.stopped()