]>
git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blob - helpers/music_effect.py
ef8dc906025a61ea71a5a1a93540532cec666516
6 def __init__(self
, effect
, audio_segment
, start
, end
, **kwargs
):
7 if effect
in self
.effect_types
:
10 raise Exception("Unknown effect {}".format(effect
))
14 self
.audio_segment
= audio_segment
15 getattr(self
, self
.effect
+ "_init")(**kwargs
)
17 def get_last_gain(self
):
18 return getattr(self
, self
.effect
+ "_get_last_gain")()
20 def get_next_gain(self
, current_frame
, frame_count
):
21 # This returns two values:
22 # - The first one is the gain to apply on that frame
23 # - The last one is True or False depending on whether it is the last
24 # call to the function and the last gain should be saved permanently
25 return getattr(self
, self
.effect
+ "_get_next_gain")(
30 def fade_init(self
, gain
=0, **kwargs
):
31 self
.first_frame
= int(self
.audio_segment
.frame_rate
* self
.start
)
32 self
.last_frame
= int(self
.audio_segment
.frame_rate
* self
.end
)
35 def fade_get_last_gain(self
):
38 def fade_get_next_gain(self
, current_frame
, frame_count
):
39 if current_frame
>= self
.last_frame
:
40 return [self
.gain
, True]
41 elif current_frame
< self
.first_frame
:
45 (current_frame
- self
.first_frame
) / \
46 (self
.last_frame
- self
.first_frame
) * self
.gain
,