Debian Codegraph @

Resources/modules/Multiband/MultiBandBeatMaker.c5

raw
1 class Module(BaseModule):
2 """
3 "Multi-band algorithmic beatmaker"
4
5 Description
6
7 MultiBandBeatMaker uses four algorithmic beat generators to play
8 spectral separated chunks of a sound.
9
10 Sliders
11
12 # Frequency Splitter :
13 Split points for multi-band processing
14 # Num of Taps :
15 Number of taps in a measure
16 # Tempo :
17 Speed of taps
18 # Tap Length :
19 Length of taps
20 # Beat 1 Index :
21 Soundfile index of the first beat
22 # Beat 2 Index :
23 Soundfile index of the second beat
24 # Beat 3 Index :
25 Soundfile index of the third beat
26 # Beat 4 Index :
27 Soundfile index of the fourth beat
28 # Beat 1 Distribution :
29 Repartition of taps for the first beat (100% weak --> 100% down)
30 # Beat 2 Distribution :
31 Repartition of taps for the second beat (100% weak --> 100% down)
32 # Beat 3 Distribution :
33 Repartition of taps for the third beat (100% weak --> 100% down)
34 # Beat 4 Distribution :
35 Repartition of taps for the fourth beat (100% weak --> 100% down)
36 # Beat 1 Gain :
37 Gain of the first beat
38 # Beat 2 Gain :
39 Gain of the second beat
40 # Beat 3 Gain :
41 Gain of the third beat
42 # Beat 4 Gain :
43 Gain of the fourth beat
44 # Global Seed :
45 Seed value for the algorithmic beats, using the same seed with
46 the same distributions will yield the exact same beats
47
48 Graph Only
49
50 # Overall Amplitude :
51 The amplitude curve applied on the total duration of the performance
52 # Beat 1 ADSR :
53 Envelope of taps for the first beat in breakpoint fashion
54 # Beat 2 ADSR :
55 Envelope of taps for the second beat in breakpoint fashion
56 # Beat 3 ADSR :
57 Envelope of taps for the third beat in breakpoint fashion
58 # Beat 4 ADSR :
59 Envelope of taps for the fourth beat in breakpoint fashion
60
61 Popups & Toggles
62
63 # Polyphony per Voice :
64 The number of streams used for each voice's polpyhony. High values
65 allow more overlaps but are more CPU expensive, only available at
66 initialization time.
67
68 """
69 def __init__(self):
70 BaseModule.__init__(self)
71 self.snd = self.addFilein("snd")
72 self.last_we1 = self.last_we2 = self.last_we3 = self.last_we4 = self.last_taps = -1
73 self.rtempo = 1/(self.tempo/15)
74 self.setGlobalSeed(int(self.seed.get()))
75 POLY = self.poly_index + 1
76 self.beat1 = Beat(time=self.rtempo, taps=int(self.taps.get()), w1=80, w2=40, w3=20, poly=POLY).play()
77 self.beat2 = Beat(time=self.rtempo, taps=int(self.taps.get()), w1=50, w2=100, w3=50, poly=POLY).play()
78 self.beat3 = Beat(time=self.rtempo, taps=int(self.taps.get()), w1=30, w2=60, w3=70, poly=POLY).play()
79 self.beat4 = Beat(time=self.rtempo, taps=int(self.taps.get()), w1=15, w2=30, w3=90, poly=POLY).play()
80 self.tre1 = TrigEnv(input=self.beat1, table=self.adsr1, dur=self.tapsl, mul=self.beat1['amp'])
81 self.tre2 = TrigEnv(input=self.beat2, table=self.adsr2, dur=self.tapsl, mul=self.beat2['amp'])
82 self.tre3 = TrigEnv(input=self.beat3, table=self.adsr3, dur=self.tapsl, mul=self.beat3['amp'])
83 self.tre4 = TrigEnv(input=self.beat4, table=self.adsr4, dur=self.tapsl, mul=self.beat4['amp'])
84 self.linseg1 = TrigLinseg(input=self.beat1, list=[(0,self.bindex1.get()),(self.tapsl.get(),1/(self.snd.getDur(False)/self.tapsl.get())+self.bindex1.get())])
85 self.linseg2 = TrigLinseg(input=self.beat2, list=[(0,self.bindex2.get()),(self.tapsl.get(),(1/(self.snd.getDur(False)/self.tapsl.get()))+self.bindex2.get())])
86 self.linseg3 = TrigLinseg(input=self.beat3, list=[(0,self.bindex3.get()),(self.tapsl.get(),(1/(self.snd.getDur(False)/self.tapsl.get()))+self.bindex3.get())])
87 self.linseg4 = TrigLinseg(input=self.beat4, list=[(0,self.bindex4.get()),(self.tapsl.get(),(1/(self.snd.getDur(False)/self.tapsl.get()))+self.bindex4.get())])
88 self.trf1 = TrigFunc(self.linseg1['trig'], self.newseg1)
89 self.trf2 = TrigFunc(self.linseg2['trig'], self.newseg2)
90 self.trf3 = TrigFunc(self.linseg3['trig'], self.newseg3)
91 self.trf4 = TrigFunc(self.linseg4['trig'], self.newseg4)
92 self.again1 = DBToA(self.gain1)
93 self.again2 = DBToA(self.gain2)
94 self.again3 = DBToA(self.gain3)
95 self.again4 = DBToA(self.gain4)
96 self.pointer1 = ButLP(Pointer(table=self.snd, index=self.linseg1, mul=self.tre1*self.again1), freq=self.splitter[0])
97 self.pointer2 = ButHP(ButLP(Pointer(table=self.snd, index=self.linseg2, mul=self.tre2*self.again2), freq=self.splitter[1]), freq=self.splitter[0])
98 self.pointer3 = ButHP(ButLP(Pointer(table=self.snd, index=self.linseg3, mul=self.tre3*self.again3), freq=self.splitter[2]), freq=self.splitter[1])
99 self.pointer4 = ButHP(Pointer(table=self.snd, index=self.linseg4, mul=self.tre4*self.again4), freq=self.splitter[2])
100 self.out = Mix(self.pointer1+self.pointer2+self.pointer3+self.pointer4, voices=self.nchnls, mul=self.env)
101
102 self.trigend = TrigFunc(self.beat1["end"], self.newdist)
103
104
105 def seed_up(self, value):
106 self.setGlobalSeed(int(value))
107 self.beat1.new()
108 self.beat2.new()
109 self.beat3.new()
110
111 def newseg1(self):
112 self.linseg1.setList([(0,self.bindex1.get()),(self.tapsl.get(),1/(self.snd.getDur(False)/self.tapsl.get())+self.bindex1.get())])
113
114 def newseg2(self):
115 self.linseg2.setList([(0,self.bindex2.get()),(self.tapsl.get(),1/(self.snd.getDur(False)/self.tapsl.get())+self.bindex2.get())])
116
117 def newseg3(self):
118 self.linseg3.setList([(0,self.bindex3.get()),(self.tapsl.get(),1/(self.snd.getDur(False)/self.tapsl.get())+self.bindex3.get())])
119
120 def newseg4(self):
121 self.linseg4.setList([(0,self.bindex4.get()),(self.tapsl.get(),1/(self.snd.getDur(False)/self.tapsl.get())+self.bindex4.get())])
122
123 def newtaps(self, value):
124 self.beat1.setTaps(value)
125 self.beat2.setTaps(value)
126 self.beat3.setTaps(value)
127 self.beat4.setTaps(value)
128
129 def newdist1(self, value):
130 w1 = int(value)
131 if value <= 50:
132 w2 = int(value*2)
133 else:
134 w2 = int((100-value)*2)
135 w3 = int(100-value)
136
137 self.beat1.setW1(w1)
138 self.beat1.setW2(w2)
139 self.beat1.setW3(w3)
140
141 def newdist2(self, value):
142 w1 = int(value)
143 if value <= 50:
144 w2 = int(value*2)
145 else:
146 w2 = int((100-value)*2)
147 w3 = int(100-value)
148
149 self.beat2.setW1(w1)
150 self.beat2.setW2(w2)
151 self.beat2.setW3(w3)
152
153 def newdist3(self, value):
154 w1 = int(value)
155 if value <= 50:
156 w2 = int(value*2)
157 else:
158 w2 = int((100-value)*2)
159 w3 = int(100-value)
160
161 self.beat3.setW1(w1)
162 self.beat3.setW2(w2)
163 self.beat3.setW3(w3)
164
165 def newdist4(self, value):
166 w1 = int(value)
167 if value <= 50:
168 w2 = int(value*2)
169 else:
170 w2 = int((100-value)*2)
171 w3 = int(100-value)
172
173 self.beat4.setW1(w1)
174 self.beat4.setW2(w2)
175 self.beat4.setW3(w3)
176
177 def newdist(self):
178 taps = int(self.taps.get())
179 if taps != self.last_taps:
180 self.last_taps = taps
181 self.newtaps(taps)
182 value = int(self.we1.get())
183 if value != self.last_we1:
184 self.last_we1 = value
185 self.newdist1(value)
186 value = int(self.we2.get())
187 if value != self.last_we2:
188 self.last_we2 = value
189 self.newdist2(value)
190 value = int(self.we3.get())
191 if value != self.last_we3:
192 self.last_we3 = value
193 self.newdist3(value)
194 value = int(self.we4.get())
195 if value != self.last_we4:
196 self.last_we4 = value
197 self.newdist4(value)
198
199 Interface = [ cfilein(name="snd", label="Audio"),
200 cgraph(name="env", label="Overall Amplitude", func=[(0,1),(1,1)], col="blue"),
201 csplitter(name="splitter", label="Frequency Splitter", min=100, max=18000, init=[150, 500, 2000],
202 num_knobs=3, rel="log", unit="Hz", col="grey"),
203 cgraph(name="adsr1", label="Beat 1 ADSR", func=[(0,0),(0.04,1),(0.13,0.5),(0.8,0.5),(1,0)], table=True, col="purple1"),
204 cgraph(name="adsr2", label="Beat 2 ADSR", func=[(0,0),(0.03,1),(0.12,0.5),(0.7,0.45),(1,0)], table=True, col="red1"),
205 cgraph(name="adsr3", label="Beat 3 ADSR", func=[(0,0),(0.02,1),(0.11,0.5),(0.6,0.4),(1,0)], table=True, col="green1"),
206 cgraph(name="adsr4", label="Beat 4 ADSR", func=[(0,0),(0.01,1),(0.1,0.5),(0.5,0.35),(1,0)], table=True, col="blue1"),
207 cslider(name="taps", label="Num of Taps", min=1, max=64, init=16, res="int", rel="lin", unit="x", col="orange1"),
208 cslider(name="tempo", label="Tempo", min=20, max=240, gliss=0, init=120, rel="lin", unit="bpm", col="orange2"),
209 cslider(name="tapsl", label="Tap Length", min=0.1, max=1, init=0.1, rel="lin", unit="sec", col="orange3"),
210 cslider(name="bindex1", label="Beat 1 Index", min=0, max=1, init=0, rel="lin", unit="x", col="purple1",half=True),
211 cslider(name="bindex2", label="Beat 2 Index", min=0, max=1, init=0.4, rel="lin", unit="x", col="red1",half=True),
212 cslider(name="we1", label="Beat 1 Distribution", min=0, max=100, init=80, res="int", rel="lin", unit="%", col="purple2",half=True),
213 cslider(name="we2", label="Beat 2 Distribution", min=0, max=100, init=80, res="int", rel="lin", unit="%", col="red2",half=True),
214 cslider(name="gain1", label="Beat 1 Gain", min=-48, max=18, init=0, rel="lin", unit="dB", col="purple3",half=True),
215 cslider(name="gain2", label="Beat 2 Gain", min=-48, max=18, init=0, rel="lin", unit="dB", col="red3",half=True),
216 cslider(name="bindex3", label="Beat 3 Index", min=0, max=1, init=0.8, rel="lin", unit="x", col="green1",half=True),
217 cslider(name="bindex4", label="Beat 4 Index", min=0, max=1, init=0.9, rel="lin", unit="x", col="blue1",half=True),
218 cslider(name="we3", label="Beat 3 Distribution", min=0, max=100, init=30, rel="lin", res="int", unit="%", col="green2",half=True),
219 cslider(name="we4", label="Beat 4 Distribution", min=0, max=100, init=20, rel="lin", res="int", unit="%", col="blue2",half=True),
220 cslider(name="gain3", label="Beat 3 Gain", min=-48, max=18, init=0, rel="lin", unit="dB", col="green3",half=True),
221 cslider(name="gain4", label="Beat 4 Gain", min=-48, max=18, init=0, rel="lin", unit="dB", col="blue3",half=True),
222 cslider(name="seed", label="Global seed", min=0, max=5000, init=0, rel="lin", res="int", unit="x", up=True),
223 cpopup(name="poly", label = "Polyphony per Voice", init= "4", rate="i", col="grey", value=[str(i+1) for i in range(8)]),
224 ]
225