From: Mark Slee Date: Thu, 13 Jun 2013 05:38:41 +0000 (-0700) Subject: APC40 is mapped, update UI to reflect that and use GLucose internals X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=cc9fcf4be00a99376a2083ddfbcf589f94ee6785;p=SugarCubes.git APC40 is mapped, update UI to reflect that and use GLucose internals --- diff --git a/_Internals.pde b/_Internals.pde index a103f13..46c3939 100644 --- a/_Internals.pde +++ b/_Internals.pde @@ -44,6 +44,8 @@ LXTransition[] transitions; LXEffect[] effects; OverlayUI ui; +boolean debugMode = false; + void setup() { startMillis = lastMillis = millis(); @@ -57,6 +59,7 @@ void setup() { // Create the GLucose engine to run the cubes glucose = new GLucose(this, new SCMapping()); lx = glucose.lx; + lx.enableKeyboardTempo(); logTime("Built GLucose engine"); // Set the patterns @@ -64,7 +67,7 @@ void setup() { logTime("Built patterns"); glucose.lx.addEffects(effects = effects(glucose)); logTime("Built effects"); - transitions = transitions(glucose); + glucose.setTransitions(transitions = transitions(glucose)); logTime("Built transitions"); // Build overlay UI @@ -72,12 +75,33 @@ void setup() { logTime("Built overlay UI"); // MIDI devices - SCMidiDevices.initializeStandardDevices(glucose, ui.patternKnobs, ui.transitionKnobs, ui.effectKnobs); + for (MidiInputDevice d : RWMidi.getInputDevices()) { + d.createInput(this); + } + SCMidiDevices.initializeStandardDevices(glucose); logTime("Setup MIDI devices"); println("Total setup: " + (millis() - startMillis) + "ms"); } +void controllerChangeReceived(rwmidi.Controller cc) { + if (debugMode) { + println("CC: " + cc.toString()); + } +} + +void noteOnReceived(Note note) { + if (debugMode) { + println("Note On: " + note.toString()); + } +} + +void noteOffReceived(Note note) { + if (debugMode) { + println("Note Off: " + note.toString()); + } +} + void logTime(String evt) { int now = millis(); println(evt + ": " + (now - lastMillis) + "ms"); @@ -102,12 +126,13 @@ boolean uiOn = true; boolean knobsOn = true; void keyPressed() { switch (key) { + case 'd': + debugMode = !debugMode; + println("Debug output: " + (debugMode ? "ON" : "OFF")); + break; case 'u': uiOn = !uiOn; break; - case 'k': - knobsOn = !knobsOn; - break; } } diff --git a/_Overlay.pde b/_Overlay.pde index c08e185..793d313 100644 --- a/_Overlay.pde +++ b/_Overlay.pde @@ -49,17 +49,6 @@ class OverlayUI { private Method patternStateMethod; private Method transitionStateMethod; private Method effectStateMethod; - - private final int NUM_PATTERN_KNOBS = 8; - private final int NUM_TRANSITION_KNOBS = 4; - private final int NUM_EFFECT_KNOBS = 4; - - private int activeTransitionIndex = 0; - private int activeEffectIndex = 0; - - public final VirtualPatternKnob[] patternKnobs; - public final VirtualTransitionKnob[] transitionKnobs; - public final VirtualEffectKnob[] effectKnobs; OverlayUI() { leftPos = width - w; @@ -70,21 +59,6 @@ class OverlayUI { transitionNames = classNameArray(transitions, "Transition"); effectNames = classNameArray(effects, "Effect"); - patternKnobs = new VirtualPatternKnob[NUM_PATTERN_KNOBS]; - for (int i = 0; i < patternKnobs.length; ++i) { - patternKnobs[i] = new VirtualPatternKnob(i); - } - - transitionKnobs = new VirtualTransitionKnob[NUM_TRANSITION_KNOBS]; - for (int i = 0; i < transitionKnobs.length; ++i) { - transitionKnobs[i] = new VirtualTransitionKnob(i); - } - - effectKnobs = new VirtualEffectKnob[NUM_EFFECT_KNOBS]; - for (int i = 0; i < effectKnobs.length; ++i) { - effectKnobs[i] = new VirtualEffectKnob(i); - } - try { patternStateMethod = getClass().getMethod("getState", LXPattern.class); effectStateMethod = getClass().getMethod("getState", LXEffect.class); @@ -114,9 +88,9 @@ class OverlayUI { yPos += controlSpacing; firstPatternKnobY = yPos; int xPos = leftTextPos; - for (int i = 0; i < NUM_PATTERN_KNOBS/2; ++i) { - drawKnob(xPos, yPos, knobSize, patternKnobs[i]); - drawKnob(xPos, yPos + knobSize + knobSpacing + knobLabelHeight, knobSize, patternKnobs[NUM_PATTERN_KNOBS/2 + i]); + for (int i = 0; i < glucose.NUM_PATTERN_KNOBS/2; ++i) { + drawKnob(xPos, yPos, knobSize, glucose.patternKnobs.get(i)); + drawKnob(xPos, yPos + knobSize + knobSpacing + knobLabelHeight, knobSize, glucose.patternKnobs.get(glucose.NUM_PATTERN_KNOBS/2 + i)); xPos += knobSize + knobSpacing; } yPos += 2*(knobSize + knobLabelHeight) + knobSpacing; @@ -127,8 +101,8 @@ class OverlayUI { yPos += controlSpacing; firstTransitionKnobY = yPos; xPos = leftTextPos; - for (int i = 0; i < transitionKnobs.length; ++i) { - drawKnob(xPos, yPos, knobSize, transitionKnobs[i]); + for (VirtualTransitionKnob knob : glucose.transitionKnobs) { + drawKnob(xPos, yPos, knobSize, knob); xPos += knobSize + knobSpacing; } yPos += knobSize + knobLabelHeight; @@ -139,8 +113,8 @@ class OverlayUI { yPos += controlSpacing; firstEffectKnobY = yPos; xPos = leftTextPos; - for (int i = 0; i < effectKnobs.length; ++i) { - drawKnob(xPos, yPos, knobSize, effectKnobs[i]); + for (VirtualEffectKnob knob : glucose.effectKnobs) { + drawKnob(xPos, yPos, knobSize, knob); xPos += knobSize + knobSpacing; } yPos += knobSize + knobLabelHeight; @@ -193,7 +167,7 @@ class OverlayUI { public int getState(LXEffect e) { if (e.isEnabled()) { return STATE_PENDING; - } else if (effects[activeEffectIndex] == e) { + } else if (e == glucose.getSelectedEffect()) { return STATE_ACTIVE; } return STATE_DEFAULT; @@ -202,7 +176,7 @@ class OverlayUI { public int getState(LXTransition t) { if (t == lx.getTransition()) { return STATE_PENDING; - } else if (t == transitions[activeTransitionIndex]) { + } else if (t == glucose.getSelectedTransition()) { return STATE_ACTIVE; } return STATE_DEFAULT; @@ -324,54 +298,6 @@ class OverlayUI { } return s; } - - class VirtualPatternKnob extends LXVirtualParameter { - private final int index; - - VirtualPatternKnob(int index) { - this.index = index; - } - - public LXParameter getRealParameter() { - List parameters = glucose.getPattern().getParameters(); - if (index < parameters.size()) { - return parameters.get(index); - } - return null; - } - } - - class VirtualTransitionKnob extends LXVirtualParameter { - private final int index; - - VirtualTransitionKnob(int index) { - this.index = index; - } - - public LXParameter getRealParameter() { - List parameters = transitions[activeTransitionIndex].getParameters(); - if (index < parameters.size()) { - return parameters.get(index); - } - return null; - } - } - - class VirtualEffectKnob extends LXVirtualParameter { - private final int index; - - VirtualEffectKnob(int index) { - this.index = index; - } - - public LXParameter getRealParameter() { - List parameters = effects[activeEffectIndex].getParameters(); - if (index < parameters.size()) { - return parameters.get(index); - } - return null; - } - } private int patternKnobIndex = -1; private int transitionKnobIndex = -1; @@ -395,28 +321,27 @@ class OverlayUI { } else if (mouseY > firstEffectY) { int effectIndex = (mouseY - firstEffectY) / lineHeight; if (effectIndex < effects.length) { - if (activeEffectIndex == effectIndex) { + if (effects[effectIndex] == glucose.getSelectedEffect()) { effects[effectIndex].enable(); releaseEffect = effectIndex; } - activeEffectIndex = effectIndex; + glucose.setSelectedEffect(effectIndex); } } else if ((mouseY >= firstTransitionKnobY) && (mouseY < firstTransitionKnobY + knobSize + knobLabelHeight)) { transitionKnobIndex = (mouseX - leftTextPos) / (knobSize + knobSpacing); } else if (mouseY > firstTransitionY) { int transitionIndex = (mouseY - firstTransitionY) / lineHeight; if (transitionIndex < transitions.length) { - activeTransitionIndex = transitionIndex; + glucose.setSelectedTransition(transitionIndex); } } else if ((mouseY >= firstPatternKnobY) && (mouseY < firstPatternKnobY + 2*(knobSize+knobLabelHeight) + knobSpacing)) { patternKnobIndex = (mouseX - leftTextPos) / (knobSize + knobSpacing); if (mouseY >= firstPatternKnobY + knobSize + knobLabelHeight + knobSpacing) { - patternKnobIndex += NUM_PATTERN_KNOBS / 2; + patternKnobIndex += glucose.NUM_PATTERN_KNOBS / 2; } } else if (mouseY > firstPatternY) { int patternIndex = (mouseY - firstPatternY) / lineHeight; if (patternIndex < patterns.length) { - patterns[patternIndex].setTransition(transitions[activeTransitionIndex]); lx.goIndex(patternIndex); } } @@ -425,14 +350,14 @@ class OverlayUI { public void mouseDragged() { int dy = lastY - mouseY; lastY = mouseY; - if (patternKnobIndex >= 0 && patternKnobIndex < NUM_PATTERN_KNOBS) { - LXParameter p = patternKnobs[patternKnobIndex]; + if (patternKnobIndex >= 0 && patternKnobIndex < glucose.NUM_PATTERN_KNOBS) { + LXParameter p = glucose.patternKnobs.get(patternKnobIndex); p.setValue(constrain(p.getValuef() + dy*.01, 0, 1)); - } else if (effectKnobIndex >= 0 && effectKnobIndex < NUM_EFFECT_KNOBS) { - LXParameter p = effectKnobs[effectKnobIndex]; + } else if (effectKnobIndex >= 0 && effectKnobIndex < glucose.NUM_EFFECT_KNOBS) { + LXParameter p = glucose.effectKnobs.get(effectKnobIndex); p.setValue(constrain(p.getValuef() + dy*.01, 0, 1)); - } else if (transitionKnobIndex >= 0 && transitionKnobIndex < NUM_TRANSITION_KNOBS) { - LXParameter p = transitionKnobs[transitionKnobIndex]; + } else if (transitionKnobIndex >= 0 && transitionKnobIndex < glucose.NUM_TRANSITION_KNOBS) { + LXParameter p = glucose.transitionKnobs.get(transitionKnobIndex); p.setValue(constrain(p.getValuef() + dy*.01, 0, 1)); } } diff --git a/code/GLucose.jar b/code/GLucose.jar index 321f2a0..6f5463d 100644 Binary files a/code/GLucose.jar and b/code/GLucose.jar differ diff --git a/code/HeronLX.jar b/code/HeronLX.jar index e6ac53e..dbe579c 100644 Binary files a/code/HeronLX.jar and b/code/HeronLX.jar differ