2 * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND
5 * ///\\\ ///\\\ ///\\\ ///\\\
6 * \\\/// \\\/// \\\/// \\\///
9 * EXPERTS ONLY!! EXPERTS ONLY!!
11 * If you are an artist, you may ignore this file! It just sets
12 * up the framework to run the patterns. Should not need modification
13 * for general animation work.
17 import glucose.control.*;
18 import glucose.effect.*;
19 import glucose.model.*;
20 import glucose.pattern.*;
21 import glucose.transform.*;
22 import glucose.transition.*;
23 import heronarts.lx.*;
24 import heronarts.lx.control.*;
25 import heronarts.lx.effect.*;
26 import heronarts.lx.modulator.*;
27 import heronarts.lx.pattern.*;
28 import heronarts.lx.transition.*;
30 import ddf.minim.analysis.*;
31 import processing.opengl.*;
34 final int VIEWPORT_WIDTH = 900;
35 final int VIEWPORT_HEIGHT = 700;
37 int targetFramerate = 30;
39 int startMillis, lastMillis;
42 MappingTool mappingTool;
44 LXTransition[] transitions;
49 PandaDriver pandaFront;
50 PandaDriver pandaRear;
51 boolean mappingMode = false;
53 boolean pandaBoardsEnabled = false;
55 boolean debugMode = false;
58 startMillis = lastMillis = millis();
60 // Initialize the Processing graphics environment
61 size(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, OPENGL);
62 frameRate(targetFramerate);
64 // hint(ENABLE_OPENGL_4X_SMOOTH); // no discernable improvement?
65 logTime("Created viewport");
67 // Create the GLucose engine to run the cubes
68 glucose = new GLucose(this, new SCMapping());
70 lx.enableKeyboardTempo();
71 logTime("Built GLucose engine");
74 glucose.lx.setPatterns(patterns = patterns(glucose));
75 logTime("Built patterns");
76 glucose.lx.addEffects(effects = effects(glucose));
77 logTime("Built effects");
78 glucose.setTransitions(transitions = transitions(glucose));
79 logTime("Built transitions");
81 // Build output driver
82 int[][] frontChannels = glucose.mapping.buildFrontChannelList();
83 int[][] rearChannels = glucose.mapping.buildRearChannelList();
84 int[][] flippedRGB = glucose.mapping.buildFlippedRGBList();
85 mappingTool = new MappingTool(glucose, frontChannels, rearChannels);
86 pandaFront = new PandaDriver(new NetAddress("192.168.1.28", 9001), glucose.model, frontChannels, flippedRGB);
87 pandaRear = new PandaDriver(new NetAddress("192.168.1.29", 9001), glucose.model, rearChannels, flippedRGB);
88 logTime("Build PandaDriver");
91 ui = controlUI = new ControlUI();
92 mappingUI = new MappingUI(mappingTool);
93 logTime("Built overlay UI");
96 for (MidiInputDevice d : RWMidi.getInputDevices()) {
99 SCMidiDevices.initializeStandardDevices(glucose);
100 logTime("Setup MIDI devices");
102 println("Total setup: " + (millis() - startMillis) + "ms");
103 println("Hit the 'p' key to toggle Panda Board output");
106 void controllerChangeReceived(rwmidi.Controller cc) {
108 println("CC: " + cc.toString());
112 void noteOnReceived(Note note) {
114 println("Note On: " + note.toString());
118 void noteOffReceived(Note note) {
120 println("Note Off: " + note.toString());
124 void logTime(String evt) {
126 println(evt + ": " + (now - lastMillis) + "ms");
131 // The glucose engine deals with the core simulation here, we don't need
132 // to do anything specific. This method just needs to exist.
134 // TODO(mcslee): move into GLucose engine
135 if (pandaBoardsEnabled) {
136 color[] colors = glucose.getColors();
137 pandaFront.send(colors);
138 pandaRear.send(colors);
152 int restoreToIndex = -1;
156 mappingTool.keyPressed();
161 frameRate(--targetFramerate);
165 frameRate(++targetFramerate);
168 debugMode = !debugMode;
169 println("Debug output: " + (debugMode ? "ON" : "OFF"));
171 mappingMode = !mappingMode;
173 LXPattern pattern = lx.getPattern();
174 for (int i = 0; i < patterns.length; ++i) {
175 if (pattern == patterns[i]) {
181 lx.setPatterns(new LXPattern[] { mappingTool });
184 lx.setPatterns(patterns);
185 lx.goIndex(restoreToIndex);
189 pandaBoardsEnabled = !pandaBoardsEnabled;
190 println("PandaBoard Output: " + (pandaBoardsEnabled ? "ON" : "OFF"));