L8on Strips 3d Life
[SugarCubes.git] / MarkSlee.pde
CommitLineData
616d4f9e
MS
1class 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
2bb56822 48 for (LXPoint p : model.points) {
616d4f9e
MS
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 }
67847b06 60 colors[p.index] = lx.hsb(
616d4f9e
MS
61 (lx.getBaseHuef() + .2*abs(p.y - model.cy)) % 360,
62 min(100, sf*dist(abs(p.x - cx), p.y, arm, middle)),
67847b06 63 constrain(120 - d*falloff, 0, 100));
616d4f9e
MS
64 }
65 }
66}
67
4214e9a2
MS
68class MidiMusic extends SCPattern {
69
09068c4e 70 private final Stack<LXLayer> newLayers = new Stack<LXLayer>();
4214e9a2 71
09068c4e
MS
72 private final Map<Integer, LightUp> lightMap = new HashMap<Integer, LightUp>();
73 private final List<LightUp> lights = new ArrayList<LightUp>();
d93c968f 74 private final BasicParameter lightSize = new BasicParameter("SIZE", 0.5);
cfb7de01 75
09068c4e
MS
76 private final List<Sweep> sweeps = new ArrayList<Sweep>();
77
d93c968f 78 private final LinearEnvelope sparkle = new LinearEnvelope(0, 1, 500);
09068c4e 79 private boolean sparkleDirection = true;
d93c968f 80 private float sparkleBright = 100;
09068c4e
MS
81
82 private final BasicParameter wave = new BasicParameter("WAVE", 0);
4214e9a2
MS
83
84 MidiMusic(GLucose glucose) {
85 super(glucose);
d93c968f 86 addParameter(lightSize);
09068c4e 87 addParameter(wave);
d93c968f 88 addModulator(sparkle).setValue(1);
09068c4e
MS
89 }
90
29d8acbb
MS
91 void onReset() {
92 for (LightUp light : lights) {
93 light.noteOff(null);
94 }
95 }
96
09068c4e
MS
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();
2bb56822 112 for (LXPoint p : model.points) {
67847b06 113 colors[p.index] = blendColor(colors[p.index], lx.hsb(
09068c4e
MS
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 }
4214e9a2
MS
120 }
121
122 class LightUp extends LXLayer {
123
09068c4e
MS
124 private final LinearEnvelope brt = new LinearEnvelope(0, 0, 0);
125 private final Accelerator yPos = new Accelerator(0, 0, 0);
4214e9a2
MS
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) {
09068c4e
MS
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();
4214e9a2
MS
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();
2bb56822 154 for (LXPoint p : model.points) {
d93c968f
MS
155 float falloff = 6 - 5*lightSize.getValuef();
156 float b = max(0, bVal - falloff*dist(p.x, p.y, xPos, yVal));
4214e9a2 157 if (b > 0) {
19d16a16 158 colors[p.index] = blendColor(colors[p.index], lx.hsb(
d93c968f 159 (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360,
4214e9a2
MS
160 100,
161 b
162 ), ADD);
163 }
164 }
165 }
166 }
167
09068c4e
MS
168 private LightUp getLight() {
169 for (LightUp light : lights) {
170 if (light.isAvailable()) {
171 return light;
4214e9a2 172 }
09068c4e
MS
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;
4214e9a2 186 }
09068c4e
MS
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);
4214e9a2 201 } else if (note.getChannel() == 1) {
d93c968f 202 } else if (note.getChannel() == 9) {
cfb7de01
MS
203 if (note.getVelocity() > 0) {
204 switch (note.getPitch()) {
205 case 36:
09068c4e
MS
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:
d93c968f 212 sparkleBright = note.getVelocity() / 127. * 100;
09068c4e 213 sparkleDirection = true;
cfb7de01
MS
214 sparkle.trigger();
215 break;
09068c4e
MS
216 case 38:
217 sparkleBright = note.getVelocity() / 127. * 100;
218 sparkleDirection = false;
219 sparkle.trigger();
cfb7de01 220 break;
29d8acbb
MS
221 case 39:
222 effects.boom.trigger();
223 break;
224 case 40:
225 effects.flash.trigger();
226 break;
cfb7de01 227 }
d93c968f 228 }
4214e9a2
MS
229 }
230 return true;
231 }
232
242b19ad 233 public synchronized boolean noteOff(Note note) {
4214e9a2
MS
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
09068c4e
MS
243 final float[] wval = new float[16];
244 float wavoff = 0;
245
4214e9a2 246 public synchronized void run(double deltaMs) {
09068c4e
MS
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.;
d93c968f
MS
252 float maxBright = sparkleBright * (1 - sparkle.getValuef());
253 for (Strip s : model.strips) {
254 int i = 0;
2bb56822 255 for (LXPoint p : s.points) {
09068c4e
MS
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]));
67847b06 258 colors[p.index] = lx.hsb(
d93c968f
MS
259 (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360,
260 100,
09068c4e 261 constrain(wavb + max(0, maxBright - 40.*abs(sparklePos - abs(i - (Cube.POINTS_PER_STRIP-1)/2.))), 0, 100)
d93c968f
MS
262 );
263 ++i;
264 }
265 }
09068c4e 266
4214e9a2
MS
267 if (!newLayers.isEmpty()) {
268 synchronized(newLayers) {
269 while (!newLayers.isEmpty()) {
270 addLayer(newLayers.pop());
271 }
272 }
273 }
274 }
275}
276
0137237d
MS
277class 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
0e6f37cf 286 private BasicParameter sz = new BasicParameter("SIZE", 0.5);
a41f334c 287 private BasicParameter beatAmount = new BasicParameter("BEAT", 0);
eb0d5167 288
0137237d
MS
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();
0e6f37cf 296 addParameter(sz);
eb0d5167 297 addParameter(beatAmount);
0137237d 298 trigger();
242b19ad 299
0137237d
MS
300 }
301
302 private void trigger() {
303 isRising = !isRising;
304 int i = 0;
305 for (Accelerator g : gravity) {
306 if (isRising) {
a41f334c 307 g.setSpeed(random(20, 33), 0).start();
0137237d
MS
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 }
242b19ad 320
a41f334c
MS
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();
0137237d 342 }
a41f334c
MS
343 ++j;
344 }
345 for (Accelerator g : gravity) {
0137237d
MS
346 if (g.getValuef() < 0) {
347 g.setValue(-g.getValuef());
348 g.setVelocity(-g.getVelocityf() * random(0.74, 0.84));
349 }
350 }
351 }
242b19ad
MS
352
353 // A little silliness to test the grid API
66067e53
MS
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 }
242b19ad
MS
361 }
362 }
0137237d 363
eb0d5167
MS
364 float fPos = 1 - lx.tempo.rampf();
365 if (fPos < .2) {
366 fPos = .2 + 4 * (.2 - fPos);
367 }
0e6f37cf 368 float falloff = 100. / (3 + sz.getValuef() * 36 + fPos * beatAmount.getValuef()*48);
2bb56822 369 for (LXPoint p : model.points) {
a41f334c 370 int gi = (int) constrain((p.x - model.xMin) * NUM_DIVISIONS / (model.xMax - model.xMin), 0, NUM_DIVISIONS-1);
19d16a16 371 colors[p.index] = lx.hsb(
0137237d
MS
372 (lx.getBaseHuef() + abs(p.x - model.cx)*.8 + p.y*.4) % 360,
373 constrain(130 - p.y*.8, 0, 100),
a41f334c 374 max(0, 100 - abs(p.y - gravity[gi].getValuef())*falloff)
0137237d
MS
375 );
376 }
377 }
378}
379
4760e696
MS
380class 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());
2bb56822 441 for (LXPoint p : model.points) {
4760e696
MS
442 float b = 100 - pFalloff * (abs(p.x - x.getValuef()) + abs(p.y - y.getValuef()));
443 if (b > 0) {
343875e3 444 colors[p.index] = blendColor(colors[p.index], lx.hsb(
4760e696
MS
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.);
616d4f9e 474 float dB = 20*GraphicEQ.log10(lx.audioInput().mix.level() / zeroDBReference);
4760e696
MS
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
2bb56822 492 for (LXPoint p : model.points) {
4760e696
MS
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);
343875e3 495 colors[p.index] = lx.hsb(
4760e696
MS
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
d1dcc4b5 508class BouncyBalls extends SCPattern {
cc8b3f82 509
d1dcc4b5 510 static final int NUM_BALLS = 6;
cc8b3f82 511
d1dcc4b5 512 class BouncyBall {
cc8b3f82
MS
513
514 Accelerator yPos;
515 TriangleLFO xPos = new TriangleLFO(0, model.xMax, random(8000, 19000));
d1dcc4b5 516 float zPos;
cc8b3f82 517
d1dcc4b5 518 BouncyBall(int i) {
d12e46b6 519 addModulator(xPos.setBasis(random(0, TWO_PI)).start());
cc8b3f82 520 addModulator(yPos = new Accelerator(0, 0, 0));
d1dcc4b5 521 zPos = lerp(model.zMin, model.zMax, (i+2.) / (NUM_BALLS + 4.));
cc8b3f82
MS
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);
d1dcc4b5
MS
545 float xv = xPos.getValuef();
546 float yv = yPos.getValuef();
547
2bb56822 548 for (LXPoint p : model.points) {
d1dcc4b5 549 float d = sqrt((p.x-xv)*(p.x-xv) + (p.y-yv)*(p.y-yv) + .1*(p.z-zPos)*(p.z-zPos));
cc8b3f82
MS
550 float b = constrain(130 - falloff*d, 0, 100);
551 if (b > 0) {
19d16a16 552 colors[p.index] = blendColor(colors[p.index], lx.hsb(
cc8b3f82
MS
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
d1dcc4b5 562 final BouncyBall[] balls = new BouncyBall[NUM_BALLS];
cc8b3f82
MS
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
d1dcc4b5 568 BouncyBalls(GLucose glucose) {
cc8b3f82 569 super(glucose);
d1dcc4b5
MS
570 for (int i = 0; i < balls.length; ++i) {
571 balls[i] = new BouncyBall(i);
cc8b3f82
MS
572 }
573 addParameter(bounce);
574 addParameter(flr);
575 addParameter(blobSize);
576 }
577
578 public void run(double deltaMs) {
579 setColors(#000000);
d1dcc4b5
MS
580 for (BouncyBall b : balls) {
581 b.run(deltaMs);
cc8b3f82
MS
582 }
583 }
584
242b19ad 585 public boolean noteOn(Note note) {
d1dcc4b5
MS
586 int pitch = (note.getPitch() + note.getChannel()) % NUM_BALLS;
587 balls[pitch].bounce(note.getVelocity());
cc8b3f82
MS
588 return true;
589 }
590}
591
49815cc0
MS
592class SpaceTime extends SCPattern {
593
3e8e60d8 594 SinLFO pos = new SinLFO(0, 1, 3000);
49815cc0
MS
595 SinLFO rate = new SinLFO(1000, 9000, 13000);
596 SinLFO falloff = new SinLFO(10, 70, 5000);
3f8be614
MS
597 float angle = 0;
598
599 BasicParameter rateParameter = new BasicParameter("RATE", 0.5);
600 BasicParameter sizeParameter = new BasicParameter("SIZE", 0.5);
49815cc0 601
3e8e60d8 602
49815cc0
MS
603 public SpaceTime(GLucose glucose) {
604 super(glucose);
3e8e60d8 605
49815cc0
MS
606 addModulator(pos).trigger();
607 addModulator(rate).trigger();
608 addModulator(falloff).trigger();
609 pos.modulateDurationBy(rate);
3f8be614
MS
610 addParameter(rateParameter);
611 addParameter(sizeParameter);
49815cc0 612 }
3f8be614
MS
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());
49815cc0
MS
619 }
620 }
621
34327c96 622 void run(double deltaMs) {
3f8be614 623 angle += deltaMs * 0.0007;
87f6fa39
MS
624 float sVal1 = model.strips.size() * (0.5 + 0.5*sin(angle));
625 float sVal2 = model.strips.size() * (0.5 + 0.5*cos(angle));
49815cc0
MS
626
627 float pVal = pos.getValuef();
628 float fVal = falloff.getValuef();
629
630 int s = 0;
cfc57fca 631 for (Strip strip : model.strips) {
49815cc0 632 int i = 0;
2bb56822 633 for (LXPoint p : strip.points) {
19d16a16 634 colors[p.index] = lx.hsb(
190d91c2 635 (lx.getBaseHuef() + 360 - p.x*.2 + p.y * .3) % 360,
3e8e60d8
MS
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 );
49815cc0
MS
639 ++i;
640 }
3f8be614 641 ++s;
49815cc0
MS
642 }
643 }
644}
645
646class Swarm extends SCPattern {
d12e46b6 647
3e8e60d8 648 SawLFO offset = new SawLFO(0, 1, 1000);
49815cc0
MS
649 SinLFO rate = new SinLFO(350, 1200, 63000);
650 SinLFO falloff = new SinLFO(15, 50, 17000);
2bb56822
MS
651 SinLFO fX = new SinLFO(model.xMin, model.xMax, 19000);
652 SinLFO fY = new SinLFO(model.yMin, model.yMax, 11000);
653 SinLFO hOffX = new SinLFO(model.xMin, model.xMax, 13000);
49815cc0
MS
654
655 public Swarm(GLucose glucose) {
656 super(glucose);
3e8e60d8 657
49815cc0
MS
658 addModulator(offset).trigger();
659 addModulator(rate).trigger();
660 addModulator(falloff).trigger();
2b6688e8 661 addModulator(fX).trigger();
49815cc0 662 addModulator(fY).trigger();
2b6688e8 663 addModulator(hOffX).trigger();
49815cc0
MS
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
34327c96 678 void run(double deltaMs) {
49815cc0 679 float s = 0;
2bb56822 680 for (Strip strip : model.strips) {
49815cc0 681 int i = 0;
2bb56822 682 for (LXPoint p : strip.points) {
190d91c2 683 float fV = max(-1, 1 - dist(p.x/2., p.y, fX.getValuef()/2., fY.getValuef()) / 64.);
19d16a16 684 colors[p.index] = lx.hsb(
190d91c2 685 (lx.getBaseHuef() + 0.3 * abs(p.x - hOffX.getValuef())) % 360,
49815cc0 686 constrain(80 + 40 * fV, 0, 100),
1d414e45
AG
687 constrain(100 -
688 (30 - fV * falloff.getValuef()) * modDist(i + (s*63)%61, offset.getValuef() * strip.metrics.numPoints, strip.metrics.numPoints), 0, 100)
49815cc0
MS
689 );
690 ++i;
1d414e45 691 }
49815cc0
MS
692 ++s;
693 }
694 }
695}
696
697class SwipeTransition extends SCTransition {
3f8be614
MS
698
699 final BasicParameter bleed = new BasicParameter("WIDTH", 0.5);
700
49815cc0
MS
701 SwipeTransition(GLucose glucose) {
702 super(glucose);
703 setDuration(5000);
3f8be614 704 addParameter(bleed);
49815cc0
MS
705 }
706
707 void computeBlend(int[] c1, int[] c2, double progress) {
3f8be614 708 float bleedf = 10 + bleed.getValuef() * 200.;
c39f7a04 709 float xPos = (float) (-bleedf + progress * (model.xMax + bleedf));
2bb56822 710 for (LXPoint p : model.points) {
190d91c2 711 float d = (p.x - xPos) / bleedf;
49815cc0
MS
712 if (d < 0) {
713 colors[p.index] = c2[p.index];
2b6688e8 714 } else if (d > 1) {
49815cc0 715 colors[p.index] = c1[p.index];
2b6688e8 716 } else {
49815cc0
MS
717 colors[p.index] = lerpColor(c2[p.index], c1[p.index], d, RGB);
718 }
719 }
720 }
721}
722
fe30b226 723abstract class BlendTransition extends SCTransition {
ed149627 724
fe30b226
MS
725 final int blendType;
726
727 BlendTransition(GLucose glucose, int blendType) {
ed149627 728 super(glucose);
fe30b226 729 this.blendType = blendType;
ed149627
MS
730 }
731
732 void computeBlend(int[] c1, int[] c2, double progress) {
733 if (progress < 0.5) {
734 for (int i = 0; i < c1.length; ++i) {
735 colors[i] = lerpColor(
736 c1[i],
fe30b226 737 blendColor(c1[i], c2[i], blendType),
ed149627
MS
738 (float) (2.*progress),
739 RGB);
740 }
741 } else {
742 for (int i = 0; i < c1.length; ++i) {
743 colors[i] = lerpColor(
744 c2[i],
fe30b226 745 blendColor(c1[i], c2[i], blendType),
ed149627
MS
746 (float) (2.*(1. - progress)),
747 RGB);
748 }
749 }
750 }
751}
752
fe30b226
MS
753class MultiplyTransition extends BlendTransition {
754 MultiplyTransition(GLucose glucose) {
755 super(glucose, MULTIPLY);
756 }
757}
758
759class ScreenTransition extends BlendTransition {
760 ScreenTransition(GLucose glucose) {
761 super(glucose, SCREEN);
762 }
763}
764
765class BurnTransition extends BlendTransition {
766 BurnTransition(GLucose glucose) {
767 super(glucose, BURN);
768 }
769}
770
771class DodgeTransition extends BlendTransition {
772 DodgeTransition(GLucose glucose) {
773 super(glucose, DODGE);
774 }
775}
776
777class OverlayTransition extends BlendTransition {
778 OverlayTransition(GLucose glucose) {
779 super(glucose, OVERLAY);
780 }
781}
782
783class AddTransition extends BlendTransition {
784 AddTransition(GLucose glucose) {
785 super(glucose, ADD);
786 }
787}
788
789class SubtractTransition extends BlendTransition {
790 SubtractTransition(GLucose glucose) {
791 super(glucose, SUBTRACT);
792 }
793}
794
795class SoftLightTransition extends BlendTransition {
796 SoftLightTransition(GLucose glucose) {
797 super(glucose, SOFT_LIGHT);
798 }
799}
ed149627 800
4c006f7b
MS
801class BassPod extends SCPattern {
802
803 private GraphicEQ eq = null;
804
32467992
MS
805 private final BasicParameter clr = new BasicParameter("CLR", 0.5);
806
4c006f7b
MS
807 public BassPod(GLucose glucose) {
808 super(glucose);
32467992 809 addParameter(clr);
4c006f7b
MS
810 }
811
812 protected void onActive() {
813 if (eq == null) {
814 eq = new GraphicEQ(lx, 16);
32467992
MS
815 eq.range.setValue(0.4);
816 eq.level.setValue(0.4);
4c006f7b
MS
817 eq.slope.setValue(0.6);
818 addParameter(eq.level);
819 addParameter(eq.range);
820 addParameter(eq.attack);
821 addParameter(eq.release);
822 addParameter(eq.slope);
823 }
824 }
825
34327c96 826 public void run(double deltaMs) {
4c006f7b
MS
827 eq.run(deltaMs);
828
829 float bassLevel = eq.getAverageLevel(0, 5);
830
32467992
MS
831 float satBase = bassLevel*480*clr.getValuef();
832
2bb56822 833 for (LXPoint p : model.points) {
32467992 834 int avgIndex = (int) constrain(1 + abs(p.x-model.cx)/(model.cx)*(eq.numBands-5), 0, eq.numBands-5);
4c006f7b
MS
835 float value = 0;
836 for (int i = avgIndex; i < avgIndex + 5; ++i) {
837 value += eq.getLevel(i);
838 }
839 value /= 5.;
840
190d91c2 841 float b = constrain(8 * (value*model.yMax - abs(p.y-model.yMax/2.)), 0, 100);
19d16a16 842 colors[p.index] = lx.hsb(
190d91c2 843 (lx.getBaseHuef() + abs(p.y - model.cy) + abs(p.x - model.cx)) % 360,
32467992 844 constrain(satBase - .6*dist(p.x, p.y, model.cx, model.cy), 0, 100),
4c006f7b
MS
845 b
846 );
847 }
848 }
849}
850
851
49815cc0
MS
852class CubeEQ extends SCPattern {
853
4c006f7b 854 private GraphicEQ eq = null;
49815cc0 855
3f8be614 856 private final BasicParameter edge = new BasicParameter("EDGE", 0.5);
3f8be614 857 private final BasicParameter clr = new BasicParameter("CLR", 0.5);
4c006f7b 858 private final BasicParameter blockiness = new BasicParameter("BLK", 0.5);
49815cc0
MS
859
860 public CubeEQ(GLucose glucose) {
861 super(glucose);
49815cc0 862 }
3f8be614 863
49815cc0 864 protected void onActive() {
4c006f7b
MS
865 if (eq == null) {
866 eq = new GraphicEQ(lx, 16);
867 addParameter(eq.level);
868 addParameter(eq.range);
869 addParameter(eq.attack);
870 addParameter(eq.release);
871 addParameter(eq.slope);
872 addParameter(edge);
873 addParameter(clr);
874 addParameter(blockiness);
49815cc0
MS
875 }
876 }
877
34327c96 878 public void run(double deltaMs) {
4c006f7b 879 eq.run(deltaMs);
3f8be614 880
4c006f7b 881 float edgeConst = 2 + 30*edge.getValuef();
49815cc0
MS
882 float clrConst = 1.1 + clr.getValuef();
883
2bb56822 884 for (LXPoint p : model.points) {
190d91c2 885 float avgIndex = constrain(2 + p.x / model.xMax * (eq.numBands-4), 0, eq.numBands-4);
49815cc0 886 int avgFloor = (int) avgIndex;
3f8be614 887
4c006f7b
MS
888 float leftVal = eq.getLevel(avgFloor);
889 float rightVal = eq.getLevel(avgFloor+1);
890 float smoothValue = lerp(leftVal, rightVal, avgIndex-avgFloor);
891
892 float chunkyValue = (
893 eq.getLevel(avgFloor/4*4) +
894 eq.getLevel(avgFloor/4*4 + 1) +
895 eq.getLevel(avgFloor/4*4 + 2) +
896 eq.getLevel(avgFloor/4*4 + 3)
897 ) / 4.;
898
899 float value = lerp(smoothValue, chunkyValue, blockiness.getValuef());
900
190d91c2 901 float b = constrain(edgeConst * (value*model.yMax - p.y), 0, 100);
19d16a16 902 colors[p.index] = lx.hsb(
190d91c2 903 (480 + lx.getBaseHuef() - min(clrConst*p.y, 120)) % 360,
4c006f7b
MS
904 100,
905 b
906 );
3f8be614
MS
907 }
908 }
909}
910
911class BoomEffect extends SCEffect {
912
913 final BasicParameter falloff = new BasicParameter("WIDTH", 0.5);
914 final BasicParameter speed = new BasicParameter("SPD", 0.5);
915 final BasicParameter bright = new BasicParameter("BRT", 1.0);
916 final BasicParameter sat = new BasicParameter("SAT", 0.2);
917 List<Layer> layers = new ArrayList<Layer>();
c39f7a04 918 final float maxr = sqrt(model.xMax*model.xMax + model.yMax*model.yMax + model.zMax*model.zMax) + 10;
3f8be614
MS
919
920 class Layer {
921 LinearEnvelope boom = new LinearEnvelope(-40, 500, 1300);
922
923 Layer() {
924 addModulator(boom);
925 trigger();
926 }
927
928 void trigger() {
929 float falloffv = falloffv();
2b6688e8 930 boom.setRange(-100 / falloffv, maxr + 100/falloffv, 4000 - speed.getValuef() * 3300);
3f8be614
MS
931 boom.trigger();
932 }
933
d12e46b6 934 void apply(int[] colors) {
3f8be614
MS
935 float brightv = 100 * bright.getValuef();
936 float falloffv = falloffv();
937 float satv = sat.getValuef() * 100;
938 float huev = lx.getBaseHuef();
2bb56822 939 for (LXPoint p : model.points) {
3f8be614
MS
940 colors[p.index] = blendColor(
941 colors[p.index],
19d16a16 942 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)),
3f8be614
MS
943 ADD);
944 }
945 }
946 }
947
948 BoomEffect(GLucose glucose) {
949 super(glucose, true);
950 addParameter(falloff);
951 addParameter(speed);
952 addParameter(bright);
953 addParameter(sat);
954 }
955
956 public void onEnable() {
957 for (Layer l : layers) {
958 if (!l.boom.isRunning()) {
959 l.trigger();
960 return;
961 }
962 }
963 layers.add(new Layer());
964 }
965
966 private float falloffv() {
967 return 20 - 19 * falloff.getValuef();
968 }
969
970 public void onTrigger() {
971 onEnable();
972 }
973
d12e46b6 974 public void apply(int[] colors) {
3f8be614
MS
975 for (Layer l : layers) {
976 if (l.boom.isRunning()) {
d12e46b6 977 l.apply(colors);
3f8be614 978 }
49815cc0
MS
979 }
980 }
981}
982
5d70e4d7
MS
983public class PianoKeyPattern extends SCPattern {
984
985 final LinearEnvelope[] cubeBrt;
986 final SinLFO base[];
987 final BasicParameter attack = new BasicParameter("ATK", 0.1);
988 final BasicParameter release = new BasicParameter("REL", 0.5);
989 final BasicParameter level = new BasicParameter("AMB", 0.6);
990
991 PianoKeyPattern(GLucose glucose) {
992 super(glucose);
a8d55ade 993
5d70e4d7
MS
994 addParameter(attack);
995 addParameter(release);
996 addParameter(level);
87f6fa39 997 cubeBrt = new LinearEnvelope[model.cubes.size() / 4];
5d70e4d7
MS
998 for (int i = 0; i < cubeBrt.length; ++i) {
999 addModulator(cubeBrt[i] = new LinearEnvelope(0, 0, 100));
1000 }
87f6fa39 1001 base = new SinLFO[model.cubes.size() / 12];
5d70e4d7
MS
1002 for (int i = 0; i < base.length; ++i) {
1003 addModulator(base[i] = new SinLFO(0, 1, 7000 + 1000*i)).trigger();
1004 }
1005 }
1006
1007 private float getAttackTime() {
1008 return 15 + attack.getValuef()*attack.getValuef() * 2000;
1009 }
1010
1011 private float getReleaseTime() {
1012 return 15 + release.getValuef() * 3000;
1013 }
1014
1015 private LinearEnvelope getEnvelope(int index) {
1016 return cubeBrt[index % cubeBrt.length];
1017 }
1018
1019 private SinLFO getBase(int index) {
1020 return base[index % base.length];
1021 }
1022
242b19ad 1023 public boolean noteOn(Note note) {
5d70e4d7
MS
1024 LinearEnvelope env = getEnvelope(note.getPitch());
1025 env.setEndVal(min(1, env.getValuef() + (note.getVelocity() / 127.)), getAttackTime()).start();
d6ac1ee8 1026 return true;
5d70e4d7
MS
1027 }
1028
242b19ad 1029 public boolean noteOff(Note note) {
5d70e4d7 1030 getEnvelope(note.getPitch()).setEndVal(0, getReleaseTime()).start();
d6ac1ee8 1031 return true;
5d70e4d7
MS
1032 }
1033
34327c96 1034 public void run(double deltaMs) {
5d70e4d7
MS
1035 int i = 0;
1036 float huef = lx.getBaseHuef();
1037 float levelf = level.getValuef();
87f6fa39 1038 for (Cube c : model.cubes) {
5d70e4d7 1039 float v = max(getBase(i).getValuef() * levelf/4., getEnvelope(i++).getValuef());
19d16a16 1040 setColor(c, lx.hsb(
e0cea600 1041 (huef + 20*v + abs(c.cx-model.xMax/2.)*.3 + c.cy) % 360,
5d70e4d7
MS
1042 min(100, 120*v),
1043 100*v
1044 ));
1045 }
1046 }
1047}
1048
0106b29c
MS
1049class CrossSections extends SCPattern {
1050
c39f7a04
MS
1051 final SinLFO x = new SinLFO(0, model.xMax, 5000);
1052 final SinLFO y = new SinLFO(0, model.yMax, 6000);
1053 final SinLFO z = new SinLFO(0, model.zMax, 7000);
0106b29c
MS
1054
1055 final BasicParameter xw = new BasicParameter("XWID", 0.3);
1056 final BasicParameter yw = new BasicParameter("YWID", 0.3);
1057 final BasicParameter zw = new BasicParameter("ZWID", 0.3);
2b6688e8 1058 final BasicParameter xr = new BasicParameter("XRAT", 0.7);
0106b29c 1059 final BasicParameter yr = new BasicParameter("YRAT", 0.6);
2b6688e8
MS
1060 final BasicParameter zr = new BasicParameter("ZRAT", 0.5);
1061 final BasicParameter xl = new BasicParameter("XLEV", 1);
0106b29c 1062 final BasicParameter yl = new BasicParameter("YLEV", 1);
2b6688e8 1063 final BasicParameter zl = new BasicParameter("ZLEV", 0.5);
0106b29c
MS
1064
1065
1066 CrossSections(GLucose glucose) {
1067 super(glucose);
1068 addModulator(x).trigger();
1069 addModulator(y).trigger();
1070 addModulator(z).trigger();
b12bca62
MS
1071 addParams();
1072 }
1073
1074 protected void addParams() {
0106b29c
MS
1075 addParameter(xr);
1076 addParameter(yr);
1077 addParameter(zr);
2b6688e8 1078 addParameter(xw);
0106b29c
MS
1079 addParameter(xl);
1080 addParameter(yl);
1081 addParameter(zl);
2b6688e8
MS
1082 addParameter(yw);
1083 addParameter(zw);
0106b29c 1084 }
3e8e60d8
MS
1085
1086 void onParameterChanged(LXParameter p) {
0106b29c 1087 if (p == xr) {
2b6688e8 1088 x.setDuration(10000 - 8800*p.getValuef());
0106b29c 1089 } else if (p == yr) {
2b6688e8 1090 y.setDuration(10000 - 9000*p.getValuef());
0106b29c
MS
1091 } else if (p == zr) {
1092 z.setDuration(10000 - 9000*p.getValuef());
1093 }
0106b29c 1094 }
b12bca62
MS
1095
1096 float xv, yv, zv;
1097
1098 protected void updateXYZVals() {
1099 xv = x.getValuef();
1100 yv = y.getValuef();
1101 zv = z.getValuef();
1102 }
0106b29c 1103
34327c96 1104 public void run(double deltaMs) {
f1c74267
MS
1105 updateXYZVals();
1106
0106b29c
MS
1107 float xlv = 100*xl.getValuef();
1108 float ylv = 100*yl.getValuef();
1109 float zlv = 100*zl.getValuef();
1110
1111 float xwv = 100. / (10 + 40*xw.getValuef());
1112 float ywv = 100. / (10 + 40*yw.getValuef());
1113 float zwv = 100. / (10 + 40*zw.getValuef());
1114
2bb56822 1115 for (LXPoint p : model.points) {
0106b29c 1116 color c = 0;
19d16a16 1117 c = blendColor(c, lx.hsb(
190d91c2
MS
1118 (lx.getBaseHuef() + p.x/10 + p.y/3) % 360,
1119 constrain(140 - 1.1*abs(p.x - model.xMax/2.), 0, 100),
1120 max(0, xlv - xwv*abs(p.x - xv))
0106b29c 1121 ), ADD);
19d16a16 1122 c = blendColor(c, lx.hsb(
190d91c2
MS
1123 (lx.getBaseHuef() + 80 + p.y/10) % 360,
1124 constrain(140 - 2.2*abs(p.y - model.yMax/2.), 0, 100),
1125 max(0, ylv - ywv*abs(p.y - yv))
0106b29c 1126 ), ADD);
19d16a16 1127 c = blendColor(c, lx.hsb(
190d91c2
MS
1128 (lx.getBaseHuef() + 160 + p.z / 10 + p.y/2) % 360,
1129 constrain(140 - 2.2*abs(p.z - model.zMax/2.), 0, 100),
1130 max(0, zlv - zwv*abs(p.z - zv))
0106b29c
MS
1131 ), ADD);
1132 colors[p.index] = c;
1133 }
1134 }
1135}
1136
1137class Blinders extends SCPattern {
1138
aa54c1ca 1139 final SinLFO[] m;
0106b29c
MS
1140 final TriangleLFO r;
1141 final SinLFO s;
1142 final TriangleLFO hs;
1143
1144 public Blinders(GLucose glucose) {
1145 super(glucose);
aa54c1ca
MS
1146 m = new SinLFO[12];
1147 for (int i = 0; i < m.length; ++i) {
1148 addModulator(m[i] = new SinLFO(0.5, 120, (120000. / (3+i)))).trigger();
1149 }
1150 addModulator(r = new TriangleLFO(9000, 15000, 29000)).trigger();
1151 addModulator(s = new SinLFO(-20, 275, 11000)).trigger();
0106b29c 1152 addModulator(hs = new TriangleLFO(0.1, 0.5, 15000)).trigger();
aa54c1ca 1153 s.modulateDurationBy(r);
0106b29c
MS
1154 }
1155
34327c96 1156 public void run(double deltaMs) {
0106b29c 1157 float hv = lx.getBaseHuef();
aa54c1ca 1158 int si = 0;
87f6fa39 1159 for (Strip strip : model.strips) {
0106b29c 1160 int i = 0;
aa54c1ca 1161 float mv = m[si % m.length].getValuef();
2bb56822 1162 for (LXPoint p : strip.points) {
19d16a16 1163 colors[p.index] = lx.hsb(
190d91c2
MS
1164 (hv + p.z + p.y*hs.getValuef()) % 360,
1165 min(100, abs(p.x - s.getValuef())/2.),
254fbb68 1166 max(0, 100 - mv/2. - mv * abs(i - (strip.metrics.length-1)/2.))
0106b29c
MS
1167 );
1168 ++i;
1169 }
aa54c1ca 1170 ++si;
0106b29c
MS
1171 }
1172 }
1173}
1174
87f6fa39
MS
1175class Psychedelia extends SCPattern {
1176
1177 final int NUM = 3;
1178 SinLFO m = new SinLFO(-0.5, NUM-0.5, 9000);
1179 SinLFO s = new SinLFO(-20, 147, 11000);
1180 TriangleLFO h = new TriangleLFO(0, 240, 19000);
1181 SinLFO c = new SinLFO(-.2, .8, 31000);
1182
1183 Psychedelia(GLucose glucose) {
1184 super(glucose);
1185 addModulator(m).trigger();
1186 addModulator(s).trigger();
1187 addModulator(h).trigger();
1188 addModulator(c).trigger();
1189 }
0106b29c 1190
34327c96 1191 void run(double deltaMs) {
87f6fa39
MS
1192 float huev = h.getValuef();
1193 float cv = c.getValuef();
1194 float sv = s.getValuef();
1195 float mv = m.getValuef();
1196 int i = 0;
1197 for (Strip strip : model.strips) {
2bb56822 1198 for (LXPoint p : strip.points) {
19d16a16 1199 colors[p.index] = lx.hsb(
190d91c2
MS
1200 (huev + i*constrain(cv, 0, 2) + p.z/2. + p.x/4.) % 360,
1201 min(100, abs(p.y-sv)),
87f6fa39
MS
1202 max(0, 100 - 50*abs((i%NUM) - mv))
1203 );
1204 }
1205 ++i;
1206 }
1207 }
1208}
5129affb
MS
1209
1210class AskewPlanes extends SCPattern {
1211
1212 class Plane {
1213 private final SinLFO a;
1214 private final SinLFO b;
1215 private final SinLFO c;
775d3394
MS
1216 float av = 1;
1217 float bv = 1;
1218 float cv = 1;
1219 float denom = 0.1;
5129affb
MS
1220
1221 Plane(int i) {
1222 addModulator(a = new SinLFO(-1, 1, 4000 + 1029*i)).trigger();
1223 addModulator(b = new SinLFO(-1, 1, 11000 - 1104*i)).trigger();
1224 addModulator(c = new SinLFO(-50, 50, 4000 + 1000*i * ((i % 2 == 0) ? 1 : -1))).trigger();
1225 }
1226
34327c96 1227 void run(double deltaMs) {
5129affb
MS
1228 av = a.getValuef();
1229 bv = b.getValuef();
1230 cv = c.getValuef();
1231 denom = sqrt(av*av + bv*bv);
1232 }
1233 }
1234
1235 final Plane[] planes;
1236 final int NUM_PLANES = 3;
1237
1238 AskewPlanes(GLucose glucose) {
1239 super(glucose);
1240 planes = new Plane[NUM_PLANES];
1241 for (int i = 0; i < planes.length; ++i) {
1242 planes[i] = new Plane(i);
1243 }
1244 }
5129affb 1245
34327c96 1246 public void run(double deltaMs) {
5129affb 1247 float huev = lx.getBaseHuef();
775d3394
MS
1248
1249 // This is super fucking bizarre. But if this is a for loop, the framerate
1250 // tanks to like 30FPS, instead of 60. Call them manually and it works fine.
1251 // Doesn't make ANY sense... there must be some weird side effect going on
1252 // with the Processing internals perhaps?
1253// for (Plane plane : planes) {
1254// plane.run(deltaMs);
1255// }
1256 planes[0].run(deltaMs);
1257 planes[1].run(deltaMs);
1258 planes[2].run(deltaMs);
1259
2bb56822 1260 for (LXPoint p : model.points) {
775d3394
MS
1261 float d = MAX_FLOAT;
1262 for (Plane plane : planes) {
1263 if (plane.denom != 0) {
190d91c2 1264 d = min(d, abs(plane.av*(p.x-model.cx) + plane.bv*(p.y-model.cy) + plane.cv) / plane.denom);
775d3394
MS
1265 }
1266 }
19d16a16 1267 colors[p.index] = lx.hsb(
190d91c2
MS
1268 (huev + abs(p.x-model.cx)*.3 + p.y*.8) % 360,
1269 max(0, 100 - .8*abs(p.x - model.cx)),
775d3394
MS
1270 constrain(140 - 10.*d, 0, 100)
1271 );
5129affb
MS
1272 }
1273 }
1274}
1275
1276class ShiftingPlane extends SCPattern {
1277
1278 final SinLFO a = new SinLFO(-.2, .2, 5300);
1279 final SinLFO b = new SinLFO(1, -1, 13300);
1280 final SinLFO c = new SinLFO(-1.4, 1.4, 5700);
1281 final SinLFO d = new SinLFO(-10, 10, 9500);
1282
1283 ShiftingPlane(GLucose glucose) {
1284 super(glucose);
1285 addModulator(a).trigger();
1286 addModulator(b).trigger();
1287 addModulator(c).trigger();
1288 addModulator(d).trigger();
1289 }
1290
34327c96 1291 public void run(double deltaMs) {
5129affb
MS
1292 float hv = lx.getBaseHuef();
1293 float av = a.getValuef();
1294 float bv = b.getValuef();
1295 float cv = c.getValuef();
1296 float dv = d.getValuef();
1297 float denom = sqrt(av*av + bv*bv + cv*cv);
2bb56822 1298 for (LXPoint p : model.points) {
190d91c2 1299 float d = abs(av*(p.x-model.cx) + bv*(p.y-model.cy) + cv*(p.z-model.cz) + dv) / denom;
19d16a16 1300 colors[p.index] = lx.hsb(
190d91c2 1301 (hv + abs(p.x-model.cx)*.6 + abs(p.y-model.cy)*.9 + abs(p.z - model.cz)) % 360,
5129affb
MS
1302 constrain(110 - d*6, 0, 100),
1303 constrain(130 - 7*d, 0, 100)
1304 );
1305 }
1306 }
1307}
f3f5a876 1308
4c006f7b
MS
1309class Traktor extends SCPattern {
1310
1311 final int FRAME_WIDTH = 60;
1312
1313 final BasicParameter speed = new BasicParameter("SPD", 0.5);
1314
1315 private float[] bass = new float[FRAME_WIDTH];
1316 private float[] treble = new float[FRAME_WIDTH];
1317
1318 private int index = 0;
1319 private GraphicEQ eq = null;
1320
1321 public Traktor(GLucose glucose) {
1322 super(glucose);
1323 for (int i = 0; i < FRAME_WIDTH; ++i) {
1324 bass[i] = 0;
1325 treble[i] = 0;
1326 }
1327 addParameter(speed);
1328 }
1329
1330 public void onActive() {
1331 if (eq == null) {
1332 eq = new GraphicEQ(lx, 16);
1333 eq.slope.setValue(0.6);
1334 eq.level.setValue(0.65);
1335 eq.range.setValue(0.35);
1336 eq.release.setValue(0.4);
1337 addParameter(eq.level);
1338 addParameter(eq.range);
1339 addParameter(eq.attack);
1340 addParameter(eq.release);
1341 addParameter(eq.slope);
1342 }
1343 }
1344
1345 int counter = 0;
1346
34327c96 1347 public void run(double deltaMs) {
4c006f7b
MS
1348 eq.run(deltaMs);
1349
1350 int stepThresh = (int) (40 - 39*speed.getValuef());
1351 counter += deltaMs;
1352 if (counter < stepThresh) {
1353 return;
1354 }
1355 counter = counter % stepThresh;
1356
1357 index = (index + 1) % FRAME_WIDTH;
1358
1359 float rawBass = eq.getAverageLevel(0, 4);
1360 float rawTreble = eq.getAverageLevel(eq.numBands-7, 7);
1361
1362 bass[index] = rawBass * rawBass * rawBass * rawBass;
1363 treble[index] = rawTreble * rawTreble;
1364
2bb56822 1365 for (LXPoint p : model.points) {
4c006f7b
MS
1366 int i = (int) constrain((model.xMax - p.x) / model.xMax * FRAME_WIDTH, 0, FRAME_WIDTH-1);
1367 int pos = (index + FRAME_WIDTH - i) % FRAME_WIDTH;
1368
19d16a16 1369 colors[p.index] = lx.hsb(
4c006f7b
MS
1370 (360 + lx.getBaseHuef() + .8*abs(p.x-model.cx)) % 360,
1371 100,
29d8acbb 1372 constrain(9 * (bass[pos]*model.cy - abs(p.y - model.cy + 5)), 0, 100)
4c006f7b 1373 );
19d16a16 1374 colors[p.index] = blendColor(colors[p.index], lx.hsb(
4c006f7b
MS
1375 (400 + lx.getBaseHuef() + .5*abs(p.x-model.cx)) % 360,
1376 60,
190d91c2 1377 constrain(5 * (treble[pos]*.6*model.cy - abs(p.y - model.cy)), 0, 100)
4c006f7b
MS
1378
1379 ), ADD);
1380 }
1381 }
1382}
6702151a
MS
1383
1384class ColorFuckerEffect extends SCEffect {
1385
e5308763 1386 final BasicParameter level = new BasicParameter("BRT", 1);
1387 final BasicParameter desat = new BasicParameter("DSAT", 0);
29d8acbb 1388 final BasicParameter hueShift = new BasicParameter("HSHFT", 0);
e5308763 1389 final BasicParameter sharp = new BasicParameter("SHARP", 0);
1390 final BasicParameter soft = new BasicParameter("SOFT", 0);
1391 final BasicParameter mono = new BasicParameter("MONO", 0);
1392 final BasicParameter invert = new BasicParameter("INVERT", 0);
29d8acbb 1393
e5308763 1394
4214e9a2 1395 float[] hsb = new float[3];
6702151a
MS
1396
1397 ColorFuckerEffect(GLucose glucose) {
1398 super(glucose);
e5308763 1399 addParameter(level);
1400 addParameter(desat);
1401 addParameter(sharp);
29d8acbb 1402 addParameter(hueShift);
e5308763 1403 addParameter(soft);
1404 addParameter(mono);
1405 addParameter(invert);
6702151a
MS
1406 }
1407
d12e46b6 1408 public void apply(int[] colors) {
d626bc9b
MS
1409 if (!enabled) {
1410 return;
1411 }
e5308763 1412 float bMod = level.getValuef();
1413 float sMod = 1 - desat.getValuef();
6702151a 1414 float hMod = hueShift.getValuef();
ef7118ad 1415 float fSharp = sharp.getValuef();
e5308763 1416 float fSoft = soft.getValuef();
1417 boolean mon = mono.getValuef() > 0.5;
1418 boolean ivt = invert.getValuef() > 0.5;
1419 if (bMod < 1 || sMod < 1 || hMod > 0 || fSharp > 0 || ivt || mon || fSoft > 0) {
6702151a 1420 for (int i = 0; i < colors.length; ++i) {
4214e9a2 1421 lx.RGBtoHSB(colors[i], hsb);
e5308763 1422 if (mon) {
1423 hsb[0] = lx.getBaseHuef() / 360.;
1424 }
1425 if (ivt) {
1426 hsb[2] = 1 - hsb[2];
1427 }
1428 if (fSharp > 0) {
ef7118ad 1429 fSharp = 1/(1-fSharp);
bae2197a
MS
1430 if (hsb[2] < .5) {
1431 hsb[2] = pow(hsb[2],fSharp);
1432 } else {
1433 hsb[2] = 1-pow(1-hsb[2],fSharp);
1434 }
e5308763 1435 }
1436 if (fSoft > 0) {
1437 if (hsb[2] > 0.5) {
1438 hsb[2] = lerp(hsb[2], 0.5 + 2 * (hsb[2]-0.5)*(hsb[2]-0.5), fSoft);
1439 } else {
1440 hsb[2] = lerp(hsb[2], 0.5 * sqrt(2*hsb[2]), fSoft);
1441 }
1442 }
4214e9a2 1443 colors[i] = lx.hsb(
e5308763 1444 (360. * hsb[0] + hMod*360.) % 360,
1445 100. * hsb[1] * sMod,
1446 100. * hsb[2] * bMod
6702151a
MS
1447 );
1448 }
1449 }
1450 }
1451}
348fed66 1452
e5308763 1453class QuantizeEffect extends SCEffect {
1454
1455 color[] quantizedFrame;
1456 float lastQuant;
1457 final BasicParameter amount = new BasicParameter("AMT", 0);
1458
1459 QuantizeEffect(GLucose glucose) {
1460 super(glucose);
1461 quantizedFrame = new color[glucose.lx.total];
1462 lastQuant = 0;
1463 }
1464
d12e46b6 1465 public void apply(int[] colors) {
e5308763 1466 float fQuant = amount.getValuef();
1467 if (fQuant > 0) {
1468 float tRamp = (lx.tempo.rampf() % (1./pow(2,floor((1-fQuant) * 4))));
1469 float f = lastQuant;
1470 lastQuant = tRamp;
1471 if (tRamp > f) {
1472 for (int i = 0; i < colors.length; ++i) {
1473 colors[i] = quantizedFrame[i];
1474 }
1475 return;
1476 }
1477 }
1478 for (int i = 0; i < colors.length; ++i) {
1479 quantizedFrame[i] = colors[i];
1480 }
1481 }
1482}
1483
348fed66
MS
1484class BlurEffect extends SCEffect {
1485
05ebfd15 1486 final BasicParameter amount = new BasicParameter("AMT", 0);
348fed66
MS
1487 final int[] frame;
1488 final LinearEnvelope env = new LinearEnvelope(0, 1, 100);
1489
1490 BlurEffect(GLucose glucose) {
1491 super(glucose);
1492 addParameter(amount);
1493 addModulator(env);
1494 frame = new int[lx.total];
1495 for (int i = 0; i < frame.length; ++i) {
1496 frame[i] = #000000;
1497 }
1498 }
1499
1500 public void onEnable() {
1501 env.setRangeFromHereTo(1, 400).start();
1502 for (int i = 0; i < frame.length; ++i) {
1503 frame[i] = #000000;
1504 }
1505 }
1506
1507 public void onDisable() {
1508 env.setRangeFromHereTo(0, 1000).start();
1509 }
1510
d12e46b6 1511 public void apply(int[] colors) {
348fed66
MS
1512 float amt = env.getValuef() * amount.getValuef();
1513 if (amt > 0) {
1514 amt = (1 - amt);
1515 amt = 1 - (amt*amt*amt);
1516 for (int i = 0; i < colors.length; ++i) {
1517 // frame[i] = colors[i] = blendColor(colors[i], lerpColor(#000000, frame[i], amt, RGB), SCREEN);
1518 frame[i] = colors[i] = lerpColor(colors[i], blendColor(colors[i], frame[i], SCREEN), amt, RGB);
1519 }
1520 }
1521
1522 }
1523}
2bb56822 1524