From: Mark Slee Date: Sat, 15 Jun 2013 02:09:05 +0000 (-0700) Subject: Merge branch 'panda-refactor' of https://github.com/sugarcubes/SugarCubes X-Git-Url: https://git.piment-noir.org/?p=SugarCubes.git;a=commitdiff_plain;h=b11ff42b4235ebf514245ac177cb4809067c988b Merge branch 'panda-refactor' of https://github.com/sugarcubes/SugarCubes Conflicts: _Internals.pde _Overlay.pde code/GLucose.jar --- b11ff42b4235ebf514245ac177cb4809067c988b diff --cc SugarCubes.pde index 5504001,5504001..3f6cc8f --- a/SugarCubes.pde +++ b/SugarCubes.pde @@@ -1,7 -1,7 +1,7 @@@ /** * +-+-+-+-+-+ +-+-+-+-+-+ * / /| |\ \ -- * / / + + \ \ ++ * / / + <+ \ \ * +-+-+-+-+-+ | +-+-+-+-+ | +-+-+-+-+-+ * | | + / \ + | | * + THE + / / \ \ + CUBES + diff --cc _Internals.pde index 46c3939,4ab6f76..0249603 --- a/_Internals.pde +++ b/_Internals.pde @@@ -43,9 -43,14 +43,16 @@@ LXPattern[] patterns 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(); @@@ -67,11 -71,21 +74,21 @@@ 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 @@@ -82,26 -93,9 +99,27 @@@ 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"); @@@ -123,12 -124,34 +148,37 @@@ void drawUI() } 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; diff --cc _Overlay.pde index 793d313,06d106a..d33e4a1 --- a/_Overlay.pde +++ b/_Overlay.pde @@@ -49,12 -174,19 +174,8 @@@ class ControlUI extends OverlayUI 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"); @@@ -270,34 -343,55 +317,7 @@@ 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 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; @@@ -319,9 -413,9 +339,9 @@@ } 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; } @@@ -330,18 -424,19 +350,18 @@@ } 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); } } diff --cc code/GLucose.jar index 6f5463d,fdf9ec3..fe2ba46 Binary files differ diff --cc code/HeronLX.jar index dbe579c,e6ac53e..608c30c Binary files differ