Cathedrals dagger logo pattern for unbound shoot
[SugarCubes.git] / MarkSlee.pde
1 class Cathedrals extends SCPattern {
2
3 private final BasicParameter xpos = new BasicParameter("XPOS", 0.5);
4 private final BasicParameter wid = new BasicParameter("WID", 0.5);
5 private final BasicParameter arms = new BasicParameter("ARMS", 0.5);
6 private final BasicParameter sat = new BasicParameter("SAT", 0.5);
7 private GraphicEQ eq;
8
9 Cathedrals(GLucose glucose) {
10 super(glucose);
11 addParameter(xpos);
12 addParameter(wid);
13 addParameter(arms);
14 addParameter(sat);
15 }
16
17 protected void onActive() {
18 if (eq == null) {
19 eq = new GraphicEQ(lx, 16);
20 eq.slope.setValue(0.7);
21 eq.range.setValue(0.4);
22 eq.attack.setValue(0.4);
23 eq.release.setValue(0.4);
24 addParameter(eq.level);
25 addParameter(eq.range);
26 addParameter(eq.attack);
27 addParameter(eq.release);
28 addParameter(eq.slope);
29 }
30 }
31
32
33 public void run(double deltaMs) {
34 eq.run(deltaMs);
35 float bassLevel = eq.getAverageLevel(0, 4);
36 float trebleLevel = eq.getAverageLevel(8, 6);
37
38 float falloff = 100 / (2 + 14*wid.getValuef());
39 float cx = model.xMin + (model.xMax-model.xMin) * xpos.getValuef();
40 float barm = 12 + 60*arms.getValuef()*max(0, 2*(bassLevel-0.1));
41 float tarm = 12 + 60*arms.getValuef()*max(0, 2*(trebleLevel-0.1));
42
43 float arm = 0;
44 float middle = 0;
45
46 float sf = 100. / (70 - 69.9*sat.getValuef());
47
48 for (Point p : model.points) {
49 float d = MAX_FLOAT;
50 if (p.y > model.cy) {
51 arm = tarm;
52 middle = model.yMax * 3/5.;
53 } else {
54 arm = barm;
55 middle = model.yMax * 1/5.;
56 }
57 if (abs(p.x - cx) < arm) {
58 d = min(abs(p.x - cx), abs(p.y - middle));
59 }
60 colors[p.index] = color(
61 (lx.getBaseHuef() + .2*abs(p.y - model.cy)) % 360,
62 min(100, sf*dist(abs(p.x - cx), p.y, arm, middle)),
63 max(0, 120 - d*falloff));
64 }
65 }
66 }
67
68 class MidiMusic extends SCPattern {
69
70 private final Stack<LXLayer> newLayers = new Stack<LXLayer>();
71
72 private final Map<Integer, LightUp> lightMap = new HashMap<Integer, LightUp>();
73 private final List<LightUp> lights = new ArrayList<LightUp>();
74 private final BasicParameter lightSize = new BasicParameter("SIZE", 0.5);
75
76 private final List<Sweep> sweeps = new ArrayList<Sweep>();
77
78 private final LinearEnvelope sparkle = new LinearEnvelope(0, 1, 500);
79 private boolean sparkleDirection = true;
80 private float sparkleBright = 100;
81
82 private final BasicParameter wave = new BasicParameter("WAVE", 0);
83
84 MidiMusic(GLucose glucose) {
85 super(glucose);
86 addParameter(lightSize);
87 addParameter(wave);
88 addModulator(sparkle).setValue(1);
89 }
90
91 void onReset() {
92 for (LightUp light : lights) {
93 light.noteOff(null);
94 }
95 }
96
97 class Sweep extends LXLayer {
98
99 final LinearEnvelope position = new LinearEnvelope(0, 1, 1000);
100 float bright = 100;
101 float falloff = 10;
102
103 Sweep() {
104 addModulator(position);
105 }
106
107 public void run(double deltaMs, color[] colors) {
108 if (!position.isRunning()) {
109 return;
110 }
111 float posf = position.getValuef();
112 for (Point p : model.points) {
113 colors[p.index] = blendColor(colors[p.index], color(
114 (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360,
115 100,
116 max(0, bright - posf*100 - falloff*abs(p.y - posf*model.yMax))
117 ), ADD);
118 }
119 }
120 }
121
122 class LightUp extends LXLayer {
123
124 private final LinearEnvelope brt = new LinearEnvelope(0, 0, 0);
125 private final Accelerator yPos = new Accelerator(0, 0, 0);
126 private float xPos;
127
128 LightUp() {
129 addModulator(brt);
130 addModulator(yPos);
131 }
132
133 boolean isAvailable() {
134 return brt.getValuef() <= 0;
135 }
136
137 void noteOn(Note note) {
138 xPos = lerp(0, model.xMax, constrain(0.5 + (note.getPitch() - 60) / 28., 0, 1));
139 yPos.setValue(lerp(20, model.yMax*.72, note.getVelocity() / 127.)).stop();
140 brt.setRangeFromHereTo(lerp(40, 100, note.getVelocity() / 127.), 20).start();
141 }
142
143 void noteOff(Note note) {
144 yPos.setVelocity(0).setAcceleration(-380).start();
145 brt.setRangeFromHereTo(0, 1000).start();
146 }
147
148 public void run(double deltaMs, color[] colors) {
149 float bVal = brt.getValuef();
150 if (bVal <= 0) {
151 return;
152 }
153 float yVal = yPos.getValuef();
154 for (Point p : model.points) {
155 float falloff = 6 - 5*lightSize.getValuef();
156 float b = max(0, bVal - falloff*dist(p.x, p.y, xPos, yVal));
157 if (b > 0) {
158 colors[p.index] = blendColor(colors[p.index], lx.hsb(
159 (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360,
160 100,
161 b
162 ), ADD);
163 }
164 }
165 }
166 }
167
168 private LightUp getLight() {
169 for (LightUp light : lights) {
170 if (light.isAvailable()) {
171 return light;
172 }
173 }
174 LightUp newLight = new LightUp();
175 lights.add(newLight);
176 synchronized(newLayers) {
177 newLayers.push(newLight);
178 }
179 return newLight;
180 }
181
182 private Sweep getSweep() {
183 for (Sweep s : sweeps) {
184 if (!s.position.isRunning()) {
185 return s;
186 }
187 }
188 Sweep newSweep = new Sweep();
189 sweeps.add(newSweep);
190 synchronized(newLayers) {
191 newLayers.push(newSweep);
192 }
193 return newSweep;
194 }
195
196 public synchronized boolean noteOn(Note note) {
197 if (note.getChannel() == 0) {
198 LightUp light = getLight();
199 lightMap.put(note.getPitch(), light);
200 light.noteOn(note);
201 } else if (note.getChannel() == 1) {
202 } else if (note.getChannel() == 9) {
203 if (note.getVelocity() > 0) {
204 switch (note.getPitch()) {
205 case 36:
206 Sweep s = getSweep();
207 s.bright = 50 + note.getVelocity() / 127. * 50;
208 s.falloff = 20 - note.getVelocity() / 127. * 17;
209 s.position.trigger();
210 break;
211 case 37:
212 sparkleBright = note.getVelocity() / 127. * 100;
213 sparkleDirection = true;
214 sparkle.trigger();
215 break;
216 case 38:
217 sparkleBright = note.getVelocity() / 127. * 100;
218 sparkleDirection = false;
219 sparkle.trigger();
220 break;
221 case 39:
222 effects.boom.trigger();
223 break;
224 case 40:
225 effects.flash.trigger();
226 break;
227 }
228 }
229 }
230 return true;
231 }
232
233 public synchronized boolean noteOff(Note note) {
234 if (note.getChannel() == 0) {
235 LightUp light = lightMap.get(note.getPitch());
236 if (light != null) {
237 light.noteOff(note);
238 }
239 }
240 return true;
241 }
242
243 final float[] wval = new float[16];
244 float wavoff = 0;
245
246 public synchronized void run(double deltaMs) {
247 wavoff += deltaMs * .001;
248 for (int i = 0; i < wval.length; ++i) {
249 wval[i] = model.cy + 0.2 * model.yMax/2. * sin(wavoff + i / 1.9);
250 }
251 float sparklePos = (sparkleDirection ? sparkle.getValuef() : (1 - sparkle.getValuef())) * (Cube.POINTS_PER_STRIP)/2.;
252 float maxBright = sparkleBright * (1 - sparkle.getValuef());
253 for (Strip s : model.strips) {
254 int i = 0;
255 for (Point p : s.points) {
256 int wavi = (int) constrain(p.x / model.xMax * wval.length, 0, wval.length-1);
257 float wavb = max(0, wave.getValuef()*100. - 8.*abs(p.y - wval[wavi]));
258 colors[p.index] = color(
259 (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360,
260 100,
261 constrain(wavb + max(0, maxBright - 40.*abs(sparklePos - abs(i - (Cube.POINTS_PER_STRIP-1)/2.))), 0, 100)
262 );
263 ++i;
264 }
265 }
266
267 if (!newLayers.isEmpty()) {
268 synchronized(newLayers) {
269 while (!newLayers.isEmpty()) {
270 addLayer(newLayers.pop());
271 }
272 }
273 }
274 }
275 }
276
277 class Pulley extends SCPattern {
278
279 final int NUM_DIVISIONS = 16;
280 private final Accelerator[] gravity = new Accelerator[NUM_DIVISIONS];
281 private final Click[] delays = new Click[NUM_DIVISIONS];
282
283 private final Click reset = new Click(9000);
284 private boolean isRising = false;
285
286 private BasicParameter sz = new BasicParameter("SIZE", 0.5);
287 private BasicParameter beatAmount = new BasicParameter("BEAT", 0);
288
289 Pulley(GLucose glucose) {
290 super(glucose);
291 for (int i = 0; i < NUM_DIVISIONS; ++i) {
292 addModulator(gravity[i] = new Accelerator(0, 0, 0));
293 addModulator(delays[i] = new Click(0));
294 }
295 addModulator(reset).start();
296 addParameter(sz);
297 addParameter(beatAmount);
298 trigger();
299
300 }
301
302 private void trigger() {
303 isRising = !isRising;
304 int i = 0;
305 for (Accelerator g : gravity) {
306 if (isRising) {
307 g.setSpeed(random(20, 33), 0).start();
308 } else {
309 g.setVelocity(0).setAcceleration(-420);
310 delays[i].setDuration(random(0, 500)).trigger();
311 }
312 ++i;
313 }
314 }
315
316 public void run(double deltaMs) {
317 if (reset.click()) {
318 trigger();
319 }
320
321 if (isRising) {
322 // Fucking A, had to comment this all out because of that bizarre
323 // Processing bug where some simple loop takes an absurd amount of
324 // time, must be some pre-processor bug
325 // for (Accelerator g : gravity) {
326 // if (g.getValuef() > model.yMax) {
327 // g.stop();
328 // } else if (g.getValuef() > model.yMax*.55) {
329 // if (g.getVelocityf() > 10) {
330 // g.setAcceleration(-16);
331 // } else {
332 // g.setAcceleration(0);
333 // }
334 // }
335 // }
336 } else {
337 int j = 0;
338 for (Click d : delays) {
339 if (d.click()) {
340 gravity[j].start();
341 d.stop();
342 }
343 ++j;
344 }
345 for (Accelerator g : gravity) {
346 if (g.getValuef() < 0) {
347 g.setValue(-g.getValuef());
348 g.setVelocity(-g.getVelocityf() * random(0.74, 0.84));
349 }
350 }
351 }
352
353 // A little silliness to test the grid API
354 if (midiEngine != null && midiEngine.getFocusedPattern() == this) {
355 for (int i = 0; i < 5; ++i) {
356 for (int j = 0; j < 8; ++j) {
357 int gi = (int) constrain(j * NUM_DIVISIONS / 8, 0, NUM_DIVISIONS-1);
358 float b = 1 - 4.*abs((6-i)/6. - gravity[gi].getValuef() / model.yMax);
359 midiEngine.grid.setState(i, j, (b < 0) ? 0 : 3);
360 }
361 }
362 }
363
364 float fPos = 1 - lx.tempo.rampf();
365 if (fPos < .2) {
366 fPos = .2 + 4 * (.2 - fPos);
367 }
368 float falloff = 100. / (3 + sz.getValuef() * 36 + fPos * beatAmount.getValuef()*48);
369 for (Point p : model.points) {
370 int gi = (int) constrain((p.x - model.xMin) * NUM_DIVISIONS / (model.xMax - model.xMin), 0, NUM_DIVISIONS-1);
371 colors[p.index] = lx.hsb(
372 (lx.getBaseHuef() + abs(p.x - model.cx)*.8 + p.y*.4) % 360,
373 constrain(130 - p.y*.8, 0, 100),
374 max(0, 100 - abs(p.y - gravity[gi].getValuef())*falloff)
375 );
376 }
377 }
378 }
379
380 class ViolinWave extends SCPattern {
381
382 BasicParameter level = new BasicParameter("LVL", 0.45);
383 BasicParameter range = new BasicParameter("RNG", 0.5);
384 BasicParameter edge = new BasicParameter("EDG", 0.5);
385 BasicParameter release = new BasicParameter("RLS", 0.5);
386 BasicParameter speed = new BasicParameter("SPD", 0.5);
387 BasicParameter amp = new BasicParameter("AMP", 0.25);
388 BasicParameter period = new BasicParameter("WAVE", 0.5);
389 BasicParameter pSize = new BasicParameter("PSIZE", 0.5);
390 BasicParameter pSpeed = new BasicParameter("PSPD", 0.5);
391 BasicParameter pDensity = new BasicParameter("PDENS", 0.25);
392
393 LinearEnvelope dbValue = new LinearEnvelope(0, 0, 10);
394
395 ViolinWave(GLucose glucose) {
396 super(glucose);
397 addParameter(level);
398 addParameter(edge);
399 addParameter(range);
400 addParameter(release);
401 addParameter(speed);
402 addParameter(amp);
403 addParameter(period);
404 addParameter(pSize);
405 addParameter(pSpeed);
406 addParameter(pDensity);
407
408 addModulator(dbValue);
409 }
410
411 final List<Particle> particles = new ArrayList<Particle>();
412
413 class Particle {
414
415 LinearEnvelope x = new LinearEnvelope(0, 0, 0);
416 LinearEnvelope y = new LinearEnvelope(0, 0, 0);
417
418 Particle() {
419 addModulator(x);
420 addModulator(y);
421 }
422
423 Particle trigger(boolean direction) {
424 float xInit = random(model.xMin, model.xMax);
425 float time = 3000 - 2500*pSpeed.getValuef();
426 x.setRange(xInit, xInit + random(-40, 40), time).trigger();
427 y.setRange(model.cy + 10, direction ? model.yMax + 50 : model.yMin - 50, time).trigger();
428 return this;
429 }
430
431 boolean isActive() {
432 return x.isRunning() || y.isRunning();
433 }
434
435 public void run(double deltaMs) {
436 if (!isActive()) {
437 return;
438 }
439
440 float pFalloff = (30 - 27*pSize.getValuef());
441 for (Point p : model.points) {
442 float b = 100 - pFalloff * (abs(p.x - x.getValuef()) + abs(p.y - y.getValuef()));
443 if (b > 0) {
444 colors[p.index] = blendColor(colors[p.index], lx.hsb(
445 lx.getBaseHuef(), 20, b
446 ), ADD);
447 }
448 }
449 }
450 }
451
452 float[] centers = new float[30];
453 double accum = 0;
454 boolean rising = true;
455
456 void fireParticle(boolean direction) {
457 boolean gotOne = false;
458 for (Particle p : particles) {
459 if (!p.isActive()) {
460 p.trigger(direction);
461 return;
462 }
463 }
464 particles.add(new Particle().trigger(direction));
465 }
466
467 public void run(double deltaMs) {
468 accum += deltaMs / (1000. - 900.*speed.getValuef());
469 for (int i = 0; i < centers.length; ++i) {
470 centers[i] = model.cy + 30*amp.getValuef()*sin((float) (accum + (i-centers.length/2.)/(1. + 9.*period.getValuef())));
471 }
472
473 float zeroDBReference = pow(10, (50 - 190*level.getValuef())/20.);
474 float dB = 20*GraphicEQ.log10(lx.audioInput().mix.level() / zeroDBReference);
475 if (dB > dbValue.getValuef()) {
476 rising = true;
477 dbValue.setRangeFromHereTo(dB, 10).trigger();
478 } else {
479 if (rising) {
480 for (int j = 0; j < pDensity.getValuef()*3; ++j) {
481 fireParticle(true);
482 fireParticle(false);
483 }
484 }
485 rising = false;
486 dbValue.setRangeFromHereTo(max(dB, -96), 50 + 1000*release.getValuef()).trigger();
487 }
488 float edg = 1 + edge.getValuef() * 40;
489 float rng = (78 - 64 * range.getValuef()) / (model.yMax - model.cy);
490 float val = max(2, dbValue.getValuef());
491
492 for (Point p : model.points) {
493 int ci = (int) lerp(0, centers.length-1, (p.x - model.xMin) / (model.xMax - model.xMin));
494 float rFactor = 1.0 - 0.9 * abs(p.x - model.cx) / (model.xMax - model.cx);
495 colors[p.index] = lx.hsb(
496 (lx.getBaseHuef() + abs(p.x - model.cx)) % 360,
497 min(100, 20 + 8*abs(p.y - centers[ci])),
498 constrain(edg*(val*rFactor - rng * abs(p.y-centers[ci])), 0, 100)
499 );
500 }
501
502 for (Particle p : particles) {
503 p.run(deltaMs);
504 }
505 }
506 }
507
508 class BouncyBalls extends SCPattern {
509
510 static final int NUM_BALLS = 6;
511
512 class BouncyBall {
513
514 Accelerator yPos;
515 TriangleLFO xPos = new TriangleLFO(0, model.xMax, random(8000, 19000));
516 float zPos;
517
518 BouncyBall(int i) {
519 addModulator(xPos).setBasis(random(0, TWO_PI)).start();
520 addModulator(yPos = new Accelerator(0, 0, 0));
521 zPos = lerp(model.zMin, model.zMax, (i+2.) / (NUM_BALLS + 4.));
522 }
523
524 void bounce(float midiVel) {
525 float v = 100 + 8*midiVel;
526 yPos.setSpeed(v, getAccel(v, 60 / lx.tempo.bpmf())).start();
527 }
528
529 float getAccel(float v, float oneBeat) {
530 return -2*v / oneBeat;
531 }
532
533 void run(double deltaMs) {
534 float flrLevel = flr.getValuef() * model.xMax/2.;
535 if (yPos.getValuef() < flrLevel) {
536 if (yPos.getVelocity() < -50) {
537 yPos.setValue(2*flrLevel-yPos.getValuef());
538 float v = -yPos.getVelocityf() * bounce.getValuef();
539 yPos.setSpeed(v, getAccel(v, 60 / lx.tempo.bpmf()));
540 } else {
541 yPos.setValue(flrLevel).stop();
542 }
543 }
544 float falloff = 130.f / (12 + blobSize.getValuef() * 36);
545 float xv = xPos.getValuef();
546 float yv = yPos.getValuef();
547
548 for (Point p : model.points) {
549 float d = sqrt((p.x-xv)*(p.x-xv) + (p.y-yv)*(p.y-yv) + .1*(p.z-zPos)*(p.z-zPos));
550 float b = constrain(130 - falloff*d, 0, 100);
551 if (b > 0) {
552 colors[p.index] = blendColor(colors[p.index], lx.hsb(
553 (lx.getBaseHuef() + p.y*.5 + abs(model.cx - p.x) * .5) % 360,
554 max(0, 100 - .45*(p.y - flrLevel)),
555 b
556 ), ADD);
557 }
558 }
559 }
560 }
561
562 final BouncyBall[] balls = new BouncyBall[NUM_BALLS];
563
564 final BasicParameter bounce = new BasicParameter("BNC", .8);
565 final BasicParameter flr = new BasicParameter("FLR", 0);
566 final BasicParameter blobSize = new BasicParameter("SIZE", 0.5);
567
568 BouncyBalls(GLucose glucose) {
569 super(glucose);
570 for (int i = 0; i < balls.length; ++i) {
571 balls[i] = new BouncyBall(i);
572 }
573 addParameter(bounce);
574 addParameter(flr);
575 addParameter(blobSize);
576 }
577
578 public void run(double deltaMs) {
579 setColors(#000000);
580 for (BouncyBall b : balls) {
581 b.run(deltaMs);
582 }
583 }
584
585 public boolean noteOn(Note note) {
586 int pitch = (note.getPitch() + note.getChannel()) % NUM_BALLS;
587 balls[pitch].bounce(note.getVelocity());
588 return true;
589 }
590 }
591
592 class SpaceTime extends SCPattern {
593
594 SinLFO pos = new SinLFO(0, 1, 3000);
595 SinLFO rate = new SinLFO(1000, 9000, 13000);
596 SinLFO falloff = new SinLFO(10, 70, 5000);
597 float angle = 0;
598
599 BasicParameter rateParameter = new BasicParameter("RATE", 0.5);
600 BasicParameter sizeParameter = new BasicParameter("SIZE", 0.5);
601
602
603 public SpaceTime(GLucose glucose) {
604 super(glucose);
605
606 addModulator(pos).trigger();
607 addModulator(rate).trigger();
608 addModulator(falloff).trigger();
609 pos.modulateDurationBy(rate);
610 addParameter(rateParameter);
611 addParameter(sizeParameter);
612 }
613
614 public void onParameterChanged(LXParameter parameter) {
615 if (parameter == rateParameter) {
616 rate.stop().setValue(9000 - 8000*parameter.getValuef());
617 } else if (parameter == sizeParameter) {
618 falloff.stop().setValue(70 - 60*parameter.getValuef());
619 }
620 }
621
622 void run(double deltaMs) {
623 angle += deltaMs * 0.0007;
624 float sVal1 = model.strips.size() * (0.5 + 0.5*sin(angle));
625 float sVal2 = model.strips.size() * (0.5 + 0.5*cos(angle));
626
627 float pVal = pos.getValuef();
628 float fVal = falloff.getValuef();
629
630 int s = 0;
631 for (Strip strip : model.strips) {
632 int i = 0;
633 for (Point p : strip.points) {
634 colors[p.index] = lx.hsb(
635 (lx.getBaseHuef() + 360 - p.x*.2 + p.y * .3) % 360,
636 constrain(.4 * min(abs(s - sVal1), abs(s - sVal2)), 20, 100),
637 max(0, 100 - fVal*abs(i - pVal*(strip.metrics.numPoints - 1)))
638 );
639 ++i;
640 }
641 ++s;
642 }
643 }
644 }
645
646 class Swarm extends SCPattern {
647
648 SawLFO offset = new SawLFO(0, 1, 1000);
649 SinLFO rate = new SinLFO(350, 1200, 63000);
650 SinLFO falloff = new SinLFO(15, 50, 17000);
651 SinLFO fX = new SinLFO(0, model.xMax, 19000);
652 SinLFO fY = new SinLFO(0, model.yMax, 11000);
653 SinLFO hOffX = new SinLFO(0, model.xMax, 13000);
654
655 public Swarm(GLucose glucose) {
656 super(glucose);
657
658 addModulator(offset).trigger();
659 addModulator(rate).trigger();
660 addModulator(falloff).trigger();
661 addModulator(fX).trigger();
662 addModulator(fY).trigger();
663 addModulator(hOffX).trigger();
664 offset.modulateDurationBy(rate);
665 }
666
667 float modDist(float v1, float v2, float mod) {
668 v1 = v1 % mod;
669 v2 = v2 % mod;
670 if (v2 > v1) {
671 return min(v2-v1, v1+mod-v2);
672 }
673 else {
674 return min(v1-v2, v2+mod-v1);
675 }
676 }
677
678 void run(double deltaMs) {
679 float s = 0;
680 for (Strip strip : model.strips ) {
681 int i = 0;
682 for (Point p : strip.points) {
683 float fV = max(-1, 1 - dist(p.x/2., p.y, fX.getValuef()/2., fY.getValuef()) / 64.);
684 colors[p.index] = lx.hsb(
685 (lx.getBaseHuef() + 0.3 * abs(p.x - hOffX.getValuef())) % 360,
686 constrain(80 + 40 * fV, 0, 100),
687 constrain(100 - (30 - fV * falloff.getValuef()) * modDist(i + (s*63)%61, offset.getValuef() * strip.metrics.numPoints, strip.metrics.numPoints), 0, 100)
688 );
689 ++i;
690 }
691 ++s;
692 }
693 }
694 }
695
696 class SwipeTransition extends SCTransition {
697
698 final BasicParameter bleed = new BasicParameter("WIDTH", 0.5);
699
700 SwipeTransition(GLucose glucose) {
701 super(glucose);
702 setDuration(5000);
703 addParameter(bleed);
704 }
705
706 void computeBlend(int[] c1, int[] c2, double progress) {
707 float bleedf = 10 + bleed.getValuef() * 200.;
708 float xPos = (float) (-bleedf + progress * (model.xMax + bleedf));
709 for (Point p : model.points) {
710 float d = (p.x - xPos) / bleedf;
711 if (d < 0) {
712 colors[p.index] = c2[p.index];
713 } else if (d > 1) {
714 colors[p.index] = c1[p.index];
715 } else {
716 colors[p.index] = lerpColor(c2[p.index], c1[p.index], d, RGB);
717 }
718 }
719 }
720 }
721
722 abstract class BlendTransition extends SCTransition {
723
724 final int blendType;
725
726 BlendTransition(GLucose glucose, int blendType) {
727 super(glucose);
728 this.blendType = blendType;
729 }
730
731 void computeBlend(int[] c1, int[] c2, double progress) {
732 if (progress < 0.5) {
733 for (int i = 0; i < c1.length; ++i) {
734 colors[i] = lerpColor(
735 c1[i],
736 blendColor(c1[i], c2[i], blendType),
737 (float) (2.*progress),
738 RGB);
739 }
740 } else {
741 for (int i = 0; i < c1.length; ++i) {
742 colors[i] = lerpColor(
743 c2[i],
744 blendColor(c1[i], c2[i], blendType),
745 (float) (2.*(1. - progress)),
746 RGB);
747 }
748 }
749 }
750 }
751
752 class MultiplyTransition extends BlendTransition {
753 MultiplyTransition(GLucose glucose) {
754 super(glucose, MULTIPLY);
755 }
756 }
757
758 class ScreenTransition extends BlendTransition {
759 ScreenTransition(GLucose glucose) {
760 super(glucose, SCREEN);
761 }
762 }
763
764 class BurnTransition extends BlendTransition {
765 BurnTransition(GLucose glucose) {
766 super(glucose, BURN);
767 }
768 }
769
770 class DodgeTransition extends BlendTransition {
771 DodgeTransition(GLucose glucose) {
772 super(glucose, DODGE);
773 }
774 }
775
776 class OverlayTransition extends BlendTransition {
777 OverlayTransition(GLucose glucose) {
778 super(glucose, OVERLAY);
779 }
780 }
781
782 class AddTransition extends BlendTransition {
783 AddTransition(GLucose glucose) {
784 super(glucose, ADD);
785 }
786 }
787
788 class SubtractTransition extends BlendTransition {
789 SubtractTransition(GLucose glucose) {
790 super(glucose, SUBTRACT);
791 }
792 }
793
794 class SoftLightTransition extends BlendTransition {
795 SoftLightTransition(GLucose glucose) {
796 super(glucose, SOFT_LIGHT);
797 }
798 }
799
800 class BassPod extends SCPattern {
801
802 private GraphicEQ eq = null;
803
804 public BassPod(GLucose glucose) {
805 super(glucose);
806 }
807
808 protected void onActive() {
809 if (eq == null) {
810 eq = new GraphicEQ(lx, 16);
811 eq.slope.setValue(0.6);
812 addParameter(eq.level);
813 addParameter(eq.range);
814 addParameter(eq.attack);
815 addParameter(eq.release);
816 addParameter(eq.slope);
817 }
818 }
819
820 public void run(double deltaMs) {
821 eq.run(deltaMs);
822
823 float bassLevel = eq.getAverageLevel(0, 5);
824
825 for (Point p : model.points) {
826 int avgIndex = (int) constrain(1 + abs(p.x-model.xMax/2.)/(model.xMax/2.)*(eq.numBands-5), 0, eq.numBands-5);
827 float value = 0;
828 for (int i = avgIndex; i < avgIndex + 5; ++i) {
829 value += eq.getLevel(i);
830 }
831 value /= 5.;
832
833 float b = constrain(8 * (value*model.yMax - abs(p.y-model.yMax/2.)), 0, 100);
834 colors[p.index] = lx.hsb(
835 (lx.getBaseHuef() + abs(p.y - model.cy) + abs(p.x - model.cx)) % 360,
836 constrain(bassLevel*240 - .6*dist(p.x, p.y, model.cx, model.cy), 0, 100),
837 b
838 );
839 }
840 }
841 }
842
843
844 class CubeEQ extends SCPattern {
845
846 private GraphicEQ eq = null;
847
848 private final BasicParameter edge = new BasicParameter("EDGE", 0.5);
849 private final BasicParameter clr = new BasicParameter("CLR", 0.5);
850 private final BasicParameter blockiness = new BasicParameter("BLK", 0.5);
851
852 public CubeEQ(GLucose glucose) {
853 super(glucose);
854 }
855
856 protected void onActive() {
857 if (eq == null) {
858 eq = new GraphicEQ(lx, 16);
859 addParameter(eq.level);
860 addParameter(eq.range);
861 addParameter(eq.attack);
862 addParameter(eq.release);
863 addParameter(eq.slope);
864 addParameter(edge);
865 addParameter(clr);
866 addParameter(blockiness);
867 }
868 }
869
870 public void run(double deltaMs) {
871 eq.run(deltaMs);
872
873 float edgeConst = 2 + 30*edge.getValuef();
874 float clrConst = 1.1 + clr.getValuef();
875
876 for (Point p : model.points) {
877 float avgIndex = constrain(2 + p.x / model.xMax * (eq.numBands-4), 0, eq.numBands-4);
878 int avgFloor = (int) avgIndex;
879
880 float leftVal = eq.getLevel(avgFloor);
881 float rightVal = eq.getLevel(avgFloor+1);
882 float smoothValue = lerp(leftVal, rightVal, avgIndex-avgFloor);
883
884 float chunkyValue = (
885 eq.getLevel(avgFloor/4*4) +
886 eq.getLevel(avgFloor/4*4 + 1) +
887 eq.getLevel(avgFloor/4*4 + 2) +
888 eq.getLevel(avgFloor/4*4 + 3)
889 ) / 4.;
890
891 float value = lerp(smoothValue, chunkyValue, blockiness.getValuef());
892
893 float b = constrain(edgeConst * (value*model.yMax - p.y), 0, 100);
894 colors[p.index] = lx.hsb(
895 (480 + lx.getBaseHuef() - min(clrConst*p.y, 120)) % 360,
896 100,
897 b
898 );
899 }
900 }
901 }
902
903 class BoomEffect extends SCEffect {
904
905 final BasicParameter falloff = new BasicParameter("WIDTH", 0.5);
906 final BasicParameter speed = new BasicParameter("SPD", 0.5);
907 final BasicParameter bright = new BasicParameter("BRT", 1.0);
908 final BasicParameter sat = new BasicParameter("SAT", 0.2);
909 List<Layer> layers = new ArrayList<Layer>();
910 final float maxr = sqrt(model.xMax*model.xMax + model.yMax*model.yMax + model.zMax*model.zMax) + 10;
911
912 class Layer {
913 LinearEnvelope boom = new LinearEnvelope(-40, 500, 1300);
914
915 Layer() {
916 addModulator(boom);
917 trigger();
918 }
919
920 void trigger() {
921 float falloffv = falloffv();
922 boom.setRange(-100 / falloffv, maxr + 100/falloffv, 4000 - speed.getValuef() * 3300);
923 boom.trigger();
924 }
925
926 void doApply(int[] colors) {
927 float brightv = 100 * bright.getValuef();
928 float falloffv = falloffv();
929 float satv = sat.getValuef() * 100;
930 float huev = lx.getBaseHuef();
931 for (Point p : model.points) {
932 colors[p.index] = blendColor(
933 colors[p.index],
934 lx.hsb(huev, satv, constrain(brightv - falloffv*abs(boom.getValuef() - dist(p.x, 2*p.y, 3*p.z, model.xMax/2, model.yMax, model.zMax*1.5)), 0, 100)),
935 ADD);
936 }
937 }
938 }
939
940 BoomEffect(GLucose glucose) {
941 super(glucose, true);
942 addParameter(falloff);
943 addParameter(speed);
944 addParameter(bright);
945 addParameter(sat);
946 }
947
948 public void onEnable() {
949 for (Layer l : layers) {
950 if (!l.boom.isRunning()) {
951 l.trigger();
952 return;
953 }
954 }
955 layers.add(new Layer());
956 }
957
958 private float falloffv() {
959 return 20 - 19 * falloff.getValuef();
960 }
961
962 public void onTrigger() {
963 onEnable();
964 }
965
966 public void doApply(int[] colors) {
967 for (Layer l : layers) {
968 if (l.boom.isRunning()) {
969 l.doApply(colors);
970 }
971 }
972 }
973 }
974
975 public class PianoKeyPattern extends SCPattern {
976
977 final LinearEnvelope[] cubeBrt;
978 final SinLFO base[];
979 final BasicParameter attack = new BasicParameter("ATK", 0.1);
980 final BasicParameter release = new BasicParameter("REL", 0.5);
981 final BasicParameter level = new BasicParameter("AMB", 0.6);
982
983 PianoKeyPattern(GLucose glucose) {
984 super(glucose);
985
986 addParameter(attack);
987 addParameter(release);
988 addParameter(level);
989 cubeBrt = new LinearEnvelope[model.cubes.size() / 4];
990 for (int i = 0; i < cubeBrt.length; ++i) {
991 addModulator(cubeBrt[i] = new LinearEnvelope(0, 0, 100));
992 }
993 base = new SinLFO[model.cubes.size() / 12];
994 for (int i = 0; i < base.length; ++i) {
995 addModulator(base[i] = new SinLFO(0, 1, 7000 + 1000*i)).trigger();
996 }
997 }
998
999 private float getAttackTime() {
1000 return 15 + attack.getValuef()*attack.getValuef() * 2000;
1001 }
1002
1003 private float getReleaseTime() {
1004 return 15 + release.getValuef() * 3000;
1005 }
1006
1007 private LinearEnvelope getEnvelope(int index) {
1008 return cubeBrt[index % cubeBrt.length];
1009 }
1010
1011 private SinLFO getBase(int index) {
1012 return base[index % base.length];
1013 }
1014
1015 public boolean noteOn(Note note) {
1016 LinearEnvelope env = getEnvelope(note.getPitch());
1017 env.setEndVal(min(1, env.getValuef() + (note.getVelocity() / 127.)), getAttackTime()).start();
1018 return true;
1019 }
1020
1021 public boolean noteOff(Note note) {
1022 getEnvelope(note.getPitch()).setEndVal(0, getReleaseTime()).start();
1023 return true;
1024 }
1025
1026 public void run(double deltaMs) {
1027 int i = 0;
1028 float huef = lx.getBaseHuef();
1029 float levelf = level.getValuef();
1030 for (Cube c : model.cubes) {
1031 float v = max(getBase(i).getValuef() * levelf/4., getEnvelope(i++).getValuef());
1032 setColor(c, lx.hsb(
1033 (huef + 20*v + abs(c.cx-model.xMax/2.)*.3 + c.cy) % 360,
1034 min(100, 120*v),
1035 100*v
1036 ));
1037 }
1038 }
1039 }
1040
1041 class CrossSections extends SCPattern {
1042
1043 final SinLFO x = new SinLFO(0, model.xMax, 5000);
1044 final SinLFO y = new SinLFO(0, model.yMax, 6000);
1045 final SinLFO z = new SinLFO(0, model.zMax, 7000);
1046
1047 final BasicParameter xw = new BasicParameter("XWID", 0.3);
1048 final BasicParameter yw = new BasicParameter("YWID", 0.3);
1049 final BasicParameter zw = new BasicParameter("ZWID", 0.3);
1050 final BasicParameter xr = new BasicParameter("XRAT", 0.7);
1051 final BasicParameter yr = new BasicParameter("YRAT", 0.6);
1052 final BasicParameter zr = new BasicParameter("ZRAT", 0.5);
1053 final BasicParameter xl = new BasicParameter("XLEV", 1);
1054 final BasicParameter yl = new BasicParameter("YLEV", 1);
1055 final BasicParameter zl = new BasicParameter("ZLEV", 0.5);
1056
1057
1058 CrossSections(GLucose glucose) {
1059 super(glucose);
1060 addModulator(x).trigger();
1061 addModulator(y).trigger();
1062 addModulator(z).trigger();
1063 addParams();
1064 }
1065
1066 protected void addParams() {
1067 addParameter(xr);
1068 addParameter(yr);
1069 addParameter(zr);
1070 addParameter(xw);
1071 addParameter(xl);
1072 addParameter(yl);
1073 addParameter(zl);
1074 addParameter(yw);
1075 addParameter(zw);
1076 }
1077
1078 void onParameterChanged(LXParameter p) {
1079 if (p == xr) {
1080 x.setDuration(10000 - 8800*p.getValuef());
1081 } else if (p == yr) {
1082 y.setDuration(10000 - 9000*p.getValuef());
1083 } else if (p == zr) {
1084 z.setDuration(10000 - 9000*p.getValuef());
1085 }
1086 }
1087
1088 float xv, yv, zv;
1089
1090 protected void updateXYZVals() {
1091 xv = x.getValuef();
1092 yv = y.getValuef();
1093 zv = z.getValuef();
1094 }
1095
1096 public void run(double deltaMs) {
1097 updateXYZVals();
1098
1099 float xlv = 100*xl.getValuef();
1100 float ylv = 100*yl.getValuef();
1101 float zlv = 100*zl.getValuef();
1102
1103 float xwv = 100. / (10 + 40*xw.getValuef());
1104 float ywv = 100. / (10 + 40*yw.getValuef());
1105 float zwv = 100. / (10 + 40*zw.getValuef());
1106
1107 for (Point p : model.points) {
1108 color c = 0;
1109 c = blendColor(c, lx.hsb(
1110 (lx.getBaseHuef() + p.x/10 + p.y/3) % 360,
1111 constrain(140 - 1.1*abs(p.x - model.xMax/2.), 0, 100),
1112 max(0, xlv - xwv*abs(p.x - xv))
1113 ), ADD);
1114 c = blendColor(c, lx.hsb(
1115 (lx.getBaseHuef() + 80 + p.y/10) % 360,
1116 constrain(140 - 2.2*abs(p.y - model.yMax/2.), 0, 100),
1117 max(0, ylv - ywv*abs(p.y - yv))
1118 ), ADD);
1119 c = blendColor(c, lx.hsb(
1120 (lx.getBaseHuef() + 160 + p.z / 10 + p.y/2) % 360,
1121 constrain(140 - 2.2*abs(p.z - model.zMax/2.), 0, 100),
1122 max(0, zlv - zwv*abs(p.z - zv))
1123 ), ADD);
1124 colors[p.index] = c;
1125 }
1126 }
1127 }
1128
1129 class Blinders extends SCPattern {
1130
1131 final SinLFO[] m;
1132 final TriangleLFO r;
1133 final SinLFO s;
1134 final TriangleLFO hs;
1135
1136 public Blinders(GLucose glucose) {
1137 super(glucose);
1138 m = new SinLFO[12];
1139 for (int i = 0; i < m.length; ++i) {
1140 addModulator(m[i] = new SinLFO(0.5, 120, (120000. / (3+i)))).trigger();
1141 }
1142 addModulator(r = new TriangleLFO(9000, 15000, 29000)).trigger();
1143 addModulator(s = new SinLFO(-20, 275, 11000)).trigger();
1144 addModulator(hs = new TriangleLFO(0.1, 0.5, 15000)).trigger();
1145 s.modulateDurationBy(r);
1146 }
1147
1148 public void run(double deltaMs) {
1149 float hv = lx.getBaseHuef();
1150 int si = 0;
1151 for (Strip strip : model.strips) {
1152 int i = 0;
1153 float mv = m[si % m.length].getValuef();
1154 for (Point p : strip.points) {
1155 colors[p.index] = lx.hsb(
1156 (hv + p.z + p.y*hs.getValuef()) % 360,
1157 min(100, abs(p.x - s.getValuef())/2.),
1158 max(0, 100 - mv/2. - mv * abs(i - (strip.metrics.length-1)/2.))
1159 );
1160 ++i;
1161 }
1162 ++si;
1163 }
1164 }
1165 }
1166
1167 class Psychedelia extends SCPattern {
1168
1169 final int NUM = 3;
1170 SinLFO m = new SinLFO(-0.5, NUM-0.5, 9000);
1171 SinLFO s = new SinLFO(-20, 147, 11000);
1172 TriangleLFO h = new TriangleLFO(0, 240, 19000);
1173 SinLFO c = new SinLFO(-.2, .8, 31000);
1174
1175 Psychedelia(GLucose glucose) {
1176 super(glucose);
1177 addModulator(m).trigger();
1178 addModulator(s).trigger();
1179 addModulator(h).trigger();
1180 addModulator(c).trigger();
1181 }
1182
1183 void run(double deltaMs) {
1184 float huev = h.getValuef();
1185 float cv = c.getValuef();
1186 float sv = s.getValuef();
1187 float mv = m.getValuef();
1188 int i = 0;
1189 for (Strip strip : model.strips) {
1190 for (Point p : strip.points) {
1191 colors[p.index] = lx.hsb(
1192 (huev + i*constrain(cv, 0, 2) + p.z/2. + p.x/4.) % 360,
1193 min(100, abs(p.y-sv)),
1194 max(0, 100 - 50*abs((i%NUM) - mv))
1195 );
1196 }
1197 ++i;
1198 }
1199 }
1200 }
1201
1202 class AskewPlanes extends SCPattern {
1203
1204 class Plane {
1205 private final SinLFO a;
1206 private final SinLFO b;
1207 private final SinLFO c;
1208 float av = 1;
1209 float bv = 1;
1210 float cv = 1;
1211 float denom = 0.1;
1212
1213 Plane(int i) {
1214 addModulator(a = new SinLFO(-1, 1, 4000 + 1029*i)).trigger();
1215 addModulator(b = new SinLFO(-1, 1, 11000 - 1104*i)).trigger();
1216 addModulator(c = new SinLFO(-50, 50, 4000 + 1000*i * ((i % 2 == 0) ? 1 : -1))).trigger();
1217 }
1218
1219 void run(double deltaMs) {
1220 av = a.getValuef();
1221 bv = b.getValuef();
1222 cv = c.getValuef();
1223 denom = sqrt(av*av + bv*bv);
1224 }
1225 }
1226
1227 final Plane[] planes;
1228 final int NUM_PLANES = 3;
1229
1230 AskewPlanes(GLucose glucose) {
1231 super(glucose);
1232 planes = new Plane[NUM_PLANES];
1233 for (int i = 0; i < planes.length; ++i) {
1234 planes[i] = new Plane(i);
1235 }
1236 }
1237
1238 public void run(double deltaMs) {
1239 float huev = lx.getBaseHuef();
1240
1241 // This is super fucking bizarre. But if this is a for loop, the framerate
1242 // tanks to like 30FPS, instead of 60. Call them manually and it works fine.
1243 // Doesn't make ANY sense... there must be some weird side effect going on
1244 // with the Processing internals perhaps?
1245 // for (Plane plane : planes) {
1246 // plane.run(deltaMs);
1247 // }
1248 planes[0].run(deltaMs);
1249 planes[1].run(deltaMs);
1250 planes[2].run(deltaMs);
1251
1252 for (Point p : model.points) {
1253 float d = MAX_FLOAT;
1254 for (Plane plane : planes) {
1255 if (plane.denom != 0) {
1256 d = min(d, abs(plane.av*(p.x-model.cx) + plane.bv*(p.y-model.cy) + plane.cv) / plane.denom);
1257 }
1258 }
1259 colors[p.index] = lx.hsb(
1260 (huev + abs(p.x-model.cx)*.3 + p.y*.8) % 360,
1261 max(0, 100 - .8*abs(p.x - model.cx)),
1262 constrain(140 - 10.*d, 0, 100)
1263 );
1264 }
1265 }
1266 }
1267
1268 class ShiftingPlane extends SCPattern {
1269
1270 final SinLFO a = new SinLFO(-.2, .2, 5300);
1271 final SinLFO b = new SinLFO(1, -1, 13300);
1272 final SinLFO c = new SinLFO(-1.4, 1.4, 5700);
1273 final SinLFO d = new SinLFO(-10, 10, 9500);
1274
1275 ShiftingPlane(GLucose glucose) {
1276 super(glucose);
1277 addModulator(a).trigger();
1278 addModulator(b).trigger();
1279 addModulator(c).trigger();
1280 addModulator(d).trigger();
1281 }
1282
1283 public void run(double deltaMs) {
1284 float hv = lx.getBaseHuef();
1285 float av = a.getValuef();
1286 float bv = b.getValuef();
1287 float cv = c.getValuef();
1288 float dv = d.getValuef();
1289 float denom = sqrt(av*av + bv*bv + cv*cv);
1290 for (Point p : model.points) {
1291 float d = abs(av*(p.x-model.cx) + bv*(p.y-model.cy) + cv*(p.z-model.cz) + dv) / denom;
1292 colors[p.index] = lx.hsb(
1293 (hv + abs(p.x-model.cx)*.6 + abs(p.y-model.cy)*.9 + abs(p.z - model.cz)) % 360,
1294 constrain(110 - d*6, 0, 100),
1295 constrain(130 - 7*d, 0, 100)
1296 );
1297 }
1298 }
1299 }
1300
1301 class Traktor extends SCPattern {
1302
1303 final int FRAME_WIDTH = 60;
1304
1305 final BasicParameter speed = new BasicParameter("SPD", 0.5);
1306
1307 private float[] bass = new float[FRAME_WIDTH];
1308 private float[] treble = new float[FRAME_WIDTH];
1309
1310 private int index = 0;
1311 private GraphicEQ eq = null;
1312
1313 public Traktor(GLucose glucose) {
1314 super(glucose);
1315 for (int i = 0; i < FRAME_WIDTH; ++i) {
1316 bass[i] = 0;
1317 treble[i] = 0;
1318 }
1319 addParameter(speed);
1320 }
1321
1322 public void onActive() {
1323 if (eq == null) {
1324 eq = new GraphicEQ(lx, 16);
1325 eq.slope.setValue(0.6);
1326 eq.level.setValue(0.65);
1327 eq.range.setValue(0.35);
1328 eq.release.setValue(0.4);
1329 addParameter(eq.level);
1330 addParameter(eq.range);
1331 addParameter(eq.attack);
1332 addParameter(eq.release);
1333 addParameter(eq.slope);
1334 }
1335 }
1336
1337 int counter = 0;
1338
1339 public void run(double deltaMs) {
1340 eq.run(deltaMs);
1341
1342 int stepThresh = (int) (40 - 39*speed.getValuef());
1343 counter += deltaMs;
1344 if (counter < stepThresh) {
1345 return;
1346 }
1347 counter = counter % stepThresh;
1348
1349 index = (index + 1) % FRAME_WIDTH;
1350
1351 float rawBass = eq.getAverageLevel(0, 4);
1352 float rawTreble = eq.getAverageLevel(eq.numBands-7, 7);
1353
1354 bass[index] = rawBass * rawBass * rawBass * rawBass;
1355 treble[index] = rawTreble * rawTreble;
1356
1357 for (Point p : model.points) {
1358 int i = (int) constrain((model.xMax - p.x) / model.xMax * FRAME_WIDTH, 0, FRAME_WIDTH-1);
1359 int pos = (index + FRAME_WIDTH - i) % FRAME_WIDTH;
1360
1361 colors[p.index] = lx.hsb(
1362 (360 + lx.getBaseHuef() + .8*abs(p.x-model.cx)) % 360,
1363 100,
1364 constrain(9 * (bass[pos]*model.cy - abs(p.y - model.cy + 5)), 0, 100)
1365 );
1366 colors[p.index] = blendColor(colors[p.index], lx.hsb(
1367 (400 + lx.getBaseHuef() + .5*abs(p.x-model.cx)) % 360,
1368 60,
1369 constrain(5 * (treble[pos]*.6*model.cy - abs(p.y - model.cy)), 0, 100)
1370
1371 ), ADD);
1372 }
1373 }
1374 }
1375
1376 class ColorFuckerEffect extends SCEffect {
1377
1378 final BasicParameter level = new BasicParameter("BRT", 1);
1379 final BasicParameter desat = new BasicParameter("DSAT", 0);
1380 final BasicParameter hueShift = new BasicParameter("HSHFT", 0);
1381 final BasicParameter sharp = new BasicParameter("SHARP", 0);
1382 final BasicParameter soft = new BasicParameter("SOFT", 0);
1383 final BasicParameter mono = new BasicParameter("MONO", 0);
1384 final BasicParameter invert = new BasicParameter("INVERT", 0);
1385
1386
1387 float[] hsb = new float[3];
1388
1389 ColorFuckerEffect(GLucose glucose) {
1390 super(glucose);
1391 addParameter(level);
1392 addParameter(desat);
1393 addParameter(sharp);
1394 addParameter(hueShift);
1395 addParameter(soft);
1396 addParameter(mono);
1397 addParameter(invert);
1398 }
1399
1400 public void doApply(int[] colors) {
1401 if (!enabled) {
1402 return;
1403 }
1404 float bMod = level.getValuef();
1405 float sMod = 1 - desat.getValuef();
1406 float hMod = hueShift.getValuef();
1407 float fSharp = 1/(1.0001-sharp.getValuef());
1408 float fSoft = soft.getValuef();
1409 boolean mon = mono.getValuef() > 0.5;
1410 boolean ivt = invert.getValuef() > 0.5;
1411 if (bMod < 1 || sMod < 1 || hMod > 0 || fSharp > 0 || ivt || mon || fSoft > 0) {
1412 for (int i = 0; i < colors.length; ++i) {
1413 lx.RGBtoHSB(colors[i], hsb);
1414 if (mon) {
1415 hsb[0] = lx.getBaseHuef() / 360.;
1416 }
1417 if (ivt) {
1418 hsb[2] = 1 - hsb[2];
1419 }
1420 if (fSharp > 0) {
1421 hsb[2] = hsb[2] < .5 ? pow(hsb[2],fSharp) : 1-pow(1-hsb[2],fSharp);
1422 }
1423 if (fSoft > 0) {
1424 if (hsb[2] > 0.5) {
1425 hsb[2] = lerp(hsb[2], 0.5 + 2 * (hsb[2]-0.5)*(hsb[2]-0.5), fSoft);
1426 } else {
1427 hsb[2] = lerp(hsb[2], 0.5 * sqrt(2*hsb[2]), fSoft);
1428 }
1429 }
1430 colors[i] = lx.hsb(
1431 (360. * hsb[0] + hMod*360.) % 360,
1432 100. * hsb[1] * sMod,
1433 100. * hsb[2] * bMod
1434 );
1435 }
1436 }
1437 }
1438 }
1439
1440 class QuantizeEffect extends SCEffect {
1441
1442 color[] quantizedFrame;
1443 float lastQuant;
1444 final BasicParameter amount = new BasicParameter("AMT", 0);
1445
1446 QuantizeEffect(GLucose glucose) {
1447 super(glucose);
1448 quantizedFrame = new color[glucose.lx.total];
1449 lastQuant = 0;
1450 }
1451
1452 public void doApply(int[] colors) {
1453 float fQuant = amount.getValuef();
1454 if (fQuant > 0) {
1455 float tRamp = (lx.tempo.rampf() % (1./pow(2,floor((1-fQuant) * 4))));
1456 float f = lastQuant;
1457 lastQuant = tRamp;
1458 if (tRamp > f) {
1459 for (int i = 0; i < colors.length; ++i) {
1460 colors[i] = quantizedFrame[i];
1461 }
1462 return;
1463 }
1464 }
1465 for (int i = 0; i < colors.length; ++i) {
1466 quantizedFrame[i] = colors[i];
1467 }
1468 }
1469 }
1470
1471 class BlurEffect extends SCEffect {
1472
1473 final LXParameter amount = new BasicParameter("AMT", 0);
1474 final int[] frame;
1475 final LinearEnvelope env = new LinearEnvelope(0, 1, 100);
1476
1477 BlurEffect(GLucose glucose) {
1478 super(glucose);
1479 addParameter(amount);
1480 addModulator(env);
1481 frame = new int[lx.total];
1482 for (int i = 0; i < frame.length; ++i) {
1483 frame[i] = #000000;
1484 }
1485 }
1486
1487 public void onEnable() {
1488 env.setRangeFromHereTo(1, 400).start();
1489 for (int i = 0; i < frame.length; ++i) {
1490 frame[i] = #000000;
1491 }
1492 }
1493
1494 public void onDisable() {
1495 env.setRangeFromHereTo(0, 1000).start();
1496 }
1497
1498 public void doApply(int[] colors) {
1499 float amt = env.getValuef() * amount.getValuef();
1500 if (amt > 0) {
1501 amt = (1 - amt);
1502 amt = 1 - (amt*amt*amt);
1503 for (int i = 0; i < colors.length; ++i) {
1504 // frame[i] = colors[i] = blendColor(colors[i], lerpColor(#000000, frame[i], amt, RGB), SCREEN);
1505 frame[i] = colors[i] = lerpColor(colors[i], blendColor(colors[i], frame[i], SCREEN), amt, RGB);
1506 }
1507 }
1508
1509 }
1510 }