]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blobdiff - helpers/music_file.py
Make 'wait' action interruptible
[perso/Immae/Projets/Python/MusicSampler.git] / helpers / music_file.py
index b40de1a2f9138a852376bfcc50c058b21af82766..e6a340da53e56c97dda679a14064f056e01fd670 100644 (file)
@@ -40,8 +40,8 @@ class MusicFile(Machine):
         self.audio_segment = None
         self.gain = gain
         self.music_lock = Lock("music__" + filename)
+        self.wait_event = threading.Event()
 
-        self.flag_paused = False
         threading.Thread(name = "MSMusicLoad", target = self.load).start()
 
     def on_enter_loading(self):
@@ -109,6 +109,9 @@ class MusicFile(Machine):
         if self.is_loaded_stopping():
             self.stopped()
 
+    def on_enter_loaded_stopped(self):
+        self.wait_event.set()
+
     def play_callback(self, out_data, frame_count, time_info, status_flags):
         with self.music_lock:
             audio_segment = self.current_audio_segment.get_sample_slice_data(
@@ -147,8 +150,8 @@ class MusicFile(Machine):
         return 20 * math.log10(max(volume, 0.0001) / 100)
 
     def wait_end(self):
-        # FIXME: todo
-        pass
+        self.wait_event.clear()
+        self.wait_event.wait()
 
 # Add some more functions to AudioSegments
 def get_sample_slice_data(self, start_sample=0, end_sample=float('inf')):