diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2016-07-14 15:39:54 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2016-07-14 15:39:54 +0200 |
commit | 0deb82a57ae3abefd44509dc88c546f6e5a94d1b (patch) | |
tree | cf082f141a89425f9014eb5b203336e49f5c0252 /helpers/music_file.py | |
parent | ecaf3148af1d9adff1819f9536f483ebf7c85a95 (diff) | |
download | MusicSampler-0deb82a57ae3abefd44509dc88c546f6e5a94d1b.tar.gz MusicSampler-0deb82a57ae3abefd44509dc88c546f6e5a94d1b.tar.zst MusicSampler-0deb82a57ae3abefd44509dc88c546f6e5a94d1b.zip |
Make 'wait' action interruptible
Diffstat (limited to 'helpers/music_file.py')
-rw-r--r-- | helpers/music_file.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/helpers/music_file.py b/helpers/music_file.py index b40de1a..e6a340d 100644 --- a/helpers/music_file.py +++ b/helpers/music_file.py | |||
@@ -40,8 +40,8 @@ class MusicFile(Machine): | |||
40 | self.audio_segment = None | 40 | self.audio_segment = None |
41 | self.gain = gain | 41 | self.gain = gain |
42 | self.music_lock = Lock("music__" + filename) | 42 | self.music_lock = Lock("music__" + filename) |
43 | self.wait_event = threading.Event() | ||
43 | 44 | ||
44 | self.flag_paused = False | ||
45 | threading.Thread(name = "MSMusicLoad", target = self.load).start() | 45 | threading.Thread(name = "MSMusicLoad", target = self.load).start() |
46 | 46 | ||
47 | def on_enter_loading(self): | 47 | def on_enter_loading(self): |
@@ -109,6 +109,9 @@ class MusicFile(Machine): | |||
109 | if self.is_loaded_stopping(): | 109 | if self.is_loaded_stopping(): |
110 | self.stopped() | 110 | self.stopped() |
111 | 111 | ||
112 | def on_enter_loaded_stopped(self): | ||
113 | self.wait_event.set() | ||
114 | |||
112 | def play_callback(self, out_data, frame_count, time_info, status_flags): | 115 | def play_callback(self, out_data, frame_count, time_info, status_flags): |
113 | with self.music_lock: | 116 | with self.music_lock: |
114 | audio_segment = self.current_audio_segment.get_sample_slice_data( | 117 | audio_segment = self.current_audio_segment.get_sample_slice_data( |
@@ -147,8 +150,8 @@ class MusicFile(Machine): | |||
147 | return 20 * math.log10(max(volume, 0.0001) / 100) | 150 | return 20 * math.log10(max(volume, 0.0001) / 100) |
148 | 151 | ||
149 | def wait_end(self): | 152 | def wait_end(self): |
150 | # FIXME: todo | 153 | self.wait_event.clear() |
151 | pass | 154 | self.wait_event.wait() |
152 | 155 | ||
153 | # Add some more functions to AudioSegments | 156 | # Add some more functions to AudioSegments |
154 | def get_sample_slice_data(self, start_sample=0, end_sample=float('inf')): | 157 | def get_sample_slice_data(self, start_sample=0, end_sample=float('inf')): |