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