LXTransition[] transitions;
LXEffect[] effects;
OverlayUI ui;
+ ControlUI controlUI;
+ MappingUI mappingUI;
+ PandaDriver pandaFront;
+ PandaDriver pandaRear;
+ boolean mappingMode = false;
+
+ boolean pandaBoardsEnabled = false;
+boolean debugMode = false;
+
void setup() {
startMillis = lastMillis = millis();
logTime("Built patterns");
glucose.lx.addEffects(effects = effects(glucose));
logTime("Built effects");
- transitions = transitions(glucose);
+ glucose.setTransitions(transitions = transitions(glucose));
logTime("Built transitions");
+
+ // Build output driver
+ int[][] frontChannels = glucose.mapping.buildFrontChannelList();
+ int[][] rearChannels = glucose.mapping.buildRearChannelList();
+ int[][] flippedRGB = glucose.mapping.buildFlippedRGBList();
+ mappingTool = new MappingTool(glucose, frontChannels, rearChannels);
+ pandaFront = new PandaDriver(new NetAddress("192.168.1.28", 9001), glucose.model, frontChannels, flippedRGB);
+ pandaRear = new PandaDriver(new NetAddress("192.168.1.29", 9001), glucose.model, rearChannels, flippedRGB);
+ logTime("Build PandaDriver");
// Build overlay UI
- ui = new OverlayUI();
+ ui = controlUI = new ControlUI();
+ mappingUI = new MappingUI(mappingTool);
logTime("Built overlay UI");
// MIDI devices
logTime("Setup MIDI devices");
println("Total setup: " + (millis() - startMillis) + "ms");
+ println("Hit the 'p' key to toggle Panda Board output");
}
+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");
}
boolean uiOn = true;
- boolean knobsOn = true;
+ int restoreToIndex = -1;
+
void keyPressed() {
+ if (mappingMode) {
+ mappingTool.keyPressed();
+ }
switch (key) {
+ case 'd':
+ debugMode = !debugMode;
+ println("Debug output: " + (debugMode ? "ON" : "OFF"));
+ case 'm':
+ mappingMode = !mappingMode;
+ if (mappingMode) {
+ LXPattern pattern = lx.getPattern();
+ for (int i = 0; i < patterns.length; ++i) {
+ if (pattern == patterns[i]) {
+ restoreToIndex = i;
+ break;
+ }
+ }
+ ui = mappingUI;
+ lx.setPatterns(new LXPattern[] { mappingTool });
+ } else {
+ ui = controlUI;
+ lx.setPatterns(patterns);
+ lx.goIndex(restoreToIndex);
+ }
+ break;
+ case 'p':
+ pandaBoardsEnabled = !pandaBoardsEnabled;
+ println("PandaBoard Output: " + (pandaBoardsEnabled ? "ON" : "OFF"));
break;
case 'u':
uiOn = !uiOn;
private Method patternStateMethod;
private Method transitionStateMethod;
private Method effectStateMethod;
-
- OverlayUI() {
- leftPos = width - w;
- leftTextPos = leftPos + 4;
- logo = loadImage("logo-sm.png");
-
-
- 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;
-
++
+ ControlUI() {
patternNames = classNameArray(patterns, "Pattern");
transitionNames = classNameArray(transitions, "Transition");
effectNames = classNameArray(effects, "Effect");
textAlign(CENTER);
textFont(knobFont);
text(knobLabel, xPos + knobSize/2, yPos + knobSize + knobLabelHeight - 2);
-
- }
-
- private String[] classNameArray(Object[] objects, String suffix) {
- if (objects == null) {
- return null;
- }
- String[] names = new String[objects.length];
- for (int i = 0; i < objects.length; ++i) {
- names[i] = className(objects[i], suffix);
- }
- return names;
- }
-
- private String className(Object p, String suffix) {
- String s = p.getClass().getName();
- int li;
- if ((li = s.lastIndexOf(".")) > 0) {
- s = s.substring(li + 1);
- }
- if (s.indexOf("SugarCubes$") == 0) {
- s = s.substring("SugarCubes$".length());
- }
- if ((suffix != null) && ((li = s.indexOf(suffix)) != -1)) {
- s = s.substring(0, li);
- }
- return s;
}
-
- class VirtualPatternKnob extends LXVirtualParameter {
- private final int index;
-
- VirtualPatternKnob(int index) {
- this.index = index;
- }
-
- public LXParameter getRealParameter() {
- List<LXParameter> 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<LXParameter> 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<LXParameter> parameters = effects[activeEffectIndex].getParameters();
- if (index < parameters.size()) {
- return parameters.get(index);
- }
- return null;
- }
- }
private int patternKnobIndex = -1;
private int transitionKnobIndex = -1;
} else if ((mouseY >= firstEffectKnobY) && (mouseY < firstEffectKnobY + knobSize + knobLabelHeight)) {
effectKnobIndex = (mouseX - leftTextPos) / (knobSize + knobSpacing);
} else if (mouseY > firstEffectY) {
- int effectIndex = (mouseY - firstEffectY) / lineHeight;
+ int effectIndex = objectClickIndex(firstEffectY);
if (effectIndex < effects.length) {
- if (activeEffectIndex == effectIndex) {
+ if (effects[effectIndex] == glucose.getSelectedEffect()) {
effects[effectIndex].enable();
releaseEffect = effectIndex;
}
} else if ((mouseY >= firstTransitionKnobY) && (mouseY < firstTransitionKnobY + knobSize + knobLabelHeight)) {
transitionKnobIndex = (mouseX - leftTextPos) / (knobSize + knobSpacing);
} else if (mouseY > firstTransitionY) {
- int transitionIndex = (mouseY - firstTransitionY) / lineHeight;
+ int transitionIndex = objectClickIndex(firstTransitionY);
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;
+ int patternIndex = objectClickIndex(firstPatternY);
if (patternIndex < patterns.length) {
- patterns[patternIndex].setTransition(transitions[activeTransitionIndex]);
lx.goIndex(patternIndex);
}
}