aboutsummaryrefslogtreecommitdiff
path: root/helpers/music_effect.py
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-27 21:33:09 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-27 21:33:09 +0200
commit63ba5a8dc2aa4ec3e6f203b0ba4db249ecf0b00e (patch)
treef043ab215425aca3434bf178029dad9f9e62dbe9 /helpers/music_effect.py
parent35bde798b6cda13579337b0ec5a803fdd5eab19a (diff)
downloadMusicSampler-63ba5a8dc2aa4ec3e6f203b0ba4db249ecf0b00e.tar.gz
MusicSampler-63ba5a8dc2aa4ec3e6f203b0ba4db249ecf0b00e.tar.zst
MusicSampler-63ba5a8dc2aa4ec3e6f203b0ba4db249ecf0b00e.zip
Rename helpers to music_sampler
Diffstat (limited to 'helpers/music_effect.py')
-rw-r--r--helpers/music_effect.py62
1 files changed, 0 insertions, 62 deletions
diff --git a/helpers/music_effect.py b/helpers/music_effect.py
deleted file mode 100644
index 4bdbb26..0000000
--- a/helpers/music_effect.py
+++ /dev/null
@@ -1,62 +0,0 @@
1class GainEffect:
2 effect_types = [
3 'fade'
4 ]
5
6 def __init__(self, effect, audio_segment, initial_loop, start, end,
7 **kwargs):
8 if effect in self.effect_types:
9 self.effect = effect
10 else:
11 raise Exception("Unknown effect {}".format(effect))
12
13 self.start = start
14 self.end = end
15 self.audio_segment = audio_segment
16 self.initial_loop = initial_loop
17 getattr(self, self.effect + "_init")(**kwargs)
18
19 def get_last_gain(self):
20 return getattr(self, self.effect + "_get_last_gain")()
21
22 def get_next_gain(self, current_frame, current_loop, frame_count):
23 # This returns two values:
24 # - The first one is the gain to apply on that frame
25 # - The last one is True or False depending on whether it is the last
26 # call to the function and the last gain should be saved permanently
27 return getattr(self, self.effect + "_get_next_gain")(
28 current_frame,
29 current_loop,
30 frame_count)
31
32 # Fading
33 def fade_init(self, gain=0, **kwargs):
34 self.audio_segment_frame_count = self.audio_segment.frame_count()
35 self.first_frame = int(
36 self.audio_segment_frame_count * self.initial_loop +\
37 self.audio_segment.frame_rate * self.start)
38 self.last_frame = int(
39 self.audio_segment_frame_count * self.initial_loop +\
40 self.audio_segment.frame_rate * self.end)
41 self.gain= gain
42
43 def fade_get_last_gain(self):
44 return self.gain
45
46 def fade_get_next_gain(self, current_frame, current_loop, frame_count):
47 current_frame = current_frame \
48 + (current_loop - self.initial_loop) \
49 * self.audio_segment_frame_count
50
51 if current_frame >= self.last_frame:
52 return [self.gain, True]
53 elif current_frame < self.first_frame:
54 return [0, False]
55 else:
56 return [
57 (current_frame - self.first_frame) / \
58 (self.last_frame - self.first_frame) * self.gain,
59 False
60 ]
61
62