]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/commitdiff
Add load_all_musics flag and corresponding actions
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 19 Sep 2016 13:57:26 +0000 (15:57 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 19 Sep 2016 14:00:43 +0000 (16:00 +0200)
music_sampler/actions/__init__.py
music_sampler/actions/load_music.py [new file with mode: 0644]
music_sampler/actions/unload_music.py [new file with mode: 0644]
music_sampler/helpers.py

index 7c812cb7097d70e3d69ba2bf1831e52a5d48e090..e0671fe3498b97d1bb70905106501867ca82f4ad 100644 (file)
@@ -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 (file)
index 0000000..f3e02ba
--- /dev/null
@@ -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 (file)
index 0000000..b3de316
--- /dev/null
@@ -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"
index 9403875cbfe49a82b91ab5772b42f1452eb78b81..fbd338b6ecfb730a630254f89c3c2f060f1c782d 100644 (file)
@@ -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 :]