Debian Codegraph @

Resources/modules/Time/BeatMaker.c5

raw
1 class Module(BaseModule):
2 """
3 "Algorithmic beat maker module"
4
5 Description
6
7 Four voices beat generator where sounds are extracted from a soundfile.
8
9 Sliders
10
11 # Num of Taps :
12 Number of taps in a measure
13 # Tempo :
14 Speed of taps in BPM (ref. to quarter note)
15 # Beat 1 Tap Length :
16 Length of taps of the first beat, in seconds
17 # Beat 1 Index :
18 Soundfile index of the first beat
19 # Beat 1 Gain :
20 Gain of the first beat
21 # Beat 1 Distribution :
22 Repartition of taps for the first beat (100% weak <--> 100% down)
23 # Beat 2 Tap Length :
24 Length of taps of the second beat, in seconds
25 # Beat 2 Index :
26 Soundfile index of the second beat
27 # Beat 2 Gain :
28 Gain of the second beat
29 # Beat 2 Distribution :
30 Repartition of taps for the second beat (100% weak <--> 100% down)
31 # Beat 3 Tap Length :
32 Length of taps of the third beat, in seconds
33 # Beat 3 Index :
34 Soundfile index of the third beat
35 # Beat 3 Gain :
36 Gain of the third beat
37 # Beat 3 Distribution :
38 Repartition of taps for the third beat (100% weak <--> 100% down)
39 # Beat 4 Tap Length :
40 Length of taps of the fourth beat, in seconds
41 # Beat 4 Index :
42 Soundfile index of the fourth beat
43 # Beat 4 Gain :
44 Gain of the fourth beat
45 # Beat 4 Distribution :
46 Repartition of taps for the fourth beat (100% weak <--> 100% down)
47 # Global Seed :
48 Seed value for the algorithmic beats, using the same seed with
49 the same distributions will yield the exact same beats.
50
51 Graph Only
52
53 # Beat 1 ADSR :
54 Envelope of taps for the first beat in breakpoint fashion
55 # Beat 2 ADSR :
56 Envelope of taps for the second beat in breakpoint fashion
57 # Beat 3 ADSR :
58 Envelope of taps for the third beat in breakpoint fashion
59 # Beat 4 ADSR :
60 Envelope of taps for the fourth beat in breakpoint fashion
61 # Overall Amplitude :
62 The amplitude curve applied on the total duration of the performance
63
64 """
65 def __init__(self):
66 BaseModule.__init__(self)
67 self.snd = self.addFilein("snd")
68 self.last_we1 =self.last_we2 = self.last_we3 = self.last_we4 = self.last_taps = -1
69 self.rtempo = 1/(self.tempo/15)
70 self.setGlobalSeed(int(self.seed.get()))
71 w1, w2, w3 = self.newdist1(int(self.we1.get()))
72 self.beat1 = Beat(time=self.rtempo, taps=int(self.taps.get()), w1=w1, w2=w2, w3=w3, poly=10).play()
73 w1, w2, w3 = self.newdist2(int(self.we2.get()))
74 self.beat2 = Beat(time=self.rtempo, taps=int(self.taps.get()), w1=w1, w2=w2, w3=w3, poly=10).play()
75 w1, w2, w3 = self.newdist3(int(self.we3.get()))
76 self.beat3 = Beat(time=self.rtempo, taps=int(self.taps.get()), w1=w1, w2=w2, w3=w3, poly=10).play()
77 w1, w2, w3 = self.newdist4(int(self.we4.get()))
78 self.beat4 = Beat(time=self.rtempo, taps=int(self.taps.get()), w1=w1, w2=w2, w3=w3, poly=10).play()
79 self.tre1 = TrigEnv(input=self.beat1, table=self.adsr1, dur=self.tapsl1, mul=self.beat1['amp'])
80 self.tre2 = TrigEnv(input=self.beat2, table=self.adsr2, dur=self.tapsl2, mul=self.beat2['amp'])
81 self.tre3 = TrigEnv(input=self.beat3, table=self.adsr3, dur=self.tapsl3, mul=self.beat3['amp'])
82 self.tre4 = TrigEnv(input=self.beat4, table=self.adsr4, dur=self.tapsl4, mul=self.beat4['amp'])
83 self.linseg1 = TrigLinseg(input=self.beat1, list=[(0,self.bindex1.get()),(self.tapsl1.get(),1/(self.snd.getDur(False)/self.tapsl1.get())+self.bindex1.get())])
84 self.linseg2 = TrigLinseg(input=self.beat2, list=[(0,self.bindex2.get()),(self.tapsl2.get(),(1/(self.snd.getDur(False)/self.tapsl2.get()))+self.bindex2.get())])
85 self.linseg3 = TrigLinseg(input=self.beat3, list=[(0,self.bindex3.get()),(self.tapsl3.get(),(1/(self.snd.getDur(False)/self.tapsl3.get()))+self.bindex3.get())])
86 self.linseg4 = TrigLinseg(input=self.beat4, list=[(0,self.bindex4.get()),(self.tapsl4.get(),(1/(self.snd.getDur(False)/self.tapsl4.get()))+self.bindex4.get())])
87 self.trf1 = TrigFunc(self.linseg1['trig'], self.newseg1)
88 self.trf2 = TrigFunc(self.linseg2['trig'], self.newseg2)
89 self.trf3 = TrigFunc(self.linseg3['trig'], self.newseg3)
90 self.trf4 = TrigFunc(self.linseg4['trig'], self.newseg4)
91 self.again1 = DBToA(self.gain1, mul=0.7)
92 self.again2 = DBToA(self.gain2, mul=0.7)
93 self.again3 = DBToA(self.gain3, mul=0.7)
94 self.again4 = DBToA(self.gain4, mul=0.7)
95 self.pointer1 = Pointer(table=self.snd, index=self.linseg1, mul=self.tre1*self.again1)
96 self.pointer2 = Pointer(table=self.snd, index=self.linseg2, mul=self.tre2*self.again2)
97 self.pointer3 = Pointer(table=self.snd, index=self.linseg3, mul=self.tre3*self.again3)
98 self.pointer4 = Pointer(table=self.snd, index=self.linseg4, mul=self.tre4*self.again4)
99 self.mixx = self.pointer1+self.pointer2+self.pointer3+self.pointer4
100 self.out = Sig(self.mixx, mul=self.env).mix(self.nchnls)
101
102 self.trigend = TrigFunc(self.beat1["end"], self.newdist)
103
104 def seed_up(self, value):
105 self.setGlobalSeed(int(value))
106 self.beat1.new()
107 self.beat2.new()
108 self.beat3.new()
109 self.beat4.new()
110
111 def newseg1(self):
112 self.linseg1.setList([(0,self.bindex1.get()),(self.tapsl1.get(),1/(self.snd.getDur(False)/self.tapsl1.get())+self.bindex1.get())])
113
114 def newseg2(self):
115 self.linseg2.setList([(0,self.bindex2.get()),(self.tapsl2.get(),1/(self.snd.getDur(False)/self.tapsl2.get())+self.bindex2.get())])
116
117 def newseg3(self):
118 self.linseg3.setList([(0,self.bindex3.get()),(self.tapsl3.get(),1/(self.snd.getDur(False)/self.tapsl3.get())+self.bindex3.get())])
119
120 def newseg4(self):
121 self.linseg4.setList([(0,self.bindex4.get()),(self.tapsl4.get(),1/(self.snd.getDur(False)/self.tapsl4.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 = value
131 if value <= 50:
132 w2 = value*2
133 else:
134 w2 = (100-value)*2
135 w3 = 100-value
136 return (w1, w2, w3)
137
138 def newdist2(self, value):
139 w1 = value
140 if value <= 50:
141 w2 = value*2
142 else:
143 w2 = (100-value)*2
144 w3 = 100-value
145 return (w1, w2, w3)
146
147 def newdist3(self, value):
148 w1 = value
149 if value <= 50:
150 w2 = value*2
151 else:
152 w2 = (100-value)*2
153 w3 = 100-value
154 return (w1, w2, w3)
155
156 def newdist4(self, value):
157 w1 = value
158 if value <= 50:
159 w2 = value*2
160 else:
161 w2 = (100-value)*2
162 w3 = 100-value
163 return (w1, w2, w3)
164
165 def newdist(self):
166 taps = int(self.taps.get())
167 if taps != self.last_taps:
168 self.last_taps = taps
169 self.newtaps(taps)
170 value = int(self.we1.get())
171 if value != self.last_we1:
172 self.last_we1 = value
173 self.beat1.setWeights(*self.newdist1(value))
174 value = int(self.we2.get())
175 if value != self.last_we2:
176 self.last_we2 = value
177 self.beat2.setWeights(*self.newdist2(value))
178 value = int(self.we3.get())
179 if value != self.last_we3:
180 self.last_we3 = value
181 self.beat3.setWeights(*self.newdist3(value))
182 value = int(self.we4.get())
183 if value != self.last_we4:
184 self.last_we4 = value
185 self.beat4.setWeights(*self.newdist4(value))
186
187 Interface = [ cfilein(name="snd", label="Audio"),
188 cgraph(name="env", label="Overall Amplitude", func=[(0,1),(1,1)], col="blue"),
189 cgraph(name="adsr1", label="Beat 1 ADSR", func=[(0,0),(0.001,1),(0.125,0.25),(1,0)], table=True, col="blue1"),
190 cgraph(name="adsr2", label="Beat 2 ADSR", func=[(0,0),(0.005,1),(0.135,0.3),(1,0)], table=True, col="purple1"),
191 cgraph(name="adsr3", label="Beat 3 ADSR", func=[(0,0),(0.01,1),(0.145,0.35),(1,0)], table=True, col="red1"),
192 cgraph(name="adsr4", label="Beat 4 ADSR", func=[(0,0),(0.015,1),(0.155,0.4),(1,0)], table=True, col="green1"),
193 cslider(name="taps", label="Num of Taps", min=1, max=64, init=16, res="int", rel="lin", unit="x", col= "orange1"),
194 cslider(name="tempo", label="Tempo", min=20, max=240, gliss=0, init=120, rel="lin", unit="bpm", col="orange3"),
195 cslider(name="tapsl1", label="Beat 1 Tap Length", min=0.01, max=1, init=0.2, rel="lin", unit="sec", col="blue1",half=True),
196 cslider(name="tapsl3", label="Beat 3 Tap Length", min=0.01, max=1, init=0.2, rel="lin", unit="sec", col="red1",half=True),
197 cslider(name="bindex1", label="Beat 1 Index", min=0, max=1, init=0, rel="lin", unit="x", col="blue2",half=True),
198 cslider(name="bindex3", label="Beat 3 Index", min=0, max=1, init=0.25, rel="lin", unit="x", col="red2",half=True),
199 cslider(name="gain1", label="Beat 1 Gain", min=-48, max=18, init=0, rel="lin", unit="dB", col="blue3",half=True),
200 cslider(name="gain3", label="Beat 3 Gain", min=-48, max=18, init=0, rel="lin", unit="dB", col="red3",half=True),
201 cslider(name="we1", label="Beat 1 Distribution", min=0, max=100, init=80, res="int", rel="lin", unit="%", col="blue4",half=True),
202 cslider(name="we3", label="Beat 3 Distribution", min=0, max=100, init=30, rel="lin", res="int", unit="%", col="red4",half=True),
203 cslider(name="tapsl2", label="Beat 2 Tap Length", min=0.01, max=1, init=0.2, rel="lin", unit="sec", col="purple1",half=True),
204 cslider(name="tapsl4", label="Beat 4 Tap Length", min=0.01, max=1, init=0.2, rel="lin", unit="sec", col="green1",half=True),
205 cslider(name="bindex2", label="Beat 2 Index", min=0, max=1, init=0.5, rel="lin", unit="x", col="purple2",half=True),
206 cslider(name="bindex4", label="Beat 4 Index", min=0, max=1, init=0.75, rel="lin", unit="x", col="green2",half=True),
207 cslider(name="gain2", label="Beat 2 Gain", min=-48, max=18, init=0, rel="lin", unit="dB", col="purple3",half=True),
208 cslider(name="gain4", label="Beat 4 Gain", min=-48, max=18, init=0, rel="lin", unit="dB", col="green3",half=True),
209 cslider(name="we2", label="Beat 2 Distribution", min=0, max=100, init=50, rel="lin", res="int", unit="%", col="purple4",half=True),
210 cslider(name="we4", label="Beat 4 Distribution", min=0, max=100, init=10, rel="lin", res="int", unit="%", col="green4",half=True),
211 cslider(name="seed", label="Global seed", min=0, max=5000, init=0, rel="lin", res="int", unit="x", up=True),
212 ]
213