1 class MidiMusic extends SCPattern {
3 private final Map<Integer, LightUp> lightMap = new HashMap<Integer, LightUp>();
4 private final List<LightUp> allLights = new ArrayList<LightUp>();
6 private final Stack<LightUp> newLayers = new Stack<LightUp>();
8 MidiMusic(GLucose glucose) {
12 class LightUp extends LXLayer {
14 private LinearEnvelope brt = new LinearEnvelope(0, 0, 0);
15 private Accelerator yPos = new Accelerator(0, 0, 0);
23 boolean isAvailable() {
24 return brt.getValuef() <= 0;
27 void noteOn(Note note) {
28 xPos = lerp(0, model.xMax, constrain(0.5 + (note.getPitch() - 64) / 12., 0, 1));
29 yPos.setValue(lerp(20, model.yMax, note.getVelocity() / 127.));
30 brt.setRangeFromHereTo(lerp(40, 100, note.getVelocity() / 127.), 20).start();
33 void noteOff(Note note) {
34 yPos.setVelocity(0).setAcceleration(-380).start();
35 brt.setRangeFromHereTo(0, 1000).start();
38 public void run(double deltaMs, color[] colors) {
39 float bVal = brt.getValuef();
43 float yVal = yPos.getValuef();
44 for (Point p : model.points) {
45 float b = max(0, bVal - 3*dist(p.x, p.y, xPos, yVal));
47 colors[p.index] = blendColor(colors[p.index], lx.hsb(
48 (lx.getBaseHuef() + abs(p.x - model.cx) + abs(p.y - model.cy)) % 360,
57 public synchronized boolean noteOn(Note note) {
58 if (note.getChannel() == 0) {
59 for (LightUp light : allLights) {
60 if (light.isAvailable()) {
62 lightMap.put(note.getPitch(), light);
66 LightUp newLight = new LightUp();
67 newLight.noteOn(note);
68 lightMap.put(note.getPitch(), newLight);
69 synchronized(newLayers) {
70 newLayers.push(newLight);
72 } else if (note.getChannel() == 1) {
77 public synchronized boolean noteOff(Note note) {
78 if (note.getChannel() == 0) {
79 LightUp light = lightMap.get(note.getPitch());
87 public synchronized void run(double deltaMs) {
89 if (!newLayers.isEmpty()) {
90 synchronized(newLayers) {
91 while (!newLayers.isEmpty()) {
92 addLayer(newLayers.pop());
99 class Pulley extends SCPattern {
101 final int NUM_DIVISIONS = 16;
102 private final Accelerator[] gravity = new Accelerator[NUM_DIVISIONS];
103 private final Click[] delays = new Click[NUM_DIVISIONS];
105 private final Click reset = new Click(9000);
106 private boolean isRising = false;
108 private BasicParameter sz = new BasicParameter("SIZE", 0.5);
109 private BasicParameter beatAmount = new BasicParameter("BEAT", 0);
111 Pulley(GLucose glucose) {
113 for (int i = 0; i < NUM_DIVISIONS; ++i) {
114 addModulator(gravity[i] = new Accelerator(0, 0, 0));
115 addModulator(delays[i] = new Click(0));
117 addModulator(reset).start();
119 addParameter(beatAmount);
124 private void trigger() {
125 isRising = !isRising;
127 for (Accelerator g : gravity) {
129 g.setSpeed(random(20, 33), 0).start();
131 g.setVelocity(0).setAcceleration(-420);
132 delays[i].setDuration(random(0, 500)).trigger();
138 public void run(double deltaMs) {
144 // Fucking A, had to comment this all out because of that bizarre
145 // Processing bug where some simple loop takes an absurd amount of
146 // time, must be some pre-processor bug
147 // for (Accelerator g : gravity) {
148 // if (g.getValuef() > model.yMax) {
150 // } else if (g.getValuef() > model.yMax*.55) {
151 // if (g.getVelocityf() > 10) {
152 // g.setAcceleration(-16);
154 // g.setAcceleration(0);
160 for (Click d : delays) {
167 for (Accelerator g : gravity) {
168 if (g.getValuef() < 0) {
169 g.setValue(-g.getValuef());
170 g.setVelocity(-g.getVelocityf() * random(0.74, 0.84));
175 // A little silliness to test the grid API
176 if (midiEngine != null && midiEngine.getFocusedPattern() == this) {
177 for (int i = 0; i < 5; ++i) {
178 for (int j = 0; j < 8; ++j) {
179 int gi = (int) constrain(j * NUM_DIVISIONS / 8, 0, NUM_DIVISIONS-1);
180 float b = 1 - 4.*abs((6-i)/6. - gravity[gi].getValuef() / model.yMax);
181 midiEngine.grid.setState(i, j, (b < 0) ? 0 : 3);
186 float fPos = 1 - lx.tempo.rampf();
188 fPos = .2 + 4 * (.2 - fPos);
190 float falloff = 100. / (3 + sz.getValuef() * 36 + fPos * beatAmount.getValuef()*48);
191 for (Point p : model.points) {
192 int gi = (int) constrain((p.x - model.xMin) * NUM_DIVISIONS / (model.xMax - model.xMin), 0, NUM_DIVISIONS-1);
193 colors[p.index] = lx.hsb(
194 (lx.getBaseHuef() + abs(p.x - model.cx)*.8 + p.y*.4) % 360,
195 constrain(130 - p.y*.8, 0, 100),
196 max(0, 100 - abs(p.y - gravity[gi].getValuef())*falloff)
202 class ViolinWave extends SCPattern {
204 BasicParameter level = new BasicParameter("LVL", 0.45);
205 BasicParameter range = new BasicParameter("RNG", 0.5);
206 BasicParameter edge = new BasicParameter("EDG", 0.5);
207 BasicParameter release = new BasicParameter("RLS", 0.5);
208 BasicParameter speed = new BasicParameter("SPD", 0.5);
209 BasicParameter amp = new BasicParameter("AMP", 0.25);
210 BasicParameter period = new BasicParameter("WAVE", 0.5);
211 BasicParameter pSize = new BasicParameter("PSIZE", 0.5);
212 BasicParameter pSpeed = new BasicParameter("PSPD", 0.5);
213 BasicParameter pDensity = new BasicParameter("PDENS", 0.25);
215 LinearEnvelope dbValue = new LinearEnvelope(0, 0, 10);
217 ViolinWave(GLucose glucose) {
222 addParameter(release);
225 addParameter(period);
227 addParameter(pSpeed);
228 addParameter(pDensity);
230 addModulator(dbValue);
233 final List<Particle> particles = new ArrayList<Particle>();
237 LinearEnvelope x = new LinearEnvelope(0, 0, 0);
238 LinearEnvelope y = new LinearEnvelope(0, 0, 0);
245 Particle trigger(boolean direction) {
246 float xInit = random(model.xMin, model.xMax);
247 float time = 3000 - 2500*pSpeed.getValuef();
248 x.setRange(xInit, xInit + random(-40, 40), time).trigger();
249 y.setRange(model.cy + 10, direction ? model.yMax + 50 : model.yMin - 50, time).trigger();
254 return x.isRunning() || y.isRunning();
257 public void run(double deltaMs) {
262 float pFalloff = (30 - 27*pSize.getValuef());
263 for (Point p : model.points) {
264 float b = 100 - pFalloff * (abs(p.x - x.getValuef()) + abs(p.y - y.getValuef()));
266 colors[p.index] = blendColor(colors[p.index], lx.hsb(
267 lx.getBaseHuef(), 20, b
274 float[] centers = new float[30];
276 boolean rising = true;
278 void fireParticle(boolean direction) {
279 boolean gotOne = false;
280 for (Particle p : particles) {
282 p.trigger(direction);
286 particles.add(new Particle().trigger(direction));
289 public void run(double deltaMs) {
290 accum += deltaMs / (1000. - 900.*speed.getValuef());
291 for (int i = 0; i < centers.length; ++i) {
292 centers[i] = model.cy + 30*amp.getValuef()*sin((float) (accum + (i-centers.length/2.)/(1. + 9.*period.getValuef())));
295 float zeroDBReference = pow(10, (50 - 190*level.getValuef())/20.);
296 float dB = 20*GraphicEQ.log10(lx.audioInput().mix.level() / zeroDBReference);
297 if (dB > dbValue.getValuef()) {
299 dbValue.setRangeFromHereTo(dB, 10).trigger();
302 for (int j = 0; j < pDensity.getValuef()*3; ++j) {
308 dbValue.setRangeFromHereTo(max(dB, -96), 50 + 1000*release.getValuef()).trigger();
310 float edg = 1 + edge.getValuef() * 40;
311 float rng = (78 - 64 * range.getValuef()) / (model.yMax - model.cy);
312 float val = max(2, dbValue.getValuef());
314 for (Point p : model.points) {
315 int ci = (int) lerp(0, centers.length-1, (p.x - model.xMin) / (model.xMax - model.xMin));
316 float rFactor = 1.0 - 0.9 * abs(p.x - model.cx) / (model.xMax - model.cx);
317 colors[p.index] = lx.hsb(
318 (lx.getBaseHuef() + abs(p.x - model.cx)) % 360,
319 min(100, 20 + 8*abs(p.y - centers[ci])),
320 constrain(edg*(val*rFactor - rng * abs(p.y-centers[ci])), 0, 100)
324 for (Particle p : particles) {
330 class BouncyBalls extends SCPattern {
332 static final int NUM_BALLS = 6;
337 TriangleLFO xPos = new TriangleLFO(0, model.xMax, random(8000, 19000));
341 addModulator(xPos).setBasis(random(0, TWO_PI)).start();
342 addModulator(yPos = new Accelerator(0, 0, 0));
343 zPos = lerp(model.zMin, model.zMax, (i+2.) / (NUM_BALLS + 4.));
346 void bounce(float midiVel) {
347 float v = 100 + 8*midiVel;
348 yPos.setSpeed(v, getAccel(v, 60 / lx.tempo.bpmf())).start();
351 float getAccel(float v, float oneBeat) {
352 return -2*v / oneBeat;
355 void run(double deltaMs) {
356 float flrLevel = flr.getValuef() * model.xMax/2.;
357 if (yPos.getValuef() < flrLevel) {
358 if (yPos.getVelocity() < -50) {
359 yPos.setValue(2*flrLevel-yPos.getValuef());
360 float v = -yPos.getVelocityf() * bounce.getValuef();
361 yPos.setSpeed(v, getAccel(v, 60 / lx.tempo.bpmf()));
363 yPos.setValue(flrLevel).stop();
366 float falloff = 130.f / (12 + blobSize.getValuef() * 36);
367 float xv = xPos.getValuef();
368 float yv = yPos.getValuef();
370 for (Point p : model.points) {
371 float d = sqrt((p.x-xv)*(p.x-xv) + (p.y-yv)*(p.y-yv) + .1*(p.z-zPos)*(p.z-zPos));
372 float b = constrain(130 - falloff*d, 0, 100);
374 colors[p.index] = blendColor(colors[p.index], lx.hsb(
375 (lx.getBaseHuef() + p.y*.5 + abs(model.cx - p.x) * .5) % 360,
376 max(0, 100 - .45*(p.y - flrLevel)),
384 final BouncyBall[] balls = new BouncyBall[NUM_BALLS];
386 final BasicParameter bounce = new BasicParameter("BNC", .8);
387 final BasicParameter flr = new BasicParameter("FLR", 0);
388 final BasicParameter blobSize = new BasicParameter("SIZE", 0.5);
390 BouncyBalls(GLucose glucose) {
392 for (int i = 0; i < balls.length; ++i) {
393 balls[i] = new BouncyBall(i);
395 addParameter(bounce);
397 addParameter(blobSize);
400 public void run(double deltaMs) {
402 for (BouncyBall b : balls) {
407 public boolean noteOn(Note note) {
408 int pitch = (note.getPitch() + note.getChannel()) % NUM_BALLS;
409 balls[pitch].bounce(note.getVelocity());
414 class SpaceTime extends SCPattern {
416 SinLFO pos = new SinLFO(0, 1, 3000);
417 SinLFO rate = new SinLFO(1000, 9000, 13000);
418 SinLFO falloff = new SinLFO(10, 70, 5000);
421 BasicParameter rateParameter = new BasicParameter("RATE", 0.5);
422 BasicParameter sizeParameter = new BasicParameter("SIZE", 0.5);
425 public SpaceTime(GLucose glucose) {
428 addModulator(pos).trigger();
429 addModulator(rate).trigger();
430 addModulator(falloff).trigger();
431 pos.modulateDurationBy(rate);
432 addParameter(rateParameter);
433 addParameter(sizeParameter);
436 public void onParameterChanged(LXParameter parameter) {
437 if (parameter == rateParameter) {
438 rate.stop().setValue(9000 - 8000*parameter.getValuef());
439 } else if (parameter == sizeParameter) {
440 falloff.stop().setValue(70 - 60*parameter.getValuef());
444 void run(double deltaMs) {
445 angle += deltaMs * 0.0007;
446 float sVal1 = model.strips.size() * (0.5 + 0.5*sin(angle));
447 float sVal2 = model.strips.size() * (0.5 + 0.5*cos(angle));
449 float pVal = pos.getValuef();
450 float fVal = falloff.getValuef();
453 for (Strip strip : model.strips) {
455 for (Point p : strip.points) {
456 colors[p.index] = lx.hsb(
457 (lx.getBaseHuef() + 360 - p.x*.2 + p.y * .3) % 360,
458 constrain(.4 * min(abs(s - sVal1), abs(s - sVal2)), 20, 100),
459 max(0, 100 - fVal*abs(i - pVal*(strip.metrics.numPoints - 1)))
468 class Swarm extends SCPattern {
470 SawLFO offset = new SawLFO(0, 1, 1000);
471 SinLFO rate = new SinLFO(350, 1200, 63000);
472 SinLFO falloff = new SinLFO(15, 50, 17000);
473 SinLFO fX = new SinLFO(0, model.xMax, 19000);
474 SinLFO fY = new SinLFO(0, model.yMax, 11000);
475 SinLFO hOffX = new SinLFO(0, model.xMax, 13000);
477 public Swarm(GLucose glucose) {
480 addModulator(offset).trigger();
481 addModulator(rate).trigger();
482 addModulator(falloff).trigger();
483 addModulator(fX).trigger();
484 addModulator(fY).trigger();
485 addModulator(hOffX).trigger();
486 offset.modulateDurationBy(rate);
489 float modDist(float v1, float v2, float mod) {
493 return min(v2-v1, v1+mod-v2);
496 return min(v1-v2, v2+mod-v1);
500 void run(double deltaMs) {
502 for (Strip strip : model.strips ) {
504 for (Point p : strip.points) {
505 float fV = max(-1, 1 - dist(p.x/2., p.y, fX.getValuef()/2., fY.getValuef()) / 64.);
506 colors[p.index] = lx.hsb(
507 (lx.getBaseHuef() + 0.3 * abs(p.x - hOffX.getValuef())) % 360,
508 constrain(80 + 40 * fV, 0, 100),
509 constrain(100 - (30 - fV * falloff.getValuef()) * modDist(i + (s*63)%61, offset.getValuef() * strip.metrics.numPoints, strip.metrics.numPoints), 0, 100)
518 class SwipeTransition extends SCTransition {
520 final BasicParameter bleed = new BasicParameter("WIDTH", 0.5);
522 SwipeTransition(GLucose glucose) {
528 void computeBlend(int[] c1, int[] c2, double progress) {
529 float bleedf = 10 + bleed.getValuef() * 200.;
530 float xPos = (float) (-bleedf + progress * (model.xMax + bleedf));
531 for (Point p : model.points) {
532 float d = (p.x - xPos) / bleedf;
534 colors[p.index] = c2[p.index];
536 colors[p.index] = c1[p.index];
538 colors[p.index] = lerpColor(c2[p.index], c1[p.index], d, RGB);
544 abstract class BlendTransition extends SCTransition {
548 BlendTransition(GLucose glucose, int blendType) {
550 this.blendType = blendType;
553 void computeBlend(int[] c1, int[] c2, double progress) {
554 if (progress < 0.5) {
555 for (int i = 0; i < c1.length; ++i) {
556 colors[i] = lerpColor(
558 blendColor(c1[i], c2[i], blendType),
559 (float) (2.*progress),
563 for (int i = 0; i < c1.length; ++i) {
564 colors[i] = lerpColor(
566 blendColor(c1[i], c2[i], blendType),
567 (float) (2.*(1. - progress)),
574 class MultiplyTransition extends BlendTransition {
575 MultiplyTransition(GLucose glucose) {
576 super(glucose, MULTIPLY);
580 class ScreenTransition extends BlendTransition {
581 ScreenTransition(GLucose glucose) {
582 super(glucose, SCREEN);
586 class BurnTransition extends BlendTransition {
587 BurnTransition(GLucose glucose) {
588 super(glucose, BURN);
592 class DodgeTransition extends BlendTransition {
593 DodgeTransition(GLucose glucose) {
594 super(glucose, DODGE);
598 class OverlayTransition extends BlendTransition {
599 OverlayTransition(GLucose glucose) {
600 super(glucose, OVERLAY);
604 class AddTransition extends BlendTransition {
605 AddTransition(GLucose glucose) {
610 class SubtractTransition extends BlendTransition {
611 SubtractTransition(GLucose glucose) {
612 super(glucose, SUBTRACT);
616 class SoftLightTransition extends BlendTransition {
617 SoftLightTransition(GLucose glucose) {
618 super(glucose, SOFT_LIGHT);
622 class BassPod extends SCPattern {
624 private GraphicEQ eq = null;
626 public BassPod(GLucose glucose) {
630 protected void onActive() {
632 eq = new GraphicEQ(lx, 16);
633 eq.slope.setValue(0.6);
634 addParameter(eq.level);
635 addParameter(eq.range);
636 addParameter(eq.attack);
637 addParameter(eq.release);
638 addParameter(eq.slope);
642 public void run(double deltaMs) {
645 float bassLevel = eq.getAverageLevel(0, 5);
647 for (Point p : model.points) {
648 int avgIndex = (int) constrain(1 + abs(p.x-model.xMax/2.)/(model.xMax/2.)*(eq.numBands-5), 0, eq.numBands-5);
650 for (int i = avgIndex; i < avgIndex + 5; ++i) {
651 value += eq.getLevel(i);
655 float b = constrain(8 * (value*model.yMax - abs(p.y-model.yMax/2.)), 0, 100);
656 colors[p.index] = lx.hsb(
657 (lx.getBaseHuef() + abs(p.y - model.cy) + abs(p.x - model.cx)) % 360,
658 constrain(bassLevel*240 - .6*dist(p.x, p.y, model.cx, model.cy), 0, 100),
666 class CubeEQ extends SCPattern {
668 private GraphicEQ eq = null;
670 private final BasicParameter edge = new BasicParameter("EDGE", 0.5);
671 private final BasicParameter clr = new BasicParameter("CLR", 0.5);
672 private final BasicParameter blockiness = new BasicParameter("BLK", 0.5);
674 public CubeEQ(GLucose glucose) {
678 protected void onActive() {
680 eq = new GraphicEQ(lx, 16);
681 addParameter(eq.level);
682 addParameter(eq.range);
683 addParameter(eq.attack);
684 addParameter(eq.release);
685 addParameter(eq.slope);
688 addParameter(blockiness);
692 public void run(double deltaMs) {
695 float edgeConst = 2 + 30*edge.getValuef();
696 float clrConst = 1.1 + clr.getValuef();
698 for (Point p : model.points) {
699 float avgIndex = constrain(2 + p.x / model.xMax * (eq.numBands-4), 0, eq.numBands-4);
700 int avgFloor = (int) avgIndex;
702 float leftVal = eq.getLevel(avgFloor);
703 float rightVal = eq.getLevel(avgFloor+1);
704 float smoothValue = lerp(leftVal, rightVal, avgIndex-avgFloor);
706 float chunkyValue = (
707 eq.getLevel(avgFloor/4*4) +
708 eq.getLevel(avgFloor/4*4 + 1) +
709 eq.getLevel(avgFloor/4*4 + 2) +
710 eq.getLevel(avgFloor/4*4 + 3)
713 float value = lerp(smoothValue, chunkyValue, blockiness.getValuef());
715 float b = constrain(edgeConst * (value*model.yMax - p.y), 0, 100);
716 colors[p.index] = lx.hsb(
717 (480 + lx.getBaseHuef() - min(clrConst*p.y, 120)) % 360,
725 class BoomEffect extends SCEffect {
727 final BasicParameter falloff = new BasicParameter("WIDTH", 0.5);
728 final BasicParameter speed = new BasicParameter("SPD", 0.5);
729 final BasicParameter bright = new BasicParameter("BRT", 1.0);
730 final BasicParameter sat = new BasicParameter("SAT", 0.2);
731 List<Layer> layers = new ArrayList<Layer>();
732 final float maxr = sqrt(model.xMax*model.xMax + model.yMax*model.yMax + model.zMax*model.zMax) + 10;
735 LinearEnvelope boom = new LinearEnvelope(-40, 500, 1300);
743 float falloffv = falloffv();
744 boom.setRange(-100 / falloffv, maxr + 100/falloffv, 4000 - speed.getValuef() * 3300);
748 void doApply(int[] colors) {
749 float brightv = 100 * bright.getValuef();
750 float falloffv = falloffv();
751 float satv = sat.getValuef() * 100;
752 float huev = lx.getBaseHuef();
753 for (Point p : model.points) {
754 colors[p.index] = blendColor(
756 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)),
762 BoomEffect(GLucose glucose) {
763 super(glucose, true);
764 addParameter(falloff);
766 addParameter(bright);
770 public void onEnable() {
771 for (Layer l : layers) {
772 if (!l.boom.isRunning()) {
777 layers.add(new Layer());
780 private float falloffv() {
781 return 20 - 19 * falloff.getValuef();
784 public void onTrigger() {
788 public void doApply(int[] colors) {
789 for (Layer l : layers) {
790 if (l.boom.isRunning()) {
797 public class PianoKeyPattern extends SCPattern {
799 final LinearEnvelope[] cubeBrt;
801 final BasicParameter attack = new BasicParameter("ATK", 0.1);
802 final BasicParameter release = new BasicParameter("REL", 0.5);
803 final BasicParameter level = new BasicParameter("AMB", 0.6);
805 PianoKeyPattern(GLucose glucose) {
808 addParameter(attack);
809 addParameter(release);
811 cubeBrt = new LinearEnvelope[model.cubes.size() / 4];
812 for (int i = 0; i < cubeBrt.length; ++i) {
813 addModulator(cubeBrt[i] = new LinearEnvelope(0, 0, 100));
815 base = new SinLFO[model.cubes.size() / 12];
816 for (int i = 0; i < base.length; ++i) {
817 addModulator(base[i] = new SinLFO(0, 1, 7000 + 1000*i)).trigger();
821 private float getAttackTime() {
822 return 15 + attack.getValuef()*attack.getValuef() * 2000;
825 private float getReleaseTime() {
826 return 15 + release.getValuef() * 3000;
829 private LinearEnvelope getEnvelope(int index) {
830 return cubeBrt[index % cubeBrt.length];
833 private SinLFO getBase(int index) {
834 return base[index % base.length];
837 public boolean noteOn(Note note) {
838 LinearEnvelope env = getEnvelope(note.getPitch());
839 env.setEndVal(min(1, env.getValuef() + (note.getVelocity() / 127.)), getAttackTime()).start();
843 public boolean noteOff(Note note) {
844 getEnvelope(note.getPitch()).setEndVal(0, getReleaseTime()).start();
848 public void run(double deltaMs) {
850 float huef = lx.getBaseHuef();
851 float levelf = level.getValuef();
852 for (Cube c : model.cubes) {
853 float v = max(getBase(i).getValuef() * levelf/4., getEnvelope(i++).getValuef());
855 (huef + 20*v + abs(c.cx-model.xMax/2.)*.3 + c.cy) % 360,
863 class CrossSections extends SCPattern {
865 final SinLFO x = new SinLFO(0, model.xMax, 5000);
866 final SinLFO y = new SinLFO(0, model.yMax, 6000);
867 final SinLFO z = new SinLFO(0, model.zMax, 7000);
869 final BasicParameter xw = new BasicParameter("XWID", 0.3);
870 final BasicParameter yw = new BasicParameter("YWID", 0.3);
871 final BasicParameter zw = new BasicParameter("ZWID", 0.3);
872 final BasicParameter xr = new BasicParameter("XRAT", 0.7);
873 final BasicParameter yr = new BasicParameter("YRAT", 0.6);
874 final BasicParameter zr = new BasicParameter("ZRAT", 0.5);
875 final BasicParameter xl = new BasicParameter("XLEV", 1);
876 final BasicParameter yl = new BasicParameter("YLEV", 1);
877 final BasicParameter zl = new BasicParameter("ZLEV", 0.5);
880 CrossSections(GLucose glucose) {
882 addModulator(x).trigger();
883 addModulator(y).trigger();
884 addModulator(z).trigger();
888 protected void addParams() {
900 void onParameterChanged(LXParameter p) {
902 x.setDuration(10000 - 8800*p.getValuef());
903 } else if (p == yr) {
904 y.setDuration(10000 - 9000*p.getValuef());
905 } else if (p == zr) {
906 z.setDuration(10000 - 9000*p.getValuef());
912 protected void updateXYZVals() {
918 public void run(double deltaMs) {
921 float xlv = 100*xl.getValuef();
922 float ylv = 100*yl.getValuef();
923 float zlv = 100*zl.getValuef();
925 float xwv = 100. / (10 + 40*xw.getValuef());
926 float ywv = 100. / (10 + 40*yw.getValuef());
927 float zwv = 100. / (10 + 40*zw.getValuef());
929 for (Point p : model.points) {
931 c = blendColor(c, lx.hsb(
932 (lx.getBaseHuef() + p.x/10 + p.y/3) % 360,
933 constrain(140 - 1.1*abs(p.x - model.xMax/2.), 0, 100),
934 max(0, xlv - xwv*abs(p.x - xv))
936 c = blendColor(c, lx.hsb(
937 (lx.getBaseHuef() + 80 + p.y/10) % 360,
938 constrain(140 - 2.2*abs(p.y - model.yMax/2.), 0, 100),
939 max(0, ylv - ywv*abs(p.y - yv))
941 c = blendColor(c, lx.hsb(
942 (lx.getBaseHuef() + 160 + p.z / 10 + p.y/2) % 360,
943 constrain(140 - 2.2*abs(p.z - model.zMax/2.), 0, 100),
944 max(0, zlv - zwv*abs(p.z - zv))
951 class Blinders extends SCPattern {
956 final TriangleLFO hs;
958 public Blinders(GLucose glucose) {
961 for (int i = 0; i < m.length; ++i) {
962 addModulator(m[i] = new SinLFO(0.5, 120, (120000. / (3+i)))).trigger();
964 addModulator(r = new TriangleLFO(9000, 15000, 29000)).trigger();
965 addModulator(s = new SinLFO(-20, 275, 11000)).trigger();
966 addModulator(hs = new TriangleLFO(0.1, 0.5, 15000)).trigger();
967 s.modulateDurationBy(r);
970 public void run(double deltaMs) {
971 float hv = lx.getBaseHuef();
973 for (Strip strip : model.strips) {
975 float mv = m[si % m.length].getValuef();
976 for (Point p : strip.points) {
977 colors[p.index] = lx.hsb(
978 (hv + p.z + p.y*hs.getValuef()) % 360,
979 min(100, abs(p.x - s.getValuef())/2.),
980 max(0, 100 - mv/2. - mv * abs(i - (strip.metrics.length-1)/2.))
989 class Psychedelia extends SCPattern {
992 SinLFO m = new SinLFO(-0.5, NUM-0.5, 9000);
993 SinLFO s = new SinLFO(-20, 147, 11000);
994 TriangleLFO h = new TriangleLFO(0, 240, 19000);
995 SinLFO c = new SinLFO(-.2, .8, 31000);
997 Psychedelia(GLucose glucose) {
999 addModulator(m).trigger();
1000 addModulator(s).trigger();
1001 addModulator(h).trigger();
1002 addModulator(c).trigger();
1005 void run(double deltaMs) {
1006 float huev = h.getValuef();
1007 float cv = c.getValuef();
1008 float sv = s.getValuef();
1009 float mv = m.getValuef();
1011 for (Strip strip : model.strips) {
1012 for (Point p : strip.points) {
1013 colors[p.index] = lx.hsb(
1014 (huev + i*constrain(cv, 0, 2) + p.z/2. + p.x/4.) % 360,
1015 min(100, abs(p.y-sv)),
1016 max(0, 100 - 50*abs((i%NUM) - mv))
1024 class AskewPlanes extends SCPattern {
1027 private final SinLFO a;
1028 private final SinLFO b;
1029 private final SinLFO c;
1036 addModulator(a = new SinLFO(-1, 1, 4000 + 1029*i)).trigger();
1037 addModulator(b = new SinLFO(-1, 1, 11000 - 1104*i)).trigger();
1038 addModulator(c = new SinLFO(-50, 50, 4000 + 1000*i * ((i % 2 == 0) ? 1 : -1))).trigger();
1041 void run(double deltaMs) {
1045 denom = sqrt(av*av + bv*bv);
1049 final Plane[] planes;
1050 final int NUM_PLANES = 3;
1052 AskewPlanes(GLucose glucose) {
1054 planes = new Plane[NUM_PLANES];
1055 for (int i = 0; i < planes.length; ++i) {
1056 planes[i] = new Plane(i);
1060 public void run(double deltaMs) {
1061 float huev = lx.getBaseHuef();
1063 // This is super fucking bizarre. But if this is a for loop, the framerate
1064 // tanks to like 30FPS, instead of 60. Call them manually and it works fine.
1065 // Doesn't make ANY sense... there must be some weird side effect going on
1066 // with the Processing internals perhaps?
1067 // for (Plane plane : planes) {
1068 // plane.run(deltaMs);
1070 planes[0].run(deltaMs);
1071 planes[1].run(deltaMs);
1072 planes[2].run(deltaMs);
1074 for (Point p : model.points) {
1075 float d = MAX_FLOAT;
1076 for (Plane plane : planes) {
1077 if (plane.denom != 0) {
1078 d = min(d, abs(plane.av*(p.x-model.cx) + plane.bv*(p.y-model.cy) + plane.cv) / plane.denom);
1081 colors[p.index] = lx.hsb(
1082 (huev + abs(p.x-model.cx)*.3 + p.y*.8) % 360,
1083 max(0, 100 - .8*abs(p.x - model.cx)),
1084 constrain(140 - 10.*d, 0, 100)
1090 class ShiftingPlane extends SCPattern {
1092 final SinLFO a = new SinLFO(-.2, .2, 5300);
1093 final SinLFO b = new SinLFO(1, -1, 13300);
1094 final SinLFO c = new SinLFO(-1.4, 1.4, 5700);
1095 final SinLFO d = new SinLFO(-10, 10, 9500);
1097 ShiftingPlane(GLucose glucose) {
1099 addModulator(a).trigger();
1100 addModulator(b).trigger();
1101 addModulator(c).trigger();
1102 addModulator(d).trigger();
1105 public void run(double deltaMs) {
1106 float hv = lx.getBaseHuef();
1107 float av = a.getValuef();
1108 float bv = b.getValuef();
1109 float cv = c.getValuef();
1110 float dv = d.getValuef();
1111 float denom = sqrt(av*av + bv*bv + cv*cv);
1112 for (Point p : model.points) {
1113 float d = abs(av*(p.x-model.cx) + bv*(p.y-model.cy) + cv*(p.z-model.cz) + dv) / denom;
1114 colors[p.index] = lx.hsb(
1115 (hv + abs(p.x-model.cx)*.6 + abs(p.y-model.cy)*.9 + abs(p.z - model.cz)) % 360,
1116 constrain(110 - d*6, 0, 100),
1117 constrain(130 - 7*d, 0, 100)
1123 class Traktor extends SCPattern {
1125 final int FRAME_WIDTH = 60;
1127 final BasicParameter speed = new BasicParameter("SPD", 0.5);
1129 private float[] bass = new float[FRAME_WIDTH];
1130 private float[] treble = new float[FRAME_WIDTH];
1132 private int index = 0;
1133 private GraphicEQ eq = null;
1135 public Traktor(GLucose glucose) {
1137 for (int i = 0; i < FRAME_WIDTH; ++i) {
1141 addParameter(speed);
1144 public void onActive() {
1146 eq = new GraphicEQ(lx, 16);
1147 eq.slope.setValue(0.6);
1148 eq.level.setValue(0.65);
1149 eq.range.setValue(0.35);
1150 eq.release.setValue(0.4);
1151 addParameter(eq.level);
1152 addParameter(eq.range);
1153 addParameter(eq.attack);
1154 addParameter(eq.release);
1155 addParameter(eq.slope);
1161 public void run(double deltaMs) {
1164 int stepThresh = (int) (40 - 39*speed.getValuef());
1166 if (counter < stepThresh) {
1169 counter = counter % stepThresh;
1171 index = (index + 1) % FRAME_WIDTH;
1173 float rawBass = eq.getAverageLevel(0, 4);
1174 float rawTreble = eq.getAverageLevel(eq.numBands-7, 7);
1176 bass[index] = rawBass * rawBass * rawBass * rawBass;
1177 treble[index] = rawTreble * rawTreble;
1179 for (Point p : model.points) {
1180 int i = (int) constrain((model.xMax - p.x) / model.xMax * FRAME_WIDTH, 0, FRAME_WIDTH-1);
1181 int pos = (index + FRAME_WIDTH - i) % FRAME_WIDTH;
1183 colors[p.index] = lx.hsb(
1184 (360 + lx.getBaseHuef() + .8*abs(p.x-model.cx)) % 360,
1186 constrain(9 * (bass[pos]*model.cy - abs(p.y - model.cy)), 0, 100)
1188 colors[p.index] = blendColor(colors[p.index], lx.hsb(
1189 (400 + lx.getBaseHuef() + .5*abs(p.x-model.cx)) % 360,
1191 constrain(5 * (treble[pos]*.6*model.cy - abs(p.y - model.cy)), 0, 100)
1198 class ColorFuckerEffect extends SCEffect {
1200 final BasicParameter level = new BasicParameter("BRT", 1);
1201 final BasicParameter desat = new BasicParameter("DSAT", 0);
1202 final BasicParameter sharp = new BasicParameter("SHARP", 0);
1203 final BasicParameter soft = new BasicParameter("SOFT", 0);
1204 final BasicParameter mono = new BasicParameter("MONO", 0);
1205 final BasicParameter invert = new BasicParameter("INVERT", 0);
1206 final BasicParameter hueShift = new BasicParameter("HSHFT", 0);
1208 float[] hsb = new float[3];
1210 ColorFuckerEffect(GLucose glucose) {
1212 addParameter(level);
1213 addParameter(desat);
1214 addParameter(sharp);
1217 addParameter(invert);
1218 addParameter(hueShift);
1221 public void doApply(int[] colors) {
1225 float bMod = level.getValuef();
1226 float sMod = 1 - desat.getValuef();
1227 float hMod = hueShift.getValuef();
1228 float fSharp = 1/(1.0001-sharp.getValuef());
1229 float fSoft = soft.getValuef();
1230 boolean mon = mono.getValuef() > 0.5;
1231 boolean ivt = invert.getValuef() > 0.5;
1232 if (bMod < 1 || sMod < 1 || hMod > 0 || fSharp > 0 || ivt || mon || fSoft > 0) {
1233 for (int i = 0; i < colors.length; ++i) {
1234 lx.RGBtoHSB(colors[i], hsb);
1236 hsb[0] = lx.getBaseHuef() / 360.;
1239 hsb[2] = 1 - hsb[2];
1242 hsb[2] = hsb[2] < .5 ? pow(hsb[2],fSharp) : 1-pow(1-hsb[2],fSharp);
1246 hsb[2] = lerp(hsb[2], 0.5 + 2 * (hsb[2]-0.5)*(hsb[2]-0.5), fSoft);
1248 hsb[2] = lerp(hsb[2], 0.5 * sqrt(2*hsb[2]), fSoft);
1252 (360. * hsb[0] + hMod*360.) % 360,
1253 100. * hsb[1] * sMod,
1254 100. * hsb[2] * bMod
1261 class QuantizeEffect extends SCEffect {
1263 color[] quantizedFrame;
1265 final BasicParameter amount = new BasicParameter("AMT", 0);
1267 QuantizeEffect(GLucose glucose) {
1269 quantizedFrame = new color[glucose.lx.total];
1273 public void doApply(int[] colors) {
1274 float fQuant = amount.getValuef();
1276 float tRamp = (lx.tempo.rampf() % (1./pow(2,floor((1-fQuant) * 4))));
1277 float f = lastQuant;
1280 for (int i = 0; i < colors.length; ++i) {
1281 colors[i] = quantizedFrame[i];
1286 for (int i = 0; i < colors.length; ++i) {
1287 quantizedFrame[i] = colors[i];
1292 class BlurEffect extends SCEffect {
1294 final LXParameter amount = new BasicParameter("AMT", 0);
1296 final LinearEnvelope env = new LinearEnvelope(0, 1, 100);
1298 BlurEffect(GLucose glucose) {
1300 addParameter(amount);
1302 frame = new int[lx.total];
1303 for (int i = 0; i < frame.length; ++i) {
1308 public void onEnable() {
1309 env.setRangeFromHereTo(1, 400).start();
1310 for (int i = 0; i < frame.length; ++i) {
1315 public void onDisable() {
1316 env.setRangeFromHereTo(0, 1000).start();
1319 public void doApply(int[] colors) {
1320 float amt = env.getValuef() * amount.getValuef();
1323 amt = 1 - (amt*amt*amt);
1324 for (int i = 0; i < colors.length; ++i) {
1325 // frame[i] = colors[i] = blendColor(colors[i], lerpColor(#000000, frame[i], amt, RGB), SCREEN);
1326 frame[i] = colors[i] = lerpColor(colors[i], blendColor(colors[i], frame[i], SCREEN), amt, RGB);