]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blame - music_sampler/actions/wait.py
Rename helpers to music_sampler
[perso/Immae/Projets/Python/MusicSampler.git] / music_sampler / actions / wait.py
CommitLineData
c4f4f2a1
IB
1import threading
2
3def 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()
6c42e32d
IB
8 action.sleep_event_timer = threading.Timer(
9 duration,
10 action.sleep_event.set)
c4f4f2a1
IB
11
12 if music is not None:
13 music.wait_end()
14
15 action.sleep_event_timer.start()
16 action.sleep_event.wait()
17
18def 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
35def 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()