1 import java.util.Stack;
2 class Cathedrals extends SCPattern {
4 private final BasicParameter xpos = new BasicParameter("XPOS", 0.5);
5 private final BasicParameter wid = new BasicParameter("WID", 0.5);
6 private final BasicParameter arms = new BasicParameter("ARMS", 0.5);
7 private final BasicParameter sat = new BasicParameter("SAT", 0.5);
10 Cathedrals(GLucose glucose) {
18 protected void onActive() {
20 eq = new GraphicEQ(lx, 16);
21 eq.slope.setValue(0.7);
22 eq.range.setValue(0.4);
23 eq.attack.setValue(0.4);
24 eq.release.setValue(0.4);
25 addParameter(eq.level);
26 addParameter(eq.range);
27 addParameter(eq.attack);
28 addParameter(eq.release);
29 addParameter(eq.slope);
34 public void run(double deltaMs) {
36 float bassLevel = eq.getAverageLevel(0, 4);
37 float trebleLevel = eq.getAverageLevel(8, 6);
39 float falloff = 100 / (2 + 14*wid.getValuef());
40 float cx = model.xMin + (model.xMax-model.xMin) * xpos.getValuef();
41 float barm = 12 + 60*arms.getValuef()*max(0, 2*(bassLevel-0.1));
42 float tarm = 12 + 60*arms.getValuef()*max(0, 2*(trebleLevel-0.1));
47 float sf = 100. / (70 - 69.9*sat.getValuef());
49 for (LXPoint p : model.points) {
53 middle = model.yMax * 3/5.;
56 middle = model.yMax * 1/5.;
58 if (abs(p.x - cx) < arm) {
59 d = min(abs(p.x - cx), abs(p.y - middle));
61 colors[p.index] = lx.hsb(
62 (lx.getBaseHuef() + .2*abs(p.y - model.cy)) % 360,
63 min(100, sf*dist(abs(p.x - cx), p.y, arm, middle)),
64 constrain(120 - d*falloff, 0, 100));
69 class MidiMusic extends SCPattern {
71 private final Stack<LXLayer> newLayers = new Stack<LXLayer>();
73 private final Map<Integer, LightUp> lightMap = new HashMap<Integer, LightUp>();
74 private final List<LightUp> lights = new ArrayList<LightUp>();
75 private final BasicParameter lightSize = new BasicParameter("SIZE", 0.5);
77 private final List<Sweep> sweeps = new ArrayList<Sweep>();
79 private final LinearEnvelope sparkle = new LinearEnvelope(0, 1, 500);
80 private boolean sparkleDirection = true;
81 private float sparkleBright = 100;
83 private final BasicParameter wave = new BasicParameter("WAVE", 0);
85 MidiMusic(GLucose glucose) {
87 addParameter(lightSize);
89 addModulator(sparkle).setValue(1);
93 for (LightUp light : lights) {
98 class Sweep extends LXLayer {
100 final LinearEnvelope position = new LinearEnvelope(0, 1, 1000);
105 addModulator(position);
108 public void run(double deltaMs, color[] colors) {
109 if (!position.isRunning()) {
112 float posf = position.getValuef();
113 for (LXPoint p : model.points) {
114 colors[p.index] = blendColor(colors[p.index], lx.hsb(
115 (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360,
117 max(0, bright - posf*100 - falloff*abs(p.y - posf*model.yMax))
123 class LightUp extends LXLayer {
125 private final LinearEnvelope brt = new LinearEnvelope(0, 0, 0);
126 private final Accelerator yPos = new Accelerator(0, 0, 0);
134 boolean isAvailable() {
135 return brt.getValuef() <= 0;
138 void noteOn(Note note) {
139 xPos = lerp(0, model.xMax, constrain(0.5 + (note.getPitch() - 60) / 28., 0, 1));
140 yPos.setValue(lerp(20, model.yMax*.72, note.getVelocity() / 127.)).stop();
141 brt.setRangeFromHereTo(lerp(40, 100, note.getVelocity() / 127.), 20).start();
144 void noteOff(Note note) {
145 yPos.setVelocity(0).setAcceleration(-380).start();
146 brt.setRangeFromHereTo(0, 1000).start();
149 public void run(double deltaMs, color[] colors) {
150 float bVal = brt.getValuef();
154 float yVal = yPos.getValuef();
155 for (LXPoint p : model.points) {
156 float falloff = 6 - 5*lightSize.getValuef();
157 float b = max(0, bVal - falloff*dist(p.x, p.y, xPos, yVal));
159 colors[p.index] = blendColor(colors[p.index], lx.hsb(
160 (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360,
169 private LightUp getLight() {
170 for (LightUp light : lights) {
171 if (light.isAvailable()) {
175 LightUp newLight = new LightUp();
176 lights.add(newLight);
177 synchronized(newLayers) {
178 newLayers.push(newLight);
183 private Sweep getSweep() {
184 for (Sweep s : sweeps) {
185 if (!s.position.isRunning()) {
189 Sweep newSweep = new Sweep();
190 sweeps.add(newSweep);
191 synchronized(newLayers) {
192 newLayers.push(newSweep);
197 public synchronized boolean noteOn(Note note) {
198 if (note.getChannel() == 0) {
199 LightUp light = getLight();
200 lightMap.put(note.getPitch(), light);
202 } else if (note.getChannel() == 1) {
203 } else if (note.getChannel() == 9) {
204 if (note.getVelocity() > 0) {
205 switch (note.getPitch()) {
207 Sweep s = getSweep();
208 s.bright = 50 + note.getVelocity() / 127. * 50;
209 s.falloff = 20 - note.getVelocity() / 127. * 17;
210 s.position.trigger();
213 sparkleBright = note.getVelocity() / 127. * 100;
214 sparkleDirection = true;
218 sparkleBright = note.getVelocity() / 127. * 100;
219 sparkleDirection = false;
223 effects.boom.trigger();
226 //effects.flash.trigger();
234 public synchronized boolean noteOff(Note note) {
235 if (note.getChannel() == 0) {
236 LightUp light = lightMap.get(note.getPitch());
244 final float[] wval = new float[16];
247 public synchronized void run(double deltaMs) {
248 wavoff += deltaMs * .001;
249 for (int i = 0; i < wval.length; ++i) {
250 wval[i] = model.cy + 0.2 * model.yMax/2. * sin(wavoff + i / 1.9);
252 float sparklePos = (sparkleDirection ? sparkle.getValuef() : (1 - sparkle.getValuef())) * (Cube.POINTS_PER_STRIP)/2.;
253 float maxBright = sparkleBright * (1 - sparkle.getValuef());
254 for (Strip s : model.strips) {
256 for (LXPoint p : s.points) {
257 int wavi = (int) constrain(p.x / model.xMax * wval.length, 0, wval.length-1);
258 float wavb = max(0, wave.getValuef()*100. - 8.*abs(p.y - wval[wavi]));
259 colors[p.index] = lx.hsb(
260 (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360,
262 constrain(wavb + max(0, maxBright - 40.*abs(sparklePos - abs(i - (Cube.POINTS_PER_STRIP-1)/2.))), 0, 100)
268 if (!newLayers.isEmpty()) {
269 synchronized(newLayers) {
270 while (!newLayers.isEmpty()) {
271 addLayer(newLayers.pop());
278 class Pulley extends SCPattern {
280 final int NUM_DIVISIONS = 16;
281 private final Accelerator[] gravity = new Accelerator[NUM_DIVISIONS];
282 private final Click[] delays = new Click[NUM_DIVISIONS];
284 private final Click reset = new Click(9000);
285 private boolean isRising = false;
287 private BasicParameter sz = new BasicParameter("SIZE", 0.5);
288 private BasicParameter beatAmount = new BasicParameter("BEAT", 0);
290 Pulley(GLucose glucose) {
292 for (int i = 0; i < NUM_DIVISIONS; ++i) {
293 addModulator(gravity[i] = new Accelerator(0, 0, 0));
294 addModulator(delays[i] = new Click(0));
296 addModulator(reset).start();
298 addParameter(beatAmount);
303 private void trigger() {
304 isRising = !isRising;
306 for (Accelerator g : gravity) {
308 g.setSpeed(random(20, 33), 0).start();
310 g.setVelocity(0).setAcceleration(-420);
311 delays[i].setDuration(random(0, 500)).trigger();
317 public void run(double deltaMs) {
323 // Fucking A, had to comment this all out because of that bizarre
324 // Processing bug where some simple loop takes an absurd amount of
325 // time, must be some pre-processor bug
326 // for (Accelerator g : gravity) {
327 // if (g.getValuef() > model.yMax) {
329 // } else if (g.getValuef() > model.yMax*.55) {
330 // if (g.getVelocityf() > 10) {
331 // g.setAcceleration(-16);
333 // g.setAcceleration(0);
339 for (Click d : delays) {
346 for (Accelerator g : gravity) {
347 if (g.getValuef() < 0) {
348 g.setValue(-g.getValuef());
349 g.setVelocity(-g.getVelocityf() * random(0.74, 0.84));
354 // A little silliness to test the grid API
355 if (midiEngine != null && midiEngine.getFocusedPattern() == this) {
356 for (int i = 0; i < 5; ++i) {
357 for (int j = 0; j < 8; ++j) {
358 int gi = (int) constrain(j * NUM_DIVISIONS / 8, 0, NUM_DIVISIONS-1);
359 float b = 1 - 4.*abs((6-i)/6. - gravity[gi].getValuef() / model.yMax);
360 midiEngine.grid.setState(i, j, (b < 0) ? 0 : 3);
365 float fPos = 1 - lx.tempo.rampf();
367 fPos = .2 + 4 * (.2 - fPos);
369 float falloff = 100. / (3 + sz.getValuef() * 36 + fPos * beatAmount.getValuef()*48);
370 for (LXPoint p : model.points) {
371 int gi = (int) constrain((p.x - model.xMin) * NUM_DIVISIONS / (model.xMax - model.xMin), 0, NUM_DIVISIONS-1);
372 colors[p.index] = lx.hsb(
373 (lx.getBaseHuef() + abs(p.x - model.cx)*.8 + p.y*.4) % 360,
374 constrain(130 - p.y*.8, 0, 100),
375 max(0, 100 - abs(p.y - gravity[gi].getValuef())*falloff)
381 class ViolinWave extends SCPattern {
383 BasicParameter level = new BasicParameter("LVL", 0.45);
384 BasicParameter range = new BasicParameter("RNG", 0.5);
385 BasicParameter edge = new BasicParameter("EDG", 0.5);
386 BasicParameter release = new BasicParameter("RLS", 0.5);
387 BasicParameter speed = new BasicParameter("SPD", 0.5);
388 BasicParameter amp = new BasicParameter("AMP", 0.25);
389 BasicParameter period = new BasicParameter("WAVE", 0.5);
390 BasicParameter pSize = new BasicParameter("PSIZE", 0.5);
391 BasicParameter pSpeed = new BasicParameter("PSPD", 0.5);
392 BasicParameter pDensity = new BasicParameter("PDENS", 0.25);
394 LinearEnvelope dbValue = new LinearEnvelope(0, 0, 10);
396 ViolinWave(GLucose glucose) {
401 addParameter(release);
404 addParameter(period);
406 addParameter(pSpeed);
407 addParameter(pDensity);
409 addModulator(dbValue);
412 final List<Particle> particles = new ArrayList<Particle>();
416 LinearEnvelope x = new LinearEnvelope(0, 0, 0);
417 LinearEnvelope y = new LinearEnvelope(0, 0, 0);
424 Particle trigger(boolean direction) {
425 float xInit = random(model.xMin, model.xMax);
426 float time = 3000 - 2500*pSpeed.getValuef();
427 x.setRange(xInit, xInit + random(-40, 40), time).trigger();
428 y.setRange(model.cy + 10, direction ? model.yMax + 50 : model.yMin - 50, time).trigger();
433 return x.isRunning() || y.isRunning();
436 public void run(double deltaMs) {
441 float pFalloff = (30 - 27*pSize.getValuef());
442 for (LXPoint p : model.points) {
443 float b = 100 - pFalloff * (abs(p.x - x.getValuef()) + abs(p.y - y.getValuef()));
445 colors[p.index] = blendColor(colors[p.index], lx.hsb(
446 lx.getBaseHuef(), 20, b
453 float[] centers = new float[30];
455 boolean rising = true;
457 void fireParticle(boolean direction) {
458 boolean gotOne = false;
459 for (Particle p : particles) {
461 p.trigger(direction);
465 particles.add(new Particle().trigger(direction));
468 public void run(double deltaMs) {
469 accum += deltaMs / (1000. - 900.*speed.getValuef());
470 for (int i = 0; i < centers.length; ++i) {
471 centers[i] = model.cy + 30*amp.getValuef()*sin((float) (accum + (i-centers.length/2.)/(1. + 9.*period.getValuef())));
474 float zeroDBReference = pow(10, (50 - 190*level.getValuef())/20.);
475 float dB = 20*GraphicEQ.log10(lx.audioInput().mix.level() / zeroDBReference);
476 if (dB > dbValue.getValuef()) {
478 dbValue.setRangeFromHereTo(dB, 10).trigger();
481 for (int j = 0; j < pDensity.getValuef()*3; ++j) {
487 dbValue.setRangeFromHereTo(max(dB, -96), 50 + 1000*release.getValuef()).trigger();
489 float edg = 1 + edge.getValuef() * 40;
490 float rng = (78 - 64 * range.getValuef()) / (model.yMax - model.cy);
491 float val = max(2, dbValue.getValuef());
493 for (LXPoint p : model.points) {
494 int ci = (int) lerp(0, centers.length-1, (p.x - model.xMin) / (model.xMax - model.xMin));
495 float rFactor = 1.0 - 0.9 * abs(p.x - model.cx) / (model.xMax - model.cx);
496 colors[p.index] = lx.hsb(
497 (lx.getBaseHuef() + abs(p.x - model.cx)) % 360,
498 min(100, 20 + 8*abs(p.y - centers[ci])),
499 constrain(edg*(val*rFactor - rng * abs(p.y-centers[ci])), 0, 100)
503 for (Particle p : particles) {
509 class BouncyBalls extends SCPattern {
511 static final int NUM_BALLS = 6;
516 TriangleLFO xPos = new TriangleLFO(0, model.xMax, random(8000, 19000));
520 addModulator(xPos.setBasis(random(0, TWO_PI)).start());
521 addModulator(yPos = new Accelerator(0, 0, 0));
522 zPos = lerp(model.zMin, model.zMax, (i+2.) / (NUM_BALLS + 4.));
525 void bounce(float midiVel) {
526 float v = 100 + 8*midiVel;
527 yPos.setSpeed(v, getAccel(v, 60 / lx.tempo.bpmf())).start();
530 float getAccel(float v, float oneBeat) {
531 return -2*v / oneBeat;
534 void run(double deltaMs) {
535 float flrLevel = flr.getValuef() * model.xMax/2.;
536 if (yPos.getValuef() < flrLevel) {
537 if (yPos.getVelocity() < -50) {
538 yPos.setValue(2*flrLevel-yPos.getValuef());
539 float v = -yPos.getVelocityf() * bounce.getValuef();
540 yPos.setSpeed(v, getAccel(v, 60 / lx.tempo.bpmf()));
542 yPos.setValue(flrLevel).stop();
545 float falloff = 130.f / (12 + blobSize.getValuef() * 36);
546 float xv = xPos.getValuef();
547 float yv = yPos.getValuef();
549 for (LXPoint p : model.points) {
550 float d = sqrt((p.x-xv)*(p.x-xv) + (p.y-yv)*(p.y-yv) + .1*(p.z-zPos)*(p.z-zPos));
551 float b = constrain(130 - falloff*d, 0, 100);
553 colors[p.index] = blendColor(colors[p.index], lx.hsb(
554 (lx.getBaseHuef() + p.y*.5 + abs(model.cx - p.x) * .5) % 360,
555 max(0, 100 - .45*(p.y - flrLevel)),
563 final BouncyBall[] balls = new BouncyBall[NUM_BALLS];
565 final BasicParameter bounce = new BasicParameter("BNC", .8);
566 final BasicParameter flr = new BasicParameter("FLR", 0);
567 final BasicParameter blobSize = new BasicParameter("SIZE", 0.5);
569 BouncyBalls(GLucose glucose) {
571 for (int i = 0; i < balls.length; ++i) {
572 balls[i] = new BouncyBall(i);
574 addParameter(bounce);
576 addParameter(blobSize);
579 public void run(double deltaMs) {
581 for (BouncyBall b : balls) {
586 public boolean noteOn(Note note) {
587 int pitch = (note.getPitch() + note.getChannel()) % NUM_BALLS;
588 balls[pitch].bounce(note.getVelocity());
593 class SpaceTime extends SCPattern {
595 SinLFO pos = new SinLFO(0, 1, 3000);
596 SinLFO rate = new SinLFO(1000, 9000, 13000);
597 SinLFO falloff = new SinLFO(10, 70, 5000);
600 BasicParameter rateParameter = new BasicParameter("RATE", 0.5);
601 BasicParameter sizeParameter = new BasicParameter("SIZE", 0.5);
604 public SpaceTime(GLucose glucose) {
607 addModulator(pos).trigger();
608 addModulator(rate).trigger();
609 addModulator(falloff).trigger();
610 pos.modulateDurationBy(rate);
611 addParameter(rateParameter);
612 addParameter(sizeParameter);
615 public void onParameterChanged(LXParameter parameter) {
616 if (parameter == rateParameter) {
617 rate.stop().setValue(9000 - 8000*parameter.getValuef());
618 } else if (parameter == sizeParameter) {
619 falloff.stop().setValue(70 - 60*parameter.getValuef());
623 void run(double deltaMs) {
624 angle += deltaMs * 0.0007;
625 float sVal1 = model.strips.size() * (0.5 + 0.5*sin(angle));
626 float sVal2 = model.strips.size() * (0.5 + 0.5*cos(angle));
628 float pVal = pos.getValuef();
629 float fVal = falloff.getValuef();
632 for (Strip strip : model.strips) {
634 for (LXPoint p : strip.points) {
635 colors[p.index] = lx.hsb(
636 (lx.getBaseHuef() + 360 - p.x*.2 + p.y * .3) % 360,
637 constrain(.4 * min(abs(s - sVal1), abs(s - sVal2)), 20, 100),
638 max(0, 100 - fVal*abs(i - pVal*(strip.metrics.numPoints - 1)))
647 class Swarm extends SCPattern {
649 SawLFO offset = new SawLFO(0, 1, 1000);
650 SinLFO rate = new SinLFO(350, 1200, 63000);
651 SinLFO falloff = new SinLFO(15, 50, 17000);
652 SinLFO fX = new SinLFO(model.xMin, model.xMax, 19000);
653 SinLFO fY = new SinLFO(model.yMin, model.yMax, 11000);
654 SinLFO hOffX = new SinLFO(model.xMin, model.xMax, 13000);
656 public Swarm(GLucose glucose) {
659 addModulator(offset).trigger();
660 addModulator(rate).trigger();
661 addModulator(falloff).trigger();
662 addModulator(fX).trigger();
663 addModulator(fY).trigger();
664 addModulator(hOffX).trigger();
665 offset.modulateDurationBy(rate);
668 float modDist(float v1, float v2, float mod) {
672 return min(v2-v1, v1+mod-v2);
675 return min(v1-v2, v2+mod-v1);
679 void run(double deltaMs) {
681 for (Strip strip : model.strips) {
683 for (LXPoint p : strip.points) {
684 float fV = max(-1, 1 - dist(p.x/2., p.y, fX.getValuef()/2., fY.getValuef()) / 64.);
685 colors[p.index] = lx.hsb(
686 (lx.getBaseHuef() + 0.3 * abs(p.x - hOffX.getValuef())) % 360,
687 constrain(80 + 40 * fV, 0, 100),
689 (30 - fV * falloff.getValuef()) * modDist(i + (s*63)%61, offset.getValuef() * strip.metrics.numPoints, strip.metrics.numPoints), 0, 100)
698 class SwipeTransition extends SCTransition {
700 final BasicParameter bleed = new BasicParameter("WIDTH", 0.5);
702 SwipeTransition(GLucose glucose) {
708 void computeBlend(int[] c1, int[] c2, double progress) {
709 float bleedf = 10 + bleed.getValuef() * 200.;
710 float xPos = (float) (-bleedf + progress * (model.xMax + bleedf));
711 for (LXPoint p : model.points) {
712 float d = (p.x - xPos) / bleedf;
714 colors[p.index] = c2[p.index];
716 colors[p.index] = c1[p.index];
718 colors[p.index] = lerpColor(c2[p.index], c1[p.index], d, RGB);
724 abstract class BlendTransition extends SCTransition {
728 BlendTransition(GLucose glucose, int blendType) {
730 this.blendType = blendType;
733 void computeBlend(int[] c1, int[] c2, double progress) {
734 if (progress < 0.5) {
735 for (int i = 0; i < c1.length; ++i) {
736 colors[i] = lerpColor(
738 blendColor(c1[i], c2[i], blendType),
739 (float) (2.*progress),
743 for (int i = 0; i < c1.length; ++i) {
744 colors[i] = lerpColor(
746 blendColor(c1[i], c2[i], blendType),
747 (float) (2.*(1. - progress)),
754 class MultiplyTransition extends BlendTransition {
755 MultiplyTransition(GLucose glucose) {
756 super(glucose, MULTIPLY);
760 class ScreenTransition extends BlendTransition {
761 ScreenTransition(GLucose glucose) {
762 super(glucose, SCREEN);
766 class BurnTransition extends BlendTransition {
767 BurnTransition(GLucose glucose) {
768 super(glucose, BURN);
772 class DodgeTransition extends BlendTransition {
773 DodgeTransition(GLucose glucose) {
774 super(glucose, DODGE);
778 class OverlayTransition extends BlendTransition {
779 OverlayTransition(GLucose glucose) {
780 super(glucose, OVERLAY);
784 class AddTransition extends BlendTransition {
785 AddTransition(GLucose glucose) {
790 class SubtractTransition extends BlendTransition {
791 SubtractTransition(GLucose glucose) {
792 super(glucose, SUBTRACT);
796 class SoftLightTransition extends BlendTransition {
797 SoftLightTransition(GLucose glucose) {
798 super(glucose, SOFT_LIGHT);
802 class BassPod extends SCPattern {
804 private GraphicEQ eq = null;
806 private final BasicParameter clr = new BasicParameter("CLR", 0.5);
808 public BassPod(GLucose glucose) {
813 protected void onActive() {
815 eq = new GraphicEQ(lx, 16);
816 eq.range.setValue(0.4);
817 eq.level.setValue(0.4);
818 eq.slope.setValue(0.6);
819 addParameter(eq.level);
820 addParameter(eq.range);
821 addParameter(eq.attack);
822 addParameter(eq.release);
823 addParameter(eq.slope);
827 public void run(double deltaMs) {
830 float bassLevel = eq.getAverageLevel(0, 5);
832 float satBase = bassLevel*480*clr.getValuef();
834 for (LXPoint p : model.points) {
835 int avgIndex = (int) constrain(1 + abs(p.x-model.cx)/(model.cx)*(eq.numBands-5), 0, eq.numBands-5);
837 for (int i = avgIndex; i < avgIndex + 5; ++i) {
838 value += eq.getLevel(i);
842 float b = constrain(8 * (value*model.yMax - abs(p.y-model.yMax/2.)), 0, 100);
843 colors[p.index] = lx.hsb(
844 (lx.getBaseHuef() + abs(p.y - model.cy) + abs(p.x - model.cx)) % 360,
845 constrain(satBase - .6*dist(p.x, p.y, model.cx, model.cy), 0, 100),
853 class CubeEQ extends SCPattern {
855 private GraphicEQ eq = null;
857 private final BasicParameter edge = new BasicParameter("EDGE", 0.5);
858 private final BasicParameter clr = new BasicParameter("CLR", 0.5);
859 private final BasicParameter blockiness = new BasicParameter("BLK", 0.5);
861 public CubeEQ(GLucose glucose) {
865 protected void onActive() {
867 eq = new GraphicEQ(lx, 16);
868 addParameter(eq.level);
869 addParameter(eq.range);
870 addParameter(eq.attack);
871 addParameter(eq.release);
872 addParameter(eq.slope);
875 addParameter(blockiness);
879 public void run(double deltaMs) {
882 float edgeConst = 2 + 30*edge.getValuef();
883 float clrConst = 1.1 + clr.getValuef();
885 for (LXPoint p : model.points) {
886 float avgIndex = constrain(2 + p.x / model.xMax * (eq.numBands-4), 0, eq.numBands-4);
887 int avgFloor = (int) avgIndex;
889 float leftVal = eq.getLevel(avgFloor);
890 float rightVal = eq.getLevel(avgFloor+1);
891 float smoothValue = lerp(leftVal, rightVal, avgIndex-avgFloor);
893 float chunkyValue = (
894 eq.getLevel(avgFloor/4*4) +
895 eq.getLevel(avgFloor/4*4 + 1) +
896 eq.getLevel(avgFloor/4*4 + 2) +
897 eq.getLevel(avgFloor/4*4 + 3)
900 float value = lerp(smoothValue, chunkyValue, blockiness.getValuef());
902 float b = constrain(edgeConst * (value*model.yMax - p.y), 0, 100);
903 colors[p.index] = lx.hsb(
904 (480 + lx.getBaseHuef() - min(clrConst*p.y, 120)) % 360,
912 class BoomEffect extends SCEffect {
914 final BasicParameter falloff = new BasicParameter("WIDTH", 0.5);
915 final BasicParameter speed = new BasicParameter("SPD", 0.5);
916 final BasicParameter bright = new BasicParameter("BRT", 1.0);
917 final BasicParameter sat = new BasicParameter("SAT", 0.2);
918 List<Layer> layers = new ArrayList<Layer>();
919 final float maxr = sqrt(model.xMax*model.xMax + model.yMax*model.yMax + model.zMax*model.zMax) + 10;
922 LinearEnvelope boom = new LinearEnvelope(-40, 500, 1300);
930 float falloffv = falloffv();
931 boom.setRange(-100 / falloffv, maxr + 100/falloffv, 4000 - speed.getValuef() * 3300);
935 void apply(int[] colors) {
936 float brightv = 100 * bright.getValuef();
937 float falloffv = falloffv();
938 float satv = sat.getValuef() * 100;
939 float huev = lx.getBaseHuef();
940 for (LXPoint p : model.points) {
941 colors[p.index] = blendColor(
943 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)),
949 BoomEffect(GLucose glucose) {
950 super(glucose, true);
951 addParameter(falloff);
953 addParameter(bright);
957 public void onEnable() {
958 for (Layer l : layers) {
959 if (!l.boom.isRunning()) {
964 layers.add(new Layer());
967 private float falloffv() {
968 return 20 - 19 * falloff.getValuef();
971 public void onTrigger() {
975 public void apply(int[] colors) {
976 for (Layer l : layers) {
977 if (l.boom.isRunning()) {
984 public class PianoKeyPattern extends SCPattern {
986 final LinearEnvelope[] cubeBrt;
988 final BasicParameter attack = new BasicParameter("ATK", 0.1);
989 final BasicParameter release = new BasicParameter("REL", 0.5);
990 final BasicParameter level = new BasicParameter("AMB", 0.6);
992 PianoKeyPattern(GLucose glucose) {
995 addParameter(attack);
996 addParameter(release);
998 cubeBrt = new LinearEnvelope[model.cubes.size() / 4];
999 for (int i = 0; i < cubeBrt.length; ++i) {
1000 addModulator(cubeBrt[i] = new LinearEnvelope(0, 0, 100));
1002 base = new SinLFO[model.cubes.size() / 12];
1003 for (int i = 0; i < base.length; ++i) {
1004 addModulator(base[i] = new SinLFO(0, 1, 7000 + 1000*i)).trigger();
1008 private float getAttackTime() {
1009 return 15 + attack.getValuef()*attack.getValuef() * 2000;
1012 private float getReleaseTime() {
1013 return 15 + release.getValuef() * 3000;
1016 private LinearEnvelope getEnvelope(int index) {
1017 return cubeBrt[index % cubeBrt.length];
1020 private SinLFO getBase(int index) {
1021 return base[index % base.length];
1024 public boolean noteOn(Note note) {
1025 LinearEnvelope env = getEnvelope(note.getPitch());
1026 env.setEndVal(min(1, env.getValuef() + (note.getVelocity() / 127.)), getAttackTime()).start();
1030 public boolean noteOff(Note note) {
1031 getEnvelope(note.getPitch()).setEndVal(0, getReleaseTime()).start();
1035 public void run(double deltaMs) {
1037 float huef = lx.getBaseHuef();
1038 float levelf = level.getValuef();
1039 for (Cube c : model.cubes) {
1040 float v = max(getBase(i).getValuef() * levelf/4., getEnvelope(i++).getValuef());
1042 (huef + 20*v + abs(c.cx-model.xMax/2.)*.3 + c.cy) % 360,
1050 class CrossSections extends SCPattern {
1052 final SinLFO x = new SinLFO(0, model.xMax, 5000);
1053 final SinLFO y = new SinLFO(0, model.yMax, 6000);
1054 final SinLFO z = new SinLFO(0, model.zMax, 7000);
1056 final BasicParameter xw = new BasicParameter("XWID", 0.3);
1057 final BasicParameter yw = new BasicParameter("YWID", 0.3);
1058 final BasicParameter zw = new BasicParameter("ZWID", 0.3);
1059 final BasicParameter xr = new BasicParameter("XRAT", 0.7);
1060 final BasicParameter yr = new BasicParameter("YRAT", 0.6);
1061 final BasicParameter zr = new BasicParameter("ZRAT", 0.5);
1062 final BasicParameter xl = new BasicParameter("XLEV", 1);
1063 final BasicParameter yl = new BasicParameter("YLEV", 1);
1064 final BasicParameter zl = new BasicParameter("ZLEV", 0.5);
1067 CrossSections(GLucose glucose) {
1069 addModulator(x).trigger();
1070 addModulator(y).trigger();
1071 addModulator(z).trigger();
1075 protected void addParams() {
1087 void onParameterChanged(LXParameter p) {
1089 x.setDuration(10000 - 8800*p.getValuef());
1090 } else if (p == yr) {
1091 y.setDuration(10000 - 9000*p.getValuef());
1092 } else if (p == zr) {
1093 z.setDuration(10000 - 9000*p.getValuef());
1099 protected void updateXYZVals() {
1105 public void run(double deltaMs) {
1108 float xlv = 100*xl.getValuef();
1109 float ylv = 100*yl.getValuef();
1110 float zlv = 100*zl.getValuef();
1112 float xwv = 100. / (10 + 40*xw.getValuef());
1113 float ywv = 100. / (10 + 40*yw.getValuef());
1114 float zwv = 100. / (10 + 40*zw.getValuef());
1116 for (LXPoint p : model.points) {
1118 c = blendColor(c, lx.hsb(
1119 (lx.getBaseHuef() + p.x/10 + p.y/3) % 360,
1120 constrain(140 - 1.1*abs(p.x - model.xMax/2.), 0, 100),
1121 max(0, xlv - xwv*abs(p.x - xv))
1123 c = blendColor(c, lx.hsb(
1124 (lx.getBaseHuef() + 80 + p.y/10) % 360,
1125 constrain(140 - 2.2*abs(p.y - model.yMax/2.), 0, 100),
1126 max(0, ylv - ywv*abs(p.y - yv))
1128 c = blendColor(c, lx.hsb(
1129 (lx.getBaseHuef() + 160 + p.z / 10 + p.y/2) % 360,
1130 constrain(140 - 2.2*abs(p.z - model.zMax/2.), 0, 100),
1131 max(0, zlv - zwv*abs(p.z - zv))
1133 colors[p.index] = c;
1138 class Blinders extends SCPattern {
1141 final TriangleLFO r;
1143 final TriangleLFO hs;
1145 public Blinders(GLucose glucose) {
1148 for (int i = 0; i < m.length; ++i) {
1149 addModulator(m[i] = new SinLFO(0.5, 120, (120000. / (3+i)))).trigger();
1151 addModulator(r = new TriangleLFO(9000, 15000, 29000)).trigger();
1152 addModulator(s = new SinLFO(-20, 275, 11000)).trigger();
1153 addModulator(hs = new TriangleLFO(0.1, 0.5, 15000)).trigger();
1154 s.modulateDurationBy(r);
1157 public void run(double deltaMs) {
1158 float hv = lx.getBaseHuef();
1160 for (Strip strip : model.strips) {
1162 float mv = m[si % m.length].getValuef();
1163 for (LXPoint p : strip.points) {
1164 colors[p.index] = lx.hsb(
1165 (hv + p.z + p.y*hs.getValuef()) % 360,
1166 min(100, abs(p.x - s.getValuef())/2.),
1167 max(0, 100 - mv/2. - mv * abs(i - (strip.metrics.length-1)/2.))
1176 class Psychedelia extends SCPattern {
1179 SinLFO m = new SinLFO(-0.5, NUM-0.5, 9000);
1180 SinLFO s = new SinLFO(-20, 147, 11000);
1181 TriangleLFO h = new TriangleLFO(0, 240, 19000);
1182 SinLFO c = new SinLFO(-.2, .8, 31000);
1184 Psychedelia(GLucose glucose) {
1186 addModulator(m).trigger();
1187 addModulator(s).trigger();
1188 addModulator(h).trigger();
1189 addModulator(c).trigger();
1192 void run(double deltaMs) {
1193 float huev = h.getValuef();
1194 float cv = c.getValuef();
1195 float sv = s.getValuef();
1196 float mv = m.getValuef();
1198 for (Strip strip : model.strips) {
1199 for (LXPoint p : strip.points) {
1200 colors[p.index] = lx.hsb(
1201 (huev + i*constrain(cv, 0, 2) + p.z/2. + p.x/4.) % 360,
1202 min(100, abs(p.y-sv)),
1203 max(0, 100 - 50*abs((i%NUM) - mv))
1211 class AskewPlanes extends SCPattern {
1214 private final SinLFO a;
1215 private final SinLFO b;
1216 private final SinLFO c;
1223 addModulator(a = new SinLFO(-1, 1, 4000 + 1029*i)).trigger();
1224 addModulator(b = new SinLFO(-1, 1, 11000 - 1104*i)).trigger();
1225 addModulator(c = new SinLFO(-50, 50, 4000 + 1000*i * ((i % 2 == 0) ? 1 : -1))).trigger();
1228 void run(double deltaMs) {
1232 denom = sqrt(av*av + bv*bv);
1236 final Plane[] planes;
1237 final int NUM_PLANES = 3;
1239 AskewPlanes(GLucose glucose) {
1241 planes = new Plane[NUM_PLANES];
1242 for (int i = 0; i < planes.length; ++i) {
1243 planes[i] = new Plane(i);
1247 public void run(double deltaMs) {
1248 float huev = lx.getBaseHuef();
1250 // This is super fucking bizarre. But if this is a for loop, the framerate
1251 // tanks to like 30FPS, instead of 60. Call them manually and it works fine.
1252 // Doesn't make ANY sense... there must be some weird side effect going on
1253 // with the Processing internals perhaps?
1254 // for (Plane plane : planes) {
1255 // plane.run(deltaMs);
1257 planes[0].run(deltaMs);
1258 planes[1].run(deltaMs);
1259 planes[2].run(deltaMs);
1261 for (LXPoint p : model.points) {
1262 float d = MAX_FLOAT;
1263 for (Plane plane : planes) {
1264 if (plane.denom != 0) {
1265 d = min(d, abs(plane.av*(p.x-model.cx) + plane.bv*(p.y-model.cy) + plane.cv) / plane.denom);
1268 colors[p.index] = lx.hsb(
1269 (huev + abs(p.x-model.cx)*.3 + p.y*.8) % 360,
1270 max(0, 100 - .8*abs(p.x - model.cx)),
1271 constrain(140 - 10.*d, 0, 100)
1277 class ShiftingPlane extends SCPattern {
1279 final SinLFO a = new SinLFO(-.2, .2, 5300);
1280 final SinLFO b = new SinLFO(1, -1, 13300);
1281 final SinLFO c = new SinLFO(-1.4, 1.4, 5700);
1282 final SinLFO d = new SinLFO(-10, 10, 9500);
1284 ShiftingPlane(GLucose glucose) {
1286 addModulator(a).trigger();
1287 addModulator(b).trigger();
1288 addModulator(c).trigger();
1289 addModulator(d).trigger();
1292 public void run(double deltaMs) {
1293 float hv = lx.getBaseHuef();
1294 float av = a.getValuef();
1295 float bv = b.getValuef();
1296 float cv = c.getValuef();
1297 float dv = d.getValuef();
1298 float denom = sqrt(av*av + bv*bv + cv*cv);
1299 for (LXPoint p : model.points) {
1300 float d = abs(av*(p.x-model.cx) + bv*(p.y-model.cy) + cv*(p.z-model.cz) + dv) / denom;
1301 colors[p.index] = lx.hsb(
1302 (hv + abs(p.x-model.cx)*.6 + abs(p.y-model.cy)*.9 + abs(p.z - model.cz)) % 360,
1303 constrain(110 - d*6, 0, 100),
1304 constrain(130 - 7*d, 0, 100)
1310 class Traktor extends SCPattern {
1312 final int FRAME_WIDTH = 60;
1314 final BasicParameter speed = new BasicParameter("SPD", 0.5);
1316 private float[] bass = new float[FRAME_WIDTH];
1317 private float[] treble = new float[FRAME_WIDTH];
1319 private int index = 0;
1320 private GraphicEQ eq = null;
1322 public Traktor(GLucose glucose) {
1324 for (int i = 0; i < FRAME_WIDTH; ++i) {
1328 addParameter(speed);
1331 public void onActive() {
1333 eq = new GraphicEQ(lx, 16);
1334 eq.slope.setValue(0.6);
1335 eq.level.setValue(0.65);
1336 eq.range.setValue(0.35);
1337 eq.release.setValue(0.4);
1338 addParameter(eq.level);
1339 addParameter(eq.range);
1340 addParameter(eq.attack);
1341 addParameter(eq.release);
1342 addParameter(eq.slope);
1348 public void run(double deltaMs) {
1351 int stepThresh = (int) (40 - 39*speed.getValuef());
1353 if (counter < stepThresh) {
1356 counter = counter % stepThresh;
1358 index = (index + 1) % FRAME_WIDTH;
1360 float rawBass = eq.getAverageLevel(0, 4);
1361 float rawTreble = eq.getAverageLevel(eq.numBands-7, 7);
1363 bass[index] = rawBass * rawBass * rawBass * rawBass;
1364 treble[index] = rawTreble * rawTreble;
1366 for (LXPoint p : model.points) {
1367 int i = (int) constrain((model.xMax - p.x) / model.xMax * FRAME_WIDTH, 0, FRAME_WIDTH-1);
1368 int pos = (index + FRAME_WIDTH - i) % FRAME_WIDTH;
1370 colors[p.index] = lx.hsb(
1371 (360 + lx.getBaseHuef() + .8*abs(p.x-model.cx)) % 360,
1373 constrain(9 * (bass[pos]*model.cy - abs(p.y - model.cy + 5)), 0, 100)
1375 colors[p.index] = blendColor(colors[p.index], lx.hsb(
1376 (400 + lx.getBaseHuef() + .5*abs(p.x-model.cx)) % 360,
1378 constrain(5 * (treble[pos]*.6*model.cy - abs(p.y - model.cy)), 0, 100)
1385 class ColorFuckerEffect extends SCEffect {
1387 final BasicParameter level = new BasicParameter("BRT", 1);
1388 final BasicParameter desat = new BasicParameter("DSAT", 0);
1389 final BasicParameter hueShift = new BasicParameter("HSHFT", 0);
1390 final BasicParameter sharp = new BasicParameter("SHARP", 0);
1391 final BasicParameter soft = new BasicParameter("SOFT", 0);
1392 final BasicParameter mono = new BasicParameter("MONO", 0);
1393 final BasicParameter invert = new BasicParameter("INVERT", 0);
1396 float[] hsb = new float[3];
1398 ColorFuckerEffect(GLucose glucose) {
1400 addParameter(level);
1401 addParameter(desat);
1402 addParameter(sharp);
1403 addParameter(hueShift);
1406 addParameter(invert);
1409 public void apply(int[] colors) {
1413 float bMod = level.getValuef();
1414 float sMod = 1 - desat.getValuef();
1415 float hMod = hueShift.getValuef();
1416 float fSharp = sharp.getValuef();
1417 float fSoft = soft.getValuef();
1418 boolean mon = mono.getValuef() > 0.5;
1419 boolean ivt = invert.getValuef() > 0.5;
1420 if (bMod < 1 || sMod < 1 || hMod > 0 || fSharp > 0 || ivt || mon || fSoft > 0) {
1421 for (int i = 0; i < colors.length; ++i) {
1422 lx.RGBtoHSB(colors[i], hsb);
1424 hsb[0] = lx.getBaseHuef() / 360.;
1427 hsb[2] = 1 - hsb[2];
1430 fSharp = 1/(1-fSharp);
1432 hsb[2] = pow(hsb[2],fSharp);
1434 hsb[2] = 1-pow(1-hsb[2],fSharp);
1439 hsb[2] = lerp(hsb[2], 0.5 + 2 * (hsb[2]-0.5)*(hsb[2]-0.5), fSoft);
1441 hsb[2] = lerp(hsb[2], 0.5 * sqrt(2*hsb[2]), fSoft);
1445 (360. * hsb[0] + hMod*360.) % 360,
1446 100. * hsb[1] * sMod,
1447 100. * hsb[2] * bMod
1454 class QuantizeEffect extends SCEffect {
1456 color[] quantizedFrame;
1458 final BasicParameter amount = new BasicParameter("AMT", 0);
1460 QuantizeEffect(GLucose glucose) {
1462 quantizedFrame = new color[glucose.lx.total];
1466 public void apply(int[] colors) {
1467 float fQuant = amount.getValuef();
1469 float tRamp = (lx.tempo.rampf() % (1./pow(2,floor((1-fQuant) * 4))));
1470 float f = lastQuant;
1473 for (int i = 0; i < colors.length; ++i) {
1474 colors[i] = quantizedFrame[i];
1479 for (int i = 0; i < colors.length; ++i) {
1480 quantizedFrame[i] = colors[i];
1485 class BlurEffect extends SCEffect {
1487 final BasicParameter amount = new BasicParameter("AMT", 0);
1489 final LinearEnvelope env = new LinearEnvelope(0, 1, 100);
1491 BlurEffect(GLucose glucose) {
1493 addParameter(amount);
1495 frame = new int[lx.total];
1496 for (int i = 0; i < frame.length; ++i) {
1501 public void onEnable() {
1502 env.setRangeFromHereTo(1, 400).start();
1503 for (int i = 0; i < frame.length; ++i) {
1508 public void onDisable() {
1509 env.setRangeFromHereTo(0, 1000).start();
1512 public void apply(int[] colors) {
1513 float amt = env.getValuef() * amount.getValuef();
1516 amt = 1 - (amt*amt*amt);
1517 for (int i = 0; i < colors.length; ++i) {
1518 // frame[i] = colors[i] = blendColor(colors[i], lerpColor(#000000, frame[i], amt, RGB), SCREEN);
1519 frame[i] = colors[i] = lerpColor(colors[i], blendColor(colors[i], frame[i], SCREEN), amt, RGB);