]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blobdiff - helpers/music_file.py
Add cleanup when stopping music
[perso/Immae/Projets/Python/MusicSampler.git] / helpers / music_file.py
index aeba1b9912fd9d2aa74da3fddd8683fc9e21fb12..9976306bcd254436f4dc030c5c51408de377b0ae 100644 (file)
@@ -48,7 +48,10 @@ class MusicFile:
         {
             'trigger': 'start_playing',
             'source': 'loaded',
-            'dest': 'loaded_playing'
+            'dest': 'loaded_playing',
+            # if a child has no transitions, then it is bubbled to the parent,
+            # and we don't want that. Not useful in that machine precisely.
+            'conditions': ['is_loaded']
         },
         {
             'trigger': 'pause',
@@ -112,6 +115,9 @@ class MusicFile:
                 debug_print("Loaded « {} »".format(self.name))
 
     def on_enter_loaded(self):
+        self.cleanup()
+
+    def cleanup(self):
         self.gain_effects = []
         self.set_gain(0, absolute=True)
         self.current_audio_segment = None
@@ -133,6 +139,7 @@ class MusicFile:
     def trigger_stopped_events(self):
         self.mixer.remove_file(self)
         self.wait_event.set()
+        self.cleanup()
 
     # Actions and properties called externally
     @property
@@ -235,13 +242,14 @@ class MusicFile:
 
     # Let other subscribe for an event when they are ready
     def subscribe_loaded(self, callback):
-        with file_lock:
-            if self.is_loaded(allow_substates=True):
-                callback(True)
-            elif self.is_failed():
-                callback(False)
-            else:
-                self.loaded_callbacks.append(callback)
+        # FIXME: should lock to be sure we have no race, but it makes the
+        # initialization screen not showing until everything is loaded
+        if self.is_loaded(allow_substates=True):
+            callback(True)
+        elif self.is_failed():
+            callback(False)
+        else:
+            self.loaded_callbacks.append(callback)
 
     def poll_loaded(self):
         for callback in self.loaded_callbacks: