]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blobdiff - helpers/music_file.py
Cleanup Machine use
[perso/Immae/Projets/Python/MusicSampler.git] / helpers / music_file.py
index 5f4fe764469c0b660b00754c5485b8fdd2ec798f..017fc596e236e14c700bff5bb88c746e56d38372 100644 (file)
@@ -14,7 +14,7 @@ from .music_effect import GainEffect
 
 file_lock = Lock("file")
 
-class MusicFile(Machine):
+class MusicFile:
     def __init__(self, filename, mapping, name=None, gain=1):
         states = [
             'initial',
@@ -22,7 +22,13 @@ class MusicFile(Machine):
             'failed',
             {
                 'name': 'loaded',
-                'children': ['stopped', 'playing', 'paused', 'stopping']
+                'children': [
+                    'stopped',
+                    'playing',
+                    'paused',
+                    'stopping',
+                    'stopped'
+                ]
             }
         ]
         transitions = [
@@ -69,7 +75,7 @@ class MusicFile(Machine):
             }
         ]
 
-        Machine.__init__(self, states=states,
+        Machine(model=self, states=states,
                 transitions=transitions, initial='initial',
                 ignore_invalid_triggers=True)
 
@@ -259,7 +265,7 @@ class MusicFile(Machine):
         self.gain_effects = []
         self.set_gain(db_gain)
 
-    def stop(self, fade_out=0, wait=False):
+    def stop(self, fade_out=0, wait=False, set_wait_id=None):
         if self.is_loaded_playing():
             ms = int(self.sound_position * 1000)
             ms_fo = max(1, int(fade_out * 1000))
@@ -270,6 +276,8 @@ class MusicFile(Machine):
                 self.current_audio_segment = new_audio_segment
             self.stop_playing()
             if wait:
+                if set_wait_id is not None:
+                    self.mapping.add_wait_id(set_wait_id, self.wait_event)
                 self.wait_end()
         else:
             self.stop_playing()