1 class MidiMusic extends SCPattern {
3 private final Stack<LXLayer> newLayers = new Stack<LXLayer>();
5 private final Map<Integer, LightUp> lightMap = new HashMap<Integer, LightUp>();
6 private final List<LightUp> lights = new ArrayList<LightUp>();
7 private final BasicParameter lightSize = new BasicParameter("SIZE", 0.5);
9 private final List<Sweep> sweeps = new ArrayList<Sweep>();
11 private final LinearEnvelope sparkle = new LinearEnvelope(0, 1, 500);
12 private boolean sparkleDirection = true;
13 private float sparkleBright = 100;
15 private final BasicParameter wave = new BasicParameter("WAVE", 0);
17 MidiMusic(GLucose glucose) {
19 addParameter(lightSize);
21 addModulator(sparkle).setValue(1);
24 class Sweep extends LXLayer {
26 final LinearEnvelope position = new LinearEnvelope(0, 1, 1000);
31 addModulator(position);
34 public void run(double deltaMs, color[] colors) {
35 if (!position.isRunning()) {
38 float posf = position.getValuef();
39 for (Point p : model.points) {
40 colors[p.index] = blendColor(colors[p.index], color(
41 (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360,
43 max(0, bright - posf*100 - falloff*abs(p.y - posf*model.yMax))
49 class LightUp extends LXLayer {
51 private final LinearEnvelope brt = new LinearEnvelope(0, 0, 0);
52 private final Accelerator yPos = new Accelerator(0, 0, 0);
60 boolean isAvailable() {
61 return brt.getValuef() <= 0;
64 void noteOn(Note note) {
65 xPos = lerp(0, model.xMax, constrain(0.5 + (note.getPitch() - 60) / 28., 0, 1));
66 yPos.setValue(lerp(20, model.yMax*.72, note.getVelocity() / 127.)).stop();
67 brt.setRangeFromHereTo(lerp(40, 100, note.getVelocity() / 127.), 20).start();
70 void noteOff(Note note) {
71 yPos.setVelocity(0).setAcceleration(-380).start();
72 brt.setRangeFromHereTo(0, 1000).start();
75 public void run(double deltaMs, color[] colors) {
76 float bVal = brt.getValuef();
80 float yVal = yPos.getValuef();
81 for (Point p : model.points) {
82 float falloff = 6 - 5*lightSize.getValuef();
83 float b = max(0, bVal - falloff*dist(p.x, p.y, xPos, yVal));
85 colors[p.index] = blendColor(colors[p.index], lx.hsb(
86 (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360,
95 private LightUp getLight() {
96 for (LightUp light : lights) {
97 if (light.isAvailable()) {
101 LightUp newLight = new LightUp();
102 lights.add(newLight);
103 synchronized(newLayers) {
104 newLayers.push(newLight);
109 private Sweep getSweep() {
110 for (Sweep s : sweeps) {
111 if (!s.position.isRunning()) {
115 Sweep newSweep = new Sweep();
116 sweeps.add(newSweep);
117 synchronized(newLayers) {
118 newLayers.push(newSweep);
123 public synchronized boolean noteOn(Note note) {
124 if (note.getChannel() == 0) {
125 LightUp light = getLight();
126 lightMap.put(note.getPitch(), light);
128 } else if (note.getChannel() == 1) {
129 } else if (note.getChannel() == 9) {
130 if (note.getVelocity() > 0) {
131 switch (note.getPitch()) {
133 Sweep s = getSweep();
134 s.bright = 50 + note.getVelocity() / 127. * 50;
135 s.falloff = 20 - note.getVelocity() / 127. * 17;
136 s.position.trigger();
139 sparkleBright = note.getVelocity() / 127. * 100;
140 sparkleDirection = true;
144 sparkleBright = note.getVelocity() / 127. * 100;
145 sparkleDirection = false;
154 public synchronized boolean noteOff(Note note) {
155 if (note.getChannel() == 0) {
156 LightUp light = lightMap.get(note.getPitch());
164 final float[] wval = new float[16];
167 public synchronized void run(double deltaMs) {
168 wavoff += deltaMs * .001;
169 for (int i = 0; i < wval.length; ++i) {
170 wval[i] = model.cy + 0.2 * model.yMax/2. * sin(wavoff + i / 1.9);
172 float sparklePos = (sparkleDirection ? sparkle.getValuef() : (1 - sparkle.getValuef())) * (Cube.POINTS_PER_STRIP)/2.;
173 float maxBright = sparkleBright * (1 - sparkle.getValuef());
174 for (Strip s : model.strips) {
176 for (Point p : s.points) {
177 int wavi = (int) constrain(p.x / model.xMax * wval.length, 0, wval.length-1);
178 float wavb = max(0, wave.getValuef()*100. - 8.*abs(p.y - wval[wavi]));
179 colors[p.index] = color(
180 (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360,
182 constrain(wavb + max(0, maxBright - 40.*abs(sparklePos - abs(i - (Cube.POINTS_PER_STRIP-1)/2.))), 0, 100)
188 if (!newLayers.isEmpty()) {
189 synchronized(newLayers) {
190 while (!newLayers.isEmpty()) {
191 addLayer(newLayers.pop());
198 class Pulley extends SCPattern {
200 final int NUM_DIVISIONS = 16;
201 private final Accelerator[] gravity = new Accelerator[NUM_DIVISIONS];
202 private final Click[] delays = new Click[NUM_DIVISIONS];
204 private final Click reset = new Click(9000);
205 private boolean isRising = false;
207 private BasicParameter sz = new BasicParameter("SIZE", 0.5);
208 private BasicParameter beatAmount = new BasicParameter("BEAT", 0);
210 Pulley(GLucose glucose) {
212 for (int i = 0; i < NUM_DIVISIONS; ++i) {
213 addModulator(gravity[i] = new Accelerator(0, 0, 0));
214 addModulator(delays[i] = new Click(0));
216 addModulator(reset).start();
218 addParameter(beatAmount);
223 private void trigger() {
224 isRising = !isRising;
226 for (Accelerator g : gravity) {
228 g.setSpeed(random(20, 33), 0).start();
230 g.setVelocity(0).setAcceleration(-420);
231 delays[i].setDuration(random(0, 500)).trigger();
237 public void run(double deltaMs) {
243 // Fucking A, had to comment this all out because of that bizarre
244 // Processing bug where some simple loop takes an absurd amount of
245 // time, must be some pre-processor bug
246 // for (Accelerator g : gravity) {
247 // if (g.getValuef() > model.yMax) {
249 // } else if (g.getValuef() > model.yMax*.55) {
250 // if (g.getVelocityf() > 10) {
251 // g.setAcceleration(-16);
253 // g.setAcceleration(0);
259 for (Click d : delays) {
266 for (Accelerator g : gravity) {
267 if (g.getValuef() < 0) {
268 g.setValue(-g.getValuef());
269 g.setVelocity(-g.getVelocityf() * random(0.74, 0.84));
274 // A little silliness to test the grid API
275 if (midiEngine != null && midiEngine.getFocusedPattern() == this) {
276 for (int i = 0; i < 5; ++i) {
277 for (int j = 0; j < 8; ++j) {
278 int gi = (int) constrain(j * NUM_DIVISIONS / 8, 0, NUM_DIVISIONS-1);
279 float b = 1 - 4.*abs((6-i)/6. - gravity[gi].getValuef() / model.yMax);
280 midiEngine.grid.setState(i, j, (b < 0) ? 0 : 3);
285 float fPos = 1 - lx.tempo.rampf();
287 fPos = .2 + 4 * (.2 - fPos);
289 float falloff = 100. / (3 + sz.getValuef() * 36 + fPos * beatAmount.getValuef()*48);
290 for (Point p : model.points) {
291 int gi = (int) constrain((p.x - model.xMin) * NUM_DIVISIONS / (model.xMax - model.xMin), 0, NUM_DIVISIONS-1);
292 colors[p.index] = lx.hsb(
293 (lx.getBaseHuef() + abs(p.x - model.cx)*.8 + p.y*.4) % 360,
294 constrain(130 - p.y*.8, 0, 100),
295 max(0, 100 - abs(p.y - gravity[gi].getValuef())*falloff)
301 class ViolinWave extends SCPattern {
303 BasicParameter level = new BasicParameter("LVL", 0.45);
304 BasicParameter range = new BasicParameter("RNG", 0.5);
305 BasicParameter edge = new BasicParameter("EDG", 0.5);
306 BasicParameter release = new BasicParameter("RLS", 0.5);
307 BasicParameter speed = new BasicParameter("SPD", 0.5);
308 BasicParameter amp = new BasicParameter("AMP", 0.25);
309 BasicParameter period = new BasicParameter("WAVE", 0.5);
310 BasicParameter pSize = new BasicParameter("PSIZE", 0.5);
311 BasicParameter pSpeed = new BasicParameter("PSPD", 0.5);
312 BasicParameter pDensity = new BasicParameter("PDENS", 0.25);
314 LinearEnvelope dbValue = new LinearEnvelope(0, 0, 10);
316 ViolinWave(GLucose glucose) {
321 addParameter(release);
324 addParameter(period);
326 addParameter(pSpeed);
327 addParameter(pDensity);
329 addModulator(dbValue);
332 final List<Particle> particles = new ArrayList<Particle>();
336 LinearEnvelope x = new LinearEnvelope(0, 0, 0);
337 LinearEnvelope y = new LinearEnvelope(0, 0, 0);
344 Particle trigger(boolean direction) {
345 float xInit = random(model.xMin, model.xMax);
346 float time = 3000 - 2500*pSpeed.getValuef();
347 x.setRange(xInit, xInit + random(-40, 40), time).trigger();
348 y.setRange(model.cy + 10, direction ? model.yMax + 50 : model.yMin - 50, time).trigger();
353 return x.isRunning() || y.isRunning();
356 public void run(double deltaMs) {
361 float pFalloff = (30 - 27*pSize.getValuef());
362 for (Point p : model.points) {
363 float b = 100 - pFalloff * (abs(p.x - x.getValuef()) + abs(p.y - y.getValuef()));
365 colors[p.index] = blendColor(colors[p.index], lx.hsb(
366 lx.getBaseHuef(), 20, b
373 float[] centers = new float[30];
375 boolean rising = true;
377 void fireParticle(boolean direction) {
378 boolean gotOne = false;
379 for (Particle p : particles) {
381 p.trigger(direction);
385 particles.add(new Particle().trigger(direction));
388 public void run(double deltaMs) {
389 accum += deltaMs / (1000. - 900.*speed.getValuef());
390 for (int i = 0; i < centers.length; ++i) {
391 centers[i] = model.cy + 30*amp.getValuef()*sin((float) (accum + (i-centers.length/2.)/(1. + 9.*period.getValuef())));
394 float zeroDBReference = pow(10, (50 - 190*level.getValuef())/20.);
395 float dB = 20*GraphicEQ.log10(lx.audioInput().mix.level() / zeroDBReference);
396 if (dB > dbValue.getValuef()) {
398 dbValue.setRangeFromHereTo(dB, 10).trigger();
401 for (int j = 0; j < pDensity.getValuef()*3; ++j) {
407 dbValue.setRangeFromHereTo(max(dB, -96), 50 + 1000*release.getValuef()).trigger();
409 float edg = 1 + edge.getValuef() * 40;
410 float rng = (78 - 64 * range.getValuef()) / (model.yMax - model.cy);
411 float val = max(2, dbValue.getValuef());
413 for (Point p : model.points) {
414 int ci = (int) lerp(0, centers.length-1, (p.x - model.xMin) / (model.xMax - model.xMin));
415 float rFactor = 1.0 - 0.9 * abs(p.x - model.cx) / (model.xMax - model.cx);
416 colors[p.index] = lx.hsb(
417 (lx.getBaseHuef() + abs(p.x - model.cx)) % 360,
418 min(100, 20 + 8*abs(p.y - centers[ci])),
419 constrain(edg*(val*rFactor - rng * abs(p.y-centers[ci])), 0, 100)
423 for (Particle p : particles) {
429 class BouncyBalls extends SCPattern {
431 static final int NUM_BALLS = 6;
436 TriangleLFO xPos = new TriangleLFO(0, model.xMax, random(8000, 19000));
440 addModulator(xPos).setBasis(random(0, TWO_PI)).start();
441 addModulator(yPos = new Accelerator(0, 0, 0));
442 zPos = lerp(model.zMin, model.zMax, (i+2.) / (NUM_BALLS + 4.));
445 void bounce(float midiVel) {
446 float v = 100 + 8*midiVel;
447 yPos.setSpeed(v, getAccel(v, 60 / lx.tempo.bpmf())).start();
450 float getAccel(float v, float oneBeat) {
451 return -2*v / oneBeat;
454 void run(double deltaMs) {
455 float flrLevel = flr.getValuef() * model.xMax/2.;
456 if (yPos.getValuef() < flrLevel) {
457 if (yPos.getVelocity() < -50) {
458 yPos.setValue(2*flrLevel-yPos.getValuef());
459 float v = -yPos.getVelocityf() * bounce.getValuef();
460 yPos.setSpeed(v, getAccel(v, 60 / lx.tempo.bpmf()));
462 yPos.setValue(flrLevel).stop();
465 float falloff = 130.f / (12 + blobSize.getValuef() * 36);
466 float xv = xPos.getValuef();
467 float yv = yPos.getValuef();
469 for (Point p : model.points) {
470 float d = sqrt((p.x-xv)*(p.x-xv) + (p.y-yv)*(p.y-yv) + .1*(p.z-zPos)*(p.z-zPos));
471 float b = constrain(130 - falloff*d, 0, 100);
473 colors[p.index] = blendColor(colors[p.index], lx.hsb(
474 (lx.getBaseHuef() + p.y*.5 + abs(model.cx - p.x) * .5) % 360,
475 max(0, 100 - .45*(p.y - flrLevel)),
483 final BouncyBall[] balls = new BouncyBall[NUM_BALLS];
485 final BasicParameter bounce = new BasicParameter("BNC", .8);
486 final BasicParameter flr = new BasicParameter("FLR", 0);
487 final BasicParameter blobSize = new BasicParameter("SIZE", 0.5);
489 BouncyBalls(GLucose glucose) {
491 for (int i = 0; i < balls.length; ++i) {
492 balls[i] = new BouncyBall(i);
494 addParameter(bounce);
496 addParameter(blobSize);
499 public void run(double deltaMs) {
501 for (BouncyBall b : balls) {
506 public boolean noteOn(Note note) {
507 int pitch = (note.getPitch() + note.getChannel()) % NUM_BALLS;
508 balls[pitch].bounce(note.getVelocity());
513 class SpaceTime extends SCPattern {
515 SinLFO pos = new SinLFO(0, 1, 3000);
516 SinLFO rate = new SinLFO(1000, 9000, 13000);
517 SinLFO falloff = new SinLFO(10, 70, 5000);
520 BasicParameter rateParameter = new BasicParameter("RATE", 0.5);
521 BasicParameter sizeParameter = new BasicParameter("SIZE", 0.5);
524 public SpaceTime(GLucose glucose) {
527 addModulator(pos).trigger();
528 addModulator(rate).trigger();
529 addModulator(falloff).trigger();
530 pos.modulateDurationBy(rate);
531 addParameter(rateParameter);
532 addParameter(sizeParameter);
535 public void onParameterChanged(LXParameter parameter) {
536 if (parameter == rateParameter) {
537 rate.stop().setValue(9000 - 8000*parameter.getValuef());
538 } else if (parameter == sizeParameter) {
539 falloff.stop().setValue(70 - 60*parameter.getValuef());
543 void run(double deltaMs) {
544 angle += deltaMs * 0.0007;
545 float sVal1 = model.strips.size() * (0.5 + 0.5*sin(angle));
546 float sVal2 = model.strips.size() * (0.5 + 0.5*cos(angle));
548 float pVal = pos.getValuef();
549 float fVal = falloff.getValuef();
552 for (Strip strip : model.strips) {
554 for (Point p : strip.points) {
555 colors[p.index] = lx.hsb(
556 (lx.getBaseHuef() + 360 - p.x*.2 + p.y * .3) % 360,
557 constrain(.4 * min(abs(s - sVal1), abs(s - sVal2)), 20, 100),
558 max(0, 100 - fVal*abs(i - pVal*(strip.metrics.numPoints - 1)))
567 class Swarm extends SCPattern {
569 SawLFO offset = new SawLFO(0, 1, 1000);
570 SinLFO rate = new SinLFO(350, 1200, 63000);
571 SinLFO falloff = new SinLFO(15, 50, 17000);
572 SinLFO fX = new SinLFO(0, model.xMax, 19000);
573 SinLFO fY = new SinLFO(0, model.yMax, 11000);
574 SinLFO hOffX = new SinLFO(0, model.xMax, 13000);
576 public Swarm(GLucose glucose) {
579 addModulator(offset).trigger();
580 addModulator(rate).trigger();
581 addModulator(falloff).trigger();
582 addModulator(fX).trigger();
583 addModulator(fY).trigger();
584 addModulator(hOffX).trigger();
585 offset.modulateDurationBy(rate);
588 float modDist(float v1, float v2, float mod) {
592 return min(v2-v1, v1+mod-v2);
595 return min(v1-v2, v2+mod-v1);
599 void run(double deltaMs) {
601 for (Strip strip : model.strips ) {
603 for (Point p : strip.points) {
604 float fV = max(-1, 1 - dist(p.x/2., p.y, fX.getValuef()/2., fY.getValuef()) / 64.);
605 colors[p.index] = lx.hsb(
606 (lx.getBaseHuef() + 0.3 * abs(p.x - hOffX.getValuef())) % 360,
607 constrain(80 + 40 * fV, 0, 100),
608 constrain(100 - (30 - fV * falloff.getValuef()) * modDist(i + (s*63)%61, offset.getValuef() * strip.metrics.numPoints, strip.metrics.numPoints), 0, 100)
617 class SwipeTransition extends SCTransition {
619 final BasicParameter bleed = new BasicParameter("WIDTH", 0.5);
621 SwipeTransition(GLucose glucose) {
627 void computeBlend(int[] c1, int[] c2, double progress) {
628 float bleedf = 10 + bleed.getValuef() * 200.;
629 float xPos = (float) (-bleedf + progress * (model.xMax + bleedf));
630 for (Point p : model.points) {
631 float d = (p.x - xPos) / bleedf;
633 colors[p.index] = c2[p.index];
635 colors[p.index] = c1[p.index];
637 colors[p.index] = lerpColor(c2[p.index], c1[p.index], d, RGB);
643 abstract class BlendTransition extends SCTransition {
647 BlendTransition(GLucose glucose, int blendType) {
649 this.blendType = blendType;
652 void computeBlend(int[] c1, int[] c2, double progress) {
653 if (progress < 0.5) {
654 for (int i = 0; i < c1.length; ++i) {
655 colors[i] = lerpColor(
657 blendColor(c1[i], c2[i], blendType),
658 (float) (2.*progress),
662 for (int i = 0; i < c1.length; ++i) {
663 colors[i] = lerpColor(
665 blendColor(c1[i], c2[i], blendType),
666 (float) (2.*(1. - progress)),
673 class MultiplyTransition extends BlendTransition {
674 MultiplyTransition(GLucose glucose) {
675 super(glucose, MULTIPLY);
679 class ScreenTransition extends BlendTransition {
680 ScreenTransition(GLucose glucose) {
681 super(glucose, SCREEN);
685 class BurnTransition extends BlendTransition {
686 BurnTransition(GLucose glucose) {
687 super(glucose, BURN);
691 class DodgeTransition extends BlendTransition {
692 DodgeTransition(GLucose glucose) {
693 super(glucose, DODGE);
697 class OverlayTransition extends BlendTransition {
698 OverlayTransition(GLucose glucose) {
699 super(glucose, OVERLAY);
703 class AddTransition extends BlendTransition {
704 AddTransition(GLucose glucose) {
709 class SubtractTransition extends BlendTransition {
710 SubtractTransition(GLucose glucose) {
711 super(glucose, SUBTRACT);
715 class SoftLightTransition extends BlendTransition {
716 SoftLightTransition(GLucose glucose) {
717 super(glucose, SOFT_LIGHT);
721 class BassPod extends SCPattern {
723 private GraphicEQ eq = null;
725 public BassPod(GLucose glucose) {
729 protected void onActive() {
731 eq = new GraphicEQ(lx, 16);
732 eq.slope.setValue(0.6);
733 addParameter(eq.level);
734 addParameter(eq.range);
735 addParameter(eq.attack);
736 addParameter(eq.release);
737 addParameter(eq.slope);
741 public void run(double deltaMs) {
744 float bassLevel = eq.getAverageLevel(0, 5);
746 for (Point p : model.points) {
747 int avgIndex = (int) constrain(1 + abs(p.x-model.xMax/2.)/(model.xMax/2.)*(eq.numBands-5), 0, eq.numBands-5);
749 for (int i = avgIndex; i < avgIndex + 5; ++i) {
750 value += eq.getLevel(i);
754 float b = constrain(8 * (value*model.yMax - abs(p.y-model.yMax/2.)), 0, 100);
755 colors[p.index] = lx.hsb(
756 (lx.getBaseHuef() + abs(p.y - model.cy) + abs(p.x - model.cx)) % 360,
757 constrain(bassLevel*240 - .6*dist(p.x, p.y, model.cx, model.cy), 0, 100),
765 class CubeEQ extends SCPattern {
767 private GraphicEQ eq = null;
769 private final BasicParameter edge = new BasicParameter("EDGE", 0.5);
770 private final BasicParameter clr = new BasicParameter("CLR", 0.5);
771 private final BasicParameter blockiness = new BasicParameter("BLK", 0.5);
773 public CubeEQ(GLucose glucose) {
777 protected void onActive() {
779 eq = new GraphicEQ(lx, 16);
780 addParameter(eq.level);
781 addParameter(eq.range);
782 addParameter(eq.attack);
783 addParameter(eq.release);
784 addParameter(eq.slope);
787 addParameter(blockiness);
791 public void run(double deltaMs) {
794 float edgeConst = 2 + 30*edge.getValuef();
795 float clrConst = 1.1 + clr.getValuef();
797 for (Point p : model.points) {
798 float avgIndex = constrain(2 + p.x / model.xMax * (eq.numBands-4), 0, eq.numBands-4);
799 int avgFloor = (int) avgIndex;
801 float leftVal = eq.getLevel(avgFloor);
802 float rightVal = eq.getLevel(avgFloor+1);
803 float smoothValue = lerp(leftVal, rightVal, avgIndex-avgFloor);
805 float chunkyValue = (
806 eq.getLevel(avgFloor/4*4) +
807 eq.getLevel(avgFloor/4*4 + 1) +
808 eq.getLevel(avgFloor/4*4 + 2) +
809 eq.getLevel(avgFloor/4*4 + 3)
812 float value = lerp(smoothValue, chunkyValue, blockiness.getValuef());
814 float b = constrain(edgeConst * (value*model.yMax - p.y), 0, 100);
815 colors[p.index] = lx.hsb(
816 (480 + lx.getBaseHuef() - min(clrConst*p.y, 120)) % 360,
824 class BoomEffect extends SCEffect {
826 final BasicParameter falloff = new BasicParameter("WIDTH", 0.5);
827 final BasicParameter speed = new BasicParameter("SPD", 0.5);
828 final BasicParameter bright = new BasicParameter("BRT", 1.0);
829 final BasicParameter sat = new BasicParameter("SAT", 0.2);
830 List<Layer> layers = new ArrayList<Layer>();
831 final float maxr = sqrt(model.xMax*model.xMax + model.yMax*model.yMax + model.zMax*model.zMax) + 10;
834 LinearEnvelope boom = new LinearEnvelope(-40, 500, 1300);
842 float falloffv = falloffv();
843 boom.setRange(-100 / falloffv, maxr + 100/falloffv, 4000 - speed.getValuef() * 3300);
847 void doApply(int[] colors) {
848 float brightv = 100 * bright.getValuef();
849 float falloffv = falloffv();
850 float satv = sat.getValuef() * 100;
851 float huev = lx.getBaseHuef();
852 for (Point p : model.points) {
853 colors[p.index] = blendColor(
855 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)),
861 BoomEffect(GLucose glucose) {
862 super(glucose, true);
863 addParameter(falloff);
865 addParameter(bright);
869 public void onEnable() {
870 for (Layer l : layers) {
871 if (!l.boom.isRunning()) {
876 layers.add(new Layer());
879 private float falloffv() {
880 return 20 - 19 * falloff.getValuef();
883 public void onTrigger() {
887 public void doApply(int[] colors) {
888 for (Layer l : layers) {
889 if (l.boom.isRunning()) {
896 public class PianoKeyPattern extends SCPattern {
898 final LinearEnvelope[] cubeBrt;
900 final BasicParameter attack = new BasicParameter("ATK", 0.1);
901 final BasicParameter release = new BasicParameter("REL", 0.5);
902 final BasicParameter level = new BasicParameter("AMB", 0.6);
904 PianoKeyPattern(GLucose glucose) {
907 addParameter(attack);
908 addParameter(release);
910 cubeBrt = new LinearEnvelope[model.cubes.size() / 4];
911 for (int i = 0; i < cubeBrt.length; ++i) {
912 addModulator(cubeBrt[i] = new LinearEnvelope(0, 0, 100));
914 base = new SinLFO[model.cubes.size() / 12];
915 for (int i = 0; i < base.length; ++i) {
916 addModulator(base[i] = new SinLFO(0, 1, 7000 + 1000*i)).trigger();
920 private float getAttackTime() {
921 return 15 + attack.getValuef()*attack.getValuef() * 2000;
924 private float getReleaseTime() {
925 return 15 + release.getValuef() * 3000;
928 private LinearEnvelope getEnvelope(int index) {
929 return cubeBrt[index % cubeBrt.length];
932 private SinLFO getBase(int index) {
933 return base[index % base.length];
936 public boolean noteOn(Note note) {
937 LinearEnvelope env = getEnvelope(note.getPitch());
938 env.setEndVal(min(1, env.getValuef() + (note.getVelocity() / 127.)), getAttackTime()).start();
942 public boolean noteOff(Note note) {
943 getEnvelope(note.getPitch()).setEndVal(0, getReleaseTime()).start();
947 public void run(double deltaMs) {
949 float huef = lx.getBaseHuef();
950 float levelf = level.getValuef();
951 for (Cube c : model.cubes) {
952 float v = max(getBase(i).getValuef() * levelf/4., getEnvelope(i++).getValuef());
954 (huef + 20*v + abs(c.cx-model.xMax/2.)*.3 + c.cy) % 360,
962 class CrossSections extends SCPattern {
964 final SinLFO x = new SinLFO(0, model.xMax, 5000);
965 final SinLFO y = new SinLFO(0, model.yMax, 6000);
966 final SinLFO z = new SinLFO(0, model.zMax, 7000);
968 final BasicParameter xw = new BasicParameter("XWID", 0.3);
969 final BasicParameter yw = new BasicParameter("YWID", 0.3);
970 final BasicParameter zw = new BasicParameter("ZWID", 0.3);
971 final BasicParameter xr = new BasicParameter("XRAT", 0.7);
972 final BasicParameter yr = new BasicParameter("YRAT", 0.6);
973 final BasicParameter zr = new BasicParameter("ZRAT", 0.5);
974 final BasicParameter xl = new BasicParameter("XLEV", 1);
975 final BasicParameter yl = new BasicParameter("YLEV", 1);
976 final BasicParameter zl = new BasicParameter("ZLEV", 0.5);
979 CrossSections(GLucose glucose) {
981 addModulator(x).trigger();
982 addModulator(y).trigger();
983 addModulator(z).trigger();
987 protected void addParams() {
999 void onParameterChanged(LXParameter p) {
1001 x.setDuration(10000 - 8800*p.getValuef());
1002 } else if (p == yr) {
1003 y.setDuration(10000 - 9000*p.getValuef());
1004 } else if (p == zr) {
1005 z.setDuration(10000 - 9000*p.getValuef());
1011 protected void updateXYZVals() {
1017 public void run(double deltaMs) {
1020 float xlv = 100*xl.getValuef();
1021 float ylv = 100*yl.getValuef();
1022 float zlv = 100*zl.getValuef();
1024 float xwv = 100. / (10 + 40*xw.getValuef());
1025 float ywv = 100. / (10 + 40*yw.getValuef());
1026 float zwv = 100. / (10 + 40*zw.getValuef());
1028 for (Point p : model.points) {
1030 c = blendColor(c, lx.hsb(
1031 (lx.getBaseHuef() + p.x/10 + p.y/3) % 360,
1032 constrain(140 - 1.1*abs(p.x - model.xMax/2.), 0, 100),
1033 max(0, xlv - xwv*abs(p.x - xv))
1035 c = blendColor(c, lx.hsb(
1036 (lx.getBaseHuef() + 80 + p.y/10) % 360,
1037 constrain(140 - 2.2*abs(p.y - model.yMax/2.), 0, 100),
1038 max(0, ylv - ywv*abs(p.y - yv))
1040 c = blendColor(c, lx.hsb(
1041 (lx.getBaseHuef() + 160 + p.z / 10 + p.y/2) % 360,
1042 constrain(140 - 2.2*abs(p.z - model.zMax/2.), 0, 100),
1043 max(0, zlv - zwv*abs(p.z - zv))
1045 colors[p.index] = c;
1050 class Blinders extends SCPattern {
1053 final TriangleLFO r;
1055 final TriangleLFO hs;
1057 public Blinders(GLucose glucose) {
1060 for (int i = 0; i < m.length; ++i) {
1061 addModulator(m[i] = new SinLFO(0.5, 120, (120000. / (3+i)))).trigger();
1063 addModulator(r = new TriangleLFO(9000, 15000, 29000)).trigger();
1064 addModulator(s = new SinLFO(-20, 275, 11000)).trigger();
1065 addModulator(hs = new TriangleLFO(0.1, 0.5, 15000)).trigger();
1066 s.modulateDurationBy(r);
1069 public void run(double deltaMs) {
1070 float hv = lx.getBaseHuef();
1072 for (Strip strip : model.strips) {
1074 float mv = m[si % m.length].getValuef();
1075 for (Point p : strip.points) {
1076 colors[p.index] = lx.hsb(
1077 (hv + p.z + p.y*hs.getValuef()) % 360,
1078 min(100, abs(p.x - s.getValuef())/2.),
1079 max(0, 100 - mv/2. - mv * abs(i - (strip.metrics.length-1)/2.))
1088 class Psychedelia extends SCPattern {
1091 SinLFO m = new SinLFO(-0.5, NUM-0.5, 9000);
1092 SinLFO s = new SinLFO(-20, 147, 11000);
1093 TriangleLFO h = new TriangleLFO(0, 240, 19000);
1094 SinLFO c = new SinLFO(-.2, .8, 31000);
1096 Psychedelia(GLucose glucose) {
1098 addModulator(m).trigger();
1099 addModulator(s).trigger();
1100 addModulator(h).trigger();
1101 addModulator(c).trigger();
1104 void run(double deltaMs) {
1105 float huev = h.getValuef();
1106 float cv = c.getValuef();
1107 float sv = s.getValuef();
1108 float mv = m.getValuef();
1110 for (Strip strip : model.strips) {
1111 for (Point p : strip.points) {
1112 colors[p.index] = lx.hsb(
1113 (huev + i*constrain(cv, 0, 2) + p.z/2. + p.x/4.) % 360,
1114 min(100, abs(p.y-sv)),
1115 max(0, 100 - 50*abs((i%NUM) - mv))
1123 class AskewPlanes extends SCPattern {
1126 private final SinLFO a;
1127 private final SinLFO b;
1128 private final SinLFO c;
1135 addModulator(a = new SinLFO(-1, 1, 4000 + 1029*i)).trigger();
1136 addModulator(b = new SinLFO(-1, 1, 11000 - 1104*i)).trigger();
1137 addModulator(c = new SinLFO(-50, 50, 4000 + 1000*i * ((i % 2 == 0) ? 1 : -1))).trigger();
1140 void run(double deltaMs) {
1144 denom = sqrt(av*av + bv*bv);
1148 final Plane[] planes;
1149 final int NUM_PLANES = 3;
1151 AskewPlanes(GLucose glucose) {
1153 planes = new Plane[NUM_PLANES];
1154 for (int i = 0; i < planes.length; ++i) {
1155 planes[i] = new Plane(i);
1159 public void run(double deltaMs) {
1160 float huev = lx.getBaseHuef();
1162 // This is super fucking bizarre. But if this is a for loop, the framerate
1163 // tanks to like 30FPS, instead of 60. Call them manually and it works fine.
1164 // Doesn't make ANY sense... there must be some weird side effect going on
1165 // with the Processing internals perhaps?
1166 // for (Plane plane : planes) {
1167 // plane.run(deltaMs);
1169 planes[0].run(deltaMs);
1170 planes[1].run(deltaMs);
1171 planes[2].run(deltaMs);
1173 for (Point p : model.points) {
1174 float d = MAX_FLOAT;
1175 for (Plane plane : planes) {
1176 if (plane.denom != 0) {
1177 d = min(d, abs(plane.av*(p.x-model.cx) + plane.bv*(p.y-model.cy) + plane.cv) / plane.denom);
1180 colors[p.index] = lx.hsb(
1181 (huev + abs(p.x-model.cx)*.3 + p.y*.8) % 360,
1182 max(0, 100 - .8*abs(p.x - model.cx)),
1183 constrain(140 - 10.*d, 0, 100)
1189 class ShiftingPlane extends SCPattern {
1191 final SinLFO a = new SinLFO(-.2, .2, 5300);
1192 final SinLFO b = new SinLFO(1, -1, 13300);
1193 final SinLFO c = new SinLFO(-1.4, 1.4, 5700);
1194 final SinLFO d = new SinLFO(-10, 10, 9500);
1196 ShiftingPlane(GLucose glucose) {
1198 addModulator(a).trigger();
1199 addModulator(b).trigger();
1200 addModulator(c).trigger();
1201 addModulator(d).trigger();
1204 public void run(double deltaMs) {
1205 float hv = lx.getBaseHuef();
1206 float av = a.getValuef();
1207 float bv = b.getValuef();
1208 float cv = c.getValuef();
1209 float dv = d.getValuef();
1210 float denom = sqrt(av*av + bv*bv + cv*cv);
1211 for (Point p : model.points) {
1212 float d = abs(av*(p.x-model.cx) + bv*(p.y-model.cy) + cv*(p.z-model.cz) + dv) / denom;
1213 colors[p.index] = lx.hsb(
1214 (hv + abs(p.x-model.cx)*.6 + abs(p.y-model.cy)*.9 + abs(p.z - model.cz)) % 360,
1215 constrain(110 - d*6, 0, 100),
1216 constrain(130 - 7*d, 0, 100)
1222 class Traktor extends SCPattern {
1224 final int FRAME_WIDTH = 60;
1226 final BasicParameter speed = new BasicParameter("SPD", 0.5);
1228 private float[] bass = new float[FRAME_WIDTH];
1229 private float[] treble = new float[FRAME_WIDTH];
1231 private int index = 0;
1232 private GraphicEQ eq = null;
1234 public Traktor(GLucose glucose) {
1236 for (int i = 0; i < FRAME_WIDTH; ++i) {
1240 addParameter(speed);
1243 public void onActive() {
1245 eq = new GraphicEQ(lx, 16);
1246 eq.slope.setValue(0.6);
1247 eq.level.setValue(0.65);
1248 eq.range.setValue(0.35);
1249 eq.release.setValue(0.4);
1250 addParameter(eq.level);
1251 addParameter(eq.range);
1252 addParameter(eq.attack);
1253 addParameter(eq.release);
1254 addParameter(eq.slope);
1260 public void run(double deltaMs) {
1263 int stepThresh = (int) (40 - 39*speed.getValuef());
1265 if (counter < stepThresh) {
1268 counter = counter % stepThresh;
1270 index = (index + 1) % FRAME_WIDTH;
1272 float rawBass = eq.getAverageLevel(0, 4);
1273 float rawTreble = eq.getAverageLevel(eq.numBands-7, 7);
1275 bass[index] = rawBass * rawBass * rawBass * rawBass;
1276 treble[index] = rawTreble * rawTreble;
1278 for (Point p : model.points) {
1279 int i = (int) constrain((model.xMax - p.x) / model.xMax * FRAME_WIDTH, 0, FRAME_WIDTH-1);
1280 int pos = (index + FRAME_WIDTH - i) % FRAME_WIDTH;
1282 colors[p.index] = lx.hsb(
1283 (360 + lx.getBaseHuef() + .8*abs(p.x-model.cx)) % 360,
1285 constrain(9 * (bass[pos]*model.cy - abs(p.y - model.cy)), 0, 100)
1287 colors[p.index] = blendColor(colors[p.index], lx.hsb(
1288 (400 + lx.getBaseHuef() + .5*abs(p.x-model.cx)) % 360,
1290 constrain(5 * (treble[pos]*.6*model.cy - abs(p.y - model.cy)), 0, 100)
1297 class ColorFuckerEffect extends SCEffect {
1299 final BasicParameter level = new BasicParameter("BRT", 1);
1300 final BasicParameter desat = new BasicParameter("DSAT", 0);
1301 final BasicParameter sharp = new BasicParameter("SHARP", 0);
1302 final BasicParameter soft = new BasicParameter("SOFT", 0);
1303 final BasicParameter mono = new BasicParameter("MONO", 0);
1304 final BasicParameter invert = new BasicParameter("INVERT", 0);
1305 final BasicParameter hueShift = new BasicParameter("HSHFT", 0);
1307 float[] hsb = new float[3];
1309 ColorFuckerEffect(GLucose glucose) {
1311 addParameter(level);
1312 addParameter(desat);
1313 addParameter(sharp);
1316 addParameter(invert);
1317 addParameter(hueShift);
1320 public void doApply(int[] colors) {
1324 float bMod = level.getValuef();
1325 float sMod = 1 - desat.getValuef();
1326 float hMod = hueShift.getValuef();
1327 float fSharp = 1/(1.0001-sharp.getValuef());
1328 float fSoft = soft.getValuef();
1329 boolean mon = mono.getValuef() > 0.5;
1330 boolean ivt = invert.getValuef() > 0.5;
1331 if (bMod < 1 || sMod < 1 || hMod > 0 || fSharp > 0 || ivt || mon || fSoft > 0) {
1332 for (int i = 0; i < colors.length; ++i) {
1333 lx.RGBtoHSB(colors[i], hsb);
1335 hsb[0] = lx.getBaseHuef() / 360.;
1338 hsb[2] = 1 - hsb[2];
1341 hsb[2] = hsb[2] < .5 ? pow(hsb[2],fSharp) : 1-pow(1-hsb[2],fSharp);
1345 hsb[2] = lerp(hsb[2], 0.5 + 2 * (hsb[2]-0.5)*(hsb[2]-0.5), fSoft);
1347 hsb[2] = lerp(hsb[2], 0.5 * sqrt(2*hsb[2]), fSoft);
1351 (360. * hsb[0] + hMod*360.) % 360,
1352 100. * hsb[1] * sMod,
1353 100. * hsb[2] * bMod
1360 class QuantizeEffect extends SCEffect {
1362 color[] quantizedFrame;
1364 final BasicParameter amount = new BasicParameter("AMT", 0);
1366 QuantizeEffect(GLucose glucose) {
1368 quantizedFrame = new color[glucose.lx.total];
1372 public void doApply(int[] colors) {
1373 float fQuant = amount.getValuef();
1375 float tRamp = (lx.tempo.rampf() % (1./pow(2,floor((1-fQuant) * 4))));
1376 float f = lastQuant;
1379 for (int i = 0; i < colors.length; ++i) {
1380 colors[i] = quantizedFrame[i];
1385 for (int i = 0; i < colors.length; ++i) {
1386 quantizedFrame[i] = colors[i];
1391 class BlurEffect extends SCEffect {
1393 final LXParameter amount = new BasicParameter("AMT", 0);
1395 final LinearEnvelope env = new LinearEnvelope(0, 1, 100);
1397 BlurEffect(GLucose glucose) {
1399 addParameter(amount);
1401 frame = new int[lx.total];
1402 for (int i = 0; i < frame.length; ++i) {
1407 public void onEnable() {
1408 env.setRangeFromHereTo(1, 400).start();
1409 for (int i = 0; i < frame.length; ++i) {
1414 public void onDisable() {
1415 env.setRangeFromHereTo(0, 1000).start();
1418 public void doApply(int[] colors) {
1419 float amt = env.getValuef() * amount.getValuef();
1422 amt = 1 - (amt*amt*amt);
1423 for (int i = 0; i < colors.length; ++i) {
1424 // frame[i] = colors[i] = blendColor(colors[i], lerpColor(#000000, frame[i], amt, RGB), SCREEN);
1425 frame[i] = colors[i] = lerpColor(colors[i], blendColor(colors[i], frame[i], SCREEN), amt, RGB);