diff options
Diffstat (limited to 'helpers')
-rw-r--r-- | helpers/music_effect.py | 3 | ||||
-rw-r--r-- | helpers/music_file.py | 29 |
2 files changed, 25 insertions, 7 deletions
diff --git a/helpers/music_effect.py b/helpers/music_effect.py index 23583cd..4bdbb26 100644 --- a/helpers/music_effect.py +++ b/helpers/music_effect.py | |||
@@ -3,7 +3,8 @@ class GainEffect: | |||
3 | 'fade' | 3 | 'fade' |
4 | ] | 4 | ] |
5 | 5 | ||
6 | def __init__(self, effect, audio_segment, initial_loop, start, end, **kwargs): | 6 | def __init__(self, effect, audio_segment, initial_loop, start, end, |
7 | **kwargs): | ||
7 | if effect in self.effect_types: | 8 | if effect in self.effect_types: |
8 | self.effect = effect | 9 | self.effect = effect |
9 | else: | 10 | else: |
diff --git a/helpers/music_file.py b/helpers/music_file.py index cff897a..aef0adc 100644 --- a/helpers/music_file.py +++ b/helpers/music_file.py | |||
@@ -125,6 +125,8 @@ class MusicFile(Machine): | |||
125 | return 0 | 125 | return 0 |
126 | 126 | ||
127 | def play(self, fade_in=0, volume=100, loop=0, start_at=0): | 127 | def play(self, fade_in=0, volume=100, loop=0, start_at=0): |
128 | # FIXME: create a "reinitialize" method | ||
129 | self.gain_effects = [] | ||
128 | self.set_gain(gain(volume) + self.mapping.master_gain, absolute=True) | 130 | self.set_gain(gain(volume) + self.mapping.master_gain, absolute=True) |
129 | self.volume = volume | 131 | self.volume = volume |
130 | self.current_loop = 0 | 132 | self.current_loop = 0 |
@@ -178,7 +180,7 @@ class MusicFile(Machine): | |||
178 | data += new_data | 180 | data += new_data |
179 | nb_frames += new_nb_frames | 181 | nb_frames += new_nb_frames |
180 | elif nb_frames == 0: | 182 | elif nb_frames == 0: |
181 | # FIXME: too slow | 183 | # FIXME: too slow when mixing multiple streams |
182 | threading.Thread( | 184 | threading.Thread( |
183 | name="MSFinishedCallback", | 185 | name="MSFinishedCallback", |
184 | target=self.finished_callback).start() | 186 | target=self.finished_callback).start() |
@@ -212,11 +214,26 @@ class MusicFile(Machine): | |||
212 | return | 214 | return |
213 | with self.music_lock: | 215 | with self.music_lock: |
214 | self.abandon_all_effects() | 216 | self.abandon_all_effects() |
215 | self.current_frame = max( | 217 | if delta: |
216 | 0, | 218 | frame_count = int(self.audio_segment.frame_count()) |
217 | int(delta) * self.current_frame | 219 | frame_diff = int(value * self.audio_segment.frame_rate) |
218 | + int(value * self.audio_segment.frame_rate)) | 220 | self.current_frame += frame_diff |
219 | # FIXME: si on fait un seek + delta, adapter le "loop" | 221 | while self.current_frame < 0: |
222 | self.current_loop -= 1 | ||
223 | self.current_frame += frame_count | ||
224 | while self.current_frame > frame_count: | ||
225 | self.current_loop += 1 | ||
226 | self.current_frame -= frame_count | ||
227 | if self.current_loop < 0: | ||
228 | self.current_loop = 0 | ||
229 | self.current_frame = 0 | ||
230 | if self.current_loop > self.last_loop: | ||
231 | self.current_loop = self.last_loop | ||
232 | self.current_frame = frame_count | ||
233 | else: | ||
234 | self.current_frame = max( | ||
235 | 0, | ||
236 | int(value * self.audio_segment.frame_rate)) | ||
220 | 237 | ||
221 | def effects_next_gain(self, frame_count): | 238 | def effects_next_gain(self, frame_count): |
222 | db_gain = 0 | 239 | db_gain = 0 |