diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2016-07-27 21:33:09 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2016-07-27 21:33:09 +0200 |
commit | 63ba5a8dc2aa4ec3e6f203b0ba4db249ecf0b00e (patch) | |
tree | f043ab215425aca3434bf178029dad9f9e62dbe9 /helpers/actions | |
parent | 35bde798b6cda13579337b0ec5a803fdd5eab19a (diff) | |
download | MusicSampler-63ba5a8dc2aa4ec3e6f203b0ba4db249ecf0b00e.tar.gz MusicSampler-63ba5a8dc2aa4ec3e6f203b0ba4db249ecf0b00e.tar.zst MusicSampler-63ba5a8dc2aa4ec3e6f203b0ba4db249ecf0b00e.zip |
Rename helpers to music_sampler
Diffstat (limited to 'helpers/actions')
-rw-r--r-- | helpers/actions/__init__.py | 10 | ||||
-rw-r--r-- | helpers/actions/interrupt_wait.py | 5 | ||||
-rw-r--r-- | helpers/actions/pause.py | 10 | ||||
-rw-r--r-- | helpers/actions/play.py | 44 | ||||
-rw-r--r-- | helpers/actions/run_command.py | 13 | ||||
-rw-r--r-- | helpers/actions/seek.py | 19 | ||||
-rw-r--r-- | helpers/actions/stop.py | 42 | ||||
-rw-r--r-- | helpers/actions/stop_all_actions.py | 14 | ||||
-rw-r--r-- | helpers/actions/unpause.py | 10 | ||||
-rw-r--r-- | helpers/actions/volume.py | 28 | ||||
-rw-r--r-- | helpers/actions/wait.py | 40 |
11 files changed, 0 insertions, 235 deletions
diff --git a/helpers/actions/__init__.py b/helpers/actions/__init__.py deleted file mode 100644 index 658cef0..0000000 --- a/helpers/actions/__init__.py +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | from . import interrupt_wait | ||
2 | from . import pause | ||
3 | from . import play | ||
4 | from . import run_command | ||
5 | from . import seek | ||
6 | from . import stop | ||
7 | from . import stop_all_actions | ||
8 | from . import unpause | ||
9 | from . import volume | ||
10 | from . import wait | ||
diff --git a/helpers/actions/interrupt_wait.py b/helpers/actions/interrupt_wait.py deleted file mode 100644 index 8f465f0..0000000 --- a/helpers/actions/interrupt_wait.py +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | def run(action, wait_id=None, **kwargs): | ||
2 | action.mapping.interrupt_wait(wait_id) | ||
3 | |||
4 | def description(action, wait_id=None, **kwargs): | ||
5 | return "interrupt wait with id {}".format(wait_id) | ||
diff --git a/helpers/actions/pause.py b/helpers/actions/pause.py deleted file mode 100644 index bb27734..0000000 --- a/helpers/actions/pause.py +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | def run(action, music=None, **kwargs): | ||
2 | for music in action.music_list(music): | ||
3 | if music.is_loaded_playing(): | ||
4 | music.pause() | ||
5 | |||
6 | def description(action, music=None, **kwargs): | ||
7 | if music is not None: | ||
8 | return "pausing « {} »".format(music.name) | ||
9 | else: | ||
10 | return "pausing all musics" | ||
diff --git a/helpers/actions/play.py b/helpers/actions/play.py deleted file mode 100644 index fdba95b..0000000 --- a/helpers/actions/play.py +++ /dev/null | |||
@@ -1,44 +0,0 @@ | |||
1 | def run(action, music=None, fade_in=0, start_at=0, | ||
2 | restart_if_running=False, volume=100, | ||
3 | loop=0, **kwargs): | ||
4 | for music in action.music_list(music): | ||
5 | if restart_if_running: | ||
6 | if music.is_in_use(): | ||
7 | music.stop() | ||
8 | music.play( | ||
9 | volume=volume, | ||
10 | fade_in=fade_in, | ||
11 | start_at=start_at, | ||
12 | loop=loop) | ||
13 | elif not music.is_in_use(): | ||
14 | music.play( | ||
15 | volume=volume, | ||
16 | fade_in=fade_in, | ||
17 | start_at=start_at, | ||
18 | loop=loop) | ||
19 | |||
20 | def description(action, music=None, fade_in=0, start_at=0, | ||
21 | restart_if_running=False, volume=100, loop=0, **kwargs): | ||
22 | message = "starting " | ||
23 | if music is not None: | ||
24 | message += "« {} »".format(music.name) | ||
25 | else: | ||
26 | message += "all musics" | ||
27 | |||
28 | if start_at != 0: | ||
29 | message += " at {}s".format(start_at) | ||
30 | |||
31 | if fade_in != 0: | ||
32 | message += " with {}s fade_in".format(fade_in) | ||
33 | |||
34 | message += " at volume {}%".format(volume) | ||
35 | |||
36 | if loop > 0: | ||
37 | message += " {} times".format(loop + 1) | ||
38 | elif loop < 0: | ||
39 | message += " in loop" | ||
40 | |||
41 | if restart_if_running: | ||
42 | message += " (restarting if already running)" | ||
43 | |||
44 | return message | ||
diff --git a/helpers/actions/run_command.py b/helpers/actions/run_command.py deleted file mode 100644 index 1e80c1e..0000000 --- a/helpers/actions/run_command.py +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | import shlex, subprocess | ||
2 | |||
3 | def run(action, command="", wait=False, **kwargs): | ||
4 | action.process = subprocess.Popen(command, shell=True) | ||
5 | if wait: | ||
6 | action.process.wait() | ||
7 | |||
8 | def description(action, command="", wait=False, **kwargs): | ||
9 | message = "running command {}".format(command) | ||
10 | if wait: | ||
11 | message += " (waiting for its execution to finish)" | ||
12 | |||
13 | return message | ||
diff --git a/helpers/actions/seek.py b/helpers/actions/seek.py deleted file mode 100644 index 467af7d..0000000 --- a/helpers/actions/seek.py +++ /dev/null | |||
@@ -1,19 +0,0 @@ | |||
1 | def run(action, music=None, value=0, delta=False, **kwargs): | ||
2 | for music in action.music_list(music): | ||
3 | music.seek(value=value, delta=delta) | ||
4 | |||
5 | def description(action, music=None, value=0, delta=False, **kwargs): | ||
6 | if delta: | ||
7 | if music is not None: | ||
8 | return "moving music « {} » by {:+d}s" \ | ||
9 | .format(music.name, value) | ||
10 | else: | ||
11 | return "moving all musics by {:+d}s" \ | ||
12 | .format(value) | ||
13 | else: | ||
14 | if music is not None: | ||
15 | return "moving music « {} » to position {}s" \ | ||
16 | .format(music.name, value) | ||
17 | else: | ||
18 | return "moving all musics to position {}s" \ | ||
19 | .format(value) | ||
diff --git a/helpers/actions/stop.py b/helpers/actions/stop.py deleted file mode 100644 index 88cc66d..0000000 --- a/helpers/actions/stop.py +++ /dev/null | |||
@@ -1,42 +0,0 @@ | |||
1 | def run(action, music=None, fade_out=0, wait=False, | ||
2 | set_wait_id=None, **kwargs): | ||
3 | previous = None | ||
4 | for music in action.music_list(music): | ||
5 | if music.is_loaded_paused() or music.is_loaded_playing(): | ||
6 | if previous is not None: | ||
7 | previous.stop(fade_out=fade_out) | ||
8 | previous = music | ||
9 | else: | ||
10 | music.stop(fade_out=fade_out) | ||
11 | |||
12 | if previous is not None: | ||
13 | action.waiting_music = previous | ||
14 | previous.stop( | ||
15 | fade_out=fade_out, | ||
16 | wait=wait, | ||
17 | set_wait_id=set_wait_id) | ||
18 | |||
19 | def description(action, music=None, fade_out=0, wait=False, | ||
20 | set_wait_id=None, **kwargs): | ||
21 | |||
22 | message = "stopping " | ||
23 | if music is not None: | ||
24 | message += "music « {} »".format(music.name) | ||
25 | else: | ||
26 | message += "all musics" | ||
27 | |||
28 | if fade_out > 0: | ||
29 | message += " with {}s fadeout".format(fade_out) | ||
30 | if wait: | ||
31 | if set_wait_id is not None: | ||
32 | message += " (waiting the end of fadeout, with id {})"\ | ||
33 | .format(set_wait_id) | ||
34 | else: | ||
35 | message += " (waiting the end of fadeout)" | ||
36 | |||
37 | return message | ||
38 | |||
39 | def interrupt(action, music=None, fade_out=0, wait=False, | ||
40 | set_wait_id=None, **kwargs): | ||
41 | if action.waiting_music is not None: | ||
42 | action.waiting_music.wait_event.set() | ||
diff --git a/helpers/actions/stop_all_actions.py b/helpers/actions/stop_all_actions.py deleted file mode 100644 index 4ea875a..0000000 --- a/helpers/actions/stop_all_actions.py +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | def run(action, key_start_time=0, other_only=False, **kwargs): | ||
2 | if other_only: | ||
3 | action.mapping.stop_all_running( | ||
4 | except_key=action.key, | ||
5 | key_start_time=key_start_time) | ||
6 | else: | ||
7 | action.mapping.stop_all_running() | ||
8 | |||
9 | def description(action, other_only=False, **kwargs): | ||
10 | message = "stopping all actions" | ||
11 | if other_only: | ||
12 | message += " except this key" | ||
13 | |||
14 | return message | ||
diff --git a/helpers/actions/unpause.py b/helpers/actions/unpause.py deleted file mode 100644 index 5fa88c3..0000000 --- a/helpers/actions/unpause.py +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | def run(action, music=None, **kwargs): | ||
2 | for music in action.music_list(music): | ||
3 | if music.is_loaded_paused(): | ||
4 | music.unpause() | ||
5 | |||
6 | def description(action, music=None, **kwargs): | ||
7 | if music is not None: | ||
8 | return "unpausing « {} »".format(music.name) | ||
9 | else: | ||
10 | return "unpausing all musics" | ||
diff --git a/helpers/actions/volume.py b/helpers/actions/volume.py deleted file mode 100644 index 7dda3c1..0000000 --- a/helpers/actions/volume.py +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
1 | def run(action, music=None, value=100, fade=0, delta=False, **kwargs): | ||
2 | if music is not None: | ||
3 | music.set_volume(value, delta=delta, fade=fade) | ||
4 | else: | ||
5 | action.mapping.set_master_volume(value, delta=delta, fade=fade) | ||
6 | |||
7 | def description(action, music=None, | ||
8 | value=100, delta=False, fade=0, **kwargs): | ||
9 | message = "" | ||
10 | if delta: | ||
11 | if music is not None: | ||
12 | message += "{:+d}% to volume of « {} »" \ | ||
13 | .format(value, music.name) | ||
14 | else: | ||
15 | message += "{:+d}% to volume" \ | ||
16 | .format(value) | ||
17 | else: | ||
18 | if music is not None: | ||
19 | message += "setting volume of « {} » to {}%" \ | ||
20 | .format(music.name, value) | ||
21 | else: | ||
22 | message += "setting volume to {}%" \ | ||
23 | .format(value) | ||
24 | |||
25 | if fade > 0: | ||
26 | message += " with {}s fade".format(fade) | ||
27 | |||
28 | return message | ||
diff --git a/helpers/actions/wait.py b/helpers/actions/wait.py deleted file mode 100644 index ea42408..0000000 --- a/helpers/actions/wait.py +++ /dev/null | |||
@@ -1,40 +0,0 @@ | |||
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() | ||