Restore normal scroll wheel speed (does Dan have a really slow mouse?)
[SugarCubes.git] / MarkSlee.pde
CommitLineData
0137237d
MS
1class Pulley extends SCPattern {
2
3 final int NUM_DIVISIONS = 16;
4 private final Accelerator[] gravity = new Accelerator[NUM_DIVISIONS];
5 private final Click[] delays = new Click[NUM_DIVISIONS];
6
7 private final Click reset = new Click(9000);
8 private boolean isRising = false;
9
10 Pulley(GLucose glucose) {
11 super(glucose);
12 for (int i = 0; i < NUM_DIVISIONS; ++i) {
13 addModulator(gravity[i] = new Accelerator(0, 0, 0));
14 addModulator(delays[i] = new Click(0));
15 }
16 addModulator(reset).start();
17 trigger();
18 }
19
20 private void trigger() {
21 isRising = !isRising;
22 int i = 0;
23 for (Accelerator g : gravity) {
24 if (isRising) {
25 g.setSpeed(random(40, 50), 0).start();
26 } else {
27 g.setVelocity(0).setAcceleration(-420);
28 delays[i].setDuration(random(0, 500)).trigger();
29 }
30 ++i;
31 }
32 }
33
34 public void run(double deltaMs) {
35 if (reset.click()) {
36 trigger();
37 }
38 int j = 0;
39 for (Click d : delays) {
40 if (d.click()) {
41 gravity[j].start();
42 d.stop();
43 }
44 ++j;
45 }
46
47 for (Accelerator g : gravity) {
48 if (isRising) {
49 if (g.getValuef() > model.yMax) {
50 g.stop();
51 } else if (g.getValuef() > model.yMax*.55) {
52 if (g.getVelocityf() > 10) {
53 g.setAcceleration(-16);
54 } else {
55 g.setAcceleration(0);
56 }
57 }
58 } else {
59 if (g.getValuef() < 0) {
60 g.setValue(-g.getValuef());
61 g.setVelocity(-g.getVelocityf() * random(0.74, 0.84));
62 }
63 }
64 }
65
66 for (Point p : model.points) {
67 int i = (int) constrain((p.x - model.xMin) * NUM_DIVISIONS / (model.xMax - model.xMin), 0, NUM_DIVISIONS-1);
68 colors[p.index] = color(
69 (lx.getBaseHuef() + abs(p.x - model.cx)*.8 + p.y*.4) % 360,
70 constrain(130 - p.y*.8, 0, 100),
71 max(0, 100 - abs(p.y - gravity[i].getValuef())*4.)
72 );
73 }
74 }
75}
76
4760e696
MS
77class ViolinWave extends SCPattern {
78
79 BasicParameter level = new BasicParameter("LVL", 0.45);
80 BasicParameter range = new BasicParameter("RNG", 0.5);
81 BasicParameter edge = new BasicParameter("EDG", 0.5);
82 BasicParameter release = new BasicParameter("RLS", 0.5);
83 BasicParameter speed = new BasicParameter("SPD", 0.5);
84 BasicParameter amp = new BasicParameter("AMP", 0.25);
85 BasicParameter period = new BasicParameter("WAVE", 0.5);
86 BasicParameter pSize = new BasicParameter("PSIZE", 0.5);
87 BasicParameter pSpeed = new BasicParameter("PSPD", 0.5);
88 BasicParameter pDensity = new BasicParameter("PDENS", 0.25);
89
90 LinearEnvelope dbValue = new LinearEnvelope(0, 0, 10);
91
92 ViolinWave(GLucose glucose) {
93 super(glucose);
94 addParameter(level);
95 addParameter(edge);
96 addParameter(range);
97 addParameter(release);
98 addParameter(speed);
99 addParameter(amp);
100 addParameter(period);
101 addParameter(pSize);
102 addParameter(pSpeed);
103 addParameter(pDensity);
104
105 addModulator(dbValue);
106 }
107
108 final List<Particle> particles = new ArrayList<Particle>();
109
110 class Particle {
111
112 LinearEnvelope x = new LinearEnvelope(0, 0, 0);
113 LinearEnvelope y = new LinearEnvelope(0, 0, 0);
114
115 Particle() {
116 addModulator(x);
117 addModulator(y);
118 }
119
120 Particle trigger(boolean direction) {
121 float xInit = random(model.xMin, model.xMax);
122 float time = 3000 - 2500*pSpeed.getValuef();
123 x.setRange(xInit, xInit + random(-40, 40), time).trigger();
124 y.setRange(model.cy + 10, direction ? model.yMax + 50 : model.yMin - 50, time).trigger();
125 return this;
126 }
127
128 boolean isActive() {
129 return x.isRunning() || y.isRunning();
130 }
131
132 public void run(double deltaMs) {
133 if (!isActive()) {
134 return;
135 }
136
137 float pFalloff = (30 - 27*pSize.getValuef());
138 for (Point p : model.points) {
139 float b = 100 - pFalloff * (abs(p.x - x.getValuef()) + abs(p.y - y.getValuef()));
140 if (b > 0) {
141 colors[p.index] = blendColor(colors[p.index], color(
142 lx.getBaseHuef(), 20, b
143 ), ADD);
144 }
145 }
146 }
147 }
148
149 float[] centers = new float[30];
150 double accum = 0;
151 boolean rising = true;
152
153 void fireParticle(boolean direction) {
154 boolean gotOne = false;
155 for (Particle p : particles) {
156 if (!p.isActive()) {
157 p.trigger(direction);
158 return;
159 }
160 }
161 particles.add(new Particle().trigger(direction));
162 }
163
164 public void run(double deltaMs) {
165 accum += deltaMs / (1000. - 900.*speed.getValuef());
166 for (int i = 0; i < centers.length; ++i) {
167 centers[i] = model.cy + 30*amp.getValuef()*sin((float) (accum + (i-centers.length/2.)/(1. + 9.*period.getValuef())));
168 }
169
170 float zeroDBReference = pow(10, (50 - 190*level.getValuef())/20.);
171 float dB = 20*GraphicEQ.log10(lx.audioInput().mix.level() / zeroDBReference);
172 if (dB > dbValue.getValuef()) {
173 rising = true;
174 dbValue.setRangeFromHereTo(dB, 10).trigger();
175 } else {
176 if (rising) {
177 for (int j = 0; j < pDensity.getValuef()*3; ++j) {
178 fireParticle(true);
179 fireParticle(false);
180 }
181 }
182 rising = false;
183 dbValue.setRangeFromHereTo(max(dB, -96), 50 + 1000*release.getValuef()).trigger();
184 }
185 float edg = 1 + edge.getValuef() * 40;
186 float rng = (78 - 64 * range.getValuef()) / (model.yMax - model.cy);
187 float val = max(2, dbValue.getValuef());
188
189 for (Point p : model.points) {
190 int ci = (int) lerp(0, centers.length-1, (p.x - model.xMin) / (model.xMax - model.xMin));
191 float rFactor = 1.0 - 0.9 * abs(p.x - model.cx) / (model.xMax - model.cx);
192 colors[p.index] = color(
193 (lx.getBaseHuef() + abs(p.x - model.cx)) % 360,
194 min(100, 20 + 8*abs(p.y - centers[ci])),
195 constrain(edg*(val*rFactor - rng * abs(p.y-centers[ci])), 0, 100)
196 );
197 }
198
199 for (Particle p : particles) {
200 p.run(deltaMs);
201 }
202 }
203}
204
d1dcc4b5 205class BouncyBalls extends SCPattern {
cc8b3f82 206
d1dcc4b5 207 static final int NUM_BALLS = 6;
cc8b3f82 208
d1dcc4b5 209 class BouncyBall {
cc8b3f82
MS
210
211 Accelerator yPos;
212 TriangleLFO xPos = new TriangleLFO(0, model.xMax, random(8000, 19000));
d1dcc4b5 213 float zPos;
cc8b3f82 214
d1dcc4b5 215 BouncyBall(int i) {
cc8b3f82
MS
216 addModulator(xPos).setBasis(random(0, TWO_PI)).start();
217 addModulator(yPos = new Accelerator(0, 0, 0));
d1dcc4b5 218 zPos = lerp(model.zMin, model.zMax, (i+2.) / (NUM_BALLS + 4.));
cc8b3f82
MS
219 }
220
221 void bounce(float midiVel) {
222 float v = 100 + 8*midiVel;
223 yPos.setSpeed(v, getAccel(v, 60 / lx.tempo.bpmf())).start();
224 }
225
226 float getAccel(float v, float oneBeat) {
227 return -2*v / oneBeat;
228 }
229
230 void run(double deltaMs) {
231 float flrLevel = flr.getValuef() * model.xMax/2.;
232 if (yPos.getValuef() < flrLevel) {
233 if (yPos.getVelocity() < -50) {
234 yPos.setValue(2*flrLevel-yPos.getValuef());
235 float v = -yPos.getVelocityf() * bounce.getValuef();
236 yPos.setSpeed(v, getAccel(v, 60 / lx.tempo.bpmf()));
237 } else {
238 yPos.setValue(flrLevel).stop();
239 }
240 }
241 float falloff = 130.f / (12 + blobSize.getValuef() * 36);
d1dcc4b5
MS
242 float xv = xPos.getValuef();
243 float yv = yPos.getValuef();
244
cc8b3f82 245 for (Point p : model.points) {
d1dcc4b5 246 float d = sqrt((p.x-xv)*(p.x-xv) + (p.y-yv)*(p.y-yv) + .1*(p.z-zPos)*(p.z-zPos));
cc8b3f82
MS
247 float b = constrain(130 - falloff*d, 0, 100);
248 if (b > 0) {
249 colors[p.index] = blendColor(colors[p.index], color(
250 (lx.getBaseHuef() + p.y*.5 + abs(model.cx - p.x) * .5) % 360,
251 max(0, 100 - .45*(p.y - flrLevel)),
252 b
253 ), ADD);
254 }
255 }
256 }
257 }
258
d1dcc4b5 259 final BouncyBall[] balls = new BouncyBall[NUM_BALLS];
cc8b3f82
MS
260
261 final BasicParameter bounce = new BasicParameter("BNC", .8);
262 final BasicParameter flr = new BasicParameter("FLR", 0);
263 final BasicParameter blobSize = new BasicParameter("SIZE", 0.5);
264
d1dcc4b5 265 BouncyBalls(GLucose glucose) {
cc8b3f82 266 super(glucose);
d1dcc4b5
MS
267 for (int i = 0; i < balls.length; ++i) {
268 balls[i] = new BouncyBall(i);
cc8b3f82
MS
269 }
270 addParameter(bounce);
271 addParameter(flr);
272 addParameter(blobSize);
273 }
274
275 public void run(double deltaMs) {
276 setColors(#000000);
d1dcc4b5
MS
277 for (BouncyBall b : balls) {
278 b.run(deltaMs);
cc8b3f82
MS
279 }
280 }
281
282 public boolean noteOnReceived(Note note) {
d1dcc4b5
MS
283 int pitch = (note.getPitch() + note.getChannel()) % NUM_BALLS;
284 balls[pitch].bounce(note.getVelocity());
cc8b3f82
MS
285 return true;
286 }
287}
288
49815cc0
MS
289class SpaceTime extends SCPattern {
290
3e8e60d8 291 SinLFO pos = new SinLFO(0, 1, 3000);
49815cc0
MS
292 SinLFO rate = new SinLFO(1000, 9000, 13000);
293 SinLFO falloff = new SinLFO(10, 70, 5000);
3f8be614
MS
294 float angle = 0;
295
296 BasicParameter rateParameter = new BasicParameter("RATE", 0.5);
297 BasicParameter sizeParameter = new BasicParameter("SIZE", 0.5);
49815cc0 298
3e8e60d8 299
49815cc0
MS
300 public SpaceTime(GLucose glucose) {
301 super(glucose);
3e8e60d8 302
49815cc0
MS
303 addModulator(pos).trigger();
304 addModulator(rate).trigger();
305 addModulator(falloff).trigger();
306 pos.modulateDurationBy(rate);
3f8be614
MS
307 addParameter(rateParameter);
308 addParameter(sizeParameter);
49815cc0 309 }
3f8be614
MS
310
311 public void onParameterChanged(LXParameter parameter) {
312 if (parameter == rateParameter) {
313 rate.stop().setValue(9000 - 8000*parameter.getValuef());
314 } else if (parameter == sizeParameter) {
315 falloff.stop().setValue(70 - 60*parameter.getValuef());
49815cc0
MS
316 }
317 }
318
34327c96 319 void run(double deltaMs) {
3f8be614 320 angle += deltaMs * 0.0007;
87f6fa39
MS
321 float sVal1 = model.strips.size() * (0.5 + 0.5*sin(angle));
322 float sVal2 = model.strips.size() * (0.5 + 0.5*cos(angle));
49815cc0
MS
323
324 float pVal = pos.getValuef();
325 float fVal = falloff.getValuef();
326
327 int s = 0;
cfc57fca 328 for (Strip strip : model.strips) {
49815cc0
MS
329 int i = 0;
330 for (Point p : strip.points) {
331 colors[p.index] = color(
3e8e60d8
MS
332 (lx.getBaseHuef() + 360 - p.fx*.2 + p.fy * .3) % 360,
333 constrain(.4 * min(abs(s - sVal1), abs(s - sVal2)), 20, 100),
334 max(0, 100 - fVal*abs(i - pVal*(strip.metrics.numPoints - 1)))
335 );
49815cc0
MS
336 ++i;
337 }
3f8be614 338 ++s;
49815cc0
MS
339 }
340 }
341}
342
343class Swarm extends SCPattern {
344
3e8e60d8 345 SawLFO offset = new SawLFO(0, 1, 1000);
49815cc0
MS
346 SinLFO rate = new SinLFO(350, 1200, 63000);
347 SinLFO falloff = new SinLFO(15, 50, 17000);
c39f7a04
MS
348 SinLFO fX = new SinLFO(0, model.xMax, 19000);
349 SinLFO fY = new SinLFO(0, model.yMax, 11000);
350 SinLFO hOffX = new SinLFO(0, model.xMax, 13000);
49815cc0
MS
351
352 public Swarm(GLucose glucose) {
353 super(glucose);
3e8e60d8 354
49815cc0
MS
355 addModulator(offset).trigger();
356 addModulator(rate).trigger();
357 addModulator(falloff).trigger();
2b6688e8 358 addModulator(fX).trigger();
49815cc0 359 addModulator(fY).trigger();
2b6688e8 360 addModulator(hOffX).trigger();
49815cc0
MS
361 offset.modulateDurationBy(rate);
362 }
363
364 float modDist(float v1, float v2, float mod) {
365 v1 = v1 % mod;
366 v2 = v2 % mod;
367 if (v2 > v1) {
368 return min(v2-v1, v1+mod-v2);
369 }
370 else {
371 return min(v1-v2, v2+mod-v1);
372 }
373 }
374
34327c96 375 void run(double deltaMs) {
49815cc0 376 float s = 0;
cfc57fca 377 for (Strip strip : model.strips ) {
49815cc0
MS
378 int i = 0;
379 for (Point p : strip.points) {
2b6688e8 380 float fV = max(-1, 1 - dist(p.fx/2., p.fy, fX.getValuef()/2., fY.getValuef()) / 64.);
49815cc0 381 colors[p.index] = color(
2b6688e8 382 (lx.getBaseHuef() + 0.3 * abs(p.fx - hOffX.getValuef())) % 360,
49815cc0 383 constrain(80 + 40 * fV, 0, 100),
34327c96 384 constrain(100 - (30 - fV * falloff.getValuef()) * modDist(i + (s*63)%61, offset.getValuef() * strip.metrics.numPoints, strip.metrics.numPoints), 0, 100)
49815cc0
MS
385 );
386 ++i;
387 }
388 ++s;
389 }
390 }
391}
392
393class SwipeTransition extends SCTransition {
3f8be614
MS
394
395 final BasicParameter bleed = new BasicParameter("WIDTH", 0.5);
396
49815cc0
MS
397 SwipeTransition(GLucose glucose) {
398 super(glucose);
399 setDuration(5000);
3f8be614 400 addParameter(bleed);
49815cc0
MS
401 }
402
403 void computeBlend(int[] c1, int[] c2, double progress) {
3f8be614 404 float bleedf = 10 + bleed.getValuef() * 200.;
c39f7a04 405 float xPos = (float) (-bleedf + progress * (model.xMax + bleedf));
87f6fa39 406 for (Point p : model.points) {
2b6688e8 407 float d = (p.fx - xPos) / bleedf;
49815cc0
MS
408 if (d < 0) {
409 colors[p.index] = c2[p.index];
2b6688e8 410 } else if (d > 1) {
49815cc0 411 colors[p.index] = c1[p.index];
2b6688e8 412 } else {
49815cc0
MS
413 colors[p.index] = lerpColor(c2[p.index], c1[p.index], d, RGB);
414 }
415 }
416 }
417}
418
fe30b226 419abstract class BlendTransition extends SCTransition {
ed149627 420
fe30b226
MS
421 final int blendType;
422
423 BlendTransition(GLucose glucose, int blendType) {
ed149627 424 super(glucose);
fe30b226 425 this.blendType = blendType;
ed149627
MS
426 }
427
428 void computeBlend(int[] c1, int[] c2, double progress) {
429 if (progress < 0.5) {
430 for (int i = 0; i < c1.length; ++i) {
431 colors[i] = lerpColor(
432 c1[i],
fe30b226 433 blendColor(c1[i], c2[i], blendType),
ed149627
MS
434 (float) (2.*progress),
435 RGB);
436 }
437 } else {
438 for (int i = 0; i < c1.length; ++i) {
439 colors[i] = lerpColor(
440 c2[i],
fe30b226 441 blendColor(c1[i], c2[i], blendType),
ed149627
MS
442 (float) (2.*(1. - progress)),
443 RGB);
444 }
445 }
446 }
447}
448
fe30b226
MS
449class MultiplyTransition extends BlendTransition {
450 MultiplyTransition(GLucose glucose) {
451 super(glucose, MULTIPLY);
452 }
453}
454
455class ScreenTransition extends BlendTransition {
456 ScreenTransition(GLucose glucose) {
457 super(glucose, SCREEN);
458 }
459}
460
461class BurnTransition extends BlendTransition {
462 BurnTransition(GLucose glucose) {
463 super(glucose, BURN);
464 }
465}
466
467class DodgeTransition extends BlendTransition {
468 DodgeTransition(GLucose glucose) {
469 super(glucose, DODGE);
470 }
471}
472
473class OverlayTransition extends BlendTransition {
474 OverlayTransition(GLucose glucose) {
475 super(glucose, OVERLAY);
476 }
477}
478
479class AddTransition extends BlendTransition {
480 AddTransition(GLucose glucose) {
481 super(glucose, ADD);
482 }
483}
484
485class SubtractTransition extends BlendTransition {
486 SubtractTransition(GLucose glucose) {
487 super(glucose, SUBTRACT);
488 }
489}
490
491class SoftLightTransition extends BlendTransition {
492 SoftLightTransition(GLucose glucose) {
493 super(glucose, SOFT_LIGHT);
494 }
495}
ed149627 496
4c006f7b
MS
497class BassPod extends SCPattern {
498
499 private GraphicEQ eq = null;
500
501 public BassPod(GLucose glucose) {
502 super(glucose);
503 }
504
505 protected void onActive() {
506 if (eq == null) {
507 eq = new GraphicEQ(lx, 16);
508 eq.slope.setValue(0.6);
509 addParameter(eq.level);
510 addParameter(eq.range);
511 addParameter(eq.attack);
512 addParameter(eq.release);
513 addParameter(eq.slope);
514 }
515 }
516
34327c96 517 public void run(double deltaMs) {
4c006f7b
MS
518 eq.run(deltaMs);
519
520 float bassLevel = eq.getAverageLevel(0, 5);
521
522 for (Point p : model.points) {
523 int avgIndex = (int) constrain(1 + abs(p.fx-model.xMax/2.)/(model.xMax/2.)*(eq.numBands-5), 0, eq.numBands-5);
524 float value = 0;
525 for (int i = avgIndex; i < avgIndex + 5; ++i) {
526 value += eq.getLevel(i);
527 }
528 value /= 5.;
529
530 float b = constrain(8 * (value*model.yMax - abs(p.fy-model.yMax/2.)), 0, 100);
531 colors[p.index] = color(
532 (lx.getBaseHuef() + abs(p.fy - model.cy) + abs(p.fx - model.cx)) % 360,
533 constrain(bassLevel*240 - .6*dist(p.fx, p.fy, model.cx, model.cy), 0, 100),
534 b
535 );
536 }
537 }
538}
539
540
49815cc0
MS
541class CubeEQ extends SCPattern {
542
4c006f7b 543 private GraphicEQ eq = null;
49815cc0 544
3f8be614 545 private final BasicParameter edge = new BasicParameter("EDGE", 0.5);
3f8be614 546 private final BasicParameter clr = new BasicParameter("CLR", 0.5);
4c006f7b 547 private final BasicParameter blockiness = new BasicParameter("BLK", 0.5);
49815cc0
MS
548
549 public CubeEQ(GLucose glucose) {
550 super(glucose);
49815cc0 551 }
3f8be614 552
49815cc0 553 protected void onActive() {
4c006f7b
MS
554 if (eq == null) {
555 eq = new GraphicEQ(lx, 16);
556 addParameter(eq.level);
557 addParameter(eq.range);
558 addParameter(eq.attack);
559 addParameter(eq.release);
560 addParameter(eq.slope);
561 addParameter(edge);
562 addParameter(clr);
563 addParameter(blockiness);
49815cc0
MS
564 }
565 }
566
34327c96 567 public void run(double deltaMs) {
4c006f7b 568 eq.run(deltaMs);
3f8be614 569
4c006f7b 570 float edgeConst = 2 + 30*edge.getValuef();
49815cc0
MS
571 float clrConst = 1.1 + clr.getValuef();
572
87f6fa39 573 for (Point p : model.points) {
4c006f7b 574 float avgIndex = constrain(2 + p.fx / model.xMax * (eq.numBands-4), 0, eq.numBands-4);
49815cc0 575 int avgFloor = (int) avgIndex;
3f8be614 576
4c006f7b
MS
577 float leftVal = eq.getLevel(avgFloor);
578 float rightVal = eq.getLevel(avgFloor+1);
579 float smoothValue = lerp(leftVal, rightVal, avgIndex-avgFloor);
580
581 float chunkyValue = (
582 eq.getLevel(avgFloor/4*4) +
583 eq.getLevel(avgFloor/4*4 + 1) +
584 eq.getLevel(avgFloor/4*4 + 2) +
585 eq.getLevel(avgFloor/4*4 + 3)
586 ) / 4.;
587
588 float value = lerp(smoothValue, chunkyValue, blockiness.getValuef());
589
590 float b = constrain(edgeConst * (value*model.yMax - p.fy), 0, 100);
49815cc0 591 colors[p.index] = color(
4c006f7b
MS
592 (480 + lx.getBaseHuef() - min(clrConst*p.fy, 120)) % 360,
593 100,
594 b
595 );
3f8be614
MS
596 }
597 }
598}
599
600class BoomEffect extends SCEffect {
601
602 final BasicParameter falloff = new BasicParameter("WIDTH", 0.5);
603 final BasicParameter speed = new BasicParameter("SPD", 0.5);
604 final BasicParameter bright = new BasicParameter("BRT", 1.0);
605 final BasicParameter sat = new BasicParameter("SAT", 0.2);
606 List<Layer> layers = new ArrayList<Layer>();
c39f7a04 607 final float maxr = sqrt(model.xMax*model.xMax + model.yMax*model.yMax + model.zMax*model.zMax) + 10;
3f8be614
MS
608
609 class Layer {
610 LinearEnvelope boom = new LinearEnvelope(-40, 500, 1300);
611
612 Layer() {
613 addModulator(boom);
614 trigger();
615 }
616
617 void trigger() {
618 float falloffv = falloffv();
2b6688e8 619 boom.setRange(-100 / falloffv, maxr + 100/falloffv, 4000 - speed.getValuef() * 3300);
3f8be614
MS
620 boom.trigger();
621 }
622
623 void doApply(int[] colors) {
624 float brightv = 100 * bright.getValuef();
625 float falloffv = falloffv();
626 float satv = sat.getValuef() * 100;
627 float huev = lx.getBaseHuef();
87f6fa39 628 for (Point p : model.points) {
3f8be614
MS
629 colors[p.index] = blendColor(
630 colors[p.index],
c39f7a04 631 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)),
3f8be614
MS
632 ADD);
633 }
634 }
635 }
636
637 BoomEffect(GLucose glucose) {
638 super(glucose, true);
639 addParameter(falloff);
640 addParameter(speed);
641 addParameter(bright);
642 addParameter(sat);
643 }
644
645 public void onEnable() {
646 for (Layer l : layers) {
647 if (!l.boom.isRunning()) {
648 l.trigger();
649 return;
650 }
651 }
652 layers.add(new Layer());
653 }
654
655 private float falloffv() {
656 return 20 - 19 * falloff.getValuef();
657 }
658
659 public void onTrigger() {
660 onEnable();
661 }
662
663 public void doApply(int[] colors) {
664 for (Layer l : layers) {
665 if (l.boom.isRunning()) {
666 l.doApply(colors);
667 }
49815cc0
MS
668 }
669 }
670}
671
5d70e4d7
MS
672public class PianoKeyPattern extends SCPattern {
673
674 final LinearEnvelope[] cubeBrt;
675 final SinLFO base[];
676 final BasicParameter attack = new BasicParameter("ATK", 0.1);
677 final BasicParameter release = new BasicParameter("REL", 0.5);
678 final BasicParameter level = new BasicParameter("AMB", 0.6);
679
680 PianoKeyPattern(GLucose glucose) {
681 super(glucose);
a8d55ade 682
5d70e4d7
MS
683 addParameter(attack);
684 addParameter(release);
685 addParameter(level);
87f6fa39 686 cubeBrt = new LinearEnvelope[model.cubes.size() / 4];
5d70e4d7
MS
687 for (int i = 0; i < cubeBrt.length; ++i) {
688 addModulator(cubeBrt[i] = new LinearEnvelope(0, 0, 100));
689 }
87f6fa39 690 base = new SinLFO[model.cubes.size() / 12];
5d70e4d7
MS
691 for (int i = 0; i < base.length; ++i) {
692 addModulator(base[i] = new SinLFO(0, 1, 7000 + 1000*i)).trigger();
693 }
694 }
695
696 private float getAttackTime() {
697 return 15 + attack.getValuef()*attack.getValuef() * 2000;
698 }
699
700 private float getReleaseTime() {
701 return 15 + release.getValuef() * 3000;
702 }
703
704 private LinearEnvelope getEnvelope(int index) {
705 return cubeBrt[index % cubeBrt.length];
706 }
707
708 private SinLFO getBase(int index) {
709 return base[index % base.length];
710 }
711
d6ac1ee8 712 public boolean noteOnReceived(Note note) {
5d70e4d7
MS
713 LinearEnvelope env = getEnvelope(note.getPitch());
714 env.setEndVal(min(1, env.getValuef() + (note.getVelocity() / 127.)), getAttackTime()).start();
d6ac1ee8 715 return true;
5d70e4d7
MS
716 }
717
d6ac1ee8 718 public boolean noteOffReceived(Note note) {
5d70e4d7 719 getEnvelope(note.getPitch()).setEndVal(0, getReleaseTime()).start();
d6ac1ee8 720 return true;
5d70e4d7
MS
721 }
722
34327c96 723 public void run(double deltaMs) {
5d70e4d7
MS
724 int i = 0;
725 float huef = lx.getBaseHuef();
726 float levelf = level.getValuef();
87f6fa39 727 for (Cube c : model.cubes) {
5d70e4d7
MS
728 float v = max(getBase(i).getValuef() * levelf/4., getEnvelope(i++).getValuef());
729 setColor(c, color(
e0cea600 730 (huef + 20*v + abs(c.cx-model.xMax/2.)*.3 + c.cy) % 360,
5d70e4d7
MS
731 min(100, 120*v),
732 100*v
733 ));
734 }
735 }
736}
737
0106b29c
MS
738class CrossSections extends SCPattern {
739
c39f7a04
MS
740 final SinLFO x = new SinLFO(0, model.xMax, 5000);
741 final SinLFO y = new SinLFO(0, model.yMax, 6000);
742 final SinLFO z = new SinLFO(0, model.zMax, 7000);
0106b29c
MS
743
744 final BasicParameter xw = new BasicParameter("XWID", 0.3);
745 final BasicParameter yw = new BasicParameter("YWID", 0.3);
746 final BasicParameter zw = new BasicParameter("ZWID", 0.3);
2b6688e8 747 final BasicParameter xr = new BasicParameter("XRAT", 0.7);
0106b29c 748 final BasicParameter yr = new BasicParameter("YRAT", 0.6);
2b6688e8
MS
749 final BasicParameter zr = new BasicParameter("ZRAT", 0.5);
750 final BasicParameter xl = new BasicParameter("XLEV", 1);
0106b29c 751 final BasicParameter yl = new BasicParameter("YLEV", 1);
2b6688e8 752 final BasicParameter zl = new BasicParameter("ZLEV", 0.5);
0106b29c
MS
753
754
755 CrossSections(GLucose glucose) {
756 super(glucose);
757 addModulator(x).trigger();
758 addModulator(y).trigger();
759 addModulator(z).trigger();
b12bca62
MS
760 addParams();
761 }
762
763 protected void addParams() {
0106b29c
MS
764 addParameter(xr);
765 addParameter(yr);
766 addParameter(zr);
2b6688e8 767 addParameter(xw);
0106b29c
MS
768 addParameter(xl);
769 addParameter(yl);
770 addParameter(zl);
2b6688e8
MS
771 addParameter(yw);
772 addParameter(zw);
0106b29c 773 }
3e8e60d8
MS
774
775 void onParameterChanged(LXParameter p) {
0106b29c 776 if (p == xr) {
2b6688e8 777 x.setDuration(10000 - 8800*p.getValuef());
0106b29c 778 } else if (p == yr) {
2b6688e8 779 y.setDuration(10000 - 9000*p.getValuef());
0106b29c
MS
780 } else if (p == zr) {
781 z.setDuration(10000 - 9000*p.getValuef());
782 }
0106b29c 783 }
b12bca62
MS
784
785 float xv, yv, zv;
786
787 protected void updateXYZVals() {
788 xv = x.getValuef();
789 yv = y.getValuef();
790 zv = z.getValuef();
791 }
0106b29c 792
34327c96 793 public void run(double deltaMs) {
f1c74267
MS
794 updateXYZVals();
795
0106b29c
MS
796 float xlv = 100*xl.getValuef();
797 float ylv = 100*yl.getValuef();
798 float zlv = 100*zl.getValuef();
799
800 float xwv = 100. / (10 + 40*xw.getValuef());
801 float ywv = 100. / (10 + 40*yw.getValuef());
802 float zwv = 100. / (10 + 40*zw.getValuef());
803
87f6fa39 804 for (Point p : model.points) {
0106b29c
MS
805 color c = 0;
806 c = blendColor(c, color(
2b6688e8 807 (lx.getBaseHuef() + p.fx/10 + p.fy/3) % 360,
c39f7a04 808 constrain(140 - 1.1*abs(p.fx - model.xMax/2.), 0, 100),
2b6688e8 809 max(0, xlv - xwv*abs(p.fx - xv))
0106b29c
MS
810 ), ADD);
811 c = blendColor(c, color(
2b6688e8 812 (lx.getBaseHuef() + 80 + p.fy/10) % 360,
c39f7a04 813 constrain(140 - 2.2*abs(p.fy - model.yMax/2.), 0, 100),
2b6688e8 814 max(0, ylv - ywv*abs(p.fy - yv))
0106b29c
MS
815 ), ADD);
816 c = blendColor(c, color(
2b6688e8 817 (lx.getBaseHuef() + 160 + p.fz / 10 + p.fy/2) % 360,
c39f7a04 818 constrain(140 - 2.2*abs(p.fz - model.zMax/2.), 0, 100),
2b6688e8 819 max(0, zlv - zwv*abs(p.fz - zv))
0106b29c
MS
820 ), ADD);
821 colors[p.index] = c;
822 }
823 }
824}
825
826class Blinders extends SCPattern {
827
aa54c1ca 828 final SinLFO[] m;
0106b29c
MS
829 final TriangleLFO r;
830 final SinLFO s;
831 final TriangleLFO hs;
832
833 public Blinders(GLucose glucose) {
834 super(glucose);
aa54c1ca
MS
835 m = new SinLFO[12];
836 for (int i = 0; i < m.length; ++i) {
837 addModulator(m[i] = new SinLFO(0.5, 120, (120000. / (3+i)))).trigger();
838 }
839 addModulator(r = new TriangleLFO(9000, 15000, 29000)).trigger();
840 addModulator(s = new SinLFO(-20, 275, 11000)).trigger();
0106b29c 841 addModulator(hs = new TriangleLFO(0.1, 0.5, 15000)).trigger();
aa54c1ca 842 s.modulateDurationBy(r);
0106b29c
MS
843 }
844
34327c96 845 public void run(double deltaMs) {
0106b29c 846 float hv = lx.getBaseHuef();
aa54c1ca 847 int si = 0;
87f6fa39 848 for (Strip strip : model.strips) {
0106b29c 849 int i = 0;
aa54c1ca 850 float mv = m[si % m.length].getValuef();
0106b29c
MS
851 for (Point p : strip.points) {
852 colors[p.index] = color(
2b6688e8
MS
853 (hv + p.fz + p.fy*hs.getValuef()) % 360,
854 min(100, abs(p.fx - s.getValuef())/2.),
254fbb68 855 max(0, 100 - mv/2. - mv * abs(i - (strip.metrics.length-1)/2.))
0106b29c
MS
856 );
857 ++i;
858 }
aa54c1ca 859 ++si;
0106b29c
MS
860 }
861 }
862}
863
87f6fa39
MS
864class Psychedelia extends SCPattern {
865
866 final int NUM = 3;
867 SinLFO m = new SinLFO(-0.5, NUM-0.5, 9000);
868 SinLFO s = new SinLFO(-20, 147, 11000);
869 TriangleLFO h = new TriangleLFO(0, 240, 19000);
870 SinLFO c = new SinLFO(-.2, .8, 31000);
871
872 Psychedelia(GLucose glucose) {
873 super(glucose);
874 addModulator(m).trigger();
875 addModulator(s).trigger();
876 addModulator(h).trigger();
877 addModulator(c).trigger();
878 }
0106b29c 879
34327c96 880 void run(double deltaMs) {
87f6fa39
MS
881 float huev = h.getValuef();
882 float cv = c.getValuef();
883 float sv = s.getValuef();
884 float mv = m.getValuef();
885 int i = 0;
886 for (Strip strip : model.strips) {
887 for (Point p : strip.points) {
888 colors[p.index] = color(
889 (huev + i*constrain(cv, 0, 2) + p.fz/2. + p.fx/4.) % 360,
890 min(100, abs(p.fy-sv)),
891 max(0, 100 - 50*abs((i%NUM) - mv))
892 );
893 }
894 ++i;
895 }
896 }
897}
5129affb
MS
898
899class AskewPlanes extends SCPattern {
900
901 class Plane {
902 private final SinLFO a;
903 private final SinLFO b;
904 private final SinLFO c;
775d3394
MS
905 float av = 1;
906 float bv = 1;
907 float cv = 1;
908 float denom = 0.1;
5129affb
MS
909
910 Plane(int i) {
911 addModulator(a = new SinLFO(-1, 1, 4000 + 1029*i)).trigger();
912 addModulator(b = new SinLFO(-1, 1, 11000 - 1104*i)).trigger();
913 addModulator(c = new SinLFO(-50, 50, 4000 + 1000*i * ((i % 2 == 0) ? 1 : -1))).trigger();
914 }
915
34327c96 916 void run(double deltaMs) {
5129affb
MS
917 av = a.getValuef();
918 bv = b.getValuef();
919 cv = c.getValuef();
920 denom = sqrt(av*av + bv*bv);
921 }
922 }
923
924 final Plane[] planes;
925 final int NUM_PLANES = 3;
926
927 AskewPlanes(GLucose glucose) {
928 super(glucose);
929 planes = new Plane[NUM_PLANES];
930 for (int i = 0; i < planes.length; ++i) {
931 planes[i] = new Plane(i);
932 }
933 }
5129affb 934
34327c96 935 public void run(double deltaMs) {
5129affb 936 float huev = lx.getBaseHuef();
775d3394
MS
937
938 // This is super fucking bizarre. But if this is a for loop, the framerate
939 // tanks to like 30FPS, instead of 60. Call them manually and it works fine.
940 // Doesn't make ANY sense... there must be some weird side effect going on
941 // with the Processing internals perhaps?
942// for (Plane plane : planes) {
943// plane.run(deltaMs);
944// }
945 planes[0].run(deltaMs);
946 planes[1].run(deltaMs);
947 planes[2].run(deltaMs);
948
5129affb 949 for (Point p : model.points) {
775d3394
MS
950 float d = MAX_FLOAT;
951 for (Plane plane : planes) {
952 if (plane.denom != 0) {
953 d = min(d, abs(plane.av*(p.fx-model.cx) + plane.bv*(p.fy-model.cy) + plane.cv) / plane.denom);
954 }
955 }
956 colors[p.index] = color(
957 (huev + abs(p.fx-model.cx)*.3 + p.fy*.8) % 360,
958 max(0, 100 - .8*abs(p.fx - model.cx)),
959 constrain(140 - 10.*d, 0, 100)
960 );
5129affb
MS
961 }
962 }
963}
964
965class ShiftingPlane extends SCPattern {
966
967 final SinLFO a = new SinLFO(-.2, .2, 5300);
968 final SinLFO b = new SinLFO(1, -1, 13300);
969 final SinLFO c = new SinLFO(-1.4, 1.4, 5700);
970 final SinLFO d = new SinLFO(-10, 10, 9500);
971
972 ShiftingPlane(GLucose glucose) {
973 super(glucose);
974 addModulator(a).trigger();
975 addModulator(b).trigger();
976 addModulator(c).trigger();
977 addModulator(d).trigger();
978 }
979
34327c96 980 public void run(double deltaMs) {
5129affb
MS
981 float hv = lx.getBaseHuef();
982 float av = a.getValuef();
983 float bv = b.getValuef();
984 float cv = c.getValuef();
985 float dv = d.getValuef();
986 float denom = sqrt(av*av + bv*bv + cv*cv);
987 for (Point p : model.points) {
775d3394 988 float d = abs(av*(p.fx-model.cx) + bv*(p.fy-model.cy) + cv*(p.fz-model.cz) + dv) / denom;
5129affb 989 colors[p.index] = color(
775d3394 990 (hv + abs(p.fx-model.cx)*.6 + abs(p.fy-model.cy)*.9 + abs(p.fz - model.cz)) % 360,
5129affb
MS
991 constrain(110 - d*6, 0, 100),
992 constrain(130 - 7*d, 0, 100)
993 );
994 }
995 }
996}
f3f5a876 997
4c006f7b
MS
998class Traktor extends SCPattern {
999
1000 final int FRAME_WIDTH = 60;
1001
1002 final BasicParameter speed = new BasicParameter("SPD", 0.5);
1003
1004 private float[] bass = new float[FRAME_WIDTH];
1005 private float[] treble = new float[FRAME_WIDTH];
1006
1007 private int index = 0;
1008 private GraphicEQ eq = null;
1009
1010 public Traktor(GLucose glucose) {
1011 super(glucose);
1012 for (int i = 0; i < FRAME_WIDTH; ++i) {
1013 bass[i] = 0;
1014 treble[i] = 0;
1015 }
1016 addParameter(speed);
1017 }
1018
1019 public void onActive() {
1020 if (eq == null) {
1021 eq = new GraphicEQ(lx, 16);
1022 eq.slope.setValue(0.6);
1023 eq.level.setValue(0.65);
1024 eq.range.setValue(0.35);
1025 eq.release.setValue(0.4);
1026 addParameter(eq.level);
1027 addParameter(eq.range);
1028 addParameter(eq.attack);
1029 addParameter(eq.release);
1030 addParameter(eq.slope);
1031 }
1032 }
1033
1034 int counter = 0;
1035
34327c96 1036 public void run(double deltaMs) {
4c006f7b
MS
1037 eq.run(deltaMs);
1038
1039 int stepThresh = (int) (40 - 39*speed.getValuef());
1040 counter += deltaMs;
1041 if (counter < stepThresh) {
1042 return;
1043 }
1044 counter = counter % stepThresh;
1045
1046 index = (index + 1) % FRAME_WIDTH;
1047
1048 float rawBass = eq.getAverageLevel(0, 4);
1049 float rawTreble = eq.getAverageLevel(eq.numBands-7, 7);
1050
1051 bass[index] = rawBass * rawBass * rawBass * rawBass;
1052 treble[index] = rawTreble * rawTreble;
1053
1054 for (Point p : model.points) {
1055 int i = (int) constrain((model.xMax - p.x) / model.xMax * FRAME_WIDTH, 0, FRAME_WIDTH-1);
1056 int pos = (index + FRAME_WIDTH - i) % FRAME_WIDTH;
1057
1058 colors[p.index] = color(
1059 (360 + lx.getBaseHuef() + .8*abs(p.x-model.cx)) % 360,
1060 100,
1061 constrain(9 * (bass[pos]*model.cy - abs(p.fy - model.cy)), 0, 100)
1062 );
1063 colors[p.index] = blendColor(colors[p.index], color(
1064 (400 + lx.getBaseHuef() + .5*abs(p.x-model.cx)) % 360,
1065 60,
1066 constrain(5 * (treble[pos]*.6*model.cy - abs(p.fy - model.cy)), 0, 100)
1067
1068 ), ADD);
1069 }
1070 }
1071}
6702151a
MS
1072
1073class ColorFuckerEffect extends SCEffect {
1074
1075 BasicParameter hueShift = new BasicParameter("HSHFT", 0);
1076 BasicParameter sat = new BasicParameter("SAT", 1);
1077 BasicParameter bright = new BasicParameter("BRT", 1);
1078
1079 ColorFuckerEffect(GLucose glucose) {
1080 super(glucose);
1081 addParameter(hueShift);
1082 addParameter(bright);
1083 addParameter(sat);
1084 }
1085
1086 public void doApply(int[] colors) {
d626bc9b
MS
1087 if (!enabled) {
1088 return;
1089 }
6702151a
MS
1090 float bMod = bright.getValuef();
1091 float sMod = sat.getValuef();
1092 float hMod = hueShift.getValuef();
1093 if (bMod < 1 || sMod < 1 || hMod > 0) {
1094 for (int i = 0; i < colors.length; ++i) {
1095 colors[i] = color(
1096 (hue(colors[i]) + hueShift.getValuef()*360.) % 360,
1097 saturation(colors[i]) * sat.getValuef(),
1098 brightness(colors[i]) * bright.getValuef()
1099 );
1100 }
1101 }
1102 }
1103}
348fed66
MS
1104
1105class BlurEffect extends SCEffect {
1106
1107 final LXParameter amount = new BasicParameter("AMT", 0);
1108 final int[] frame;
1109 final LinearEnvelope env = new LinearEnvelope(0, 1, 100);
1110
1111 BlurEffect(GLucose glucose) {
1112 super(glucose);
1113 addParameter(amount);
1114 addModulator(env);
1115 frame = new int[lx.total];
1116 for (int i = 0; i < frame.length; ++i) {
1117 frame[i] = #000000;
1118 }
1119 }
1120
1121 public void onEnable() {
1122 env.setRangeFromHereTo(1, 400).start();
1123 for (int i = 0; i < frame.length; ++i) {
1124 frame[i] = #000000;
1125 }
1126 }
1127
1128 public void onDisable() {
1129 env.setRangeFromHereTo(0, 1000).start();
1130 }
1131
1132 public void doApply(int[] colors) {
1133 float amt = env.getValuef() * amount.getValuef();
1134 if (amt > 0) {
1135 amt = (1 - amt);
1136 amt = 1 - (amt*amt*amt);
1137 for (int i = 0; i < colors.length; ++i) {
1138 // frame[i] = colors[i] = blendColor(colors[i], lerpColor(#000000, frame[i], amt, RGB), SCREEN);
1139 frame[i] = colors[i] = lerpColor(colors[i], blendColor(colors[i], frame[i], SCREEN), amt, RGB);
1140 }
1141 }
1142
1143 }
1144}