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