From 6dc040edf2f31497d4492c159397c4634037be66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Mon, 19 Sep 2016 15:57:26 +0200 Subject: Add load_all_musics flag and corresponding actions --- music_sampler/actions/__init__.py | 2 ++ music_sampler/actions/load_music.py | 12 ++++++++++++ music_sampler/actions/unload_music.py | 10 ++++++++++ music_sampler/helpers.py | 8 ++++++++ 4 files changed, 32 insertions(+) create mode 100644 music_sampler/actions/load_music.py create mode 100644 music_sampler/actions/unload_music.py 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 @@ from . import interrupt_wait +from . import load_music from . import pause from . import pause_wait from . import play @@ -7,6 +8,7 @@ from . import run_command from . import seek from . import stop from . import stop_all_actions +from . import unload_music from . import unpause from . import unpause_wait 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 @@ +import threading + +def run(action, music=None, **kwargs): + for music in action.music_list(music): + if not music.is_loaded(allow_substates=True): + threading.Thread(name="MSMusicLoad", target=music.load).start() + +def description(action, music=None, **kwargs): + if music is not None: + return "load music « {} » to memory".format(music.name) + else: + 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 @@ +def run(action, music=None, **kwargs): + for music in action.music_list(music): + if music.is_unloadable(): + music.unload() + +def description(action, music=None, **kwargs): + if music is not None: + return "unload music « {} » from memory".format(music.name) + else: + 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 = { 'help_no': _("Don't show warning when focus is lost"), 'type': 'boolean' }, + 'load_all_musics': { + 'default': True, + 'help_yes': _("Load all the musics at launch time (default)"), + 'help_no': _("Don't load all the musics at launch time (use it if you \ + have memory problems)"), + 'type': 'boolean' + }, 'list_devices': { 'help': _("List available sound devices"), 'type': 'action' @@ -142,6 +149,7 @@ Configs_order = [ 'language', 'list_devices', 'device', + 'load_all_musics', ] def parse_args(): argv = sys.argv[1 :] -- cgit v1.2.3