From 1e44fe7e6c1464b49582a163615e8cb3ed279d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Wed, 20 Jul 2016 22:31:17 +0200 Subject: Remove a_s_with_effect in profit to GainEffect Use loop number in the effect --- helpers/music_effect.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'helpers/music_effect.py') diff --git a/helpers/music_effect.py b/helpers/music_effect.py index ef8dc90..23583cd 100644 --- a/helpers/music_effect.py +++ b/helpers/music_effect.py @@ -3,7 +3,7 @@ class GainEffect: 'fade' ] - def __init__(self, effect, audio_segment, start, end, **kwargs): + def __init__(self, effect, audio_segment, initial_loop, start, end, **kwargs): if effect in self.effect_types: self.effect = effect else: @@ -12,30 +12,41 @@ class GainEffect: self.start = start self.end = end self.audio_segment = audio_segment + self.initial_loop = initial_loop getattr(self, self.effect + "_init")(**kwargs) def get_last_gain(self): return getattr(self, self.effect + "_get_last_gain")() - def get_next_gain(self, current_frame, frame_count): + def get_next_gain(self, current_frame, current_loop, frame_count): # This returns two values: # - The first one is the gain to apply on that frame # - The last one is True or False depending on whether it is the last # call to the function and the last gain should be saved permanently return getattr(self, self.effect + "_get_next_gain")( current_frame, + current_loop, frame_count) # Fading def fade_init(self, gain=0, **kwargs): - self.first_frame = int(self.audio_segment.frame_rate * self.start) - self.last_frame = int(self.audio_segment.frame_rate * self.end) + self.audio_segment_frame_count = self.audio_segment.frame_count() + self.first_frame = int( + self.audio_segment_frame_count * self.initial_loop +\ + self.audio_segment.frame_rate * self.start) + self.last_frame = int( + self.audio_segment_frame_count * self.initial_loop +\ + self.audio_segment.frame_rate * self.end) self.gain= gain def fade_get_last_gain(self): return self.gain - def fade_get_next_gain(self, current_frame, frame_count): + def fade_get_next_gain(self, current_frame, current_loop, frame_count): + current_frame = current_frame \ + + (current_loop - self.initial_loop) \ + * self.audio_segment_frame_count + if current_frame >= self.last_frame: return [self.gain, True] elif current_frame < self.first_frame: -- cgit v1.2.3