diff options
Diffstat (limited to 'music_sampler/actions')
-rw-r--r-- | music_sampler/actions/__init__.py | 3 | ||||
-rw-r--r-- | music_sampler/actions/pause_wait.py | 8 | ||||
-rw-r--r-- | music_sampler/actions/reset_wait.py | 8 | ||||
-rw-r--r-- | music_sampler/actions/unpause_wait.py | 8 | ||||
-rw-r--r-- | music_sampler/actions/wait.py | 54 |
5 files changed, 80 insertions, 1 deletions
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 @@ | |||
1 | from . import interrupt_wait | 1 | from . import interrupt_wait |
2 | from . import pause | 2 | from . import pause |
3 | from . import pause_wait | ||
3 | from . import play | 4 | from . import play |
5 | from . import reset_wait | ||
4 | from . import run_command | 6 | from . import run_command |
5 | from . import seek | 7 | from . import seek |
6 | from . import stop | 8 | from . import stop |
7 | from . import stop_all_actions | 9 | from . import stop_all_actions |
8 | from . import unpause | 10 | from . import unpause |
11 | from . import unpause_wait | ||
9 | from . import volume | 12 | from . import volume |
10 | from . import wait | 13 | from . 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 @@ | |||
1 | def run(action, wait_id=None, **kwargs): | ||
2 | action.mapping.pause_wait(wait_id) | ||
3 | |||
4 | def 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 @@ | |||
1 | def run(action, wait_id=None, **kwargs): | ||
2 | action.mapping.reset_wait(wait_id) | ||
3 | |||
4 | def 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 @@ | |||
1 | def run(action, wait_id=None, **kwargs): | ||
2 | action.mapping.unpause_wait(wait_id) | ||
3 | |||
4 | def 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 @@ | |||
1 | import threading | 1 | import threading |
2 | import time | ||
2 | 3 | ||
3 | def run(action, duration=0, music=None, set_wait_id=None, **kwargs): | 4 | def 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 | ||
17 | def description(action, duration=0, music=None, set_wait_id=None, **kwargs): | 25 | def 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 | ||
45 | def 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 | |||
61 | def 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 | |||
74 | def 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 | |||
37 | def interrupt(action, duration=0, music=None, **kwargs): | 89 | def 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() |