Commit | Line | Data |
---|---|---|
49815cc0 MS |
1 | class SpaceTime extends SCPattern { |
2 | ||
3 | SinLFO pos = new SinLFO(0, 15, 3000); | |
4 | SinLFO rate = new SinLFO(1000, 9000, 13000); | |
5 | SinLFO falloff = new SinLFO(10, 70, 5000); | |
3f8be614 MS |
6 | float angle = 0; |
7 | ||
8 | BasicParameter rateParameter = new BasicParameter("RATE", 0.5); | |
9 | BasicParameter sizeParameter = new BasicParameter("SIZE", 0.5); | |
49815cc0 MS |
10 | |
11 | public SpaceTime(GLucose glucose) { | |
12 | super(glucose); | |
13 | addModulator(pos).trigger(); | |
14 | addModulator(rate).trigger(); | |
15 | addModulator(falloff).trigger(); | |
16 | pos.modulateDurationBy(rate); | |
3f8be614 MS |
17 | addParameter(rateParameter); |
18 | addParameter(sizeParameter); | |
49815cc0 | 19 | } |
3f8be614 MS |
20 | |
21 | public void onParameterChanged(LXParameter parameter) { | |
22 | if (parameter == rateParameter) { | |
23 | rate.stop().setValue(9000 - 8000*parameter.getValuef()); | |
24 | } else if (parameter == sizeParameter) { | |
25 | falloff.stop().setValue(70 - 60*parameter.getValuef()); | |
49815cc0 MS |
26 | } |
27 | } | |
28 | ||
29 | void run(int deltaMs) { | |
3f8be614 MS |
30 | angle += deltaMs * 0.0007; |
31 | float sVal1 = Strip.list.size() * (0.5 + 0.5*sin(angle)); | |
32 | float sVal2 = Strip.list.size() * (0.5 + 0.5*cos(angle)); | |
49815cc0 MS |
33 | |
34 | float pVal = pos.getValuef(); | |
35 | float fVal = falloff.getValuef(); | |
36 | ||
37 | int s = 0; | |
38 | for (Strip strip : Strip.list) { | |
39 | int i = 0; | |
40 | for (Point p : strip.points) { | |
41 | colors[p.index] = color( | |
2b6688e8 | 42 | (lx.getBaseHuef() + 360 - p.fx*.2 + p.fy * .3) % 360, |
3f8be614 | 43 | constrain(.4 * min(abs(s - sVal1), abs(s - sVal2)), 20, 100), |
49815cc0 MS |
44 | max(0, 100 - fVal*abs(i - pVal)) |
45 | ); | |
46 | ++i; | |
47 | } | |
3f8be614 | 48 | ++s; |
49815cc0 MS |
49 | } |
50 | } | |
51 | } | |
52 | ||
53 | class Swarm extends SCPattern { | |
54 | ||
55 | SawLFO offset = new SawLFO(0, 16, 1000); | |
56 | SinLFO rate = new SinLFO(350, 1200, 63000); | |
57 | SinLFO falloff = new SinLFO(15, 50, 17000); | |
2b6688e8 MS |
58 | SinLFO fX = new SinLFO(0, 255, 19000); |
59 | SinLFO fY = new SinLFO(0, 127, 11000); | |
60 | SinLFO hOffX = new SinLFO(0, 255, 13000); | |
49815cc0 MS |
61 | |
62 | public Swarm(GLucose glucose) { | |
63 | super(glucose); | |
64 | addModulator(offset).trigger(); | |
65 | addModulator(rate).trigger(); | |
66 | addModulator(falloff).trigger(); | |
2b6688e8 | 67 | addModulator(fX).trigger(); |
49815cc0 | 68 | addModulator(fY).trigger(); |
2b6688e8 | 69 | addModulator(hOffX).trigger(); |
49815cc0 MS |
70 | offset.modulateDurationBy(rate); |
71 | } | |
72 | ||
73 | float modDist(float v1, float v2, float mod) { | |
74 | v1 = v1 % mod; | |
75 | v2 = v2 % mod; | |
76 | if (v2 > v1) { | |
77 | return min(v2-v1, v1+mod-v2); | |
78 | } | |
79 | else { | |
80 | return min(v1-v2, v2+mod-v1); | |
81 | } | |
82 | } | |
83 | ||
84 | void run(int deltaMs) { | |
85 | float s = 0; | |
86 | for (Strip strip : Strip.list) { | |
87 | int i = 0; | |
88 | for (Point p : strip.points) { | |
2b6688e8 | 89 | float fV = max(-1, 1 - dist(p.fx/2., p.fy, fX.getValuef()/2., fY.getValuef()) / 64.); |
49815cc0 | 90 | colors[p.index] = color( |
2b6688e8 | 91 | (lx.getBaseHuef() + 0.3 * abs(p.fx - hOffX.getValuef())) % 360, |
49815cc0 MS |
92 | constrain(80 + 40 * fV, 0, 100), |
93 | constrain(100 - (30 - fV * falloff.getValuef()) * modDist(i + (s*63)%61, offset.getValuef(), 16), 0, 100) | |
94 | ); | |
95 | ++i; | |
96 | } | |
97 | ++s; | |
98 | } | |
99 | } | |
100 | } | |
101 | ||
102 | class SwipeTransition extends SCTransition { | |
3f8be614 MS |
103 | |
104 | final BasicParameter bleed = new BasicParameter("WIDTH", 0.5); | |
105 | ||
49815cc0 MS |
106 | SwipeTransition(GLucose glucose) { |
107 | super(glucose); | |
108 | setDuration(5000); | |
3f8be614 | 109 | addParameter(bleed); |
49815cc0 MS |
110 | } |
111 | ||
112 | void computeBlend(int[] c1, int[] c2, double progress) { | |
3f8be614 | 113 | float bleedf = 10 + bleed.getValuef() * 200.; |
2b6688e8 | 114 | float xPos = (float) (-bleedf + progress * (255. + bleedf)); |
49815cc0 | 115 | for (Point p : Point.list) { |
2b6688e8 | 116 | float d = (p.fx - xPos) / bleedf; |
49815cc0 MS |
117 | if (d < 0) { |
118 | colors[p.index] = c2[p.index]; | |
2b6688e8 | 119 | } else if (d > 1) { |
49815cc0 | 120 | colors[p.index] = c1[p.index]; |
2b6688e8 | 121 | } else { |
49815cc0 MS |
122 | colors[p.index] = lerpColor(c2[p.index], c1[p.index], d, RGB); |
123 | } | |
124 | } | |
125 | } | |
126 | } | |
127 | ||
128 | class CubeEQ extends SCPattern { | |
129 | ||
130 | private FFT fft = null; | |
131 | private LinearEnvelope[] bandVals = null; | |
132 | private int avgSize; | |
133 | ||
3f8be614 MS |
134 | private final BasicParameter thrsh = new BasicParameter("LVL", 0.35); |
135 | private final BasicParameter range = new BasicParameter("RANG", 0.45); | |
136 | private final BasicParameter edge = new BasicParameter("EDGE", 0.5); | |
137 | private final BasicParameter speed = new BasicParameter("SPD", 0.5); | |
138 | private final BasicParameter tone = new BasicParameter("TONE", 0.5); | |
139 | private final BasicParameter clr = new BasicParameter("CLR", 0.5); | |
49815cc0 MS |
140 | |
141 | public CubeEQ(GLucose glucose) { | |
142 | super(glucose); | |
3f8be614 MS |
143 | addParameter(thrsh); |
144 | addParameter(range); | |
145 | addParameter(edge); | |
146 | addParameter(speed); | |
147 | addParameter(tone); | |
148 | addParameter(clr); | |
49815cc0 | 149 | } |
3f8be614 | 150 | |
49815cc0 MS |
151 | protected void onActive() { |
152 | if (this.fft == null) { | |
153 | this.fft = new FFT(lx.audioInput().bufferSize(), lx.audioInput().sampleRate()); | |
154 | this.fft.window(FFT.HAMMING); | |
155 | this.fft.logAverages(40, 1); | |
156 | this.avgSize = this.fft.avgSize(); | |
157 | this.bandVals = new LinearEnvelope[this.avgSize]; | |
158 | for (int i = 0; i < this.bandVals.length; ++i) { | |
159 | this.addModulator(this.bandVals[i] = (new LinearEnvelope(0, 0, 700+i*4))).trigger(); | |
160 | } | |
161 | } | |
162 | } | |
163 | ||
164 | public void run(int deltaMs) { | |
165 | this.fft.forward(this.lx.audioInput().mix); | |
166 | float toneConst = .35 + .4 * (tone.getValuef() - 0.5); | |
167 | float edgeConst = 2 + 30*(edge.getValuef()*edge.getValuef()*edge.getValuef()); | |
3f8be614 | 168 | |
49815cc0 MS |
169 | for (int i = 0; i < avgSize; ++i) { |
170 | float value = this.fft.getAvg(i); | |
171 | value = 20*log(1 + sqrt(value)); | |
172 | float sqdist = avgSize - i; | |
173 | value -= toneConst*sqdist*sqdist + .5*sqdist; | |
174 | value *= 6; | |
175 | if (value > this.bandVals[i].getValue()) { | |
176 | this.bandVals[i].setEndVal(value, 40).trigger(); | |
3f8be614 MS |
177 | } |
178 | else { | |
49815cc0 MS |
179 | this.bandVals[i].setEndVal(value, 1000 - 900*speed.getValuef()).trigger(); |
180 | } | |
181 | } | |
3f8be614 | 182 | |
49815cc0 MS |
183 | float jBase = 120 - 360*thrsh.getValuef(); |
184 | float jConst = 300.*(1-range.getValuef()); | |
185 | float clrConst = 1.1 + clr.getValuef(); | |
186 | ||
187 | for (Point p : Point.list) { | |
2b6688e8 | 188 | float avgIndex = constrain((p.fx / 256. * avgSize), 0, avgSize-2); |
49815cc0 | 189 | int avgFloor = (int) avgIndex; |
2b6688e8 | 190 | float j = jBase + jConst * (p.fy / 128.); |
49815cc0 | 191 | float value = lerp( |
3f8be614 MS |
192 | this.bandVals[avgFloor].getValuef(), |
193 | this.bandVals[avgFloor+1].getValuef(), | |
194 | avgIndex-avgFloor | |
195 | ); | |
196 | ||
49815cc0 MS |
197 | float b = constrain(edgeConst * (value - j), 0, 100); |
198 | colors[p.index] = color( | |
2b6688e8 | 199 | (480 + lx.getBaseHuef() - min(clrConst*p.fy, 120)) % 360, |
3f8be614 MS |
200 | 100, |
201 | b); | |
202 | } | |
203 | } | |
204 | } | |
205 | ||
206 | class BoomEffect extends SCEffect { | |
207 | ||
208 | final BasicParameter falloff = new BasicParameter("WIDTH", 0.5); | |
209 | final BasicParameter speed = new BasicParameter("SPD", 0.5); | |
210 | final BasicParameter bright = new BasicParameter("BRT", 1.0); | |
211 | final BasicParameter sat = new BasicParameter("SAT", 0.2); | |
212 | List<Layer> layers = new ArrayList<Layer>(); | |
2b6688e8 | 213 | final float maxr = sqrt(127*127 + 127*127 + 255*255) + 10; |
3f8be614 MS |
214 | |
215 | class Layer { | |
216 | LinearEnvelope boom = new LinearEnvelope(-40, 500, 1300); | |
217 | ||
218 | Layer() { | |
219 | addModulator(boom); | |
220 | trigger(); | |
221 | } | |
222 | ||
223 | void trigger() { | |
224 | float falloffv = falloffv(); | |
2b6688e8 | 225 | boom.setRange(-100 / falloffv, maxr + 100/falloffv, 4000 - speed.getValuef() * 3300); |
3f8be614 MS |
226 | boom.trigger(); |
227 | } | |
228 | ||
229 | void doApply(int[] colors) { | |
230 | float brightv = 100 * bright.getValuef(); | |
231 | float falloffv = falloffv(); | |
232 | float satv = sat.getValuef() * 100; | |
233 | float huev = lx.getBaseHuef(); | |
234 | for (Point p : Point.list) { | |
235 | colors[p.index] = blendColor( | |
236 | colors[p.index], | |
2b6688e8 | 237 | color(huev, satv, constrain(brightv - falloffv*abs(boom.getValuef() - dist(p.fx, 2*p.fy, 2*p.fz, 128, 128, 128)), 0, 100)), |
3f8be614 MS |
238 | ADD); |
239 | } | |
240 | } | |
241 | } | |
242 | ||
243 | BoomEffect(GLucose glucose) { | |
244 | super(glucose, true); | |
245 | addParameter(falloff); | |
246 | addParameter(speed); | |
247 | addParameter(bright); | |
248 | addParameter(sat); | |
249 | } | |
250 | ||
251 | public void onEnable() { | |
252 | for (Layer l : layers) { | |
253 | if (!l.boom.isRunning()) { | |
254 | l.trigger(); | |
255 | return; | |
256 | } | |
257 | } | |
258 | layers.add(new Layer()); | |
259 | } | |
260 | ||
261 | private float falloffv() { | |
262 | return 20 - 19 * falloff.getValuef(); | |
263 | } | |
264 | ||
265 | public void onTrigger() { | |
266 | onEnable(); | |
267 | } | |
268 | ||
269 | public void doApply(int[] colors) { | |
270 | for (Layer l : layers) { | |
271 | if (l.boom.isRunning()) { | |
272 | l.doApply(colors); | |
273 | } | |
49815cc0 MS |
274 | } |
275 | } | |
276 | } | |
277 | ||
5d70e4d7 MS |
278 | public class PianoKeyPattern extends SCPattern { |
279 | ||
280 | final LinearEnvelope[] cubeBrt; | |
281 | final SinLFO base[]; | |
282 | final BasicParameter attack = new BasicParameter("ATK", 0.1); | |
283 | final BasicParameter release = new BasicParameter("REL", 0.5); | |
284 | final BasicParameter level = new BasicParameter("AMB", 0.6); | |
285 | ||
286 | PianoKeyPattern(GLucose glucose) { | |
287 | super(glucose); | |
288 | ||
289 | for (MidiInputDevice input : RWMidi.getInputDevices()) { | |
290 | input.createInput(this); | |
291 | } | |
292 | ||
293 | addParameter(attack); | |
294 | addParameter(release); | |
295 | addParameter(level); | |
296 | cubeBrt = new LinearEnvelope[Cube.list.size() / 4]; | |
297 | for (int i = 0; i < cubeBrt.length; ++i) { | |
298 | addModulator(cubeBrt[i] = new LinearEnvelope(0, 0, 100)); | |
299 | } | |
300 | base = new SinLFO[Cube.list.size() / 12]; | |
301 | for (int i = 0; i < base.length; ++i) { | |
302 | addModulator(base[i] = new SinLFO(0, 1, 7000 + 1000*i)).trigger(); | |
303 | } | |
304 | } | |
305 | ||
306 | private float getAttackTime() { | |
307 | return 15 + attack.getValuef()*attack.getValuef() * 2000; | |
308 | } | |
309 | ||
310 | private float getReleaseTime() { | |
311 | return 15 + release.getValuef() * 3000; | |
312 | } | |
313 | ||
314 | private LinearEnvelope getEnvelope(int index) { | |
315 | return cubeBrt[index % cubeBrt.length]; | |
316 | } | |
317 | ||
318 | private SinLFO getBase(int index) { | |
319 | return base[index % base.length]; | |
320 | } | |
321 | ||
322 | public void noteOnReceived(Note note) { | |
323 | LinearEnvelope env = getEnvelope(note.getPitch()); | |
324 | env.setEndVal(min(1, env.getValuef() + (note.getVelocity() / 127.)), getAttackTime()).start(); | |
325 | } | |
326 | ||
327 | public void noteOffReceived(Note note) { | |
328 | getEnvelope(note.getPitch()).setEndVal(0, getReleaseTime()).start(); | |
329 | } | |
330 | ||
331 | public void run(int deltaMs) { | |
332 | int i = 0; | |
333 | float huef = lx.getBaseHuef(); | |
334 | float levelf = level.getValuef(); | |
335 | for (Cube c : Cube.list) { | |
336 | float v = max(getBase(i).getValuef() * levelf/4., getEnvelope(i++).getValuef()); | |
337 | setColor(c, color( | |
2b6688e8 | 338 | (huef + 20*v + abs(c.fx-128.)*.3 + c.fy) % 360, |
5d70e4d7 MS |
339 | min(100, 120*v), |
340 | 100*v | |
341 | )); | |
342 | } | |
343 | } | |
344 | } | |
345 | ||
0106b29c MS |
346 | class CrossSections extends SCPattern { |
347 | ||
2b6688e8 MS |
348 | final SinLFO x = new SinLFO(0, 255, 5000); |
349 | final SinLFO y = new SinLFO(0, 127, 6000); | |
350 | final SinLFO z = new SinLFO(0, 127, 7000); | |
0106b29c MS |
351 | |
352 | final BasicParameter xw = new BasicParameter("XWID", 0.3); | |
353 | final BasicParameter yw = new BasicParameter("YWID", 0.3); | |
354 | final BasicParameter zw = new BasicParameter("ZWID", 0.3); | |
2b6688e8 | 355 | final BasicParameter xr = new BasicParameter("XRAT", 0.7); |
0106b29c | 356 | final BasicParameter yr = new BasicParameter("YRAT", 0.6); |
2b6688e8 MS |
357 | final BasicParameter zr = new BasicParameter("ZRAT", 0.5); |
358 | final BasicParameter xl = new BasicParameter("XLEV", 1); | |
0106b29c | 359 | final BasicParameter yl = new BasicParameter("YLEV", 1); |
2b6688e8 | 360 | final BasicParameter zl = new BasicParameter("ZLEV", 0.5); |
0106b29c MS |
361 | |
362 | ||
363 | CrossSections(GLucose glucose) { | |
364 | super(glucose); | |
365 | addModulator(x).trigger(); | |
366 | addModulator(y).trigger(); | |
367 | addModulator(z).trigger(); | |
368 | addParameter(xr); | |
369 | addParameter(yr); | |
370 | addParameter(zr); | |
2b6688e8 | 371 | addParameter(xw); |
0106b29c MS |
372 | addParameter(xl); |
373 | addParameter(yl); | |
374 | addParameter(zl); | |
2b6688e8 MS |
375 | addParameter(yw); |
376 | addParameter(zw); | |
0106b29c MS |
377 | } |
378 | ||
379 | void onParameterChanged(LXParameter p) { | |
380 | if (p == xr) { | |
2b6688e8 | 381 | x.setDuration(10000 - 8800*p.getValuef()); |
0106b29c | 382 | } else if (p == yr) { |
2b6688e8 | 383 | y.setDuration(10000 - 9000*p.getValuef()); |
0106b29c MS |
384 | } else if (p == zr) { |
385 | z.setDuration(10000 - 9000*p.getValuef()); | |
386 | } | |
0106b29c MS |
387 | } |
388 | ||
389 | public void run(int deltaMs) { | |
390 | float xv = x.getValuef(); | |
391 | float yv = y.getValuef(); | |
392 | float zv = z.getValuef(); | |
393 | float xlv = 100*xl.getValuef(); | |
394 | float ylv = 100*yl.getValuef(); | |
395 | float zlv = 100*zl.getValuef(); | |
396 | ||
397 | float xwv = 100. / (10 + 40*xw.getValuef()); | |
398 | float ywv = 100. / (10 + 40*yw.getValuef()); | |
399 | float zwv = 100. / (10 + 40*zw.getValuef()); | |
400 | ||
401 | for (Point p : Point.list) { | |
402 | color c = 0; | |
403 | c = blendColor(c, color( | |
2b6688e8 MS |
404 | (lx.getBaseHuef() + p.fx/10 + p.fy/3) % 360, |
405 | constrain(140 - 1.1*abs(p.fx - 127), 0, 100), | |
406 | max(0, xlv - xwv*abs(p.fx - xv)) | |
0106b29c MS |
407 | ), ADD); |
408 | c = blendColor(c, color( | |
2b6688e8 MS |
409 | (lx.getBaseHuef() + 80 + p.fy/10) % 360, |
410 | constrain(140 - 2.2*abs(p.fy - 64), 0, 100), | |
411 | max(0, ylv - ywv*abs(p.fy - yv)) | |
0106b29c MS |
412 | ), ADD); |
413 | c = blendColor(c, color( | |
2b6688e8 MS |
414 | (lx.getBaseHuef() + 160 + p.fz / 10 + p.fy/2) % 360, |
415 | constrain(140 - 2.2*abs(p.fz - 64), 0, 100), | |
416 | max(0, zlv - zwv*abs(p.fz - zv)) | |
0106b29c MS |
417 | ), ADD); |
418 | colors[p.index] = c; | |
419 | } | |
420 | } | |
421 | } | |
422 | ||
423 | class Blinders extends SCPattern { | |
424 | ||
aa54c1ca | 425 | final SinLFO[] m; |
0106b29c MS |
426 | final TriangleLFO r; |
427 | final SinLFO s; | |
428 | final TriangleLFO hs; | |
429 | ||
430 | public Blinders(GLucose glucose) { | |
431 | super(glucose); | |
aa54c1ca MS |
432 | m = new SinLFO[12]; |
433 | for (int i = 0; i < m.length; ++i) { | |
434 | addModulator(m[i] = new SinLFO(0.5, 120, (120000. / (3+i)))).trigger(); | |
435 | } | |
436 | addModulator(r = new TriangleLFO(9000, 15000, 29000)).trigger(); | |
437 | addModulator(s = new SinLFO(-20, 275, 11000)).trigger(); | |
0106b29c | 438 | addModulator(hs = new TriangleLFO(0.1, 0.5, 15000)).trigger(); |
aa54c1ca | 439 | s.modulateDurationBy(r); |
0106b29c MS |
440 | } |
441 | ||
442 | public void run(int deltaMs) { | |
443 | float hv = lx.getBaseHuef(); | |
aa54c1ca | 444 | int si = 0; |
0106b29c MS |
445 | for (Strip strip : Strip.list) { |
446 | int i = 0; | |
aa54c1ca | 447 | float mv = m[si % m.length].getValuef(); |
0106b29c MS |
448 | for (Point p : strip.points) { |
449 | colors[p.index] = color( | |
2b6688e8 MS |
450 | (hv + p.fz + p.fy*hs.getValuef()) % 360, |
451 | min(100, abs(p.fx - s.getValuef())/2.), | |
452 | max(0, 100 - mv/2. - mv * abs(i - 7.5)) | |
0106b29c MS |
453 | ); |
454 | ++i; | |
455 | } | |
aa54c1ca | 456 | ++si; |
0106b29c MS |
457 | } |
458 | } | |
459 | } | |
460 | ||
461 |