X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=_Internals.pde;h=5603698adf2d4f907aa832a1ec09ef9e27db2661;hb=0e3c55427eb3c56557e42dd3a21aa159e47243de;hp=46c39390dcf93ac1dfe29deaee243eba0c36efa5;hpb=cc9fcf4be00a99376a2083ddfbcf589f94ee6785;p=SugarCubes.git diff --git a/_Internals.pde b/_Internals.pde index 46c3939..5603698 100644 --- a/_Internals.pde +++ b/_Internals.pde @@ -29,20 +29,28 @@ import heronarts.lx.transition.*; import ddf.minim.*; import ddf.minim.analysis.*; import processing.opengl.*; -import java.lang.reflect.*; import rwmidi.*; final int VIEWPORT_WIDTH = 900; final int VIEWPORT_HEIGHT = 700; -final int TARGET_FRAMERATE = 45; + +int targetFramerate = 30; int startMillis, lastMillis; GLucose glucose; HeronLX lx; +MappingTool mappingTool; 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; @@ -51,7 +59,7 @@ void setup() { // Initialize the Processing graphics environment size(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, OPENGL); - frameRate(TARGET_FRAMERATE); + frameRate(targetFramerate); noSmooth(); // hint(ENABLE_OPENGL_4X_SMOOTH); // no discernable improvement? logTime("Created viewport"); @@ -69,9 +77,19 @@ void setup() { logTime("Built effects"); 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,6 +100,7 @@ void setup() { 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) { @@ -111,6 +130,13 @@ void logTime(String evt) { void draw() { // The glucose engine deals with the core simulation here, we don't need // to do anything specific. This method just needs to exist. + + // TODO(mcslee): move into GLucose engine + if (pandaBoardsEnabled) { + color[] colors = glucose.getColors(); + pandaFront.send(colors); + pandaRear.send(colors); + } } void drawUI() { @@ -123,12 +149,45 @@ void drawUI() { } boolean uiOn = true; -boolean knobsOn = true; +int restoreToIndex = -1; + void keyPressed() { + if (mappingMode) { + mappingTool.keyPressed(); + } switch (key) { + case '-': + case '_': + frameRate(--targetFramerate); + break; + case '=': + case '+': + frameRate(++targetFramerate); + break; 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;