return 0
def play(self, fade_in=0, volume=100, loop=0, start_at=0):
+ # FIXME: create a "reinitialize" method
+ self.gain_effects = []
self.set_gain(gain(volume) + self.mapping.master_gain, absolute=True)
self.volume = volume
self.current_loop = 0
- self.loop_left = loop
+ if loop < 0:
+ self.last_loop = float('inf')
+ else:
+ self.last_loop = loop
with self.music_lock:
self.current_audio_segment = self.audio_segment
with self.music_lock:
[data, nb_frames] = self.get_next_sample(frame_count)
if nb_frames < frame_count:
- if self.is_loaded_playing() and self.loop_left != 0:
- self.loop_left -= 1
+ if self.is_loaded_playing() and\
+ self.current_loop < self.last_loop:
self.current_loop += 1
self.current_frame = 0
[new_data, new_nb_frames] = self.get_next_sample(
data += new_data
nb_frames += new_nb_frames
elif nb_frames == 0:
- # FIXME: too slow
+ # FIXME: too slow when mixing multiple streams
threading.Thread(
name="MSFinishedCallback",
target=self.finished_callback).start()
return
with self.music_lock:
self.abandon_all_effects()
- self.current_frame = max(
- 0,
- int(delta) * self.current_frame
- + int(value * self.audio_segment.frame_rate))
- # FIXME: si on fait un seek + delta, adapter le "loop"
+ if delta:
+ frame_count = int(self.audio_segment.frame_count())
+ frame_diff = int(value * self.audio_segment.frame_rate)
+ self.current_frame += frame_diff
+ while self.current_frame < 0:
+ self.current_loop -= 1
+ self.current_frame += frame_count
+ while self.current_frame > frame_count:
+ self.current_loop += 1
+ self.current_frame -= frame_count
+ if self.current_loop < 0:
+ self.current_loop = 0
+ self.current_frame = 0
+ if self.current_loop > self.last_loop:
+ self.current_loop = self.last_loop
+ self.current_frame = frame_count
+ else:
+ self.current_frame = max(
+ 0,
+ int(value * self.audio_segment.frame_rate))
def effects_next_gain(self, frame_count):
db_gain = 0