diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2016-09-19 15:57:26 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2016-09-19 16:00:43 +0200 |
commit | 6dc040edf2f31497d4492c159397c4634037be66 (patch) | |
tree | 93da3ca7f67fc3012e3793870c6f6a9b4e96220c /music_sampler | |
parent | a9324e30da6292f53f008f1b827779c7f8e2fcdf (diff) | |
download | MusicSampler-6dc040edf2f31497d4492c159397c4634037be66.tar.gz MusicSampler-6dc040edf2f31497d4492c159397c4634037be66.tar.zst MusicSampler-6dc040edf2f31497d4492c159397c4634037be66.zip |
Add load_all_musics flag and corresponding actions
Diffstat (limited to 'music_sampler')
-rw-r--r-- | music_sampler/actions/__init__.py | 2 | ||||
-rw-r--r-- | music_sampler/actions/load_music.py | 12 | ||||
-rw-r--r-- | music_sampler/actions/unload_music.py | 10 | ||||
-rw-r--r-- | music_sampler/helpers.py | 8 |
4 files changed, 32 insertions, 0 deletions
diff --git a/music_sampler/actions/__init__.py b/music_sampler/actions/__init__.py index 7c812cb..e0671fe 100644 --- a/music_sampler/actions/__init__.py +++ b/music_sampler/actions/__init__.py | |||
@@ -1,4 +1,5 @@ | |||
1 | from . import interrupt_wait | 1 | from . import interrupt_wait |
2 | from . import load_music | ||
2 | from . import pause | 3 | from . import pause |
3 | from . import pause_wait | 4 | from . import pause_wait |
4 | from . import play | 5 | from . import play |
@@ -7,6 +8,7 @@ from . import run_command | |||
7 | from . import seek | 8 | from . import seek |
8 | from . import stop | 9 | from . import stop |
9 | from . import stop_all_actions | 10 | from . import stop_all_actions |
11 | from . import unload_music | ||
10 | from . import unpause | 12 | from . import unpause |
11 | from . import unpause_wait | 13 | from . import unpause_wait |
12 | from . import volume | 14 | from . import volume |
diff --git a/music_sampler/actions/load_music.py b/music_sampler/actions/load_music.py new file mode 100644 index 0000000..f3e02ba --- /dev/null +++ b/music_sampler/actions/load_music.py | |||
@@ -0,0 +1,12 @@ | |||
1 | import threading | ||
2 | |||
3 | def run(action, music=None, **kwargs): | ||
4 | for music in action.music_list(music): | ||
5 | if not music.is_loaded(allow_substates=True): | ||
6 | threading.Thread(name="MSMusicLoad", target=music.load).start() | ||
7 | |||
8 | def description(action, music=None, **kwargs): | ||
9 | if music is not None: | ||
10 | return "load music « {} » to memory".format(music.name) | ||
11 | else: | ||
12 | return "load all music to memory" | ||
diff --git a/music_sampler/actions/unload_music.py b/music_sampler/actions/unload_music.py new file mode 100644 index 0000000..b3de316 --- /dev/null +++ b/music_sampler/actions/unload_music.py | |||
@@ -0,0 +1,10 @@ | |||
1 | def run(action, music=None, **kwargs): | ||
2 | for music in action.music_list(music): | ||
3 | if music.is_unloadable(): | ||
4 | music.unload() | ||
5 | |||
6 | def description(action, music=None, **kwargs): | ||
7 | if music is not None: | ||
8 | return "unload music « {} » from memory".format(music.name) | ||
9 | else: | ||
10 | return "unload all music from memory" | ||
diff --git a/music_sampler/helpers.py b/music_sampler/helpers.py index 9403875..fbd338b 100644 --- a/music_sampler/helpers.py +++ b/music_sampler/helpers.py | |||
@@ -124,6 +124,13 @@ Configs = { | |||
124 | 'help_no': _("Don't show warning when focus is lost"), | 124 | 'help_no': _("Don't show warning when focus is lost"), |
125 | 'type': 'boolean' | 125 | 'type': 'boolean' |
126 | }, | 126 | }, |
127 | 'load_all_musics': { | ||
128 | 'default': True, | ||
129 | 'help_yes': _("Load all the musics at launch time (default)"), | ||
130 | 'help_no': _("Don't load all the musics at launch time (use it if you \ | ||
131 | have memory problems)"), | ||
132 | 'type': 'boolean' | ||
133 | }, | ||
127 | 'list_devices': { | 134 | 'list_devices': { |
128 | 'help': _("List available sound devices"), | 135 | 'help': _("List available sound devices"), |
129 | 'type': 'action' | 136 | 'type': 'action' |
@@ -142,6 +149,7 @@ Configs_order = [ | |||
142 | 'language', | 149 | 'language', |
143 | 'list_devices', | 150 | 'list_devices', |
144 | 'device', | 151 | 'device', |
152 | 'load_all_musics', | ||
145 | ] | 153 | ] |
146 | def parse_args(): | 154 | def parse_args(): |
147 | argv = sys.argv[1 :] | 155 | argv = sys.argv[1 :] |