]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blob - music_sampler/actions/wait.py
ea424081f8c2d984e86b9e2b8b2171dd82ee5cc9
[perso/Immae/Projets/Python/MusicSampler.git] / music_sampler / actions / wait.py
1 import threading
2
3 def run(action, duration=0, music=None, set_wait_id=None, **kwargs):
4 if set_wait_id is not None:
5 action.mapping.add_wait_id(set_wait_id, action)
6
7 action.sleep_event = threading.Event()
8 action.sleep_event_timer = threading.Timer(
9 duration,
10 action.sleep_event.set)
11
12 if music is not None:
13 music.wait_end()
14
15 action.sleep_event_timer.start()
16 action.sleep_event.wait()
17
18 def description(action, duration=0, music=None, set_wait_id=None, **kwargs):
19 message = ""
20 if music is None:
21 message += "waiting {}s" \
22 .format(duration)
23 elif duration == 0:
24 message += "waiting the end of « {} »" \
25 .format(music.name)
26 else:
27 message += "waiting the end of « {} » + {}s" \
28 .format(music.name, duration)
29
30 if set_wait_id is not None:
31 message += " (setting id = {})".format(set_wait_id)
32
33 return message
34
35 def interrupt(action, duration=0, music=None, **kwargs):
36 if action.sleep_event is not None:
37 action.sleep_event.set()
38 action.sleep_event_timer.cancel()
39 if music is not None:
40 music.wait_event.set()