1 class Cathedrals extends SCPattern {
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);
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);
33 public void run(double deltaMs) {
35 float bassLevel = eq.getAverageLevel(0, 4);
36 float trebleLevel = eq.getAverageLevel(8, 6);
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));
46 float sf = 100. / (70 - 69.9*sat.getValuef());
48 for (LXPoint p : model.points) {
52 middle = model.yMax * 3/5.;
55 middle = model.yMax * 1/5.;
57 if (abs(p.x - cx) < arm) {
58 d = min(abs(p.x - cx), abs(p.y - middle));
60 colors[p.index] = lx.hsb(
61 (lx.getBaseHuef() + .2*abs(p.y - model.cy)) % 360,
62 min(100, sf*dist(abs(p.x - cx), p.y, arm, middle)),
63 constrain(120 - d*falloff, 0, 100));
68 class MidiMusic extends SCPattern {
70 private final Stack<LXLayer> newLayers = new Stack<LXLayer>();
72 private final Map<Integer, LightUp> lightMap = new HashMap<Integer, LightUp>();
73 private final List<LightUp> lights = new ArrayList<LightUp>();
74 private final BasicParameter lightSize = new BasicParameter("SIZE", 0.5);
76 private final List<Sweep> sweeps = new ArrayList<Sweep>();
78 private final LinearEnvelope sparkle = new LinearEnvelope(0, 1, 500);
79 private boolean sparkleDirection = true;
80 private float sparkleBright = 100;
82 private final BasicParameter wave = new BasicParameter("WAVE", 0);
86 addParameter(lightSize);
88 addModulator(sparkle).setValue(1);
92 for (LightUp light : lights) {
97 class Sweep extends LXLayer {
99 final LinearEnvelope position = new LinearEnvelope(0, 1, 1000);
104 addModulator(position);
107 public void run(double deltaMs, color[] colors) {
108 if (!position.isRunning()) {
111 float posf = position.getValuef();
112 for (LXPoint p : model.points) {
113 colors[p.index] = blendColor(colors[p.index], lx.hsb(
114 (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360,
116 max(0, bright - posf*100 - falloff*abs(p.y - posf*model.yMax))
122 class LightUp extends LXLayer {
124 private final LinearEnvelope brt = new LinearEnvelope(0, 0, 0);
125 private final Accelerator yPos = new Accelerator(0, 0, 0);
133 boolean isAvailable() {
134 return brt.getValuef() <= 0;
137 void noteOn(Note note) {
138 xPos = lerp(0, model.xMax, constrain(0.5 + (note.getPitch() - 60) / 28., 0, 1));
139 yPos.setValue(lerp(20, model.yMax*.72, note.getVelocity() / 127.)).stop();
140 brt.setRangeFromHereTo(lerp(40, 100, note.getVelocity() / 127.), 20).start();
143 void noteOff(Note note) {
144 yPos.setVelocity(0).setAcceleration(-380).start();
145 brt.setRangeFromHereTo(0, 1000).start();
148 public void run(double deltaMs, color[] colors) {
149 float bVal = brt.getValuef();
153 float yVal = yPos.getValuef();
154 for (LXPoint p : model.points) {
155 float falloff = 6 - 5*lightSize.getValuef();
156 float b = max(0, bVal - falloff*dist(p.x, p.y, xPos, yVal));
158 colors[p.index] = blendColor(colors[p.index], lx.hsb(
159 (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360,
168 private LightUp getLight() {
169 for (LightUp light : lights) {
170 if (light.isAvailable()) {
174 LightUp newLight = new LightUp();
175 lights.add(newLight);
176 synchronized(newLayers) {
177 newLayers.push(newLight);
182 private Sweep getSweep() {
183 for (Sweep s : sweeps) {
184 if (!s.position.isRunning()) {
188 Sweep newSweep = new Sweep();
189 sweeps.add(newSweep);
190 synchronized(newLayers) {
191 newLayers.push(newSweep);
196 public synchronized boolean noteOn(Note note) {
197 if (note.getChannel() == 0) {
198 LightUp light = getLight();
199 lightMap.put(note.getPitch(), light);
201 } else if (note.getChannel() == 1) {
202 } else if (note.getChannel() == 9) {
203 if (note.getVelocity() > 0) {
204 switch (note.getPitch()) {
206 Sweep s = getSweep();
207 s.bright = 50 + note.getVelocity() / 127. * 50;
208 s.falloff = 20 - note.getVelocity() / 127. * 17;
209 s.position.trigger();
212 sparkleBright = note.getVelocity() / 127. * 100;
213 sparkleDirection = true;
217 sparkleBright = note.getVelocity() / 127. * 100;
218 sparkleDirection = false;
222 effects.boom.trigger();
225 effects.flash.trigger();
233 public synchronized boolean noteOff(Note note) {
234 if (note.getChannel() == 0) {
235 LightUp light = lightMap.get(note.getPitch());
243 final float[] wval = new float[16];
246 public synchronized void run(double deltaMs) {
247 wavoff += deltaMs * .001;
248 for (int i = 0; i < wval.length; ++i) {
249 wval[i] = model.cy + 0.2 * model.yMax/2. * sin(wavoff + i / 1.9);
251 float sparklePos = (sparkleDirection ? sparkle.getValuef() : (1 - sparkle.getValuef())) * (Cube.POINTS_PER_STRIP)/2.;
252 float maxBright = sparkleBright * (1 - sparkle.getValuef());
253 for (Strip s : model.strips) {
255 for (LXPoint p : s.points) {
256 int wavi = (int) constrain(p.x / model.xMax * wval.length, 0, wval.length-1);
257 float wavb = max(0, wave.getValuef()*100. - 8.*abs(p.y - wval[wavi]));
258 colors[p.index] = lx.hsb(
259 (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360,
261 constrain(wavb + max(0, maxBright - 40.*abs(sparklePos - abs(i - (Cube.POINTS_PER_STRIP-1)/2.))), 0, 100)
267 if (!newLayers.isEmpty()) {
268 synchronized(newLayers) {
269 while (!newLayers.isEmpty()) {
270 addLayer(newLayers.pop());
277 class Pulley extends SCPattern {
279 final int NUM_DIVISIONS = 16;
280 private final Accelerator[] gravity = new Accelerator[NUM_DIVISIONS];
281 private final Click[] delays = new Click[NUM_DIVISIONS];
283 private final Click reset = new Click(9000);
284 private boolean isRising = false;
286 private BasicParameter sz = new BasicParameter("SIZE", 0.5);
287 private BasicParameter beatAmount = new BasicParameter("BEAT", 0);
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));
295 addModulator(reset).start();
297 addParameter(beatAmount);
302 private void trigger() {
303 isRising = !isRising;
305 for (Accelerator g : gravity) {
307 g.setSpeed(random(20, 33), 0).start();
309 g.setVelocity(0).setAcceleration(-420);
310 delays[i].setDuration(random(0, 500)).trigger();
316 public void run(double deltaMs) {
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) {
328 // } else if (g.getValuef() > model.yMax*.55) {
329 // if (g.getVelocityf() > 10) {
330 // g.setAcceleration(-16);
332 // g.setAcceleration(0);
338 for (Click d : delays) {
345 for (Accelerator g : gravity) {
346 if (g.getValuef() < 0) {
347 g.setValue(-g.getValuef());
348 g.setVelocity(-g.getVelocityf() * random(0.74, 0.84));
353 // A little silliness to test the grid API
354 if (midiEngine != null && midiEngine.getFocusedPattern() == this) {
355 for (int i = 0; i < 5; ++i) {
356 for (int j = 0; j < 8; ++j) {
357 int gi = (int) constrain(j * NUM_DIVISIONS / 8, 0, NUM_DIVISIONS-1);
358 float b = 1 - 4.*abs((6-i)/6. - gravity[gi].getValuef() / model.yMax);
359 midiEngine.grid.setState(i, j, (b < 0) ? 0 : 3);
364 float fPos = 1 - lx.tempo.rampf();
366 fPos = .2 + 4 * (.2 - fPos);
368 float falloff = 100. / (3 + sz.getValuef() * 36 + fPos * beatAmount.getValuef()*48);
369 for (LXPoint p : model.points) {
370 int gi = (int) constrain((p.x - model.xMin) * NUM_DIVISIONS / (model.xMax - model.xMin), 0, NUM_DIVISIONS-1);
371 colors[p.index] = lx.hsb(
372 (lx.getBaseHuef() + abs(p.x - model.cx)*.8 + p.y*.4) % 360,
373 constrain(130 - p.y*.8, 0, 100),
374 max(0, 100 - abs(p.y - gravity[gi].getValuef())*falloff)
380 class ViolinWave extends SCPattern {
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);
393 LinearEnvelope dbValue = new LinearEnvelope(0, 0, 10);
400 addParameter(release);
403 addParameter(period);
405 addParameter(pSpeed);
406 addParameter(pDensity);
408 addModulator(dbValue);
411 final List<Particle> particles = new ArrayList<Particle>();
415 LinearEnvelope x = new LinearEnvelope(0, 0, 0);
416 LinearEnvelope y = new LinearEnvelope(0, 0, 0);
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();
432 return x.isRunning() || y.isRunning();
435 public void run(double deltaMs) {
440 float pFalloff = (30 - 27*pSize.getValuef());
441 for (LXPoint p : model.points) {
442 float b = 100 - pFalloff * (abs(p.x - x.getValuef()) + abs(p.y - y.getValuef()));
444 colors[p.index] = blendColor(colors[p.index], lx.hsb(
445 lx.getBaseHuef(), 20, b
452 float[] centers = new float[30];
454 boolean rising = true;
456 void fireParticle(boolean direction) {
457 boolean gotOne = false;
458 for (Particle p : particles) {
460 p.trigger(direction);
464 particles.add(new Particle().trigger(direction));
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())));
473 float zeroDBReference = pow(10, (50 - 190*level.getValuef())/20.);
474 float dB = 20*GraphicEQ.log10(lx.audioInput().mix.level() / zeroDBReference);
475 if (dB > dbValue.getValuef()) {
477 dbValue.setRangeFromHereTo(dB, 10).trigger();
480 for (int j = 0; j < pDensity.getValuef()*3; ++j) {
486 dbValue.setRangeFromHereTo(max(dB, -96), 50 + 1000*release.getValuef()).trigger();
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());
492 for (LXPoint p : model.points) {
493 int ci = (int) lerp(0, centers.length-1, (p.x - model.xMin) / (model.xMax - model.xMin));
494 float rFactor = 1.0 - 0.9 * abs(p.x - model.cx) / (model.xMax - model.cx);
495 colors[p.index] = lx.hsb(
496 (lx.getBaseHuef() + abs(p.x - model.cx)) % 360,
497 min(100, 20 + 8*abs(p.y - centers[ci])),
498 constrain(edg*(val*rFactor - rng * abs(p.y-centers[ci])), 0, 100)
502 for (Particle p : particles) {
508 class BouncyBalls extends SCPattern {
510 static final int NUM_BALLS = 6;
515 TriangleLFO xPos = new TriangleLFO(0, model.xMax, random(8000, 19000));
519 addModulator(xPos.setBasis(random(0, TWO_PI)).start());
520 addModulator(yPos = new Accelerator(0, 0, 0));
521 zPos = lerp(model.zMin, model.zMax, (i+2.) / (NUM_BALLS + 4.));
524 void bounce(float midiVel) {
525 float v = 100 + 8*midiVel;
526 yPos.setSpeed(v, getAccel(v, 60 / lx.tempo.bpmf())).start();
529 float getAccel(float v, float oneBeat) {
530 return -2*v / oneBeat;
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()));
541 yPos.setValue(flrLevel).stop();
544 float falloff = 130.f / (12 + blobSize.getValuef() * 36);
545 float xv = xPos.getValuef();
546 float yv = yPos.getValuef();
548 for (LXPoint p : model.points) {
549 float d = sqrt((p.x-xv)*(p.x-xv) + (p.y-yv)*(p.y-yv) + .1*(p.z-zPos)*(p.z-zPos));
550 float b = constrain(130 - falloff*d, 0, 100);
552 colors[p.index] = blendColor(colors[p.index], lx.hsb(
553 (lx.getBaseHuef() + p.y*.5 + abs(model.cx - p.x) * .5) % 360,
554 max(0, 100 - .45*(p.y - flrLevel)),
562 final BouncyBall[] balls = new BouncyBall[NUM_BALLS];
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);
570 for (int i = 0; i < balls.length; ++i) {
571 balls[i] = new BouncyBall(i);
573 addParameter(bounce);
575 addParameter(blobSize);
578 public void run(double deltaMs) {
580 for (BouncyBall b : balls) {
585 public boolean noteOn(Note note) {
586 int pitch = (note.getPitch() + note.getChannel()) % NUM_BALLS;
587 balls[pitch].bounce(note.getVelocity());
592 class SpaceTime extends SCPattern {
594 SinLFO pos = new SinLFO(0, 1, 3000);
595 SinLFO rate = new SinLFO(1000, 9000, 13000);
596 SinLFO falloff = new SinLFO(10, 70, 5000);
599 BasicParameter rateParameter = new BasicParameter("RATE", 0.5);
600 BasicParameter sizeParameter = new BasicParameter("SIZE", 0.5);
603 public SpaceTime(LX lx) {
606 addModulator(pos).trigger();
607 addModulator(rate).trigger();
608 addModulator(falloff).trigger();
609 pos.modulateDurationBy(rate);
610 addParameter(rateParameter);
611 addParameter(sizeParameter);
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());
622 void run(double deltaMs) {
623 angle += deltaMs * 0.0007;
624 float sVal1 = model.strips.size() * (0.5 + 0.5*sin(angle));
625 float sVal2 = model.strips.size() * (0.5 + 0.5*cos(angle));
627 float pVal = pos.getValuef();
628 float fVal = falloff.getValuef();
631 for (Strip strip : model.strips) {
633 for (LXPoint p : strip.points) {
634 colors[p.index] = lx.hsb(
635 (lx.getBaseHuef() + 360 - p.x*.2 + p.y * .3) % 360,
636 constrain(.4 * min(abs(s - sVal1), abs(s - sVal2)), 20, 100),
637 max(0, 100 - fVal*abs(i - pVal*(strip.metrics.numPoints - 1)))
646 class Swarm extends SCPattern {
648 SawLFO offset = new SawLFO(0, 1, 1000);
649 SinLFO rate = new SinLFO(350, 1200, 63000);
650 SinLFO falloff = new SinLFO(15, 50, 17000);
651 SinLFO fX = new SinLFO(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);
655 public Swarm(LX lx) {
658 addModulator(offset).trigger();
659 addModulator(rate).trigger();
660 addModulator(falloff).trigger();
661 addModulator(fX).trigger();
662 addModulator(fY).trigger();
663 addModulator(hOffX).trigger();
664 offset.modulateDurationBy(rate);
667 float modDist(float v1, float v2, float mod) {
671 return min(v2-v1, v1+mod-v2);
674 return min(v1-v2, v2+mod-v1);
678 void run(double deltaMs) {
680 for (Strip strip : model.strips) {
682 for (LXPoint p : strip.points) {
683 float fV = max(-1, 1 - dist(p.x/2., p.y, fX.getValuef()/2., fY.getValuef()) / 64.);
684 colors[p.index] = lx.hsb(
685 (lx.getBaseHuef() + 0.3 * abs(p.x - hOffX.getValuef())) % 360,
686 constrain(80 + 40 * fV, 0, 100),
688 (30 - fV * falloff.getValuef()) * modDist(i + (s*63)%61, offset.getValuef() * strip.metrics.numPoints, strip.metrics.numPoints), 0, 100)
697 class SwipeTransition extends LXTransition {
699 final BasicParameter bleed = new BasicParameter("WIDTH", 0.5);
701 SwipeTransition(LX lx) {
707 void computeBlend(int[] c1, int[] c2, double progress) {
708 float bleedf = 10 + bleed.getValuef() * 200.;
709 float xPos = (float) (-bleedf + progress * (model.xMax + bleedf));
710 for (LXPoint p : model.points) {
711 float d = (p.x - xPos) / bleedf;
713 colors[p.index] = c2[p.index];
715 colors[p.index] = c1[p.index];
717 colors[p.index] = lerpColor(c2[p.index], c1[p.index], d, RGB);
723 class BassPod extends SCPattern {
725 private GraphicEQ eq = null;
727 private final BasicParameter clr = new BasicParameter("CLR", 0.5);
729 public BassPod(LX lx) {
736 eq = new GraphicEQ(lx, 16);
737 eq.range.setValue(0.4);
738 eq.level.setValue(0.4);
739 eq.slope.setValue(0.6);
740 addParameter(eq.level);
741 addParameter(eq.range);
742 addParameter(eq.attack);
743 addParameter(eq.release);
744 addParameter(eq.slope);
748 public void run(double deltaMs) {
751 float bassLevel = eq.getAverageLevel(0, 5);
753 float satBase = bassLevel*480*clr.getValuef();
755 for (LXPoint p : model.points) {
756 int avgIndex = (int) constrain(1 + abs(p.x-model.cx)/(model.cx)*(eq.numBands-5), 0, eq.numBands-5);
758 for (int i = avgIndex; i < avgIndex + 5; ++i) {
759 value += eq.getLevel(i);
763 float b = constrain(8 * (value*model.yMax - abs(p.y-model.yMax/2.)), 0, 100);
764 colors[p.index] = lx.hsb(
765 (lx.getBaseHuef() + abs(p.y - model.cy) + abs(p.x - model.cx)) % 360,
766 constrain(satBase - .6*dist(p.x, p.y, model.cx, model.cy), 0, 100),
774 class CubeEQ extends SCPattern {
776 private GraphicEQ eq = null;
778 private final BasicParameter edge = new BasicParameter("EDGE", 0.5);
779 private final BasicParameter clr = new BasicParameter("CLR", 0.5);
780 private final BasicParameter blockiness = new BasicParameter("BLK", 0.5);
782 public CubeEQ(LX lx) {
788 eq = new GraphicEQ(lx, 16);
789 addParameter(eq.level);
790 addParameter(eq.range);
791 addParameter(eq.attack);
792 addParameter(eq.release);
793 addParameter(eq.slope);
796 addParameter(blockiness);
800 public void run(double deltaMs) {
803 float edgeConst = 2 + 30*edge.getValuef();
804 float clrConst = 1.1 + clr.getValuef();
806 for (LXPoint p : model.points) {
807 float avgIndex = constrain(2 + p.x / model.xMax * (eq.numBands-4), 0, eq.numBands-4);
808 int avgFloor = (int) avgIndex;
810 float leftVal = eq.getLevel(avgFloor);
811 float rightVal = eq.getLevel(avgFloor+1);
812 float smoothValue = lerp(leftVal, rightVal, avgIndex-avgFloor);
814 float chunkyValue = (
815 eq.getLevel(avgFloor/4*4) +
816 eq.getLevel(avgFloor/4*4 + 1) +
817 eq.getLevel(avgFloor/4*4 + 2) +
818 eq.getLevel(avgFloor/4*4 + 3)
821 float value = lerp(smoothValue, chunkyValue, blockiness.getValuef());
823 float b = constrain(edgeConst * (value*model.yMax - p.y), 0, 100);
824 colors[p.index] = lx.hsb(
825 (480 + lx.getBaseHuef() - min(clrConst*p.y, 120)) % 360,
833 class BoomEffect extends LXEffect {
835 final BasicParameter falloff = new BasicParameter("WIDTH", 0.5);
836 final BasicParameter speed = new BasicParameter("SPD", 0.5);
837 final BasicParameter bright = new BasicParameter("BRT", 1.0);
838 final BasicParameter sat = new BasicParameter("SAT", 0.2);
839 List<Layer> layers = new ArrayList<Layer>();
840 final float maxr = sqrt(model.xMax*model.xMax + model.yMax*model.yMax + model.zMax*model.zMax) + 10;
843 LinearEnvelope boom = new LinearEnvelope(-40, 500, 1300);
851 float falloffv = falloffv();
852 boom.setRange(-100 / falloffv, maxr + 100/falloffv, 4000 - speed.getValuef() * 3300);
856 void apply(int[] colors) {
857 float brightv = 100 * bright.getValuef();
858 float falloffv = falloffv();
859 float satv = sat.getValuef() * 100;
860 float huev = lx.getBaseHuef();
861 for (LXPoint p : model.points) {
862 colors[p.index] = blendColor(
864 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)),
872 addParameter(falloff);
874 addParameter(bright);
878 public void onEnable() {
879 for (Layer l : layers) {
880 if (!l.boom.isRunning()) {
885 layers.add(new Layer());
888 private float falloffv() {
889 return 20 - 19 * falloff.getValuef();
892 public void onTrigger() {
896 public void apply(int[] colors) {
897 for (Layer l : layers) {
898 if (l.boom.isRunning()) {
905 public class PianoKeyPattern extends SCPattern {
907 final LinearEnvelope[] cubeBrt;
909 final BasicParameter attack = new BasicParameter("ATK", 0.1);
910 final BasicParameter release = new BasicParameter("REL", 0.5);
911 final BasicParameter level = new BasicParameter("AMB", 0.6);
913 PianoKeyPattern(LX lx) {
916 addParameter(attack);
917 addParameter(release);
919 cubeBrt = new LinearEnvelope[model.cubes.size() / 4];
920 for (int i = 0; i < cubeBrt.length; ++i) {
921 addModulator(cubeBrt[i] = new LinearEnvelope(0, 0, 100));
923 base = new SinLFO[model.cubes.size() / 12];
924 for (int i = 0; i < base.length; ++i) {
925 addModulator(base[i] = new SinLFO(0, 1, 7000 + 1000*i)).trigger();
929 private float getAttackTime() {
930 return 15 + attack.getValuef()*attack.getValuef() * 2000;
933 private float getReleaseTime() {
934 return 15 + release.getValuef() * 3000;
937 private LinearEnvelope getEnvelope(int index) {
938 return cubeBrt[index % cubeBrt.length];
941 private SinLFO getBase(int index) {
942 return base[index % base.length];
945 public boolean noteOn(Note note) {
946 LinearEnvelope env = getEnvelope(note.getPitch());
947 env.setEndVal(min(1, env.getValuef() + (note.getVelocity() / 127.)), getAttackTime()).start();
951 public boolean noteOff(Note note) {
952 getEnvelope(note.getPitch()).setEndVal(0, getReleaseTime()).start();
956 public void run(double deltaMs) {
958 float huef = lx.getBaseHuef();
959 float levelf = level.getValuef();
960 for (Cube c : model.cubes) {
961 float v = max(getBase(i).getValuef() * levelf/4., getEnvelope(i++).getValuef());
963 (huef + 20*v + abs(c.cx-model.xMax/2.)*.3 + c.cy) % 360,
971 class CrossSections extends SCPattern {
973 final SinLFO x = new SinLFO(0, model.xMax, 5000);
974 final SinLFO y = new SinLFO(0, model.yMax, 6000);
975 final SinLFO z = new SinLFO(0, model.zMax, 7000);
977 final BasicParameter xw = new BasicParameter("XWID", 0.3);
978 final BasicParameter yw = new BasicParameter("YWID", 0.3);
979 final BasicParameter zw = new BasicParameter("ZWID", 0.3);
980 final BasicParameter xr = new BasicParameter("XRAT", 0.7);
981 final BasicParameter yr = new BasicParameter("YRAT", 0.6);
982 final BasicParameter zr = new BasicParameter("ZRAT", 0.5);
983 final BasicParameter xl = new BasicParameter("XLEV", 1);
984 final BasicParameter yl = new BasicParameter("YLEV", 1);
985 final BasicParameter zl = new BasicParameter("ZLEV", 0.5);
988 CrossSections(LX lx) {
990 addModulator(x).trigger();
991 addModulator(y).trigger();
992 addModulator(z).trigger();
996 protected void addParams() {
1008 void onParameterChanged(LXParameter p) {
1010 x.setDuration(10000 - 8800*p.getValuef());
1011 } else if (p == yr) {
1012 y.setDuration(10000 - 9000*p.getValuef());
1013 } else if (p == zr) {
1014 z.setDuration(10000 - 9000*p.getValuef());
1020 protected void updateXYZVals() {
1026 public void run(double deltaMs) {
1029 float xlv = 100*xl.getValuef();
1030 float ylv = 100*yl.getValuef();
1031 float zlv = 100*zl.getValuef();
1033 float xwv = 100. / (10 + 40*xw.getValuef());
1034 float ywv = 100. / (10 + 40*yw.getValuef());
1035 float zwv = 100. / (10 + 40*zw.getValuef());
1037 for (LXPoint p : model.points) {
1039 c = blendColor(c, lx.hsb(
1040 (lx.getBaseHuef() + p.x/10 + p.y/3) % 360,
1041 constrain(140 - 1.1*abs(p.x - model.xMax/2.), 0, 100),
1042 max(0, xlv - xwv*abs(p.x - xv))
1044 c = blendColor(c, lx.hsb(
1045 (lx.getBaseHuef() + 80 + p.y/10) % 360,
1046 constrain(140 - 2.2*abs(p.y - model.yMax/2.), 0, 100),
1047 max(0, ylv - ywv*abs(p.y - yv))
1049 c = blendColor(c, lx.hsb(
1050 (lx.getBaseHuef() + 160 + p.z / 10 + p.y/2) % 360,
1051 constrain(140 - 2.2*abs(p.z - model.zMax/2.), 0, 100),
1052 max(0, zlv - zwv*abs(p.z - zv))
1054 colors[p.index] = c;
1059 class Blinders extends SCPattern {
1062 final TriangleLFO r;
1064 final TriangleLFO hs;
1066 public Blinders(LX lx) {
1069 for (int i = 0; i < m.length; ++i) {
1070 addModulator(m[i] = new SinLFO(0.5, 120, (120000. / (3+i)))).trigger();
1072 addModulator(r = new TriangleLFO(9000, 15000, 29000)).trigger();
1073 addModulator(s = new SinLFO(-20, 275, 11000)).trigger();
1074 addModulator(hs = new TriangleLFO(0.1, 0.5, 15000)).trigger();
1075 s.modulateDurationBy(r);
1078 public void run(double deltaMs) {
1079 float hv = lx.getBaseHuef();
1081 for (Strip strip : model.strips) {
1083 float mv = m[si % m.length].getValuef();
1084 for (LXPoint p : strip.points) {
1085 colors[p.index] = lx.hsb(
1086 (hv + p.z + p.y*hs.getValuef()) % 360,
1087 min(100, abs(p.x - s.getValuef())/2.),
1088 max(0, 100 - mv/2. - mv * abs(i - (strip.metrics.length-1)/2.))
1097 class Psychedelia extends SCPattern {
1100 SinLFO m = new SinLFO(-0.5, NUM-0.5, 9000);
1101 SinLFO s = new SinLFO(-20, 147, 11000);
1102 TriangleLFO h = new TriangleLFO(0, 240, 19000);
1103 SinLFO c = new SinLFO(-.2, .8, 31000);
1105 Psychedelia(LX lx) {
1107 addModulator(m).trigger();
1108 addModulator(s).trigger();
1109 addModulator(h).trigger();
1110 addModulator(c).trigger();
1113 void run(double deltaMs) {
1114 float huev = h.getValuef();
1115 float cv = c.getValuef();
1116 float sv = s.getValuef();
1117 float mv = m.getValuef();
1119 for (Strip strip : model.strips) {
1120 for (LXPoint p : strip.points) {
1121 colors[p.index] = lx.hsb(
1122 (huev + i*constrain(cv, 0, 2) + p.z/2. + p.x/4.) % 360,
1123 min(100, abs(p.y-sv)),
1124 max(0, 100 - 50*abs((i%NUM) - mv))
1132 class AskewPlanes extends SCPattern {
1135 private final SinLFO a;
1136 private final SinLFO b;
1137 private final SinLFO c;
1144 addModulator(a = new SinLFO(-1, 1, 4000 + 1029*i)).trigger();
1145 addModulator(b = new SinLFO(-1, 1, 11000 - 1104*i)).trigger();
1146 addModulator(c = new SinLFO(-50, 50, 4000 + 1000*i * ((i % 2 == 0) ? 1 : -1))).trigger();
1149 void run(double deltaMs) {
1153 denom = sqrt(av*av + bv*bv);
1157 final Plane[] planes;
1158 final int NUM_PLANES = 3;
1160 AskewPlanes(LX lx) {
1162 planes = new Plane[NUM_PLANES];
1163 for (int i = 0; i < planes.length; ++i) {
1164 planes[i] = new Plane(i);
1168 public void run(double deltaMs) {
1169 float huev = lx.getBaseHuef();
1171 // This is super fucking bizarre. But if this is a for loop, the framerate
1172 // tanks to like 30FPS, instead of 60. Call them manually and it works fine.
1173 // Doesn't make ANY sense... there must be some weird side effect going on
1174 // with the Processing internals perhaps?
1175 // for (Plane plane : planes) {
1176 // plane.run(deltaMs);
1178 planes[0].run(deltaMs);
1179 planes[1].run(deltaMs);
1180 planes[2].run(deltaMs);
1182 for (LXPoint p : model.points) {
1183 float d = MAX_FLOAT;
1184 for (Plane plane : planes) {
1185 if (plane.denom != 0) {
1186 d = min(d, abs(plane.av*(p.x-model.cx) + plane.bv*(p.y-model.cy) + plane.cv) / plane.denom);
1189 colors[p.index] = lx.hsb(
1190 (huev + abs(p.x-model.cx)*.3 + p.y*.8) % 360,
1191 max(0, 100 - .8*abs(p.x - model.cx)),
1192 constrain(140 - 10.*d, 0, 100)
1198 class ShiftingPlane extends SCPattern {
1200 final SinLFO a = new SinLFO(-.2, .2, 5300);
1201 final SinLFO b = new SinLFO(1, -1, 13300);
1202 final SinLFO c = new SinLFO(-1.4, 1.4, 5700);
1203 final SinLFO d = new SinLFO(-10, 10, 9500);
1205 ShiftingPlane(LX lx) {
1207 addModulator(a).trigger();
1208 addModulator(b).trigger();
1209 addModulator(c).trigger();
1210 addModulator(d).trigger();
1213 public void run(double deltaMs) {
1214 float hv = lx.getBaseHuef();
1215 float av = a.getValuef();
1216 float bv = b.getValuef();
1217 float cv = c.getValuef();
1218 float dv = d.getValuef();
1219 float denom = sqrt(av*av + bv*bv + cv*cv);
1220 for (LXPoint p : model.points) {
1221 float d = abs(av*(p.x-model.cx) + bv*(p.y-model.cy) + cv*(p.z-model.cz) + dv) / denom;
1222 colors[p.index] = lx.hsb(
1223 (hv + abs(p.x-model.cx)*.6 + abs(p.y-model.cy)*.9 + abs(p.z - model.cz)) % 360,
1224 constrain(110 - d*6, 0, 100),
1225 constrain(130 - 7*d, 0, 100)
1231 class Traktor extends SCPattern {
1233 final int FRAME_WIDTH = 60;
1235 final BasicParameter speed = new BasicParameter("SPD", 0.5);
1237 private float[] bass = new float[FRAME_WIDTH];
1238 private float[] treble = new float[FRAME_WIDTH];
1240 private int index = 0;
1241 private GraphicEQ eq = null;
1243 public Traktor(LX lx) {
1245 for (int i = 0; i < FRAME_WIDTH; ++i) {
1249 addParameter(speed);
1252 public void onActive() {
1254 eq = new GraphicEQ(lx, 16);
1255 eq.slope.setValue(0.6);
1256 eq.level.setValue(0.65);
1257 eq.range.setValue(0.35);
1258 eq.release.setValue(0.4);
1259 addParameter(eq.level);
1260 addParameter(eq.range);
1261 addParameter(eq.attack);
1262 addParameter(eq.release);
1263 addParameter(eq.slope);
1269 public void run(double deltaMs) {
1272 int stepThresh = (int) (40 - 39*speed.getValuef());
1274 if (counter < stepThresh) {
1277 counter = counter % stepThresh;
1279 index = (index + 1) % FRAME_WIDTH;
1281 float rawBass = eq.getAverageLevel(0, 4);
1282 float rawTreble = eq.getAverageLevel(eq.numBands-7, 7);
1284 bass[index] = rawBass * rawBass * rawBass * rawBass;
1285 treble[index] = rawTreble * rawTreble;
1287 for (LXPoint p : model.points) {
1288 int i = (int) constrain((model.xMax - p.x) / model.xMax * FRAME_WIDTH, 0, FRAME_WIDTH-1);
1289 int pos = (index + FRAME_WIDTH - i) % FRAME_WIDTH;
1291 colors[p.index] = lx.hsb(
1292 (360 + lx.getBaseHuef() + .8*abs(p.x-model.cx)) % 360,
1294 constrain(9 * (bass[pos]*model.cy - abs(p.y - model.cy + 5)), 0, 100)
1296 colors[p.index] = blendColor(colors[p.index], lx.hsb(
1297 (400 + lx.getBaseHuef() + .5*abs(p.x-model.cx)) % 360,
1299 constrain(5 * (treble[pos]*.6*model.cy - abs(p.y - model.cy)), 0, 100)
1306 class ColorFuckerEffect extends LXEffect {
1308 final BasicParameter level = new BasicParameter("BRT", 1);
1309 final BasicParameter desat = new BasicParameter("DSAT", 0);
1310 final BasicParameter hueShift = new BasicParameter("HSHFT", 0);
1311 final BasicParameter sharp = new BasicParameter("SHARP", 0);
1312 final BasicParameter soft = new BasicParameter("SOFT", 0);
1313 final BasicParameter mono = new BasicParameter("MONO", 0);
1314 final BasicParameter invert = new BasicParameter("INVERT", 0);
1317 float[] hsb = new float[3];
1319 ColorFuckerEffect(LX lx) {
1321 addParameter(level);
1322 addParameter(desat);
1323 addParameter(sharp);
1324 addParameter(hueShift);
1327 addParameter(invert);
1330 public void apply(int[] colors) {
1334 float bMod = level.getValuef();
1335 float sMod = 1 - desat.getValuef();
1336 float hMod = hueShift.getValuef();
1337 float fSharp = sharp.getValuef();
1338 float fSoft = soft.getValuef();
1339 boolean mon = mono.getValuef() > 0.5;
1340 boolean ivt = invert.getValuef() > 0.5;
1341 if (bMod < 1 || sMod < 1 || hMod > 0 || fSharp > 0 || ivt || mon || fSoft > 0) {
1342 for (int i = 0; i < colors.length; ++i) {
1343 lx.RGBtoHSB(colors[i], hsb);
1345 hsb[0] = lx.getBaseHuef() / 360.;
1348 hsb[2] = 1 - hsb[2];
1351 fSharp = 1/(1-fSharp);
1353 hsb[2] = pow(hsb[2],fSharp);
1355 hsb[2] = 1-pow(1-hsb[2],fSharp);
1360 hsb[2] = lerp(hsb[2], 0.5 + 2 * (hsb[2]-0.5)*(hsb[2]-0.5), fSoft);
1362 hsb[2] = lerp(hsb[2], 0.5 * sqrt(2*hsb[2]), fSoft);
1366 (360. * hsb[0] + hMod*360.) % 360,
1367 100. * hsb[1] * sMod,
1368 100. * hsb[2] * bMod
1375 class QuantizeEffect extends LXEffect {
1377 color[] quantizedFrame;
1379 final BasicParameter amount = new BasicParameter("AMT", 0);
1381 QuantizeEffect(LX lx) {
1383 quantizedFrame = new color[glucose.lx.total];
1387 public void apply(int[] colors) {
1388 float fQuant = amount.getValuef();
1390 float tRamp = (lx.tempo.rampf() % (1./pow(2,floor((1-fQuant) * 4))));
1391 float f = lastQuant;
1394 for (int i = 0; i < colors.length; ++i) {
1395 colors[i] = quantizedFrame[i];
1400 for (int i = 0; i < colors.length; ++i) {
1401 quantizedFrame[i] = colors[i];
1406 class BlurEffect extends LXEffect {
1408 final BasicParameter amount = new BasicParameter("AMT", 0);
1410 final LinearEnvelope env = new LinearEnvelope(0, 1, 100);
1414 addParameter(amount);
1416 frame = new int[lx.total];
1417 for (int i = 0; i < frame.length; ++i) {
1422 public void onEnable() {
1423 env.setRangeFromHereTo(1, 400).start();
1424 for (int i = 0; i < frame.length; ++i) {
1429 public void onDisable() {
1430 env.setRangeFromHereTo(0, 1000).start();
1433 public void apply(int[] colors) {
1434 float amt = env.getValuef() * amount.getValuef();
1437 amt = 1 - (amt*amt*amt);
1438 for (int i = 0; i < colors.length; ++i) {
1439 // frame[i] = colors[i] = blendColor(colors[i], lerpColor(#000000, frame[i], amt, RGB), SCREEN);
1440 frame[i] = colors[i] = lerpColor(colors[i], blendColor(colors[i], frame[i], SCREEN), amt, RGB);