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);
9 private final LinearEnvelope sparkle = new LinearEnvelope(0, 1, 500);
10 private float sparkleBright = 100;
12 private final LinearEnvelope sweep = new LinearEnvelope(0, 1, 1000);
14 MidiMusic(GLucose glucose) {
16 addParameter(lightSize);
17 addModulator(sparkle).setValue(1);
21 class LightUp extends LXLayer {
23 private LinearEnvelope brt = new LinearEnvelope(0, 0, 0);
24 private Accelerator yPos = new Accelerator(0, 0, 0);
32 boolean isAvailable() {
33 return brt.getValuef() <= 0;
36 void noteOn(Note note) {
37 xPos = lerp(0, model.xMax, constrain(0.5 + (note.getPitch() - 60) / 26., 0, 1));
38 yPos.setValue(lerp(20, model.yMax, note.getVelocity() / 127.));
39 brt.setRangeFromHereTo(lerp(40, 100, note.getVelocity() / 127.), 20).start();
42 void noteOff(Note note) {
43 yPos.setVelocity(0).setAcceleration(-380).start();
44 brt.setRangeFromHereTo(0, 1000).start();
47 public void run(double deltaMs, color[] colors) {
48 float bVal = brt.getValuef();
52 float yVal = yPos.getValuef();
53 for (Point p : model.points) {
54 float falloff = 6 - 5*lightSize.getValuef();
55 float b = max(0, bVal - falloff*dist(p.x, p.y, xPos, yVal));
57 colors[p.index] = blendColor(colors[p.index], lx.hsb(
58 (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360,
67 public synchronized boolean noteOn(Note note) {
68 if (note.getChannel() == 0) {
69 for (LightUp light : allLights) {
70 if (light.isAvailable()) {
72 lightMap.put(note.getPitch(), light);
76 LightUp newLight = new LightUp();
77 newLight.noteOn(note);
78 lightMap.put(note.getPitch(), newLight);
79 synchronized(newLayers) {
80 newLayers.push(newLight);
82 } else if (note.getChannel() == 1) {
83 } else if (note.getChannel() == 9) {
84 if (note.getVelocity() > 0) {
85 switch (note.getPitch()) {
87 sparkleBright = note.getVelocity() / 127. * 100;
99 public synchronized boolean noteOff(Note note) {
100 if (note.getChannel() == 0) {
101 LightUp light = lightMap.get(note.getPitch());
109 public synchronized void run(double deltaMs) {
110 float sparklePos = sparkle.getValuef() * Cube.POINTS_PER_STRIP * .75;
111 float maxBright = sparkleBright * (1 - sparkle.getValuef());
112 for (Strip s : model.strips) {
114 for (Point p : s.points) {
115 colors[p.index] = color(
116 (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360,
118 maxBright - 40.*abs(sparklePos - abs(i - (Cube.POINTS_PER_STRIP-1)/2.))
124 if (sweep.isRunning()) {
125 for (Point p : model.points) {
126 colors[p.index] = blendColor(colors[p.index], color(
127 (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360,
128 100 - 100.*sweep.getValuef(),
129 100 - 15.*abs(p.y - sweep.getValuef()*model.yMax)
134 if (!newLayers.isEmpty()) {
135 synchronized(newLayers) {
136 while (!newLayers.isEmpty()) {
137 addLayer(newLayers.pop());
144 class Pulley extends SCPattern {
146 final int NUM_DIVISIONS = 16;
147 private final Accelerator[] gravity = new Accelerator[NUM_DIVISIONS];
148 private final Click[] delays = new Click[NUM_DIVISIONS];
150 private final Click reset = new Click(9000);
151 private boolean isRising = false;
153 private BasicParameter sz = new BasicParameter("SIZE", 0.5);
154 private BasicParameter beatAmount = new BasicParameter("BEAT", 0);
156 Pulley(GLucose glucose) {
158 for (int i = 0; i < NUM_DIVISIONS; ++i) {
159 addModulator(gravity[i] = new Accelerator(0, 0, 0));
160 addModulator(delays[i] = new Click(0));
162 addModulator(reset).start();
164 addParameter(beatAmount);
169 private void trigger() {
170 isRising = !isRising;
172 for (Accelerator g : gravity) {
174 g.setSpeed(random(20, 33), 0).start();
176 g.setVelocity(0).setAcceleration(-420);
177 delays[i].setDuration(random(0, 500)).trigger();
183 public void run(double deltaMs) {
189 // Fucking A, had to comment this all out because of that bizarre
190 // Processing bug where some simple loop takes an absurd amount of
191 // time, must be some pre-processor bug
192 // for (Accelerator g : gravity) {
193 // if (g.getValuef() > model.yMax) {
195 // } else if (g.getValuef() > model.yMax*.55) {
196 // if (g.getVelocityf() > 10) {
197 // g.setAcceleration(-16);
199 // g.setAcceleration(0);
205 for (Click d : delays) {
212 for (Accelerator g : gravity) {
213 if (g.getValuef() < 0) {
214 g.setValue(-g.getValuef());
215 g.setVelocity(-g.getVelocityf() * random(0.74, 0.84));
220 // A little silliness to test the grid API
221 if (midiEngine != null && midiEngine.getFocusedPattern() == this) {
222 for (int i = 0; i < 5; ++i) {
223 for (int j = 0; j < 8; ++j) {
224 int gi = (int) constrain(j * NUM_DIVISIONS / 8, 0, NUM_DIVISIONS-1);
225 float b = 1 - 4.*abs((6-i)/6. - gravity[gi].getValuef() / model.yMax);
226 midiEngine.grid.setState(i, j, (b < 0) ? 0 : 3);
231 float fPos = 1 - lx.tempo.rampf();
233 fPos = .2 + 4 * (.2 - fPos);
235 float falloff = 100. / (3 + sz.getValuef() * 36 + fPos * beatAmount.getValuef()*48);
236 for (Point p : model.points) {
237 int gi = (int) constrain((p.x - model.xMin) * NUM_DIVISIONS / (model.xMax - model.xMin), 0, NUM_DIVISIONS-1);
238 colors[p.index] = lx.hsb(
239 (lx.getBaseHuef() + abs(p.x - model.cx)*.8 + p.y*.4) % 360,
240 constrain(130 - p.y*.8, 0, 100),
241 max(0, 100 - abs(p.y - gravity[gi].getValuef())*falloff)
247 class ViolinWave extends SCPattern {
249 BasicParameter level = new BasicParameter("LVL", 0.45);
250 BasicParameter range = new BasicParameter("RNG", 0.5);
251 BasicParameter edge = new BasicParameter("EDG", 0.5);
252 BasicParameter release = new BasicParameter("RLS", 0.5);
253 BasicParameter speed = new BasicParameter("SPD", 0.5);
254 BasicParameter amp = new BasicParameter("AMP", 0.25);
255 BasicParameter period = new BasicParameter("WAVE", 0.5);
256 BasicParameter pSize = new BasicParameter("PSIZE", 0.5);
257 BasicParameter pSpeed = new BasicParameter("PSPD", 0.5);
258 BasicParameter pDensity = new BasicParameter("PDENS", 0.25);
260 LinearEnvelope dbValue = new LinearEnvelope(0, 0, 10);
262 ViolinWave(GLucose glucose) {
267 addParameter(release);
270 addParameter(period);
272 addParameter(pSpeed);
273 addParameter(pDensity);
275 addModulator(dbValue);
278 final List<Particle> particles = new ArrayList<Particle>();
282 LinearEnvelope x = new LinearEnvelope(0, 0, 0);
283 LinearEnvelope y = new LinearEnvelope(0, 0, 0);
290 Particle trigger(boolean direction) {
291 float xInit = random(model.xMin, model.xMax);
292 float time = 3000 - 2500*pSpeed.getValuef();
293 x.setRange(xInit, xInit + random(-40, 40), time).trigger();
294 y.setRange(model.cy + 10, direction ? model.yMax + 50 : model.yMin - 50, time).trigger();
299 return x.isRunning() || y.isRunning();
302 public void run(double deltaMs) {
307 float pFalloff = (30 - 27*pSize.getValuef());
308 for (Point p : model.points) {
309 float b = 100 - pFalloff * (abs(p.x - x.getValuef()) + abs(p.y - y.getValuef()));
311 colors[p.index] = blendColor(colors[p.index], lx.hsb(
312 lx.getBaseHuef(), 20, b
319 float[] centers = new float[30];
321 boolean rising = true;
323 void fireParticle(boolean direction) {
324 boolean gotOne = false;
325 for (Particle p : particles) {
327 p.trigger(direction);
331 particles.add(new Particle().trigger(direction));
334 public void run(double deltaMs) {
335 accum += deltaMs / (1000. - 900.*speed.getValuef());
336 for (int i = 0; i < centers.length; ++i) {
337 centers[i] = model.cy + 30*amp.getValuef()*sin((float) (accum + (i-centers.length/2.)/(1. + 9.*period.getValuef())));
340 float zeroDBReference = pow(10, (50 - 190*level.getValuef())/20.);
341 float dB = 20*GraphicEQ.log10(lx.audioInput().mix.level() / zeroDBReference);
342 if (dB > dbValue.getValuef()) {
344 dbValue.setRangeFromHereTo(dB, 10).trigger();
347 for (int j = 0; j < pDensity.getValuef()*3; ++j) {
353 dbValue.setRangeFromHereTo(max(dB, -96), 50 + 1000*release.getValuef()).trigger();
355 float edg = 1 + edge.getValuef() * 40;
356 float rng = (78 - 64 * range.getValuef()) / (model.yMax - model.cy);
357 float val = max(2, dbValue.getValuef());
359 for (Point p : model.points) {
360 int ci = (int) lerp(0, centers.length-1, (p.x - model.xMin) / (model.xMax - model.xMin));
361 float rFactor = 1.0 - 0.9 * abs(p.x - model.cx) / (model.xMax - model.cx);
362 colors[p.index] = lx.hsb(
363 (lx.getBaseHuef() + abs(p.x - model.cx)) % 360,
364 min(100, 20 + 8*abs(p.y - centers[ci])),
365 constrain(edg*(val*rFactor - rng * abs(p.y-centers[ci])), 0, 100)
369 for (Particle p : particles) {
375 class BouncyBalls extends SCPattern {
377 static final int NUM_BALLS = 6;
382 TriangleLFO xPos = new TriangleLFO(0, model.xMax, random(8000, 19000));
386 addModulator(xPos).setBasis(random(0, TWO_PI)).start();
387 addModulator(yPos = new Accelerator(0, 0, 0));
388 zPos = lerp(model.zMin, model.zMax, (i+2.) / (NUM_BALLS + 4.));
391 void bounce(float midiVel) {
392 float v = 100 + 8*midiVel;
393 yPos.setSpeed(v, getAccel(v, 60 / lx.tempo.bpmf())).start();
396 float getAccel(float v, float oneBeat) {
397 return -2*v / oneBeat;
400 void run(double deltaMs) {
401 float flrLevel = flr.getValuef() * model.xMax/2.;
402 if (yPos.getValuef() < flrLevel) {
403 if (yPos.getVelocity() < -50) {
404 yPos.setValue(2*flrLevel-yPos.getValuef());
405 float v = -yPos.getVelocityf() * bounce.getValuef();
406 yPos.setSpeed(v, getAccel(v, 60 / lx.tempo.bpmf()));
408 yPos.setValue(flrLevel).stop();
411 float falloff = 130.f / (12 + blobSize.getValuef() * 36);
412 float xv = xPos.getValuef();
413 float yv = yPos.getValuef();
415 for (Point p : model.points) {
416 float d = sqrt((p.x-xv)*(p.x-xv) + (p.y-yv)*(p.y-yv) + .1*(p.z-zPos)*(p.z-zPos));
417 float b = constrain(130 - falloff*d, 0, 100);
419 colors[p.index] = blendColor(colors[p.index], lx.hsb(
420 (lx.getBaseHuef() + p.y*.5 + abs(model.cx - p.x) * .5) % 360,
421 max(0, 100 - .45*(p.y - flrLevel)),
429 final BouncyBall[] balls = new BouncyBall[NUM_BALLS];
431 final BasicParameter bounce = new BasicParameter("BNC", .8);
432 final BasicParameter flr = new BasicParameter("FLR", 0);
433 final BasicParameter blobSize = new BasicParameter("SIZE", 0.5);
435 BouncyBalls(GLucose glucose) {
437 for (int i = 0; i < balls.length; ++i) {
438 balls[i] = new BouncyBall(i);
440 addParameter(bounce);
442 addParameter(blobSize);
445 public void run(double deltaMs) {
447 for (BouncyBall b : balls) {
452 public boolean noteOn(Note note) {
453 int pitch = (note.getPitch() + note.getChannel()) % NUM_BALLS;
454 balls[pitch].bounce(note.getVelocity());
459 class SpaceTime extends SCPattern {
461 SinLFO pos = new SinLFO(0, 1, 3000);
462 SinLFO rate = new SinLFO(1000, 9000, 13000);
463 SinLFO falloff = new SinLFO(10, 70, 5000);
466 BasicParameter rateParameter = new BasicParameter("RATE", 0.5);
467 BasicParameter sizeParameter = new BasicParameter("SIZE", 0.5);
470 public SpaceTime(GLucose glucose) {
473 addModulator(pos).trigger();
474 addModulator(rate).trigger();
475 addModulator(falloff).trigger();
476 pos.modulateDurationBy(rate);
477 addParameter(rateParameter);
478 addParameter(sizeParameter);
481 public void onParameterChanged(LXParameter parameter) {
482 if (parameter == rateParameter) {
483 rate.stop().setValue(9000 - 8000*parameter.getValuef());
484 } else if (parameter == sizeParameter) {
485 falloff.stop().setValue(70 - 60*parameter.getValuef());
489 void run(double deltaMs) {
490 angle += deltaMs * 0.0007;
491 float sVal1 = model.strips.size() * (0.5 + 0.5*sin(angle));
492 float sVal2 = model.strips.size() * (0.5 + 0.5*cos(angle));
494 float pVal = pos.getValuef();
495 float fVal = falloff.getValuef();
498 for (Strip strip : model.strips) {
500 for (Point p : strip.points) {
501 colors[p.index] = lx.hsb(
502 (lx.getBaseHuef() + 360 - p.x*.2 + p.y * .3) % 360,
503 constrain(.4 * min(abs(s - sVal1), abs(s - sVal2)), 20, 100),
504 max(0, 100 - fVal*abs(i - pVal*(strip.metrics.numPoints - 1)))
513 class Swarm extends SCPattern {
515 SawLFO offset = new SawLFO(0, 1, 1000);
516 SinLFO rate = new SinLFO(350, 1200, 63000);
517 SinLFO falloff = new SinLFO(15, 50, 17000);
518 SinLFO fX = new SinLFO(0, model.xMax, 19000);
519 SinLFO fY = new SinLFO(0, model.yMax, 11000);
520 SinLFO hOffX = new SinLFO(0, model.xMax, 13000);
522 public Swarm(GLucose glucose) {
525 addModulator(offset).trigger();
526 addModulator(rate).trigger();
527 addModulator(falloff).trigger();
528 addModulator(fX).trigger();
529 addModulator(fY).trigger();
530 addModulator(hOffX).trigger();
531 offset.modulateDurationBy(rate);
534 float modDist(float v1, float v2, float mod) {
538 return min(v2-v1, v1+mod-v2);
541 return min(v1-v2, v2+mod-v1);
545 void run(double deltaMs) {
547 for (Strip strip : model.strips ) {
549 for (Point p : strip.points) {
550 float fV = max(-1, 1 - dist(p.x/2., p.y, fX.getValuef()/2., fY.getValuef()) / 64.);
551 colors[p.index] = lx.hsb(
552 (lx.getBaseHuef() + 0.3 * abs(p.x - hOffX.getValuef())) % 360,
553 constrain(80 + 40 * fV, 0, 100),
554 constrain(100 - (30 - fV * falloff.getValuef()) * modDist(i + (s*63)%61, offset.getValuef() * strip.metrics.numPoints, strip.metrics.numPoints), 0, 100)
563 class SwipeTransition extends SCTransition {
565 final BasicParameter bleed = new BasicParameter("WIDTH", 0.5);
567 SwipeTransition(GLucose glucose) {
573 void computeBlend(int[] c1, int[] c2, double progress) {
574 float bleedf = 10 + bleed.getValuef() * 200.;
575 float xPos = (float) (-bleedf + progress * (model.xMax + bleedf));
576 for (Point p : model.points) {
577 float d = (p.x - xPos) / bleedf;
579 colors[p.index] = c2[p.index];
581 colors[p.index] = c1[p.index];
583 colors[p.index] = lerpColor(c2[p.index], c1[p.index], d, RGB);
589 abstract class BlendTransition extends SCTransition {
593 BlendTransition(GLucose glucose, int blendType) {
595 this.blendType = blendType;
598 void computeBlend(int[] c1, int[] c2, double progress) {
599 if (progress < 0.5) {
600 for (int i = 0; i < c1.length; ++i) {
601 colors[i] = lerpColor(
603 blendColor(c1[i], c2[i], blendType),
604 (float) (2.*progress),
608 for (int i = 0; i < c1.length; ++i) {
609 colors[i] = lerpColor(
611 blendColor(c1[i], c2[i], blendType),
612 (float) (2.*(1. - progress)),
619 class MultiplyTransition extends BlendTransition {
620 MultiplyTransition(GLucose glucose) {
621 super(glucose, MULTIPLY);
625 class ScreenTransition extends BlendTransition {
626 ScreenTransition(GLucose glucose) {
627 super(glucose, SCREEN);
631 class BurnTransition extends BlendTransition {
632 BurnTransition(GLucose glucose) {
633 super(glucose, BURN);
637 class DodgeTransition extends BlendTransition {
638 DodgeTransition(GLucose glucose) {
639 super(glucose, DODGE);
643 class OverlayTransition extends BlendTransition {
644 OverlayTransition(GLucose glucose) {
645 super(glucose, OVERLAY);
649 class AddTransition extends BlendTransition {
650 AddTransition(GLucose glucose) {
655 class SubtractTransition extends BlendTransition {
656 SubtractTransition(GLucose glucose) {
657 super(glucose, SUBTRACT);
661 class SoftLightTransition extends BlendTransition {
662 SoftLightTransition(GLucose glucose) {
663 super(glucose, SOFT_LIGHT);
667 class BassPod extends SCPattern {
669 private GraphicEQ eq = null;
671 public BassPod(GLucose glucose) {
675 protected void onActive() {
677 eq = new GraphicEQ(lx, 16);
678 eq.slope.setValue(0.6);
679 addParameter(eq.level);
680 addParameter(eq.range);
681 addParameter(eq.attack);
682 addParameter(eq.release);
683 addParameter(eq.slope);
687 public void run(double deltaMs) {
690 float bassLevel = eq.getAverageLevel(0, 5);
692 for (Point p : model.points) {
693 int avgIndex = (int) constrain(1 + abs(p.x-model.xMax/2.)/(model.xMax/2.)*(eq.numBands-5), 0, eq.numBands-5);
695 for (int i = avgIndex; i < avgIndex + 5; ++i) {
696 value += eq.getLevel(i);
700 float b = constrain(8 * (value*model.yMax - abs(p.y-model.yMax/2.)), 0, 100);
701 colors[p.index] = lx.hsb(
702 (lx.getBaseHuef() + abs(p.y - model.cy) + abs(p.x - model.cx)) % 360,
703 constrain(bassLevel*240 - .6*dist(p.x, p.y, model.cx, model.cy), 0, 100),
711 class CubeEQ extends SCPattern {
713 private GraphicEQ eq = null;
715 private final BasicParameter edge = new BasicParameter("EDGE", 0.5);
716 private final BasicParameter clr = new BasicParameter("CLR", 0.5);
717 private final BasicParameter blockiness = new BasicParameter("BLK", 0.5);
719 public CubeEQ(GLucose glucose) {
723 protected void onActive() {
725 eq = new GraphicEQ(lx, 16);
726 addParameter(eq.level);
727 addParameter(eq.range);
728 addParameter(eq.attack);
729 addParameter(eq.release);
730 addParameter(eq.slope);
733 addParameter(blockiness);
737 public void run(double deltaMs) {
740 float edgeConst = 2 + 30*edge.getValuef();
741 float clrConst = 1.1 + clr.getValuef();
743 for (Point p : model.points) {
744 float avgIndex = constrain(2 + p.x / model.xMax * (eq.numBands-4), 0, eq.numBands-4);
745 int avgFloor = (int) avgIndex;
747 float leftVal = eq.getLevel(avgFloor);
748 float rightVal = eq.getLevel(avgFloor+1);
749 float smoothValue = lerp(leftVal, rightVal, avgIndex-avgFloor);
751 float chunkyValue = (
752 eq.getLevel(avgFloor/4*4) +
753 eq.getLevel(avgFloor/4*4 + 1) +
754 eq.getLevel(avgFloor/4*4 + 2) +
755 eq.getLevel(avgFloor/4*4 + 3)
758 float value = lerp(smoothValue, chunkyValue, blockiness.getValuef());
760 float b = constrain(edgeConst * (value*model.yMax - p.y), 0, 100);
761 colors[p.index] = lx.hsb(
762 (480 + lx.getBaseHuef() - min(clrConst*p.y, 120)) % 360,
770 class BoomEffect extends SCEffect {
772 final BasicParameter falloff = new BasicParameter("WIDTH", 0.5);
773 final BasicParameter speed = new BasicParameter("SPD", 0.5);
774 final BasicParameter bright = new BasicParameter("BRT", 1.0);
775 final BasicParameter sat = new BasicParameter("SAT", 0.2);
776 List<Layer> layers = new ArrayList<Layer>();
777 final float maxr = sqrt(model.xMax*model.xMax + model.yMax*model.yMax + model.zMax*model.zMax) + 10;
780 LinearEnvelope boom = new LinearEnvelope(-40, 500, 1300);
788 float falloffv = falloffv();
789 boom.setRange(-100 / falloffv, maxr + 100/falloffv, 4000 - speed.getValuef() * 3300);
793 void doApply(int[] colors) {
794 float brightv = 100 * bright.getValuef();
795 float falloffv = falloffv();
796 float satv = sat.getValuef() * 100;
797 float huev = lx.getBaseHuef();
798 for (Point p : model.points) {
799 colors[p.index] = blendColor(
801 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)),
807 BoomEffect(GLucose glucose) {
808 super(glucose, true);
809 addParameter(falloff);
811 addParameter(bright);
815 public void onEnable() {
816 for (Layer l : layers) {
817 if (!l.boom.isRunning()) {
822 layers.add(new Layer());
825 private float falloffv() {
826 return 20 - 19 * falloff.getValuef();
829 public void onTrigger() {
833 public void doApply(int[] colors) {
834 for (Layer l : layers) {
835 if (l.boom.isRunning()) {
842 public class PianoKeyPattern extends SCPattern {
844 final LinearEnvelope[] cubeBrt;
846 final BasicParameter attack = new BasicParameter("ATK", 0.1);
847 final BasicParameter release = new BasicParameter("REL", 0.5);
848 final BasicParameter level = new BasicParameter("AMB", 0.6);
850 PianoKeyPattern(GLucose glucose) {
853 addParameter(attack);
854 addParameter(release);
856 cubeBrt = new LinearEnvelope[model.cubes.size() / 4];
857 for (int i = 0; i < cubeBrt.length; ++i) {
858 addModulator(cubeBrt[i] = new LinearEnvelope(0, 0, 100));
860 base = new SinLFO[model.cubes.size() / 12];
861 for (int i = 0; i < base.length; ++i) {
862 addModulator(base[i] = new SinLFO(0, 1, 7000 + 1000*i)).trigger();
866 private float getAttackTime() {
867 return 15 + attack.getValuef()*attack.getValuef() * 2000;
870 private float getReleaseTime() {
871 return 15 + release.getValuef() * 3000;
874 private LinearEnvelope getEnvelope(int index) {
875 return cubeBrt[index % cubeBrt.length];
878 private SinLFO getBase(int index) {
879 return base[index % base.length];
882 public boolean noteOn(Note note) {
883 LinearEnvelope env = getEnvelope(note.getPitch());
884 env.setEndVal(min(1, env.getValuef() + (note.getVelocity() / 127.)), getAttackTime()).start();
888 public boolean noteOff(Note note) {
889 getEnvelope(note.getPitch()).setEndVal(0, getReleaseTime()).start();
893 public void run(double deltaMs) {
895 float huef = lx.getBaseHuef();
896 float levelf = level.getValuef();
897 for (Cube c : model.cubes) {
898 float v = max(getBase(i).getValuef() * levelf/4., getEnvelope(i++).getValuef());
900 (huef + 20*v + abs(c.cx-model.xMax/2.)*.3 + c.cy) % 360,
908 class CrossSections extends SCPattern {
910 final SinLFO x = new SinLFO(0, model.xMax, 5000);
911 final SinLFO y = new SinLFO(0, model.yMax, 6000);
912 final SinLFO z = new SinLFO(0, model.zMax, 7000);
914 final BasicParameter xw = new BasicParameter("XWID", 0.3);
915 final BasicParameter yw = new BasicParameter("YWID", 0.3);
916 final BasicParameter zw = new BasicParameter("ZWID", 0.3);
917 final BasicParameter xr = new BasicParameter("XRAT", 0.7);
918 final BasicParameter yr = new BasicParameter("YRAT", 0.6);
919 final BasicParameter zr = new BasicParameter("ZRAT", 0.5);
920 final BasicParameter xl = new BasicParameter("XLEV", 1);
921 final BasicParameter yl = new BasicParameter("YLEV", 1);
922 final BasicParameter zl = new BasicParameter("ZLEV", 0.5);
925 CrossSections(GLucose glucose) {
927 addModulator(x).trigger();
928 addModulator(y).trigger();
929 addModulator(z).trigger();
933 protected void addParams() {
945 void onParameterChanged(LXParameter p) {
947 x.setDuration(10000 - 8800*p.getValuef());
948 } else if (p == yr) {
949 y.setDuration(10000 - 9000*p.getValuef());
950 } else if (p == zr) {
951 z.setDuration(10000 - 9000*p.getValuef());
957 protected void updateXYZVals() {
963 public void run(double deltaMs) {
966 float xlv = 100*xl.getValuef();
967 float ylv = 100*yl.getValuef();
968 float zlv = 100*zl.getValuef();
970 float xwv = 100. / (10 + 40*xw.getValuef());
971 float ywv = 100. / (10 + 40*yw.getValuef());
972 float zwv = 100. / (10 + 40*zw.getValuef());
974 for (Point p : model.points) {
976 c = blendColor(c, lx.hsb(
977 (lx.getBaseHuef() + p.x/10 + p.y/3) % 360,
978 constrain(140 - 1.1*abs(p.x - model.xMax/2.), 0, 100),
979 max(0, xlv - xwv*abs(p.x - xv))
981 c = blendColor(c, lx.hsb(
982 (lx.getBaseHuef() + 80 + p.y/10) % 360,
983 constrain(140 - 2.2*abs(p.y - model.yMax/2.), 0, 100),
984 max(0, ylv - ywv*abs(p.y - yv))
986 c = blendColor(c, lx.hsb(
987 (lx.getBaseHuef() + 160 + p.z / 10 + p.y/2) % 360,
988 constrain(140 - 2.2*abs(p.z - model.zMax/2.), 0, 100),
989 max(0, zlv - zwv*abs(p.z - zv))
996 class Blinders extends SCPattern {
1001 final TriangleLFO hs;
1003 public Blinders(GLucose glucose) {
1006 for (int i = 0; i < m.length; ++i) {
1007 addModulator(m[i] = new SinLFO(0.5, 120, (120000. / (3+i)))).trigger();
1009 addModulator(r = new TriangleLFO(9000, 15000, 29000)).trigger();
1010 addModulator(s = new SinLFO(-20, 275, 11000)).trigger();
1011 addModulator(hs = new TriangleLFO(0.1, 0.5, 15000)).trigger();
1012 s.modulateDurationBy(r);
1015 public void run(double deltaMs) {
1016 float hv = lx.getBaseHuef();
1018 for (Strip strip : model.strips) {
1020 float mv = m[si % m.length].getValuef();
1021 for (Point p : strip.points) {
1022 colors[p.index] = lx.hsb(
1023 (hv + p.z + p.y*hs.getValuef()) % 360,
1024 min(100, abs(p.x - s.getValuef())/2.),
1025 max(0, 100 - mv/2. - mv * abs(i - (strip.metrics.length-1)/2.))
1034 class Psychedelia extends SCPattern {
1037 SinLFO m = new SinLFO(-0.5, NUM-0.5, 9000);
1038 SinLFO s = new SinLFO(-20, 147, 11000);
1039 TriangleLFO h = new TriangleLFO(0, 240, 19000);
1040 SinLFO c = new SinLFO(-.2, .8, 31000);
1042 Psychedelia(GLucose glucose) {
1044 addModulator(m).trigger();
1045 addModulator(s).trigger();
1046 addModulator(h).trigger();
1047 addModulator(c).trigger();
1050 void run(double deltaMs) {
1051 float huev = h.getValuef();
1052 float cv = c.getValuef();
1053 float sv = s.getValuef();
1054 float mv = m.getValuef();
1056 for (Strip strip : model.strips) {
1057 for (Point p : strip.points) {
1058 colors[p.index] = lx.hsb(
1059 (huev + i*constrain(cv, 0, 2) + p.z/2. + p.x/4.) % 360,
1060 min(100, abs(p.y-sv)),
1061 max(0, 100 - 50*abs((i%NUM) - mv))
1069 class AskewPlanes extends SCPattern {
1072 private final SinLFO a;
1073 private final SinLFO b;
1074 private final SinLFO c;
1081 addModulator(a = new SinLFO(-1, 1, 4000 + 1029*i)).trigger();
1082 addModulator(b = new SinLFO(-1, 1, 11000 - 1104*i)).trigger();
1083 addModulator(c = new SinLFO(-50, 50, 4000 + 1000*i * ((i % 2 == 0) ? 1 : -1))).trigger();
1086 void run(double deltaMs) {
1090 denom = sqrt(av*av + bv*bv);
1094 final Plane[] planes;
1095 final int NUM_PLANES = 3;
1097 AskewPlanes(GLucose glucose) {
1099 planes = new Plane[NUM_PLANES];
1100 for (int i = 0; i < planes.length; ++i) {
1101 planes[i] = new Plane(i);
1105 public void run(double deltaMs) {
1106 float huev = lx.getBaseHuef();
1108 // This is super fucking bizarre. But if this is a for loop, the framerate
1109 // tanks to like 30FPS, instead of 60. Call them manually and it works fine.
1110 // Doesn't make ANY sense... there must be some weird side effect going on
1111 // with the Processing internals perhaps?
1112 // for (Plane plane : planes) {
1113 // plane.run(deltaMs);
1115 planes[0].run(deltaMs);
1116 planes[1].run(deltaMs);
1117 planes[2].run(deltaMs);
1119 for (Point p : model.points) {
1120 float d = MAX_FLOAT;
1121 for (Plane plane : planes) {
1122 if (plane.denom != 0) {
1123 d = min(d, abs(plane.av*(p.x-model.cx) + plane.bv*(p.y-model.cy) + plane.cv) / plane.denom);
1126 colors[p.index] = lx.hsb(
1127 (huev + abs(p.x-model.cx)*.3 + p.y*.8) % 360,
1128 max(0, 100 - .8*abs(p.x - model.cx)),
1129 constrain(140 - 10.*d, 0, 100)
1135 class ShiftingPlane extends SCPattern {
1137 final SinLFO a = new SinLFO(-.2, .2, 5300);
1138 final SinLFO b = new SinLFO(1, -1, 13300);
1139 final SinLFO c = new SinLFO(-1.4, 1.4, 5700);
1140 final SinLFO d = new SinLFO(-10, 10, 9500);
1142 ShiftingPlane(GLucose glucose) {
1144 addModulator(a).trigger();
1145 addModulator(b).trigger();
1146 addModulator(c).trigger();
1147 addModulator(d).trigger();
1150 public void run(double deltaMs) {
1151 float hv = lx.getBaseHuef();
1152 float av = a.getValuef();
1153 float bv = b.getValuef();
1154 float cv = c.getValuef();
1155 float dv = d.getValuef();
1156 float denom = sqrt(av*av + bv*bv + cv*cv);
1157 for (Point p : model.points) {
1158 float d = abs(av*(p.x-model.cx) + bv*(p.y-model.cy) + cv*(p.z-model.cz) + dv) / denom;
1159 colors[p.index] = lx.hsb(
1160 (hv + abs(p.x-model.cx)*.6 + abs(p.y-model.cy)*.9 + abs(p.z - model.cz)) % 360,
1161 constrain(110 - d*6, 0, 100),
1162 constrain(130 - 7*d, 0, 100)
1168 class Traktor extends SCPattern {
1170 final int FRAME_WIDTH = 60;
1172 final BasicParameter speed = new BasicParameter("SPD", 0.5);
1174 private float[] bass = new float[FRAME_WIDTH];
1175 private float[] treble = new float[FRAME_WIDTH];
1177 private int index = 0;
1178 private GraphicEQ eq = null;
1180 public Traktor(GLucose glucose) {
1182 for (int i = 0; i < FRAME_WIDTH; ++i) {
1186 addParameter(speed);
1189 public void onActive() {
1191 eq = new GraphicEQ(lx, 16);
1192 eq.slope.setValue(0.6);
1193 eq.level.setValue(0.65);
1194 eq.range.setValue(0.35);
1195 eq.release.setValue(0.4);
1196 addParameter(eq.level);
1197 addParameter(eq.range);
1198 addParameter(eq.attack);
1199 addParameter(eq.release);
1200 addParameter(eq.slope);
1206 public void run(double deltaMs) {
1209 int stepThresh = (int) (40 - 39*speed.getValuef());
1211 if (counter < stepThresh) {
1214 counter = counter % stepThresh;
1216 index = (index + 1) % FRAME_WIDTH;
1218 float rawBass = eq.getAverageLevel(0, 4);
1219 float rawTreble = eq.getAverageLevel(eq.numBands-7, 7);
1221 bass[index] = rawBass * rawBass * rawBass * rawBass;
1222 treble[index] = rawTreble * rawTreble;
1224 for (Point p : model.points) {
1225 int i = (int) constrain((model.xMax - p.x) / model.xMax * FRAME_WIDTH, 0, FRAME_WIDTH-1);
1226 int pos = (index + FRAME_WIDTH - i) % FRAME_WIDTH;
1228 colors[p.index] = lx.hsb(
1229 (360 + lx.getBaseHuef() + .8*abs(p.x-model.cx)) % 360,
1231 constrain(9 * (bass[pos]*model.cy - abs(p.y - model.cy)), 0, 100)
1233 colors[p.index] = blendColor(colors[p.index], lx.hsb(
1234 (400 + lx.getBaseHuef() + .5*abs(p.x-model.cx)) % 360,
1236 constrain(5 * (treble[pos]*.6*model.cy - abs(p.y - model.cy)), 0, 100)
1243 class ColorFuckerEffect extends SCEffect {
1245 final BasicParameter level = new BasicParameter("BRT", 1);
1246 final BasicParameter desat = new BasicParameter("DSAT", 0);
1247 final BasicParameter sharp = new BasicParameter("SHARP", 0);
1248 final BasicParameter soft = new BasicParameter("SOFT", 0);
1249 final BasicParameter mono = new BasicParameter("MONO", 0);
1250 final BasicParameter invert = new BasicParameter("INVERT", 0);
1251 final BasicParameter hueShift = new BasicParameter("HSHFT", 0);
1253 float[] hsb = new float[3];
1255 ColorFuckerEffect(GLucose glucose) {
1257 addParameter(level);
1258 addParameter(desat);
1259 addParameter(sharp);
1262 addParameter(invert);
1263 addParameter(hueShift);
1266 public void doApply(int[] colors) {
1270 float bMod = level.getValuef();
1271 float sMod = 1 - desat.getValuef();
1272 float hMod = hueShift.getValuef();
1273 float fSharp = 1/(1.0001-sharp.getValuef());
1274 float fSoft = soft.getValuef();
1275 boolean mon = mono.getValuef() > 0.5;
1276 boolean ivt = invert.getValuef() > 0.5;
1277 if (bMod < 1 || sMod < 1 || hMod > 0 || fSharp > 0 || ivt || mon || fSoft > 0) {
1278 for (int i = 0; i < colors.length; ++i) {
1279 lx.RGBtoHSB(colors[i], hsb);
1281 hsb[0] = lx.getBaseHuef() / 360.;
1284 hsb[2] = 1 - hsb[2];
1287 hsb[2] = hsb[2] < .5 ? pow(hsb[2],fSharp) : 1-pow(1-hsb[2],fSharp);
1291 hsb[2] = lerp(hsb[2], 0.5 + 2 * (hsb[2]-0.5)*(hsb[2]-0.5), fSoft);
1293 hsb[2] = lerp(hsb[2], 0.5 * sqrt(2*hsb[2]), fSoft);
1297 (360. * hsb[0] + hMod*360.) % 360,
1298 100. * hsb[1] * sMod,
1299 100. * hsb[2] * bMod
1306 class QuantizeEffect extends SCEffect {
1308 color[] quantizedFrame;
1310 final BasicParameter amount = new BasicParameter("AMT", 0);
1312 QuantizeEffect(GLucose glucose) {
1314 quantizedFrame = new color[glucose.lx.total];
1318 public void doApply(int[] colors) {
1319 float fQuant = amount.getValuef();
1321 float tRamp = (lx.tempo.rampf() % (1./pow(2,floor((1-fQuant) * 4))));
1322 float f = lastQuant;
1325 for (int i = 0; i < colors.length; ++i) {
1326 colors[i] = quantizedFrame[i];
1331 for (int i = 0; i < colors.length; ++i) {
1332 quantizedFrame[i] = colors[i];
1337 class BlurEffect extends SCEffect {
1339 final LXParameter amount = new BasicParameter("AMT", 0);
1341 final LinearEnvelope env = new LinearEnvelope(0, 1, 100);
1343 BlurEffect(GLucose glucose) {
1345 addParameter(amount);
1347 frame = new int[lx.total];
1348 for (int i = 0; i < frame.length; ++i) {
1353 public void onEnable() {
1354 env.setRangeFromHereTo(1, 400).start();
1355 for (int i = 0; i < frame.length; ++i) {
1360 public void onDisable() {
1361 env.setRangeFromHereTo(0, 1000).start();
1364 public void doApply(int[] colors) {
1365 float amt = env.getValuef() * amount.getValuef();
1368 amt = 1 - (amt*amt*amt);
1369 for (int i = 0; i < colors.length; ++i) {
1370 // frame[i] = colors[i] = blendColor(colors[i], lerpColor(#000000, frame[i], amt, RGB), SCREEN);
1371 frame[i] = colors[i] = lerpColor(colors[i], blendColor(colors[i], frame[i], SCREEN), amt, RGB);