Refactor MIDI stuff so deck focusing is listenable and controllable
[SugarCubes.git] / MarkSlee.pde
1 class SpaceTime extends SCPattern {
2
3 SinLFO pos = new SinLFO(0, 1, 3000);
4 SinLFO rate = new SinLFO(1000, 9000, 13000);
5 SinLFO falloff = new SinLFO(10, 70, 5000);
6 float angle = 0;
7
8 BasicParameter rateParameter = new BasicParameter("RATE", 0.5);
9 BasicParameter sizeParameter = new BasicParameter("SIZE", 0.5);
10
11
12 public SpaceTime(GLucose glucose) {
13 super(glucose);
14
15 addModulator(pos).trigger();
16 addModulator(rate).trigger();
17 addModulator(falloff).trigger();
18 pos.modulateDurationBy(rate);
19 addParameter(rateParameter);
20 addParameter(sizeParameter);
21 }
22
23 public void onParameterChanged(LXParameter parameter) {
24 if (parameter == rateParameter) {
25 rate.stop().setValue(9000 - 8000*parameter.getValuef());
26 } else if (parameter == sizeParameter) {
27 falloff.stop().setValue(70 - 60*parameter.getValuef());
28 }
29 }
30
31 void run(double deltaMs) {
32 angle += deltaMs * 0.0007;
33 float sVal1 = model.strips.size() * (0.5 + 0.5*sin(angle));
34 float sVal2 = model.strips.size() * (0.5 + 0.5*cos(angle));
35
36 float pVal = pos.getValuef();
37 float fVal = falloff.getValuef();
38
39 int s = 0;
40 for (Strip strip : model.strips) {
41 int i = 0;
42 for (Point p : strip.points) {
43 colors[p.index] = color(
44 (lx.getBaseHuef() + 360 - p.fx*.2 + p.fy * .3) % 360,
45 constrain(.4 * min(abs(s - sVal1), abs(s - sVal2)), 20, 100),
46 max(0, 100 - fVal*abs(i - pVal*(strip.metrics.numPoints - 1)))
47 );
48 ++i;
49 }
50 ++s;
51 }
52 }
53 }
54
55 class Swarm extends SCPattern {
56
57 SawLFO offset = new SawLFO(0, 1, 1000);
58 SinLFO rate = new SinLFO(350, 1200, 63000);
59 SinLFO falloff = new SinLFO(15, 50, 17000);
60 SinLFO fX = new SinLFO(0, model.xMax, 19000);
61 SinLFO fY = new SinLFO(0, model.yMax, 11000);
62 SinLFO hOffX = new SinLFO(0, model.xMax, 13000);
63
64 public Swarm(GLucose glucose) {
65 super(glucose);
66
67 addModulator(offset).trigger();
68 addModulator(rate).trigger();
69 addModulator(falloff).trigger();
70 addModulator(fX).trigger();
71 addModulator(fY).trigger();
72 addModulator(hOffX).trigger();
73 offset.modulateDurationBy(rate);
74 }
75
76 float modDist(float v1, float v2, float mod) {
77 v1 = v1 % mod;
78 v2 = v2 % mod;
79 if (v2 > v1) {
80 return min(v2-v1, v1+mod-v2);
81 }
82 else {
83 return min(v1-v2, v2+mod-v1);
84 }
85 }
86
87 void run(double deltaMs) {
88 float s = 0;
89 for (Strip strip : model.strips ) {
90 int i = 0;
91 for (Point p : strip.points) {
92 float fV = max(-1, 1 - dist(p.fx/2., p.fy, fX.getValuef()/2., fY.getValuef()) / 64.);
93 colors[p.index] = color(
94 (lx.getBaseHuef() + 0.3 * abs(p.fx - hOffX.getValuef())) % 360,
95 constrain(80 + 40 * fV, 0, 100),
96 constrain(100 - (30 - fV * falloff.getValuef()) * modDist(i + (s*63)%61, offset.getValuef() * strip.metrics.numPoints, strip.metrics.numPoints), 0, 100)
97 );
98 ++i;
99 }
100 ++s;
101 }
102 }
103 }
104
105 class SwipeTransition extends SCTransition {
106
107 final BasicParameter bleed = new BasicParameter("WIDTH", 0.5);
108
109 SwipeTransition(GLucose glucose) {
110 super(glucose);
111 setDuration(5000);
112 addParameter(bleed);
113 }
114
115 void computeBlend(int[] c1, int[] c2, double progress) {
116 float bleedf = 10 + bleed.getValuef() * 200.;
117 float xPos = (float) (-bleedf + progress * (model.xMax + bleedf));
118 for (Point p : model.points) {
119 float d = (p.fx - xPos) / bleedf;
120 if (d < 0) {
121 colors[p.index] = c2[p.index];
122 } else if (d > 1) {
123 colors[p.index] = c1[p.index];
124 } else {
125 colors[p.index] = lerpColor(c2[p.index], c1[p.index], d, RGB);
126 }
127 }
128 }
129 }
130
131 abstract class BlendTransition extends SCTransition {
132
133 final int blendType;
134
135 BlendTransition(GLucose glucose, int blendType) {
136 super(glucose);
137 this.blendType = blendType;
138 }
139
140 void computeBlend(int[] c1, int[] c2, double progress) {
141 if (progress < 0.5) {
142 for (int i = 0; i < c1.length; ++i) {
143 colors[i] = lerpColor(
144 c1[i],
145 blendColor(c1[i], c2[i], blendType),
146 (float) (2.*progress),
147 RGB);
148 }
149 } else {
150 for (int i = 0; i < c1.length; ++i) {
151 colors[i] = lerpColor(
152 c2[i],
153 blendColor(c1[i], c2[i], blendType),
154 (float) (2.*(1. - progress)),
155 RGB);
156 }
157 }
158 }
159 }
160
161 class MultiplyTransition extends BlendTransition {
162 MultiplyTransition(GLucose glucose) {
163 super(glucose, MULTIPLY);
164 }
165 }
166
167 class ScreenTransition extends BlendTransition {
168 ScreenTransition(GLucose glucose) {
169 super(glucose, SCREEN);
170 }
171 }
172
173 class BurnTransition extends BlendTransition {
174 BurnTransition(GLucose glucose) {
175 super(glucose, BURN);
176 }
177 }
178
179 class DodgeTransition extends BlendTransition {
180 DodgeTransition(GLucose glucose) {
181 super(glucose, DODGE);
182 }
183 }
184
185 class OverlayTransition extends BlendTransition {
186 OverlayTransition(GLucose glucose) {
187 super(glucose, OVERLAY);
188 }
189 }
190
191 class AddTransition extends BlendTransition {
192 AddTransition(GLucose glucose) {
193 super(glucose, ADD);
194 }
195 }
196
197 class SubtractTransition extends BlendTransition {
198 SubtractTransition(GLucose glucose) {
199 super(glucose, SUBTRACT);
200 }
201 }
202
203 class SoftLightTransition extends BlendTransition {
204 SoftLightTransition(GLucose glucose) {
205 super(glucose, SOFT_LIGHT);
206 }
207 }
208
209 class BassPod extends SCPattern {
210
211 private GraphicEQ eq = null;
212
213 public BassPod(GLucose glucose) {
214 super(glucose);
215 }
216
217 protected void onActive() {
218 if (eq == null) {
219 eq = new GraphicEQ(lx, 16);
220 eq.slope.setValue(0.6);
221 addParameter(eq.level);
222 addParameter(eq.range);
223 addParameter(eq.attack);
224 addParameter(eq.release);
225 addParameter(eq.slope);
226 }
227 }
228
229 public void run(double deltaMs) {
230 eq.run(deltaMs);
231
232 float bassLevel = eq.getAverageLevel(0, 5);
233
234 for (Point p : model.points) {
235 int avgIndex = (int) constrain(1 + abs(p.fx-model.xMax/2.)/(model.xMax/2.)*(eq.numBands-5), 0, eq.numBands-5);
236 float value = 0;
237 for (int i = avgIndex; i < avgIndex + 5; ++i) {
238 value += eq.getLevel(i);
239 }
240 value /= 5.;
241
242 float b = constrain(8 * (value*model.yMax - abs(p.fy-model.yMax/2.)), 0, 100);
243 colors[p.index] = color(
244 (lx.getBaseHuef() + abs(p.fy - model.cy) + abs(p.fx - model.cx)) % 360,
245 constrain(bassLevel*240 - .6*dist(p.fx, p.fy, model.cx, model.cy), 0, 100),
246 b
247 );
248 }
249 }
250 }
251
252
253 class CubeEQ extends SCPattern {
254
255 private GraphicEQ eq = null;
256
257 private final BasicParameter edge = new BasicParameter("EDGE", 0.5);
258 private final BasicParameter clr = new BasicParameter("CLR", 0.5);
259 private final BasicParameter blockiness = new BasicParameter("BLK", 0.5);
260
261 public CubeEQ(GLucose glucose) {
262 super(glucose);
263 }
264
265 protected void onActive() {
266 if (eq == null) {
267 eq = new GraphicEQ(lx, 16);
268 addParameter(eq.level);
269 addParameter(eq.range);
270 addParameter(eq.attack);
271 addParameter(eq.release);
272 addParameter(eq.slope);
273 addParameter(edge);
274 addParameter(clr);
275 addParameter(blockiness);
276 }
277 }
278
279 public void run(double deltaMs) {
280 eq.run(deltaMs);
281
282 float edgeConst = 2 + 30*edge.getValuef();
283 float clrConst = 1.1 + clr.getValuef();
284
285 for (Point p : model.points) {
286 float avgIndex = constrain(2 + p.fx / model.xMax * (eq.numBands-4), 0, eq.numBands-4);
287 int avgFloor = (int) avgIndex;
288
289 float leftVal = eq.getLevel(avgFloor);
290 float rightVal = eq.getLevel(avgFloor+1);
291 float smoothValue = lerp(leftVal, rightVal, avgIndex-avgFloor);
292
293 float chunkyValue = (
294 eq.getLevel(avgFloor/4*4) +
295 eq.getLevel(avgFloor/4*4 + 1) +
296 eq.getLevel(avgFloor/4*4 + 2) +
297 eq.getLevel(avgFloor/4*4 + 3)
298 ) / 4.;
299
300 float value = lerp(smoothValue, chunkyValue, blockiness.getValuef());
301
302 float b = constrain(edgeConst * (value*model.yMax - p.fy), 0, 100);
303 colors[p.index] = color(
304 (480 + lx.getBaseHuef() - min(clrConst*p.fy, 120)) % 360,
305 100,
306 b
307 );
308 }
309 }
310 }
311
312 class BoomEffect extends SCEffect {
313
314 final BasicParameter falloff = new BasicParameter("WIDTH", 0.5);
315 final BasicParameter speed = new BasicParameter("SPD", 0.5);
316 final BasicParameter bright = new BasicParameter("BRT", 1.0);
317 final BasicParameter sat = new BasicParameter("SAT", 0.2);
318 List<Layer> layers = new ArrayList<Layer>();
319 final float maxr = sqrt(model.xMax*model.xMax + model.yMax*model.yMax + model.zMax*model.zMax) + 10;
320
321 class Layer {
322 LinearEnvelope boom = new LinearEnvelope(-40, 500, 1300);
323
324 Layer() {
325 addModulator(boom);
326 trigger();
327 }
328
329 void trigger() {
330 float falloffv = falloffv();
331 boom.setRange(-100 / falloffv, maxr + 100/falloffv, 4000 - speed.getValuef() * 3300);
332 boom.trigger();
333 }
334
335 void doApply(int[] colors) {
336 float brightv = 100 * bright.getValuef();
337 float falloffv = falloffv();
338 float satv = sat.getValuef() * 100;
339 float huev = lx.getBaseHuef();
340 for (Point p : model.points) {
341 colors[p.index] = blendColor(
342 colors[p.index],
343 color(huev, satv, constrain(brightv - falloffv*abs(boom.getValuef() - dist(p.fx, 2*p.fy, 3*p.fz, model.xMax/2, model.yMax, model.zMax*1.5)), 0, 100)),
344 ADD);
345 }
346 }
347 }
348
349 BoomEffect(GLucose glucose) {
350 super(glucose, true);
351 addParameter(falloff);
352 addParameter(speed);
353 addParameter(bright);
354 addParameter(sat);
355 }
356
357 public void onEnable() {
358 for (Layer l : layers) {
359 if (!l.boom.isRunning()) {
360 l.trigger();
361 return;
362 }
363 }
364 layers.add(new Layer());
365 }
366
367 private float falloffv() {
368 return 20 - 19 * falloff.getValuef();
369 }
370
371 public void onTrigger() {
372 onEnable();
373 }
374
375 public void doApply(int[] colors) {
376 for (Layer l : layers) {
377 if (l.boom.isRunning()) {
378 l.doApply(colors);
379 }
380 }
381 }
382 }
383
384 public class PianoKeyPattern extends SCPattern {
385
386 final LinearEnvelope[] cubeBrt;
387 final SinLFO base[];
388 final BasicParameter attack = new BasicParameter("ATK", 0.1);
389 final BasicParameter release = new BasicParameter("REL", 0.5);
390 final BasicParameter level = new BasicParameter("AMB", 0.6);
391
392 PianoKeyPattern(GLucose glucose) {
393 super(glucose);
394
395 addParameter(attack);
396 addParameter(release);
397 addParameter(level);
398 cubeBrt = new LinearEnvelope[model.cubes.size() / 4];
399 for (int i = 0; i < cubeBrt.length; ++i) {
400 addModulator(cubeBrt[i] = new LinearEnvelope(0, 0, 100));
401 }
402 base = new SinLFO[model.cubes.size() / 12];
403 for (int i = 0; i < base.length; ++i) {
404 addModulator(base[i] = new SinLFO(0, 1, 7000 + 1000*i)).trigger();
405 }
406 }
407
408 private float getAttackTime() {
409 return 15 + attack.getValuef()*attack.getValuef() * 2000;
410 }
411
412 private float getReleaseTime() {
413 return 15 + release.getValuef() * 3000;
414 }
415
416 private LinearEnvelope getEnvelope(int index) {
417 return cubeBrt[index % cubeBrt.length];
418 }
419
420 private SinLFO getBase(int index) {
421 return base[index % base.length];
422 }
423
424 public boolean noteOnReceived(Note note) {
425 LinearEnvelope env = getEnvelope(note.getPitch());
426 env.setEndVal(min(1, env.getValuef() + (note.getVelocity() / 127.)), getAttackTime()).start();
427 return true;
428 }
429
430 public boolean noteOffReceived(Note note) {
431 getEnvelope(note.getPitch()).setEndVal(0, getReleaseTime()).start();
432 return true;
433 }
434
435 public void run(double deltaMs) {
436 int i = 0;
437 float huef = lx.getBaseHuef();
438 float levelf = level.getValuef();
439 for (Cube c : model.cubes) {
440 float v = max(getBase(i).getValuef() * levelf/4., getEnvelope(i++).getValuef());
441 setColor(c, color(
442 (huef + 20*v + abs(c.cx-model.xMax/2.)*.3 + c.cy) % 360,
443 min(100, 120*v),
444 100*v
445 ));
446 }
447 }
448 }
449
450 class CrossSections extends SCPattern {
451
452 final SinLFO x = new SinLFO(0, model.xMax, 5000);
453 final SinLFO y = new SinLFO(0, model.yMax, 6000);
454 final SinLFO z = new SinLFO(0, model.zMax, 7000);
455
456 final BasicParameter xw = new BasicParameter("XWID", 0.3);
457 final BasicParameter yw = new BasicParameter("YWID", 0.3);
458 final BasicParameter zw = new BasicParameter("ZWID", 0.3);
459 final BasicParameter xr = new BasicParameter("XRAT", 0.7);
460 final BasicParameter yr = new BasicParameter("YRAT", 0.6);
461 final BasicParameter zr = new BasicParameter("ZRAT", 0.5);
462 final BasicParameter xl = new BasicParameter("XLEV", 1);
463 final BasicParameter yl = new BasicParameter("YLEV", 1);
464 final BasicParameter zl = new BasicParameter("ZLEV", 0.5);
465
466
467 CrossSections(GLucose glucose) {
468 super(glucose);
469 addModulator(x).trigger();
470 addModulator(y).trigger();
471 addModulator(z).trigger();
472 addParams();
473 }
474
475 protected void addParams() {
476 addParameter(xr);
477 addParameter(yr);
478 addParameter(zr);
479 addParameter(xw);
480 addParameter(xl);
481 addParameter(yl);
482 addParameter(zl);
483 addParameter(yw);
484 addParameter(zw);
485 }
486
487 void onParameterChanged(LXParameter p) {
488 if (p == xr) {
489 x.setDuration(10000 - 8800*p.getValuef());
490 } else if (p == yr) {
491 y.setDuration(10000 - 9000*p.getValuef());
492 } else if (p == zr) {
493 z.setDuration(10000 - 9000*p.getValuef());
494 }
495 }
496
497 float xv, yv, zv;
498
499 protected void updateXYZVals() {
500 xv = x.getValuef();
501 yv = y.getValuef();
502 zv = z.getValuef();
503 }
504
505 public void run(double deltaMs) {
506 updateXYZVals();
507
508 float xlv = 100*xl.getValuef();
509 float ylv = 100*yl.getValuef();
510 float zlv = 100*zl.getValuef();
511
512 float xwv = 100. / (10 + 40*xw.getValuef());
513 float ywv = 100. / (10 + 40*yw.getValuef());
514 float zwv = 100. / (10 + 40*zw.getValuef());
515
516 for (Point p : model.points) {
517 color c = 0;
518 c = blendColor(c, color(
519 (lx.getBaseHuef() + p.fx/10 + p.fy/3) % 360,
520 constrain(140 - 1.1*abs(p.fx - model.xMax/2.), 0, 100),
521 max(0, xlv - xwv*abs(p.fx - xv))
522 ), ADD);
523 c = blendColor(c, color(
524 (lx.getBaseHuef() + 80 + p.fy/10) % 360,
525 constrain(140 - 2.2*abs(p.fy - model.yMax/2.), 0, 100),
526 max(0, ylv - ywv*abs(p.fy - yv))
527 ), ADD);
528 c = blendColor(c, color(
529 (lx.getBaseHuef() + 160 + p.fz / 10 + p.fy/2) % 360,
530 constrain(140 - 2.2*abs(p.fz - model.zMax/2.), 0, 100),
531 max(0, zlv - zwv*abs(p.fz - zv))
532 ), ADD);
533 colors[p.index] = c;
534 }
535 }
536 }
537
538 class Blinders extends SCPattern {
539
540 final SinLFO[] m;
541 final TriangleLFO r;
542 final SinLFO s;
543 final TriangleLFO hs;
544
545 public Blinders(GLucose glucose) {
546 super(glucose);
547 m = new SinLFO[12];
548 for (int i = 0; i < m.length; ++i) {
549 addModulator(m[i] = new SinLFO(0.5, 120, (120000. / (3+i)))).trigger();
550 }
551 addModulator(r = new TriangleLFO(9000, 15000, 29000)).trigger();
552 addModulator(s = new SinLFO(-20, 275, 11000)).trigger();
553 addModulator(hs = new TriangleLFO(0.1, 0.5, 15000)).trigger();
554 s.modulateDurationBy(r);
555 }
556
557 public void run(double deltaMs) {
558 float hv = lx.getBaseHuef();
559 int si = 0;
560 for (Strip strip : model.strips) {
561 int i = 0;
562 float mv = m[si % m.length].getValuef();
563 for (Point p : strip.points) {
564 colors[p.index] = color(
565 (hv + p.fz + p.fy*hs.getValuef()) % 360,
566 min(100, abs(p.fx - s.getValuef())/2.),
567 max(0, 100 - mv/2. - mv * abs(i - (strip.metrics.length-1)/2.))
568 );
569 ++i;
570 }
571 ++si;
572 }
573 }
574 }
575
576 class Psychedelia extends SCPattern {
577
578 final int NUM = 3;
579 SinLFO m = new SinLFO(-0.5, NUM-0.5, 9000);
580 SinLFO s = new SinLFO(-20, 147, 11000);
581 TriangleLFO h = new TriangleLFO(0, 240, 19000);
582 SinLFO c = new SinLFO(-.2, .8, 31000);
583
584 Psychedelia(GLucose glucose) {
585 super(glucose);
586 addModulator(m).trigger();
587 addModulator(s).trigger();
588 addModulator(h).trigger();
589 addModulator(c).trigger();
590 }
591
592 void run(double deltaMs) {
593 float huev = h.getValuef();
594 float cv = c.getValuef();
595 float sv = s.getValuef();
596 float mv = m.getValuef();
597 int i = 0;
598 for (Strip strip : model.strips) {
599 for (Point p : strip.points) {
600 colors[p.index] = color(
601 (huev + i*constrain(cv, 0, 2) + p.fz/2. + p.fx/4.) % 360,
602 min(100, abs(p.fy-sv)),
603 max(0, 100 - 50*abs((i%NUM) - mv))
604 );
605 }
606 ++i;
607 }
608 }
609 }
610
611 class AskewPlanes extends SCPattern {
612
613 class Plane {
614 private final SinLFO a;
615 private final SinLFO b;
616 private final SinLFO c;
617 float av = 1;
618 float bv = 1;
619 float cv = 1;
620 float denom = 0.1;
621
622 Plane(int i) {
623 addModulator(a = new SinLFO(-1, 1, 4000 + 1029*i)).trigger();
624 addModulator(b = new SinLFO(-1, 1, 11000 - 1104*i)).trigger();
625 addModulator(c = new SinLFO(-50, 50, 4000 + 1000*i * ((i % 2 == 0) ? 1 : -1))).trigger();
626 }
627
628 void run(double deltaMs) {
629 av = a.getValuef();
630 bv = b.getValuef();
631 cv = c.getValuef();
632 denom = sqrt(av*av + bv*bv);
633 }
634 }
635
636 final Plane[] planes;
637 final int NUM_PLANES = 3;
638
639 AskewPlanes(GLucose glucose) {
640 super(glucose);
641 planes = new Plane[NUM_PLANES];
642 for (int i = 0; i < planes.length; ++i) {
643 planes[i] = new Plane(i);
644 }
645 }
646
647 public void run(double deltaMs) {
648 float huev = lx.getBaseHuef();
649
650 // This is super fucking bizarre. But if this is a for loop, the framerate
651 // tanks to like 30FPS, instead of 60. Call them manually and it works fine.
652 // Doesn't make ANY sense... there must be some weird side effect going on
653 // with the Processing internals perhaps?
654 // for (Plane plane : planes) {
655 // plane.run(deltaMs);
656 // }
657 planes[0].run(deltaMs);
658 planes[1].run(deltaMs);
659 planes[2].run(deltaMs);
660
661 for (Point p : model.points) {
662 float d = MAX_FLOAT;
663 for (Plane plane : planes) {
664 if (plane.denom != 0) {
665 d = min(d, abs(plane.av*(p.fx-model.cx) + plane.bv*(p.fy-model.cy) + plane.cv) / plane.denom);
666 }
667 }
668 colors[p.index] = color(
669 (huev + abs(p.fx-model.cx)*.3 + p.fy*.8) % 360,
670 max(0, 100 - .8*abs(p.fx - model.cx)),
671 constrain(140 - 10.*d, 0, 100)
672 );
673 }
674 }
675 }
676
677 class ShiftingPlane extends SCPattern {
678
679 final SinLFO a = new SinLFO(-.2, .2, 5300);
680 final SinLFO b = new SinLFO(1, -1, 13300);
681 final SinLFO c = new SinLFO(-1.4, 1.4, 5700);
682 final SinLFO d = new SinLFO(-10, 10, 9500);
683
684 ShiftingPlane(GLucose glucose) {
685 super(glucose);
686 addModulator(a).trigger();
687 addModulator(b).trigger();
688 addModulator(c).trigger();
689 addModulator(d).trigger();
690 }
691
692 public void run(double deltaMs) {
693 float hv = lx.getBaseHuef();
694 float av = a.getValuef();
695 float bv = b.getValuef();
696 float cv = c.getValuef();
697 float dv = d.getValuef();
698 float denom = sqrt(av*av + bv*bv + cv*cv);
699 for (Point p : model.points) {
700 float d = abs(av*(p.fx-model.cx) + bv*(p.fy-model.cy) + cv*(p.fz-model.cz) + dv) / denom;
701 colors[p.index] = color(
702 (hv + abs(p.fx-model.cx)*.6 + abs(p.fy-model.cy)*.9 + abs(p.fz - model.cz)) % 360,
703 constrain(110 - d*6, 0, 100),
704 constrain(130 - 7*d, 0, 100)
705 );
706 }
707 }
708 }
709
710 class Traktor extends SCPattern {
711
712 final int FRAME_WIDTH = 60;
713
714 final BasicParameter speed = new BasicParameter("SPD", 0.5);
715
716 private float[] bass = new float[FRAME_WIDTH];
717 private float[] treble = new float[FRAME_WIDTH];
718
719 private int index = 0;
720 private GraphicEQ eq = null;
721
722 public Traktor(GLucose glucose) {
723 super(glucose);
724 for (int i = 0; i < FRAME_WIDTH; ++i) {
725 bass[i] = 0;
726 treble[i] = 0;
727 }
728 addParameter(speed);
729 }
730
731 public void onActive() {
732 if (eq == null) {
733 eq = new GraphicEQ(lx, 16);
734 eq.slope.setValue(0.6);
735 eq.level.setValue(0.65);
736 eq.range.setValue(0.35);
737 eq.release.setValue(0.4);
738 addParameter(eq.level);
739 addParameter(eq.range);
740 addParameter(eq.attack);
741 addParameter(eq.release);
742 addParameter(eq.slope);
743 }
744 }
745
746 int counter = 0;
747
748 public void run(double deltaMs) {
749 eq.run(deltaMs);
750
751 int stepThresh = (int) (40 - 39*speed.getValuef());
752 counter += deltaMs;
753 if (counter < stepThresh) {
754 return;
755 }
756 counter = counter % stepThresh;
757
758 index = (index + 1) % FRAME_WIDTH;
759
760 float rawBass = eq.getAverageLevel(0, 4);
761 float rawTreble = eq.getAverageLevel(eq.numBands-7, 7);
762
763 bass[index] = rawBass * rawBass * rawBass * rawBass;
764 treble[index] = rawTreble * rawTreble;
765
766 for (Point p : model.points) {
767 int i = (int) constrain((model.xMax - p.x) / model.xMax * FRAME_WIDTH, 0, FRAME_WIDTH-1);
768 int pos = (index + FRAME_WIDTH - i) % FRAME_WIDTH;
769
770 colors[p.index] = color(
771 (360 + lx.getBaseHuef() + .8*abs(p.x-model.cx)) % 360,
772 100,
773 constrain(9 * (bass[pos]*model.cy - abs(p.fy - model.cy)), 0, 100)
774 );
775 colors[p.index] = blendColor(colors[p.index], color(
776 (400 + lx.getBaseHuef() + .5*abs(p.x-model.cx)) % 360,
777 60,
778 constrain(5 * (treble[pos]*.6*model.cy - abs(p.fy - model.cy)), 0, 100)
779
780 ), ADD);
781 }
782 }
783 }
784
785 class ColorFuckerEffect extends SCEffect {
786
787 BasicParameter hueShift = new BasicParameter("HSHFT", 0);
788 BasicParameter sat = new BasicParameter("SAT", 1);
789 BasicParameter bright = new BasicParameter("BRT", 1);
790
791 ColorFuckerEffect(GLucose glucose) {
792 super(glucose);
793 addParameter(hueShift);
794 addParameter(bright);
795 addParameter(sat);
796 }
797
798 public void doApply(int[] colors) {
799 if (!enabled) {
800 return;
801 }
802 float bMod = bright.getValuef();
803 float sMod = sat.getValuef();
804 float hMod = hueShift.getValuef();
805 if (bMod < 1 || sMod < 1 || hMod > 0) {
806 for (int i = 0; i < colors.length; ++i) {
807 colors[i] = color(
808 (hue(colors[i]) + hueShift.getValuef()*360.) % 360,
809 saturation(colors[i]) * sat.getValuef(),
810 brightness(colors[i]) * bright.getValuef()
811 );
812 }
813 }
814 }
815 }
816
817 class BlurEffect extends SCEffect {
818
819 final LXParameter amount = new BasicParameter("AMT", 0);
820 final int[] frame;
821 final LinearEnvelope env = new LinearEnvelope(0, 1, 100);
822
823 BlurEffect(GLucose glucose) {
824 super(glucose);
825 addParameter(amount);
826 addModulator(env);
827 frame = new int[lx.total];
828 for (int i = 0; i < frame.length; ++i) {
829 frame[i] = #000000;
830 }
831 }
832
833 public void onEnable() {
834 env.setRangeFromHereTo(1, 400).start();
835 for (int i = 0; i < frame.length; ++i) {
836 frame[i] = #000000;
837 }
838 }
839
840 public void onDisable() {
841 env.setRangeFromHereTo(0, 1000).start();
842 }
843
844 public void doApply(int[] colors) {
845 float amt = env.getValuef() * amount.getValuef();
846 if (amt > 0) {
847 amt = (1 - amt);
848 amt = 1 - (amt*amt*amt);
849 for (int i = 0; i < colors.length; ++i) {
850 // frame[i] = colors[i] = blendColor(colors[i], lerpColor(#000000, frame[i], amt, RGB), SCREEN);
851 frame[i] = colors[i] = lerpColor(colors[i], blendColor(colors[i], frame[i], SCREEN), amt, RGB);
852 }
853 }
854
855 }
856 }