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;
36 final int TARGET_FRAMERATE = 45;
38 int startMillis, lastMillis;
41 MappingTool mappingTool;
43 LXTransition[] transitions;
48 PandaDriver pandaFront;
49 PandaDriver pandaRear;
50 boolean mappingMode = false;
52 boolean pandaBoardsEnabled = false;
54 boolean debugMode = false;
57 startMillis = lastMillis = millis();
59 // Initialize the Processing graphics environment
60 size(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, OPENGL);
61 frameRate(TARGET_FRAMERATE);
63 // hint(ENABLE_OPENGL_4X_SMOOTH); // no discernable improvement?
64 logTime("Created viewport");
66 // Create the GLucose engine to run the cubes
67 glucose = new GLucose(this, new SCMapping());
69 lx.enableKeyboardTempo();
70 logTime("Built GLucose engine");
73 glucose.lx.setPatterns(patterns = patterns(glucose));
74 logTime("Built patterns");
75 glucose.lx.addEffects(effects = effects(glucose));
76 logTime("Built effects");
77 glucose.setTransitions(transitions = transitions(glucose));
78 logTime("Built transitions");
80 // Build output driver
81 int[][] frontChannels = glucose.mapping.buildFrontChannelList();
82 int[][] rearChannels = glucose.mapping.buildRearChannelList();
83 int[][] flippedRGB = glucose.mapping.buildFlippedRGBList();
84 mappingTool = new MappingTool(glucose, frontChannels, rearChannels);
85 pandaFront = new PandaDriver(new NetAddress("192.168.1.28", 9001), glucose.model, frontChannels, flippedRGB);
86 pandaRear = new PandaDriver(new NetAddress("192.168.1.29", 9001), glucose.model, rearChannels, flippedRGB);
87 logTime("Build PandaDriver");
90 ui = controlUI = new ControlUI();
91 mappingUI = new MappingUI(mappingTool);
92 logTime("Built overlay UI");
95 for (MidiInputDevice d : RWMidi.getInputDevices()) {
98 SCMidiDevices.initializeStandardDevices(glucose);
99 logTime("Setup MIDI devices");
101 println("Total setup: " + (millis() - startMillis) + "ms");
102 println("Hit the 'p' key to toggle Panda Board output");
105 void controllerChangeReceived(rwmidi.Controller cc) {
107 println("CC: " + cc.toString());
111 void noteOnReceived(Note note) {
113 println("Note On: " + note.toString());
117 void noteOffReceived(Note note) {
119 println("Note Off: " + note.toString());
123 void logTime(String evt) {
125 println(evt + ": " + (now - lastMillis) + "ms");
130 // The glucose engine deals with the core simulation here, we don't need
131 // to do anything specific. This method just needs to exist.
133 // TODO(mcslee): move into GLucose engine
134 if (pandaBoardsEnabled) {
135 color[] colors = glucose.getColors();
136 pandaFront.send(colors);
137 pandaRear.send(colors);
151 int restoreToIndex = -1;
155 mappingTool.keyPressed();
159 debugMode = !debugMode;
160 println("Debug output: " + (debugMode ? "ON" : "OFF"));
162 mappingMode = !mappingMode;
164 LXPattern pattern = lx.getPattern();
165 for (int i = 0; i < patterns.length; ++i) {
166 if (pattern == patterns[i]) {
172 lx.setPatterns(new LXPattern[] { mappingTool });
175 lx.setPatterns(patterns);
176 lx.goIndex(restoreToIndex);
180 pandaBoardsEnabled = !pandaBoardsEnabled;
181 println("PandaBoard Output: " + (pandaBoardsEnabled ? "ON" : "OFF"));