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>();
7 private final BasicParameter lightSize = new BasicParameter("SIZE", 0.5);
8 private final LinearEnvelope sparkle = new LinearEnvelope(0, 1, 500);
9 private float sparkleBright = 100;
11 MidiMusic(GLucose glucose) {
13 addParameter(lightSize);
14 addModulator(sparkle).setValue(1);
17 class LightUp extends LXLayer {
19 private LinearEnvelope brt = new LinearEnvelope(0, 0, 0);
20 private Accelerator yPos = new Accelerator(0, 0, 0);
28 boolean isAvailable() {
29 return brt.getValuef() <= 0;
32 void noteOn(Note note) {
33 xPos = lerp(0, model.xMax, constrain(0.5 + (note.getPitch() - 60) / 26., 0, 1));
34 yPos.setValue(lerp(20, model.yMax, note.getVelocity() / 127.));
35 brt.setRangeFromHereTo(lerp(40, 100, note.getVelocity() / 127.), 20).start();
38 void noteOff(Note note) {
39 yPos.setVelocity(0).setAcceleration(-380).start();
40 brt.setRangeFromHereTo(0, 1000).start();
43 public void run(double deltaMs, color[] colors) {
44 float bVal = brt.getValuef();
48 float yVal = yPos.getValuef();
49 for (Point p : model.points) {
50 float falloff = 6 - 5*lightSize.getValuef();
51 float b = max(0, bVal - falloff*dist(p.x, p.y, xPos, yVal));
53 colors[p.index] = blendColor(colors[p.index], lx.hsb(
54 (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360,
63 public synchronized boolean noteOn(Note note) {
64 if (note.getChannel() == 0) {
65 for (LightUp light : allLights) {
66 if (light.isAvailable()) {
68 lightMap.put(note.getPitch(), light);
72 LightUp newLight = new LightUp();
73 newLight.noteOn(note);
74 lightMap.put(note.getPitch(), newLight);
75 synchronized(newLayers) {
76 newLayers.push(newLight);
78 } else if (note.getChannel() == 1) {
79 } else if (note.getChannel() == 9) {
80 switch (note.getPitch()) {
82 if (note.getVelocity() > 0) {
83 sparkleBright = note.getVelocity() / 127. * 100;
84 if (sparkleBright > 0) {
94 public synchronized boolean noteOff(Note note) {
95 if (note.getChannel() == 0) {
96 LightUp light = lightMap.get(note.getPitch());
104 public synchronized void run(double deltaMs) {
105 float sparklePos = sparkle.getValuef() * Cube.POINTS_PER_STRIP * .75;
106 float maxBright = sparkleBright * (1 - sparkle.getValuef());
107 for (Strip s : model.strips) {
109 for (Point p : s.points) {
110 colors[p.index] = color(
111 (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360,
113 maxBright - 40.*abs(sparklePos - abs(i - (Cube.POINTS_PER_STRIP-1)/2.))
118 if (!newLayers.isEmpty()) {
119 synchronized(newLayers) {
120 while (!newLayers.isEmpty()) {
121 addLayer(newLayers.pop());
128 class Pulley extends SCPattern {
130 final int NUM_DIVISIONS = 16;
131 private final Accelerator[] gravity = new Accelerator[NUM_DIVISIONS];
132 private final Click[] delays = new Click[NUM_DIVISIONS];
134 private final Click reset = new Click(9000);
135 private boolean isRising = false;
137 private BasicParameter sz = new BasicParameter("SIZE", 0.5);
138 private BasicParameter beatAmount = new BasicParameter("BEAT", 0);
140 Pulley(GLucose glucose) {
142 for (int i = 0; i < NUM_DIVISIONS; ++i) {
143 addModulator(gravity[i] = new Accelerator(0, 0, 0));
144 addModulator(delays[i] = new Click(0));
146 addModulator(reset).start();
148 addParameter(beatAmount);
153 private void trigger() {
154 isRising = !isRising;
156 for (Accelerator g : gravity) {
158 g.setSpeed(random(20, 33), 0).start();
160 g.setVelocity(0).setAcceleration(-420);
161 delays[i].setDuration(random(0, 500)).trigger();
167 public void run(double deltaMs) {
173 // Fucking A, had to comment this all out because of that bizarre
174 // Processing bug where some simple loop takes an absurd amount of
175 // time, must be some pre-processor bug
176 // for (Accelerator g : gravity) {
177 // if (g.getValuef() > model.yMax) {
179 // } else if (g.getValuef() > model.yMax*.55) {
180 // if (g.getVelocityf() > 10) {
181 // g.setAcceleration(-16);
183 // g.setAcceleration(0);
189 for (Click d : delays) {
196 for (Accelerator g : gravity) {
197 if (g.getValuef() < 0) {
198 g.setValue(-g.getValuef());
199 g.setVelocity(-g.getVelocityf() * random(0.74, 0.84));
204 // A little silliness to test the grid API
205 if (midiEngine != null && midiEngine.getFocusedPattern() == this) {
206 for (int i = 0; i < 5; ++i) {
207 for (int j = 0; j < 8; ++j) {
208 int gi = (int) constrain(j * NUM_DIVISIONS / 8, 0, NUM_DIVISIONS-1);
209 float b = 1 - 4.*abs((6-i)/6. - gravity[gi].getValuef() / model.yMax);
210 midiEngine.grid.setState(i, j, (b < 0) ? 0 : 3);
215 float fPos = 1 - lx.tempo.rampf();
217 fPos = .2 + 4 * (.2 - fPos);
219 float falloff = 100. / (3 + sz.getValuef() * 36 + fPos * beatAmount.getValuef()*48);
220 for (Point p : model.points) {
221 int gi = (int) constrain((p.x - model.xMin) * NUM_DIVISIONS / (model.xMax - model.xMin), 0, NUM_DIVISIONS-1);
222 colors[p.index] = lx.hsb(
223 (lx.getBaseHuef() + abs(p.x - model.cx)*.8 + p.y*.4) % 360,
224 constrain(130 - p.y*.8, 0, 100),
225 max(0, 100 - abs(p.y - gravity[gi].getValuef())*falloff)
231 class ViolinWave extends SCPattern {
233 BasicParameter level = new BasicParameter("LVL", 0.45);
234 BasicParameter range = new BasicParameter("RNG", 0.5);
235 BasicParameter edge = new BasicParameter("EDG", 0.5);
236 BasicParameter release = new BasicParameter("RLS", 0.5);
237 BasicParameter speed = new BasicParameter("SPD", 0.5);
238 BasicParameter amp = new BasicParameter("AMP", 0.25);
239 BasicParameter period = new BasicParameter("WAVE", 0.5);
240 BasicParameter pSize = new BasicParameter("PSIZE", 0.5);
241 BasicParameter pSpeed = new BasicParameter("PSPD", 0.5);
242 BasicParameter pDensity = new BasicParameter("PDENS", 0.25);
244 LinearEnvelope dbValue = new LinearEnvelope(0, 0, 10);
246 ViolinWave(GLucose glucose) {
251 addParameter(release);
254 addParameter(period);
256 addParameter(pSpeed);
257 addParameter(pDensity);
259 addModulator(dbValue);
262 final List<Particle> particles = new ArrayList<Particle>();
266 LinearEnvelope x = new LinearEnvelope(0, 0, 0);
267 LinearEnvelope y = new LinearEnvelope(0, 0, 0);
274 Particle trigger(boolean direction) {
275 float xInit = random(model.xMin, model.xMax);
276 float time = 3000 - 2500*pSpeed.getValuef();
277 x.setRange(xInit, xInit + random(-40, 40), time).trigger();
278 y.setRange(model.cy + 10, direction ? model.yMax + 50 : model.yMin - 50, time).trigger();
283 return x.isRunning() || y.isRunning();
286 public void run(double deltaMs) {
291 float pFalloff = (30 - 27*pSize.getValuef());
292 for (Point p : model.points) {
293 float b = 100 - pFalloff * (abs(p.x - x.getValuef()) + abs(p.y - y.getValuef()));
295 colors[p.index] = blendColor(colors[p.index], lx.hsb(
296 lx.getBaseHuef(), 20, b
303 float[] centers = new float[30];
305 boolean rising = true;
307 void fireParticle(boolean direction) {
308 boolean gotOne = false;
309 for (Particle p : particles) {
311 p.trigger(direction);
315 particles.add(new Particle().trigger(direction));
318 public void run(double deltaMs) {
319 accum += deltaMs / (1000. - 900.*speed.getValuef());
320 for (int i = 0; i < centers.length; ++i) {
321 centers[i] = model.cy + 30*amp.getValuef()*sin((float) (accum + (i-centers.length/2.)/(1. + 9.*period.getValuef())));
324 float zeroDBReference = pow(10, (50 - 190*level.getValuef())/20.);
325 float dB = 20*GraphicEQ.log10(lx.audioInput().mix.level() / zeroDBReference);
326 if (dB > dbValue.getValuef()) {
328 dbValue.setRangeFromHereTo(dB, 10).trigger();
331 for (int j = 0; j < pDensity.getValuef()*3; ++j) {
337 dbValue.setRangeFromHereTo(max(dB, -96), 50 + 1000*release.getValuef()).trigger();
339 float edg = 1 + edge.getValuef() * 40;
340 float rng = (78 - 64 * range.getValuef()) / (model.yMax - model.cy);
341 float val = max(2, dbValue.getValuef());
343 for (Point p : model.points) {
344 int ci = (int) lerp(0, centers.length-1, (p.x - model.xMin) / (model.xMax - model.xMin));
345 float rFactor = 1.0 - 0.9 * abs(p.x - model.cx) / (model.xMax - model.cx);
346 colors[p.index] = lx.hsb(
347 (lx.getBaseHuef() + abs(p.x - model.cx)) % 360,
348 min(100, 20 + 8*abs(p.y - centers[ci])),
349 constrain(edg*(val*rFactor - rng * abs(p.y-centers[ci])), 0, 100)
353 for (Particle p : particles) {
359 class BouncyBalls extends SCPattern {
361 static final int NUM_BALLS = 6;
366 TriangleLFO xPos = new TriangleLFO(0, model.xMax, random(8000, 19000));
370 addModulator(xPos).setBasis(random(0, TWO_PI)).start();
371 addModulator(yPos = new Accelerator(0, 0, 0));
372 zPos = lerp(model.zMin, model.zMax, (i+2.) / (NUM_BALLS + 4.));
375 void bounce(float midiVel) {
376 float v = 100 + 8*midiVel;
377 yPos.setSpeed(v, getAccel(v, 60 / lx.tempo.bpmf())).start();
380 float getAccel(float v, float oneBeat) {
381 return -2*v / oneBeat;
384 void run(double deltaMs) {
385 float flrLevel = flr.getValuef() * model.xMax/2.;
386 if (yPos.getValuef() < flrLevel) {
387 if (yPos.getVelocity() < -50) {
388 yPos.setValue(2*flrLevel-yPos.getValuef());
389 float v = -yPos.getVelocityf() * bounce.getValuef();
390 yPos.setSpeed(v, getAccel(v, 60 / lx.tempo.bpmf()));
392 yPos.setValue(flrLevel).stop();
395 float falloff = 130.f / (12 + blobSize.getValuef() * 36);
396 float xv = xPos.getValuef();
397 float yv = yPos.getValuef();
399 for (Point p : model.points) {
400 float d = sqrt((p.x-xv)*(p.x-xv) + (p.y-yv)*(p.y-yv) + .1*(p.z-zPos)*(p.z-zPos));
401 float b = constrain(130 - falloff*d, 0, 100);
403 colors[p.index] = blendColor(colors[p.index], lx.hsb(
404 (lx.getBaseHuef() + p.y*.5 + abs(model.cx - p.x) * .5) % 360,
405 max(0, 100 - .45*(p.y - flrLevel)),
413 final BouncyBall[] balls = new BouncyBall[NUM_BALLS];
415 final BasicParameter bounce = new BasicParameter("BNC", .8);
416 final BasicParameter flr = new BasicParameter("FLR", 0);
417 final BasicParameter blobSize = new BasicParameter("SIZE", 0.5);
419 BouncyBalls(GLucose glucose) {
421 for (int i = 0; i < balls.length; ++i) {
422 balls[i] = new BouncyBall(i);
424 addParameter(bounce);
426 addParameter(blobSize);
429 public void run(double deltaMs) {
431 for (BouncyBall b : balls) {
436 public boolean noteOn(Note note) {
437 int pitch = (note.getPitch() + note.getChannel()) % NUM_BALLS;
438 balls[pitch].bounce(note.getVelocity());
443 class SpaceTime extends SCPattern {
445 SinLFO pos = new SinLFO(0, 1, 3000);
446 SinLFO rate = new SinLFO(1000, 9000, 13000);
447 SinLFO falloff = new SinLFO(10, 70, 5000);
450 BasicParameter rateParameter = new BasicParameter("RATE", 0.5);
451 BasicParameter sizeParameter = new BasicParameter("SIZE", 0.5);
454 public SpaceTime(GLucose glucose) {
457 addModulator(pos).trigger();
458 addModulator(rate).trigger();
459 addModulator(falloff).trigger();
460 pos.modulateDurationBy(rate);
461 addParameter(rateParameter);
462 addParameter(sizeParameter);
465 public void onParameterChanged(LXParameter parameter) {
466 if (parameter == rateParameter) {
467 rate.stop().setValue(9000 - 8000*parameter.getValuef());
468 } else if (parameter == sizeParameter) {
469 falloff.stop().setValue(70 - 60*parameter.getValuef());
473 void run(double deltaMs) {
474 angle += deltaMs * 0.0007;
475 float sVal1 = model.strips.size() * (0.5 + 0.5*sin(angle));
476 float sVal2 = model.strips.size() * (0.5 + 0.5*cos(angle));
478 float pVal = pos.getValuef();
479 float fVal = falloff.getValuef();
482 for (Strip strip : model.strips) {
484 for (Point p : strip.points) {
485 colors[p.index] = lx.hsb(
486 (lx.getBaseHuef() + 360 - p.x*.2 + p.y * .3) % 360,
487 constrain(.4 * min(abs(s - sVal1), abs(s - sVal2)), 20, 100),
488 max(0, 100 - fVal*abs(i - pVal*(strip.metrics.numPoints - 1)))
497 class Swarm extends SCPattern {
499 SawLFO offset = new SawLFO(0, 1, 1000);
500 SinLFO rate = new SinLFO(350, 1200, 63000);
501 SinLFO falloff = new SinLFO(15, 50, 17000);
502 SinLFO fX = new SinLFO(0, model.xMax, 19000);
503 SinLFO fY = new SinLFO(0, model.yMax, 11000);
504 SinLFO hOffX = new SinLFO(0, model.xMax, 13000);
506 public Swarm(GLucose glucose) {
509 addModulator(offset).trigger();
510 addModulator(rate).trigger();
511 addModulator(falloff).trigger();
512 addModulator(fX).trigger();
513 addModulator(fY).trigger();
514 addModulator(hOffX).trigger();
515 offset.modulateDurationBy(rate);
518 float modDist(float v1, float v2, float mod) {
522 return min(v2-v1, v1+mod-v2);
525 return min(v1-v2, v2+mod-v1);
529 void run(double deltaMs) {
531 for (Strip strip : model.strips ) {
533 for (Point p : strip.points) {
534 float fV = max(-1, 1 - dist(p.x/2., p.y, fX.getValuef()/2., fY.getValuef()) / 64.);
535 colors[p.index] = lx.hsb(
536 (lx.getBaseHuef() + 0.3 * abs(p.x - hOffX.getValuef())) % 360,
537 constrain(80 + 40 * fV, 0, 100),
538 constrain(100 - (30 - fV * falloff.getValuef()) * modDist(i + (s*63)%61, offset.getValuef() * strip.metrics.numPoints, strip.metrics.numPoints), 0, 100)
547 class SwipeTransition extends SCTransition {
549 final BasicParameter bleed = new BasicParameter("WIDTH", 0.5);
551 SwipeTransition(GLucose glucose) {
557 void computeBlend(int[] c1, int[] c2, double progress) {
558 float bleedf = 10 + bleed.getValuef() * 200.;
559 float xPos = (float) (-bleedf + progress * (model.xMax + bleedf));
560 for (Point p : model.points) {
561 float d = (p.x - xPos) / bleedf;
563 colors[p.index] = c2[p.index];
565 colors[p.index] = c1[p.index];
567 colors[p.index] = lerpColor(c2[p.index], c1[p.index], d, RGB);
573 abstract class BlendTransition extends SCTransition {
577 BlendTransition(GLucose glucose, int blendType) {
579 this.blendType = blendType;
582 void computeBlend(int[] c1, int[] c2, double progress) {
583 if (progress < 0.5) {
584 for (int i = 0; i < c1.length; ++i) {
585 colors[i] = lerpColor(
587 blendColor(c1[i], c2[i], blendType),
588 (float) (2.*progress),
592 for (int i = 0; i < c1.length; ++i) {
593 colors[i] = lerpColor(
595 blendColor(c1[i], c2[i], blendType),
596 (float) (2.*(1. - progress)),
603 class MultiplyTransition extends BlendTransition {
604 MultiplyTransition(GLucose glucose) {
605 super(glucose, MULTIPLY);
609 class ScreenTransition extends BlendTransition {
610 ScreenTransition(GLucose glucose) {
611 super(glucose, SCREEN);
615 class BurnTransition extends BlendTransition {
616 BurnTransition(GLucose glucose) {
617 super(glucose, BURN);
621 class DodgeTransition extends BlendTransition {
622 DodgeTransition(GLucose glucose) {
623 super(glucose, DODGE);
627 class OverlayTransition extends BlendTransition {
628 OverlayTransition(GLucose glucose) {
629 super(glucose, OVERLAY);
633 class AddTransition extends BlendTransition {
634 AddTransition(GLucose glucose) {
639 class SubtractTransition extends BlendTransition {
640 SubtractTransition(GLucose glucose) {
641 super(glucose, SUBTRACT);
645 class SoftLightTransition extends BlendTransition {
646 SoftLightTransition(GLucose glucose) {
647 super(glucose, SOFT_LIGHT);
651 class BassPod extends SCPattern {
653 private GraphicEQ eq = null;
655 public BassPod(GLucose glucose) {
659 protected void onActive() {
661 eq = new GraphicEQ(lx, 16);
662 eq.slope.setValue(0.6);
663 addParameter(eq.level);
664 addParameter(eq.range);
665 addParameter(eq.attack);
666 addParameter(eq.release);
667 addParameter(eq.slope);
671 public void run(double deltaMs) {
674 float bassLevel = eq.getAverageLevel(0, 5);
676 for (Point p : model.points) {
677 int avgIndex = (int) constrain(1 + abs(p.x-model.xMax/2.)/(model.xMax/2.)*(eq.numBands-5), 0, eq.numBands-5);
679 for (int i = avgIndex; i < avgIndex + 5; ++i) {
680 value += eq.getLevel(i);
684 float b = constrain(8 * (value*model.yMax - abs(p.y-model.yMax/2.)), 0, 100);
685 colors[p.index] = lx.hsb(
686 (lx.getBaseHuef() + abs(p.y - model.cy) + abs(p.x - model.cx)) % 360,
687 constrain(bassLevel*240 - .6*dist(p.x, p.y, model.cx, model.cy), 0, 100),
695 class CubeEQ extends SCPattern {
697 private GraphicEQ eq = null;
699 private final BasicParameter edge = new BasicParameter("EDGE", 0.5);
700 private final BasicParameter clr = new BasicParameter("CLR", 0.5);
701 private final BasicParameter blockiness = new BasicParameter("BLK", 0.5);
703 public CubeEQ(GLucose glucose) {
707 protected void onActive() {
709 eq = new GraphicEQ(lx, 16);
710 addParameter(eq.level);
711 addParameter(eq.range);
712 addParameter(eq.attack);
713 addParameter(eq.release);
714 addParameter(eq.slope);
717 addParameter(blockiness);
721 public void run(double deltaMs) {
724 float edgeConst = 2 + 30*edge.getValuef();
725 float clrConst = 1.1 + clr.getValuef();
727 for (Point p : model.points) {
728 float avgIndex = constrain(2 + p.x / model.xMax * (eq.numBands-4), 0, eq.numBands-4);
729 int avgFloor = (int) avgIndex;
731 float leftVal = eq.getLevel(avgFloor);
732 float rightVal = eq.getLevel(avgFloor+1);
733 float smoothValue = lerp(leftVal, rightVal, avgIndex-avgFloor);
735 float chunkyValue = (
736 eq.getLevel(avgFloor/4*4) +
737 eq.getLevel(avgFloor/4*4 + 1) +
738 eq.getLevel(avgFloor/4*4 + 2) +
739 eq.getLevel(avgFloor/4*4 + 3)
742 float value = lerp(smoothValue, chunkyValue, blockiness.getValuef());
744 float b = constrain(edgeConst * (value*model.yMax - p.y), 0, 100);
745 colors[p.index] = lx.hsb(
746 (480 + lx.getBaseHuef() - min(clrConst*p.y, 120)) % 360,
754 class BoomEffect extends SCEffect {
756 final BasicParameter falloff = new BasicParameter("WIDTH", 0.5);
757 final BasicParameter speed = new BasicParameter("SPD", 0.5);
758 final BasicParameter bright = new BasicParameter("BRT", 1.0);
759 final BasicParameter sat = new BasicParameter("SAT", 0.2);
760 List<Layer> layers = new ArrayList<Layer>();
761 final float maxr = sqrt(model.xMax*model.xMax + model.yMax*model.yMax + model.zMax*model.zMax) + 10;
764 LinearEnvelope boom = new LinearEnvelope(-40, 500, 1300);
772 float falloffv = falloffv();
773 boom.setRange(-100 / falloffv, maxr + 100/falloffv, 4000 - speed.getValuef() * 3300);
777 void doApply(int[] colors) {
778 float brightv = 100 * bright.getValuef();
779 float falloffv = falloffv();
780 float satv = sat.getValuef() * 100;
781 float huev = lx.getBaseHuef();
782 for (Point p : model.points) {
783 colors[p.index] = blendColor(
785 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)),
791 BoomEffect(GLucose glucose) {
792 super(glucose, true);
793 addParameter(falloff);
795 addParameter(bright);
799 public void onEnable() {
800 for (Layer l : layers) {
801 if (!l.boom.isRunning()) {
806 layers.add(new Layer());
809 private float falloffv() {
810 return 20 - 19 * falloff.getValuef();
813 public void onTrigger() {
817 public void doApply(int[] colors) {
818 for (Layer l : layers) {
819 if (l.boom.isRunning()) {
826 public class PianoKeyPattern extends SCPattern {
828 final LinearEnvelope[] cubeBrt;
830 final BasicParameter attack = new BasicParameter("ATK", 0.1);
831 final BasicParameter release = new BasicParameter("REL", 0.5);
832 final BasicParameter level = new BasicParameter("AMB", 0.6);
834 PianoKeyPattern(GLucose glucose) {
837 addParameter(attack);
838 addParameter(release);
840 cubeBrt = new LinearEnvelope[model.cubes.size() / 4];
841 for (int i = 0; i < cubeBrt.length; ++i) {
842 addModulator(cubeBrt[i] = new LinearEnvelope(0, 0, 100));
844 base = new SinLFO[model.cubes.size() / 12];
845 for (int i = 0; i < base.length; ++i) {
846 addModulator(base[i] = new SinLFO(0, 1, 7000 + 1000*i)).trigger();
850 private float getAttackTime() {
851 return 15 + attack.getValuef()*attack.getValuef() * 2000;
854 private float getReleaseTime() {
855 return 15 + release.getValuef() * 3000;
858 private LinearEnvelope getEnvelope(int index) {
859 return cubeBrt[index % cubeBrt.length];
862 private SinLFO getBase(int index) {
863 return base[index % base.length];
866 public boolean noteOn(Note note) {
867 LinearEnvelope env = getEnvelope(note.getPitch());
868 env.setEndVal(min(1, env.getValuef() + (note.getVelocity() / 127.)), getAttackTime()).start();
872 public boolean noteOff(Note note) {
873 getEnvelope(note.getPitch()).setEndVal(0, getReleaseTime()).start();
877 public void run(double deltaMs) {
879 float huef = lx.getBaseHuef();
880 float levelf = level.getValuef();
881 for (Cube c : model.cubes) {
882 float v = max(getBase(i).getValuef() * levelf/4., getEnvelope(i++).getValuef());
884 (huef + 20*v + abs(c.cx-model.xMax/2.)*.3 + c.cy) % 360,
892 class CrossSections extends SCPattern {
894 final SinLFO x = new SinLFO(0, model.xMax, 5000);
895 final SinLFO y = new SinLFO(0, model.yMax, 6000);
896 final SinLFO z = new SinLFO(0, model.zMax, 7000);
898 final BasicParameter xw = new BasicParameter("XWID", 0.3);
899 final BasicParameter yw = new BasicParameter("YWID", 0.3);
900 final BasicParameter zw = new BasicParameter("ZWID", 0.3);
901 final BasicParameter xr = new BasicParameter("XRAT", 0.7);
902 final BasicParameter yr = new BasicParameter("YRAT", 0.6);
903 final BasicParameter zr = new BasicParameter("ZRAT", 0.5);
904 final BasicParameter xl = new BasicParameter("XLEV", 1);
905 final BasicParameter yl = new BasicParameter("YLEV", 1);
906 final BasicParameter zl = new BasicParameter("ZLEV", 0.5);
909 CrossSections(GLucose glucose) {
911 addModulator(x).trigger();
912 addModulator(y).trigger();
913 addModulator(z).trigger();
917 protected void addParams() {
929 void onParameterChanged(LXParameter p) {
931 x.setDuration(10000 - 8800*p.getValuef());
932 } else if (p == yr) {
933 y.setDuration(10000 - 9000*p.getValuef());
934 } else if (p == zr) {
935 z.setDuration(10000 - 9000*p.getValuef());
941 protected void updateXYZVals() {
947 public void run(double deltaMs) {
950 float xlv = 100*xl.getValuef();
951 float ylv = 100*yl.getValuef();
952 float zlv = 100*zl.getValuef();
954 float xwv = 100. / (10 + 40*xw.getValuef());
955 float ywv = 100. / (10 + 40*yw.getValuef());
956 float zwv = 100. / (10 + 40*zw.getValuef());
958 for (Point p : model.points) {
960 c = blendColor(c, lx.hsb(
961 (lx.getBaseHuef() + p.x/10 + p.y/3) % 360,
962 constrain(140 - 1.1*abs(p.x - model.xMax/2.), 0, 100),
963 max(0, xlv - xwv*abs(p.x - xv))
965 c = blendColor(c, lx.hsb(
966 (lx.getBaseHuef() + 80 + p.y/10) % 360,
967 constrain(140 - 2.2*abs(p.y - model.yMax/2.), 0, 100),
968 max(0, ylv - ywv*abs(p.y - yv))
970 c = blendColor(c, lx.hsb(
971 (lx.getBaseHuef() + 160 + p.z / 10 + p.y/2) % 360,
972 constrain(140 - 2.2*abs(p.z - model.zMax/2.), 0, 100),
973 max(0, zlv - zwv*abs(p.z - zv))
980 class Blinders extends SCPattern {
985 final TriangleLFO hs;
987 public Blinders(GLucose glucose) {
990 for (int i = 0; i < m.length; ++i) {
991 addModulator(m[i] = new SinLFO(0.5, 120, (120000. / (3+i)))).trigger();
993 addModulator(r = new TriangleLFO(9000, 15000, 29000)).trigger();
994 addModulator(s = new SinLFO(-20, 275, 11000)).trigger();
995 addModulator(hs = new TriangleLFO(0.1, 0.5, 15000)).trigger();
996 s.modulateDurationBy(r);
999 public void run(double deltaMs) {
1000 float hv = lx.getBaseHuef();
1002 for (Strip strip : model.strips) {
1004 float mv = m[si % m.length].getValuef();
1005 for (Point p : strip.points) {
1006 colors[p.index] = lx.hsb(
1007 (hv + p.z + p.y*hs.getValuef()) % 360,
1008 min(100, abs(p.x - s.getValuef())/2.),
1009 max(0, 100 - mv/2. - mv * abs(i - (strip.metrics.length-1)/2.))
1018 class Psychedelia extends SCPattern {
1021 SinLFO m = new SinLFO(-0.5, NUM-0.5, 9000);
1022 SinLFO s = new SinLFO(-20, 147, 11000);
1023 TriangleLFO h = new TriangleLFO(0, 240, 19000);
1024 SinLFO c = new SinLFO(-.2, .8, 31000);
1026 Psychedelia(GLucose glucose) {
1028 addModulator(m).trigger();
1029 addModulator(s).trigger();
1030 addModulator(h).trigger();
1031 addModulator(c).trigger();
1034 void run(double deltaMs) {
1035 float huev = h.getValuef();
1036 float cv = c.getValuef();
1037 float sv = s.getValuef();
1038 float mv = m.getValuef();
1040 for (Strip strip : model.strips) {
1041 for (Point p : strip.points) {
1042 colors[p.index] = lx.hsb(
1043 (huev + i*constrain(cv, 0, 2) + p.z/2. + p.x/4.) % 360,
1044 min(100, abs(p.y-sv)),
1045 max(0, 100 - 50*abs((i%NUM) - mv))
1053 class AskewPlanes extends SCPattern {
1056 private final SinLFO a;
1057 private final SinLFO b;
1058 private final SinLFO c;
1065 addModulator(a = new SinLFO(-1, 1, 4000 + 1029*i)).trigger();
1066 addModulator(b = new SinLFO(-1, 1, 11000 - 1104*i)).trigger();
1067 addModulator(c = new SinLFO(-50, 50, 4000 + 1000*i * ((i % 2 == 0) ? 1 : -1))).trigger();
1070 void run(double deltaMs) {
1074 denom = sqrt(av*av + bv*bv);
1078 final Plane[] planes;
1079 final int NUM_PLANES = 3;
1081 AskewPlanes(GLucose glucose) {
1083 planes = new Plane[NUM_PLANES];
1084 for (int i = 0; i < planes.length; ++i) {
1085 planes[i] = new Plane(i);
1089 public void run(double deltaMs) {
1090 float huev = lx.getBaseHuef();
1092 // This is super fucking bizarre. But if this is a for loop, the framerate
1093 // tanks to like 30FPS, instead of 60. Call them manually and it works fine.
1094 // Doesn't make ANY sense... there must be some weird side effect going on
1095 // with the Processing internals perhaps?
1096 // for (Plane plane : planes) {
1097 // plane.run(deltaMs);
1099 planes[0].run(deltaMs);
1100 planes[1].run(deltaMs);
1101 planes[2].run(deltaMs);
1103 for (Point p : model.points) {
1104 float d = MAX_FLOAT;
1105 for (Plane plane : planes) {
1106 if (plane.denom != 0) {
1107 d = min(d, abs(plane.av*(p.x-model.cx) + plane.bv*(p.y-model.cy) + plane.cv) / plane.denom);
1110 colors[p.index] = lx.hsb(
1111 (huev + abs(p.x-model.cx)*.3 + p.y*.8) % 360,
1112 max(0, 100 - .8*abs(p.x - model.cx)),
1113 constrain(140 - 10.*d, 0, 100)
1119 class ShiftingPlane extends SCPattern {
1121 final SinLFO a = new SinLFO(-.2, .2, 5300);
1122 final SinLFO b = new SinLFO(1, -1, 13300);
1123 final SinLFO c = new SinLFO(-1.4, 1.4, 5700);
1124 final SinLFO d = new SinLFO(-10, 10, 9500);
1126 ShiftingPlane(GLucose glucose) {
1128 addModulator(a).trigger();
1129 addModulator(b).trigger();
1130 addModulator(c).trigger();
1131 addModulator(d).trigger();
1134 public void run(double deltaMs) {
1135 float hv = lx.getBaseHuef();
1136 float av = a.getValuef();
1137 float bv = b.getValuef();
1138 float cv = c.getValuef();
1139 float dv = d.getValuef();
1140 float denom = sqrt(av*av + bv*bv + cv*cv);
1141 for (Point p : model.points) {
1142 float d = abs(av*(p.x-model.cx) + bv*(p.y-model.cy) + cv*(p.z-model.cz) + dv) / denom;
1143 colors[p.index] = lx.hsb(
1144 (hv + abs(p.x-model.cx)*.6 + abs(p.y-model.cy)*.9 + abs(p.z - model.cz)) % 360,
1145 constrain(110 - d*6, 0, 100),
1146 constrain(130 - 7*d, 0, 100)
1152 class Traktor extends SCPattern {
1154 final int FRAME_WIDTH = 60;
1156 final BasicParameter speed = new BasicParameter("SPD", 0.5);
1158 private float[] bass = new float[FRAME_WIDTH];
1159 private float[] treble = new float[FRAME_WIDTH];
1161 private int index = 0;
1162 private GraphicEQ eq = null;
1164 public Traktor(GLucose glucose) {
1166 for (int i = 0; i < FRAME_WIDTH; ++i) {
1170 addParameter(speed);
1173 public void onActive() {
1175 eq = new GraphicEQ(lx, 16);
1176 eq.slope.setValue(0.6);
1177 eq.level.setValue(0.65);
1178 eq.range.setValue(0.35);
1179 eq.release.setValue(0.4);
1180 addParameter(eq.level);
1181 addParameter(eq.range);
1182 addParameter(eq.attack);
1183 addParameter(eq.release);
1184 addParameter(eq.slope);
1190 public void run(double deltaMs) {
1193 int stepThresh = (int) (40 - 39*speed.getValuef());
1195 if (counter < stepThresh) {
1198 counter = counter % stepThresh;
1200 index = (index + 1) % FRAME_WIDTH;
1202 float rawBass = eq.getAverageLevel(0, 4);
1203 float rawTreble = eq.getAverageLevel(eq.numBands-7, 7);
1205 bass[index] = rawBass * rawBass * rawBass * rawBass;
1206 treble[index] = rawTreble * rawTreble;
1208 for (Point p : model.points) {
1209 int i = (int) constrain((model.xMax - p.x) / model.xMax * FRAME_WIDTH, 0, FRAME_WIDTH-1);
1210 int pos = (index + FRAME_WIDTH - i) % FRAME_WIDTH;
1212 colors[p.index] = lx.hsb(
1213 (360 + lx.getBaseHuef() + .8*abs(p.x-model.cx)) % 360,
1215 constrain(9 * (bass[pos]*model.cy - abs(p.y - model.cy)), 0, 100)
1217 colors[p.index] = blendColor(colors[p.index], lx.hsb(
1218 (400 + lx.getBaseHuef() + .5*abs(p.x-model.cx)) % 360,
1220 constrain(5 * (treble[pos]*.6*model.cy - abs(p.y - model.cy)), 0, 100)
1227 class ColorFuckerEffect extends SCEffect {
1229 final BasicParameter level = new BasicParameter("BRT", 1);
1230 final BasicParameter desat = new BasicParameter("DSAT", 0);
1231 final BasicParameter sharp = new BasicParameter("SHARP", 0);
1232 final BasicParameter soft = new BasicParameter("SOFT", 0);
1233 final BasicParameter mono = new BasicParameter("MONO", 0);
1234 final BasicParameter invert = new BasicParameter("INVERT", 0);
1235 final BasicParameter hueShift = new BasicParameter("HSHFT", 0);
1237 float[] hsb = new float[3];
1239 ColorFuckerEffect(GLucose glucose) {
1241 addParameter(level);
1242 addParameter(desat);
1243 addParameter(sharp);
1246 addParameter(invert);
1247 addParameter(hueShift);
1250 public void doApply(int[] colors) {
1254 float bMod = level.getValuef();
1255 float sMod = 1 - desat.getValuef();
1256 float hMod = hueShift.getValuef();
1257 float fSharp = 1/(1.0001-sharp.getValuef());
1258 float fSoft = soft.getValuef();
1259 boolean mon = mono.getValuef() > 0.5;
1260 boolean ivt = invert.getValuef() > 0.5;
1261 if (bMod < 1 || sMod < 1 || hMod > 0 || fSharp > 0 || ivt || mon || fSoft > 0) {
1262 for (int i = 0; i < colors.length; ++i) {
1263 lx.RGBtoHSB(colors[i], hsb);
1265 hsb[0] = lx.getBaseHuef() / 360.;
1268 hsb[2] = 1 - hsb[2];
1271 hsb[2] = hsb[2] < .5 ? pow(hsb[2],fSharp) : 1-pow(1-hsb[2],fSharp);
1275 hsb[2] = lerp(hsb[2], 0.5 + 2 * (hsb[2]-0.5)*(hsb[2]-0.5), fSoft);
1277 hsb[2] = lerp(hsb[2], 0.5 * sqrt(2*hsb[2]), fSoft);
1281 (360. * hsb[0] + hMod*360.) % 360,
1282 100. * hsb[1] * sMod,
1283 100. * hsb[2] * bMod
1290 class QuantizeEffect extends SCEffect {
1292 color[] quantizedFrame;
1294 final BasicParameter amount = new BasicParameter("AMT", 0);
1296 QuantizeEffect(GLucose glucose) {
1298 quantizedFrame = new color[glucose.lx.total];
1302 public void doApply(int[] colors) {
1303 float fQuant = amount.getValuef();
1305 float tRamp = (lx.tempo.rampf() % (1./pow(2,floor((1-fQuant) * 4))));
1306 float f = lastQuant;
1309 for (int i = 0; i < colors.length; ++i) {
1310 colors[i] = quantizedFrame[i];
1315 for (int i = 0; i < colors.length; ++i) {
1316 quantizedFrame[i] = colors[i];
1321 class BlurEffect extends SCEffect {
1323 final LXParameter amount = new BasicParameter("AMT", 0);
1325 final LinearEnvelope env = new LinearEnvelope(0, 1, 100);
1327 BlurEffect(GLucose glucose) {
1329 addParameter(amount);
1331 frame = new int[lx.total];
1332 for (int i = 0; i < frame.length; ++i) {
1337 public void onEnable() {
1338 env.setRangeFromHereTo(1, 400).start();
1339 for (int i = 0; i < frame.length; ++i) {
1344 public void onDisable() {
1345 env.setRangeFromHereTo(0, 1000).start();
1348 public void doApply(int[] colors) {
1349 float amt = env.getValuef() * amount.getValuef();
1352 amt = 1 - (amt*amt*amt);
1353 for (int i = 0; i < colors.length; ++i) {
1354 // frame[i] = colors[i] = blendColor(colors[i], lerpColor(#000000, frame[i], amt, RGB), SCREEN);
1355 frame[i] = colors[i] = lerpColor(colors[i], blendColor(colors[i], frame[i], SCREEN), amt, RGB);