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);
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);
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);
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);
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);
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(LX lx) {
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(LX lx) {
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 LXTransition {
700 final BasicParameter bleed = new BasicParameter("WIDTH", 0.5);
702 SwipeTransition(LX lx) {
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 class BassPod extends SCPattern {
726 private GraphicEQ eq = null;
728 private final BasicParameter clr = new BasicParameter("CLR", 0.5);
730 public BassPod(LX lx) {
737 eq = new GraphicEQ(lx, 16);
738 eq.range.setValue(0.4);
739 eq.level.setValue(0.4);
740 eq.slope.setValue(0.6);
741 addParameter(eq.level);
742 addParameter(eq.range);
743 addParameter(eq.attack);
744 addParameter(eq.release);
745 addParameter(eq.slope);
749 public void run(double deltaMs) {
752 float bassLevel = eq.getAverageLevel(0, 5);
754 float satBase = bassLevel*480*clr.getValuef();
756 for (LXPoint p : model.points) {
757 int avgIndex = (int) constrain(1 + abs(p.x-model.cx)/(model.cx)*(eq.numBands-5), 0, eq.numBands-5);
759 for (int i = avgIndex; i < avgIndex + 5; ++i) {
760 value += eq.getLevel(i);
764 float b = constrain(8 * (value*model.yMax - abs(p.y-model.yMax/2.)), 0, 100);
765 colors[p.index] = lx.hsb(
766 (lx.getBaseHuef() + abs(p.y - model.cy) + abs(p.x - model.cx)) % 360,
767 constrain(satBase - .6*dist(p.x, p.y, model.cx, model.cy), 0, 100),
775 class CubeEQ extends SCPattern {
777 private GraphicEQ eq = null;
779 private final BasicParameter edge = new BasicParameter("EDGE", 0.5);
780 private final BasicParameter clr = new BasicParameter("CLR", 0.5);
781 private final BasicParameter blockiness = new BasicParameter("BLK", 0.5);
783 public CubeEQ(LX lx) {
789 eq = new GraphicEQ(lx, 16);
790 addParameter(eq.level);
791 addParameter(eq.range);
792 addParameter(eq.attack);
793 addParameter(eq.release);
794 addParameter(eq.slope);
797 addParameter(blockiness);
801 public void run(double deltaMs) {
804 float edgeConst = 2 + 30*edge.getValuef();
805 float clrConst = 1.1 + clr.getValuef();
807 for (LXPoint p : model.points) {
808 float avgIndex = constrain(2 + p.x / model.xMax * (eq.numBands-4), 0, eq.numBands-4);
809 int avgFloor = (int) avgIndex;
811 float leftVal = eq.getLevel(avgFloor);
812 float rightVal = eq.getLevel(avgFloor+1);
813 float smoothValue = lerp(leftVal, rightVal, avgIndex-avgFloor);
815 float chunkyValue = (
816 eq.getLevel(avgFloor/4*4) +
817 eq.getLevel(avgFloor/4*4 + 1) +
818 eq.getLevel(avgFloor/4*4 + 2) +
819 eq.getLevel(avgFloor/4*4 + 3)
822 float value = lerp(smoothValue, chunkyValue, blockiness.getValuef());
824 float b = constrain(edgeConst * (value*model.yMax - p.y), 0, 100);
825 colors[p.index] = lx.hsb(
826 (480 + lx.getBaseHuef() - min(clrConst*p.y, 120)) % 360,
834 class BoomEffect extends LXEffect {
836 final BasicParameter falloff = new BasicParameter("WIDTH", 0.5);
837 final BasicParameter speed = new BasicParameter("SPD", 0.5);
838 final BasicParameter bright = new BasicParameter("BRT", 1.0);
839 final BasicParameter sat = new BasicParameter("SAT", 0.2);
840 List<Layer> layers = new ArrayList<Layer>();
841 final float maxr = sqrt(model.xMax*model.xMax + model.yMax*model.yMax + model.zMax*model.zMax) + 10;
844 LinearEnvelope boom = new LinearEnvelope(-40, 500, 1300);
852 float falloffv = falloffv();
853 boom.setRange(-100 / falloffv, maxr + 100/falloffv, 4000 - speed.getValuef() * 3300);
857 void apply(int[] colors) {
858 float brightv = 100 * bright.getValuef();
859 float falloffv = falloffv();
860 float satv = sat.getValuef() * 100;
861 float huev = lx.getBaseHuef();
862 for (LXPoint p : model.points) {
863 colors[p.index] = blendColor(
865 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)),
873 addParameter(falloff);
875 addParameter(bright);
879 public void onEnable() {
880 for (Layer l : layers) {
881 if (!l.boom.isRunning()) {
886 layers.add(new Layer());
889 private float falloffv() {
890 return 20 - 19 * falloff.getValuef();
893 public void onTrigger() {
897 public void apply(int[] colors) {
898 for (Layer l : layers) {
899 if (l.boom.isRunning()) {
906 public class PianoKeyPattern extends SCPattern {
908 final LinearEnvelope[] cubeBrt;
910 final BasicParameter attack = new BasicParameter("ATK", 0.1);
911 final BasicParameter release = new BasicParameter("REL", 0.5);
912 final BasicParameter level = new BasicParameter("AMB", 0.6);
914 PianoKeyPattern(LX lx) {
917 addParameter(attack);
918 addParameter(release);
920 cubeBrt = new LinearEnvelope[model.cubes.size() / 4];
921 for (int i = 0; i < cubeBrt.length; ++i) {
922 addModulator(cubeBrt[i] = new LinearEnvelope(0, 0, 100));
924 base = new SinLFO[model.cubes.size() / 12];
925 for (int i = 0; i < base.length; ++i) {
926 addModulator(base[i] = new SinLFO(0, 1, 7000 + 1000*i)).trigger();
930 private float getAttackTime() {
931 return 15 + attack.getValuef()*attack.getValuef() * 2000;
934 private float getReleaseTime() {
935 return 15 + release.getValuef() * 3000;
938 private LinearEnvelope getEnvelope(int index) {
939 return cubeBrt[index % cubeBrt.length];
942 private SinLFO getBase(int index) {
943 return base[index % base.length];
946 public boolean noteOn(Note note) {
947 LinearEnvelope env = getEnvelope(note.getPitch());
948 env.setEndVal(min(1, env.getValuef() + (note.getVelocity() / 127.)), getAttackTime()).start();
952 public boolean noteOff(Note note) {
953 getEnvelope(note.getPitch()).setEndVal(0, getReleaseTime()).start();
957 public void run(double deltaMs) {
959 float huef = lx.getBaseHuef();
960 float levelf = level.getValuef();
961 for (Cube c : model.cubes) {
962 float v = max(getBase(i).getValuef() * levelf/4., getEnvelope(i++).getValuef());
964 (huef + 20*v + abs(c.cx-model.xMax/2.)*.3 + c.cy) % 360,
972 class CrossSections extends SCPattern {
974 final SinLFO x = new SinLFO(0, model.xMax, 5000);
975 final SinLFO y = new SinLFO(0, model.yMax, 6000);
976 final SinLFO z = new SinLFO(0, model.zMax, 7000);
978 final BasicParameter xw = new BasicParameter("XWID", 0.3);
979 final BasicParameter yw = new BasicParameter("YWID", 0.3);
980 final BasicParameter zw = new BasicParameter("ZWID", 0.3);
981 final BasicParameter xr = new BasicParameter("XRAT", 0.7);
982 final BasicParameter yr = new BasicParameter("YRAT", 0.6);
983 final BasicParameter zr = new BasicParameter("ZRAT", 0.5);
984 final BasicParameter xl = new BasicParameter("XLEV", 1);
985 final BasicParameter yl = new BasicParameter("YLEV", 1);
986 final BasicParameter zl = new BasicParameter("ZLEV", 0.5);
989 CrossSections(LX lx) {
991 addModulator(x).trigger();
992 addModulator(y).trigger();
993 addModulator(z).trigger();
997 protected void addParams() {
1009 void onParameterChanged(LXParameter p) {
1011 x.setDuration(10000 - 8800*p.getValuef());
1012 } else if (p == yr) {
1013 y.setDuration(10000 - 9000*p.getValuef());
1014 } else if (p == zr) {
1015 z.setDuration(10000 - 9000*p.getValuef());
1021 protected void updateXYZVals() {
1027 public void run(double deltaMs) {
1030 float xlv = 100*xl.getValuef();
1031 float ylv = 100*yl.getValuef();
1032 float zlv = 100*zl.getValuef();
1034 float xwv = 100. / (10 + 40*xw.getValuef());
1035 float ywv = 100. / (10 + 40*yw.getValuef());
1036 float zwv = 100. / (10 + 40*zw.getValuef());
1038 for (LXPoint p : model.points) {
1040 c = blendColor(c, lx.hsb(
1041 (lx.getBaseHuef() + p.x/10 + p.y/3) % 360,
1042 constrain(140 - 1.1*abs(p.x - model.xMax/2.), 0, 100),
1043 max(0, xlv - xwv*abs(p.x - xv))
1045 c = blendColor(c, lx.hsb(
1046 (lx.getBaseHuef() + 80 + p.y/10) % 360,
1047 constrain(140 - 2.2*abs(p.y - model.yMax/2.), 0, 100),
1048 max(0, ylv - ywv*abs(p.y - yv))
1050 c = blendColor(c, lx.hsb(
1051 (lx.getBaseHuef() + 160 + p.z / 10 + p.y/2) % 360,
1052 constrain(140 - 2.2*abs(p.z - model.zMax/2.), 0, 100),
1053 max(0, zlv - zwv*abs(p.z - zv))
1055 colors[p.index] = c;
1060 class Blinders extends SCPattern {
1063 final TriangleLFO r;
1065 final TriangleLFO hs;
1067 public Blinders(LX lx) {
1070 for (int i = 0; i < m.length; ++i) {
1071 addModulator(m[i] = new SinLFO(0.5, 120, (120000. / (3+i)))).trigger();
1073 addModulator(r = new TriangleLFO(9000, 15000, 29000)).trigger();
1074 addModulator(s = new SinLFO(-20, 275, 11000)).trigger();
1075 addModulator(hs = new TriangleLFO(0.1, 0.5, 15000)).trigger();
1076 s.modulateDurationBy(r);
1079 public void run(double deltaMs) {
1080 float hv = lx.getBaseHuef();
1082 for (Strip strip : model.strips) {
1084 float mv = m[si % m.length].getValuef();
1085 for (LXPoint p : strip.points) {
1086 colors[p.index] = lx.hsb(
1087 (hv + p.z + p.y*hs.getValuef()) % 360,
1088 min(100, abs(p.x - s.getValuef())/2.),
1089 max(0, 100 - mv/2. - mv * abs(i - (strip.metrics.length-1)/2.))
1098 class Psychedelia extends SCPattern {
1101 SinLFO m = new SinLFO(-0.5, NUM-0.5, 9000);
1102 SinLFO s = new SinLFO(-20, 147, 11000);
1103 TriangleLFO h = new TriangleLFO(0, 240, 19000);
1104 SinLFO c = new SinLFO(-.2, .8, 31000);
1106 Psychedelia(LX lx) {
1108 addModulator(m).trigger();
1109 addModulator(s).trigger();
1110 addModulator(h).trigger();
1111 addModulator(c).trigger();
1114 void run(double deltaMs) {
1115 float huev = h.getValuef();
1116 float cv = c.getValuef();
1117 float sv = s.getValuef();
1118 float mv = m.getValuef();
1120 for (Strip strip : model.strips) {
1121 for (LXPoint p : strip.points) {
1122 colors[p.index] = lx.hsb(
1123 (huev + i*constrain(cv, 0, 2) + p.z/2. + p.x/4.) % 360,
1124 min(100, abs(p.y-sv)),
1125 max(0, 100 - 50*abs((i%NUM) - mv))
1133 class AskewPlanes extends SCPattern {
1136 private final SinLFO a;
1137 private final SinLFO b;
1138 private final SinLFO c;
1145 addModulator(a = new SinLFO(-1, 1, 4000 + 1029*i)).trigger();
1146 addModulator(b = new SinLFO(-1, 1, 11000 - 1104*i)).trigger();
1147 addModulator(c = new SinLFO(-50, 50, 4000 + 1000*i * ((i % 2 == 0) ? 1 : -1))).trigger();
1150 void run(double deltaMs) {
1154 denom = sqrt(av*av + bv*bv);
1158 final Plane[] planes;
1159 final int NUM_PLANES = 3;
1161 AskewPlanes(LX lx) {
1163 planes = new Plane[NUM_PLANES];
1164 for (int i = 0; i < planes.length; ++i) {
1165 planes[i] = new Plane(i);
1169 public void run(double deltaMs) {
1170 float huev = lx.getBaseHuef();
1172 // This is super fucking bizarre. But if this is a for loop, the framerate
1173 // tanks to like 30FPS, instead of 60. Call them manually and it works fine.
1174 // Doesn't make ANY sense... there must be some weird side effect going on
1175 // with the Processing internals perhaps?
1176 // for (Plane plane : planes) {
1177 // plane.run(deltaMs);
1179 planes[0].run(deltaMs);
1180 planes[1].run(deltaMs);
1181 planes[2].run(deltaMs);
1183 for (LXPoint p : model.points) {
1184 float d = MAX_FLOAT;
1185 for (Plane plane : planes) {
1186 if (plane.denom != 0) {
1187 d = min(d, abs(plane.av*(p.x-model.cx) + plane.bv*(p.y-model.cy) + plane.cv) / plane.denom);
1190 colors[p.index] = lx.hsb(
1191 (huev + abs(p.x-model.cx)*.3 + p.y*.8) % 360,
1192 max(0, 100 - .8*abs(p.x - model.cx)),
1193 constrain(140 - 10.*d, 0, 100)
1199 class ShiftingPlane extends SCPattern {
1201 final SinLFO a = new SinLFO(-.2, .2, 5300);
1202 final SinLFO b = new SinLFO(1, -1, 13300);
1203 final SinLFO c = new SinLFO(-1.4, 1.4, 5700);
1204 final SinLFO d = new SinLFO(-10, 10, 9500);
1206 ShiftingPlane(LX lx) {
1208 addModulator(a).trigger();
1209 addModulator(b).trigger();
1210 addModulator(c).trigger();
1211 addModulator(d).trigger();
1214 public void run(double deltaMs) {
1215 float hv = lx.getBaseHuef();
1216 float av = a.getValuef();
1217 float bv = b.getValuef();
1218 float cv = c.getValuef();
1219 float dv = d.getValuef();
1220 float denom = sqrt(av*av + bv*bv + cv*cv);
1221 for (LXPoint p : model.points) {
1222 float d = abs(av*(p.x-model.cx) + bv*(p.y-model.cy) + cv*(p.z-model.cz) + dv) / denom;
1223 colors[p.index] = lx.hsb(
1224 (hv + abs(p.x-model.cx)*.6 + abs(p.y-model.cy)*.9 + abs(p.z - model.cz)) % 360,
1225 constrain(110 - d*6, 0, 100),
1226 constrain(130 - 7*d, 0, 100)
1232 class Traktor extends SCPattern {
1234 final int FRAME_WIDTH = 60;
1236 final BasicParameter speed = new BasicParameter("SPD", 0.5);
1238 private float[] bass = new float[FRAME_WIDTH];
1239 private float[] treble = new float[FRAME_WIDTH];
1241 private int index = 0;
1242 private GraphicEQ eq = null;
1244 public Traktor(LX lx) {
1246 for (int i = 0; i < FRAME_WIDTH; ++i) {
1250 addParameter(speed);
1253 public void onActive() {
1255 eq = new GraphicEQ(lx, 16);
1256 eq.slope.setValue(0.6);
1257 eq.level.setValue(0.65);
1258 eq.range.setValue(0.35);
1259 eq.release.setValue(0.4);
1260 addParameter(eq.level);
1261 addParameter(eq.range);
1262 addParameter(eq.attack);
1263 addParameter(eq.release);
1264 addParameter(eq.slope);
1270 public void run(double deltaMs) {
1273 int stepThresh = (int) (40 - 39*speed.getValuef());
1275 if (counter < stepThresh) {
1278 counter = counter % stepThresh;
1280 index = (index + 1) % FRAME_WIDTH;
1282 float rawBass = eq.getAverageLevel(0, 4);
1283 float rawTreble = eq.getAverageLevel(eq.numBands-7, 7);
1285 bass[index] = rawBass * rawBass * rawBass * rawBass;
1286 treble[index] = rawTreble * rawTreble;
1288 for (LXPoint p : model.points) {
1289 int i = (int) constrain((model.xMax - p.x) / model.xMax * FRAME_WIDTH, 0, FRAME_WIDTH-1);
1290 int pos = (index + FRAME_WIDTH - i) % FRAME_WIDTH;
1292 colors[p.index] = lx.hsb(
1293 (360 + lx.getBaseHuef() + .8*abs(p.x-model.cx)) % 360,
1295 constrain(9 * (bass[pos]*model.cy - abs(p.y - model.cy + 5)), 0, 100)
1297 colors[p.index] = blendColor(colors[p.index], lx.hsb(
1298 (400 + lx.getBaseHuef() + .5*abs(p.x-model.cx)) % 360,
1300 constrain(5 * (treble[pos]*.6*model.cy - abs(p.y - model.cy)), 0, 100)
1307 class ColorFuckerEffect extends LXEffect {
1309 final BasicParameter level = new BasicParameter("BRT", 1);
1310 final BasicParameter desat = new BasicParameter("DSAT", 0);
1311 final BasicParameter hueShift = new BasicParameter("HSHFT", 0);
1312 final BasicParameter sharp = new BasicParameter("SHARP", 0);
1313 final BasicParameter soft = new BasicParameter("SOFT", 0);
1314 final BasicParameter mono = new BasicParameter("MONO", 0);
1315 final BasicParameter invert = new BasicParameter("INVERT", 0);
1318 float[] hsb = new float[3];
1320 ColorFuckerEffect(LX lx) {
1322 addParameter(level);
1323 addParameter(desat);
1324 addParameter(sharp);
1325 addParameter(hueShift);
1328 addParameter(invert);
1331 public void apply(int[] colors) {
1335 float bMod = level.getValuef();
1336 float sMod = 1 - desat.getValuef();
1337 float hMod = hueShift.getValuef();
1338 float fSharp = sharp.getValuef();
1339 float fSoft = soft.getValuef();
1340 boolean mon = mono.getValuef() > 0.5;
1341 boolean ivt = invert.getValuef() > 0.5;
1342 if (bMod < 1 || sMod < 1 || hMod > 0 || fSharp > 0 || ivt || mon || fSoft > 0) {
1343 for (int i = 0; i < colors.length; ++i) {
1344 lx.RGBtoHSB(colors[i], hsb);
1346 hsb[0] = lx.getBaseHuef() / 360.;
1349 hsb[2] = 1 - hsb[2];
1352 fSharp = 1/(1-fSharp);
1354 hsb[2] = pow(hsb[2],fSharp);
1356 hsb[2] = 1-pow(1-hsb[2],fSharp);
1361 hsb[2] = lerp(hsb[2], 0.5 + 2 * (hsb[2]-0.5)*(hsb[2]-0.5), fSoft);
1363 hsb[2] = lerp(hsb[2], 0.5 * sqrt(2*hsb[2]), fSoft);
1367 (360. * hsb[0] + hMod*360.) % 360,
1368 100. * hsb[1] * sMod,
1369 100. * hsb[2] * bMod
1376 class QuantizeEffect extends LXEffect {
1378 color[] quantizedFrame;
1380 final BasicParameter amount = new BasicParameter("AMT", 0);
1382 QuantizeEffect(LX lx) {
1384 quantizedFrame = new color[lx.total];
1388 public void apply(int[] colors) {
1389 float fQuant = amount.getValuef();
1391 float tRamp = (lx.tempo.rampf() % (1./pow(2,floor((1-fQuant) * 4))));
1392 float f = lastQuant;
1395 for (int i = 0; i < colors.length; ++i) {
1396 colors[i] = quantizedFrame[i];
1401 for (int i = 0; i < colors.length; ++i) {
1402 quantizedFrame[i] = colors[i];
1407 class BlurEffect extends LXEffect {
1409 final BasicParameter amount = new BasicParameter("AMT", 0);
1411 final LinearEnvelope env = new LinearEnvelope(0, 1, 100);
1415 addParameter(amount);
1417 frame = new int[lx.total];
1418 for (int i = 0; i < frame.length; ++i) {
1423 public void onEnable() {
1424 env.setRangeFromHereTo(1, 400).start();
1425 for (int i = 0; i < frame.length; ++i) {
1430 public void onDisable() {
1431 env.setRangeFromHereTo(0, 1000).start();
1434 public void apply(int[] colors) {
1435 float amt = env.getValuef() * amount.getValuef();
1438 amt = 1 - (amt*amt*amt);
1439 for (int i = 0; i < colors.length; ++i) {
1440 // frame[i] = colors[i] = blendColor(colors[i], lerpColor(#000000, frame[i], amt, RGB), SCREEN);
1441 frame[i] = colors[i] = lerpColor(colors[i], blendColor(colors[i], frame[i], SCREEN), amt, RGB);