]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blobdiff - helpers/mapping.py
Use machine for key handling
[perso/Immae/Projets/Python/MusicSampler.git] / helpers / mapping.py
index d60e709bde0a80e96be783131d5ad4b847be6faa..ba2c3401cb3966278c6fd07e9093f5a8c23e980d 100644 (file)
@@ -7,10 +7,9 @@ import threading
 import yaml
 import sys
 
-from .music_file import *
+from .music_file import MusicFile
 from .mixer import Mixer
 from . import Config, gain, error_print
-from .music_effect import GainEffect
 from .action import Action
 
 class Mapping(RelativeLayout):
@@ -47,19 +46,7 @@ class Mapping(RelativeLayout):
                 self.master_volume)
 
         for music in self.open_files.values():
-            if not (music.is_loaded_playing() or music.is_loaded_paused()):
-                continue
-
-            if fade > 0:
-                music.gain_effects.append(GainEffect(
-                    "fade",
-                    music.current_audio_segment,
-                    music.current_loop,
-                    music.sound_position,
-                    music.sound_position + fade,
-                    gain=db_gain))
-            else:
-                music.set_gain(db_gain)
+            music.set_gain_with_effect(db_gain, fade=fade)
 
     def add_wait_id(self, wait_id, action_or_wait):
         self.wait_ids[wait_id] = action_or_wait
@@ -80,7 +67,7 @@ class Mapping(RelativeLayout):
     def _on_keyboard_down(self, keyboard, keycode, text, modifiers):
         key = self.find_by_key_code(keycode)
         if len(modifiers) == 0 and key is not None:
-            threading.Thread(name="MSKeyAction", target=key.do_actions).start()
+            threading.Thread(name="MSKeyAction", target=key.run).start()
         elif 'ctrl' in modifiers and (keycode[0] == 113 or keycode[0] == '99'):
             for thread in threading.enumerate():
                 if thread.getName()[0:2] != "MS":
@@ -99,7 +86,7 @@ class Mapping(RelativeLayout):
         for key in self.children:
             if not type(key).__name__ == "Key":
                 continue
-            if not key.is_key_ready:
+            if not key.is_loaded_or_failed():
                 return True
         self.ready_color = [0, 1, 0, 1]
         return False
@@ -108,7 +95,7 @@ class Mapping(RelativeLayout):
         running = self.running
         self.running = []
         for (key, start_time) in running:
-            key.interrupt_action()
+            key.interrupt()
 
     def start_running(self, key, start_time):
         self.running.append((key, start_time))
@@ -191,8 +178,8 @@ class Mapping(RelativeLayout):
                                         **config['music_properties'][filename])
                             else:
                                 seen_files[filename] = MusicFile(
-                                        self,
-                                        filename)
+                                        filename,
+                                        self)
 
                         if filename not in key_properties[mapped_key]['files']:
                             key_properties[mapped_key]['files'] \