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 ++++++++++ 3 files changed, 24 insertions(+) create mode 100644 music_sampler/actions/load_music.py create mode 100644 music_sampler/actions/unload_music.py (limited to 'music_sampler/actions') 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" -- cgit v1.2.3