+class Cathedrals extends SCPattern {
+
+ private final BasicParameter xpos = new BasicParameter("XPOS", 0.5);
+ private final BasicParameter wid = new BasicParameter("WID", 0.5);
+ private final BasicParameter arms = new BasicParameter("ARMS", 0.5);
+ private final BasicParameter sat = new BasicParameter("SAT", 0.5);
+ private GraphicEQ eq;
+
+ Cathedrals(GLucose glucose) {
+ super(glucose);
+ addParameter(xpos);
+ addParameter(wid);
+ addParameter(arms);
+ addParameter(sat);
+ }
+
+ protected void onActive() {
+ if (eq == null) {
+ eq = new GraphicEQ(lx, 16);
+ eq.slope.setValue(0.7);
+ eq.range.setValue(0.4);
+ eq.attack.setValue(0.4);
+ eq.release.setValue(0.4);
+ addParameter(eq.level);
+ addParameter(eq.range);
+ addParameter(eq.attack);
+ addParameter(eq.release);
+ addParameter(eq.slope);
+ }
+ }
+
+
+ public void run(double deltaMs) {
+ eq.run(deltaMs);
+ float bassLevel = eq.getAverageLevel(0, 4);
+ float trebleLevel = eq.getAverageLevel(8, 6);
+
+ float falloff = 100 / (2 + 14*wid.getValuef());
+ float cx = model.xMin + (model.xMax-model.xMin) * xpos.getValuef();
+ float barm = 12 + 60*arms.getValuef()*max(0, 2*(bassLevel-0.1));
+ float tarm = 12 + 60*arms.getValuef()*max(0, 2*(trebleLevel-0.1));
+
+ float arm = 0;
+ float middle = 0;
+
+ float sf = 100. / (70 - 69.9*sat.getValuef());
+
+ for (Point p : model.points) {
+ float d = MAX_FLOAT;
+ if (p.y > model.cy) {
+ arm = tarm;
+ middle = model.yMax * 3/5.;
+ } else {
+ arm = barm;
+ middle = model.yMax * 1/5.;
+ }
+ if (abs(p.x - cx) < arm) {
+ d = min(abs(p.x - cx), abs(p.y - middle));
+ }
+ colors[p.index] = color(
+ (lx.getBaseHuef() + .2*abs(p.y - model.cy)) % 360,
+ min(100, sf*dist(abs(p.x - cx), p.y, arm, middle)),
+ max(0, 120 - d*falloff));
+ }
+ }
+}
+
class MidiMusic extends SCPattern {
- private final Map<Integer, LightUp> lightMap = new HashMap<Integer, LightUp>();
- private final List<LightUp> allLights = new ArrayList<LightUp>();
+ private final Stack<LXLayer> newLayers = new Stack<LXLayer>();
- private final Stack<LightUp> newLayers = new Stack<LightUp>();
+ private final Map<Integer, LightUp> lightMap = new HashMap<Integer, LightUp>();
+ private final List<LightUp> lights = new ArrayList<LightUp>();
private final BasicParameter lightSize = new BasicParameter("SIZE", 0.5);
+
+ private final List<Sweep> sweeps = new ArrayList<Sweep>();
+
private final LinearEnvelope sparkle = new LinearEnvelope(0, 1, 500);
+ private boolean sparkleDirection = true;
private float sparkleBright = 100;
+ private final BasicParameter wave = new BasicParameter("WAVE", 0);
+
MidiMusic(GLucose glucose) {
super(glucose);
addParameter(lightSize);
+ addParameter(wave);
addModulator(sparkle).setValue(1);
}
+ void onReset() {
+ for (LightUp light : lights) {
+ light.noteOff(null);
+ }
+ }
+
+ class Sweep extends LXLayer {
+
+ final LinearEnvelope position = new LinearEnvelope(0, 1, 1000);
+ float bright = 100;
+ float falloff = 10;
+
+ Sweep() {
+ addModulator(position);
+ }
+
+ public void run(double deltaMs, color[] colors) {
+ if (!position.isRunning()) {
+ return;
+ }
+ float posf = position.getValuef();
+ for (Point p : model.points) {
+ colors[p.index] = blendColor(colors[p.index], color(
+ (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360,
+ 100,
+ max(0, bright - posf*100 - falloff*abs(p.y - posf*model.yMax))
+ ), ADD);
+ }
+ }
+ }
+
class LightUp extends LXLayer {
- private LinearEnvelope brt = new LinearEnvelope(0, 0, 0);
- private Accelerator yPos = new Accelerator(0, 0, 0);
+ private final LinearEnvelope brt = new LinearEnvelope(0, 0, 0);
+ private final Accelerator yPos = new Accelerator(0, 0, 0);
private float xPos;
LightUp() {
}
void noteOn(Note note) {
- xPos = lerp(0, model.xMax, constrain(0.5 + (note.getPitch() - 60) / 26., 0, 1));
- yPos.setValue(lerp(20, model.yMax, note.getVelocity() / 127.));
+ xPos = lerp(0, model.xMax, constrain(0.5 + (note.getPitch() - 60) / 28., 0, 1));
+ yPos.setValue(lerp(20, model.yMax*.72, note.getVelocity() / 127.)).stop();
brt.setRangeFromHereTo(lerp(40, 100, note.getVelocity() / 127.), 20).start();
}
}
}
- public synchronized boolean noteOn(Note note) {
- if (note.getChannel() == 0) {
- for (LightUp light : allLights) {
- if (light.isAvailable()) {
- light.noteOn(note);
- lightMap.put(note.getPitch(), light);
- return true;
- }
+ private LightUp getLight() {
+ for (LightUp light : lights) {
+ if (light.isAvailable()) {
+ return light;
}
- LightUp newLight = new LightUp();
- newLight.noteOn(note);
- lightMap.put(note.getPitch(), newLight);
- synchronized(newLayers) {
- newLayers.push(newLight);
+ }
+ LightUp newLight = new LightUp();
+ lights.add(newLight);
+ synchronized(newLayers) {
+ newLayers.push(newLight);
+ }
+ return newLight;
+ }
+
+ private Sweep getSweep() {
+ for (Sweep s : sweeps) {
+ if (!s.position.isRunning()) {
+ return s;
}
+ }
+ Sweep newSweep = new Sweep();
+ sweeps.add(newSweep);
+ synchronized(newLayers) {
+ newLayers.push(newSweep);
+ }
+ return newSweep;
+ }
+
+ public synchronized boolean noteOn(Note note) {
+ if (note.getChannel() == 0) {
+ LightUp light = getLight();
+ lightMap.put(note.getPitch(), light);
+ light.noteOn(note);
} else if (note.getChannel() == 1) {
} else if (note.getChannel() == 9) {
- switch (note.getPitch()) {
- case 36:
- if (note.getVelocity() > 0) {
+ if (note.getVelocity() > 0) {
+ switch (note.getPitch()) {
+ case 36:
+ Sweep s = getSweep();
+ s.bright = 50 + note.getVelocity() / 127. * 50;
+ s.falloff = 20 - note.getVelocity() / 127. * 17;
+ s.position.trigger();
+ break;
+ case 37:
sparkleBright = note.getVelocity() / 127. * 100;
- if (sparkleBright > 0) {
- sparkle.trigger();
- }
- }
- break;
+ sparkleDirection = true;
+ sparkle.trigger();
+ break;
+ case 38:
+ sparkleBright = note.getVelocity() / 127. * 100;
+ sparkleDirection = false;
+ sparkle.trigger();
+ break;
+ case 39:
+ effects.boom.trigger();
+ break;
+ case 40:
+ effects.flash.trigger();
+ break;
+ }
}
}
return true;
return true;
}
+ final float[] wval = new float[16];
+ float wavoff = 0;
+
public synchronized void run(double deltaMs) {
- float sparklePos = sparkle.getValuef() * Cube.POINTS_PER_STRIP * .75;
+ wavoff += deltaMs * .001;
+ for (int i = 0; i < wval.length; ++i) {
+ wval[i] = model.cy + 0.2 * model.yMax/2. * sin(wavoff + i / 1.9);
+ }
+ float sparklePos = (sparkleDirection ? sparkle.getValuef() : (1 - sparkle.getValuef())) * (Cube.POINTS_PER_STRIP)/2.;
float maxBright = sparkleBright * (1 - sparkle.getValuef());
for (Strip s : model.strips) {
int i = 0;
for (Point p : s.points) {
+ int wavi = (int) constrain(p.x / model.xMax * wval.length, 0, wval.length-1);
+ float wavb = max(0, wave.getValuef()*100. - 8.*abs(p.y - wval[wavi]));
colors[p.index] = color(
(lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360,
100,
- maxBright - 40.*abs(sparklePos - abs(i - (Cube.POINTS_PER_STRIP-1)/2.))
+ constrain(wavb + max(0, maxBright - 40.*abs(sparklePos - abs(i - (Cube.POINTS_PER_STRIP-1)/2.))), 0, 100)
);
++i;
}
}
+
if (!newLayers.isEmpty()) {
synchronized(newLayers) {
while (!newLayers.isEmpty()) {
}
float zeroDBReference = pow(10, (50 - 190*level.getValuef())/20.);
- float dB = 20*GraphicEQ.log10(lx.audioInput().mix.level() / zeroDBReference);
+ float dB = 20*GraphicEQ.log10(lx.audioInput().mix.level() / zeroDBReference);
if (dB > dbValue.getValuef()) {
rising = true;
dbValue.setRangeFromHereTo(dB, 10).trigger();
colors[p.index] = lx.hsb(
(360 + lx.getBaseHuef() + .8*abs(p.x-model.cx)) % 360,
100,
- constrain(9 * (bass[pos]*model.cy - abs(p.y - model.cy)), 0, 100)
+ constrain(9 * (bass[pos]*model.cy - abs(p.y - model.cy + 5)), 0, 100)
);
colors[p.index] = blendColor(colors[p.index], lx.hsb(
(400 + lx.getBaseHuef() + .5*abs(p.x-model.cx)) % 360,
final BasicParameter level = new BasicParameter("BRT", 1);
final BasicParameter desat = new BasicParameter("DSAT", 0);
+ final BasicParameter hueShift = new BasicParameter("HSHFT", 0);
final BasicParameter sharp = new BasicParameter("SHARP", 0);
final BasicParameter soft = new BasicParameter("SOFT", 0);
final BasicParameter mono = new BasicParameter("MONO", 0);
final BasicParameter invert = new BasicParameter("INVERT", 0);
- final BasicParameter hueShift = new BasicParameter("HSHFT", 0);
+
float[] hsb = new float[3];
addParameter(level);
addParameter(desat);
addParameter(sharp);
+ addParameter(hueShift);
addParameter(soft);
addParameter(mono);
addParameter(invert);
- addParameter(hueShift);
}
public void doApply(int[] colors) {