From: Mark Slee Date: Sun, 13 Oct 2013 22:30:06 +0000 (-0700) Subject: MidiMusic pattern in progress and some framework changes X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=4214e9a2908a28344f1e90f98a645ebc2efa0fae;p=SugarCubes.git MidiMusic pattern in progress and some framework changes --- diff --git a/MarkSlee.pde b/MarkSlee.pde index 71e8660..d501786 100644 --- a/MarkSlee.pde +++ b/MarkSlee.pde @@ -1,3 +1,101 @@ +class MidiMusic extends SCPattern { + + private final Map lightMap = new HashMap(); + private final List allLights = new ArrayList(); + + private final Stack newLayers = new Stack(); + + MidiMusic(GLucose glucose) { + super(glucose); + } + + class LightUp extends LXLayer { + + private LinearEnvelope brt = new LinearEnvelope(0, 0, 0); + private Accelerator yPos = new Accelerator(0, 0, 0); + private float xPos; + + LightUp() { + addModulator(brt); + addModulator(yPos); + } + + boolean isAvailable() { + return brt.getValuef() <= 0; + } + + void noteOn(Note note) { + xPos = lerp(0, model.xMax, constrain(0.5 + (note.getPitch() - 64) / 12., 0, 1)); + yPos.setValue(lerp(20, model.yMax, note.getVelocity() / 127.)); + brt.setRangeFromHereTo(lerp(40, 100, note.getVelocity() / 127.), 20).start(); + } + + void noteOff(Note note) { + yPos.setVelocity(0).setAcceleration(-380).start(); + brt.setRangeFromHereTo(0, 1000).start(); + } + + public void run(double deltaMs, color[] colors) { + float bVal = brt.getValuef(); + if (bVal <= 0) { + return; + } + float yVal = yPos.getValuef(); + for (Point p : model.points) { + float b = max(0, bVal - 3*dist(p.x, p.y, xPos, yVal)); + if (b > 0) { + colors[p.index] = blendColor(colors[p.index], color( + (lx.getBaseHuef() + abs(p.x - model.cx) + abs(p.y - model.cy)) % 360, + 100, + b + ), ADD); + } + } + } + } + + public synchronized boolean noteOnReceived(Note note) { + if (note.getChannel() == 0) { + for (LightUp light : allLights) { + if (light.isAvailable()) { + light.noteOn(note); + lightMap.put(note.getPitch(), light); + return true; + } + } + LightUp newLight = new LightUp(); + newLight.noteOn(note); + lightMap.put(note.getPitch(), newLight); + synchronized(newLayers) { + newLayers.push(newLight); + } + } else if (note.getChannel() == 1) { + } + return true; + } + + public synchronized boolean noteOffReceived(Note note) { + if (note.getChannel() == 0) { + LightUp light = lightMap.get(note.getPitch()); + if (light != null) { + light.noteOff(note); + } + } + return true; + } + + public synchronized void run(double deltaMs) { + setColors(#000000); + if (!newLayers.isEmpty()) { + synchronized(newLayers) { + while (!newLayers.isEmpty()) { + addLayer(newLayers.pop()); + } + } + } + } +} + class Pulley extends SCPattern { final int NUM_DIVISIONS = 16; @@ -1085,6 +1183,7 @@ class ColorFuckerEffect extends SCEffect { BasicParameter hueShift = new BasicParameter("HSHFT", 0); BasicParameter sat = new BasicParameter("SAT", 1); BasicParameter bright = new BasicParameter("BRT", 1); + float[] hsb = new float[3]; ColorFuckerEffect(GLucose glucose) { super(glucose); @@ -1102,10 +1201,11 @@ class ColorFuckerEffect extends SCEffect { float hMod = hueShift.getValuef(); if (bMod < 1 || sMod < 1 || hMod > 0) { for (int i = 0; i < colors.length; ++i) { - colors[i] = color( - (hue(colors[i]) + hueShift.getValuef()*360.) % 360, - saturation(colors[i]) * sat.getValuef(), - brightness(colors[i]) * bright.getValuef() + lx.RGBtoHSB(colors[i], hsb); + colors[i] = lx.hsb( + (360. * hsb[0] + hueShift.getValuef()*360.) % 360, + 100. * hsb[1] * sat.getValuef(), + 100. * hsb[2] * bright.getValuef() ); } } diff --git a/SugarCubes.pde b/SugarCubes.pde index a551ca1..d37e12f 100644 --- a/SugarCubes.pde +++ b/SugarCubes.pde @@ -28,6 +28,7 @@ LXPattern[] patterns(GLucose glucose) { // Slee + // new MidiMusic(glucose), new Pulley(glucose), new Swarm(glucose), new ViolinWave(glucose), diff --git a/_Internals.pde b/_Internals.pde index 16a7cf8..45a9363 100644 --- a/_Internals.pde +++ b/_Internals.pde @@ -122,10 +122,6 @@ void setup() { lx.enableKeyboardTempo(); logTime("Built GLucose engine"); - // MIDI devices - midiEngine = new MidiEngine(); - logTime("Setup MIDI devices"); - // Set the patterns Engine engine = lx.engine; engine.setPatterns(patterns = _leftPatterns(glucose)); @@ -135,7 +131,11 @@ void setup() { logTime("Built transitions"); glucose.lx.addEffects(effects(glucose)); logTime("Built effects"); - + + // MIDI devices + midiEngine = new MidiEngine(); + logTime("Setup MIDI devices"); + // Build output driver PandaMapping[] pandaMappings = buildPandaList(); pandaBoards = new PandaDriver[pandaMappings.length]; diff --git a/_MIDI.pde b/_MIDI.pde index 68cc832..e26050f 100644 --- a/_MIDI.pde +++ b/_MIDI.pde @@ -50,7 +50,7 @@ class MidiEngine { } else if (device.getName().contains("SLIDER/KNOB KORG")) { midiControllers.add(new KorgNanoKontrolMidiInput(device).setEnabled(true)); } else { - boolean enabled = device.getName().contains("KEYBOARD KORG"); + boolean enabled = device.getName().contains("KEYBOARD KORG") || device.getName().contains("Bus 1 Apple"); midiControllers.add(new SCMidiInput(device).setEnabled(enabled)); } } diff --git a/_UIFramework.pde b/_UIFramework.pde index 0e0be79..ec590fe 100644 --- a/_UIFramework.pde +++ b/_UIFramework.pde @@ -703,7 +703,7 @@ public class UIScrollList extends UIObject { itemColor = #707070; } float factor = even ? .92 : 1.08; - itemColor = color(hue(itemColor), saturation(itemColor), min(100, factor*brightness(itemColor))); + itemColor = lx.scaleBrightness(itemColor, factor); pg.noStroke(); pg.fill(itemColor); diff --git a/code/HeronLX.jar b/code/HeronLX.jar index a3f6241..430832e 100755 Binary files a/code/HeronLX.jar and b/code/HeronLX.jar differ