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 = 45;
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 final float eyeR = -270;
59 float eyeA, eyeX, eyeY, eyeZ, midX, midY, midZ;
62 startMillis = lastMillis = millis();
64 // Initialize the Processing graphics environment
65 size(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, OPENGL);
66 frameRate(targetFramerate);
68 // hint(ENABLE_OPENGL_4X_SMOOTH); // no discernable improvement?
69 logTime("Created viewport");
71 // Create the GLucose engine to run the cubes
72 glucose = new GLucose(this, new SCMapping());
74 lx.enableKeyboardTempo();
75 logTime("Built GLucose engine");
78 glucose.lx.setPatterns(patterns = patterns(glucose));
79 logTime("Built patterns");
80 glucose.lx.addEffects(effects = effects(glucose));
81 logTime("Built effects");
82 glucose.setTransitions(transitions = transitions(glucose));
83 logTime("Built transitions");
85 // Build output driver
86 int[][] frontChannels = glucose.mapping.buildFrontChannelList();
87 int[][] rearChannels = glucose.mapping.buildRearChannelList();
88 int[][] flippedRGB = glucose.mapping.buildFlippedRGBList();
89 mappingTool = new MappingTool(glucose, frontChannels, rearChannels);
90 pandaFront = new PandaDriver(new NetAddress("192.168.1.28", 9001), glucose.model, frontChannels, flippedRGB);
91 pandaRear = new PandaDriver(new NetAddress("192.168.1.29", 9001), glucose.model, rearChannels, flippedRGB);
92 logTime("Build PandaDriver");
95 ui = controlUI = new ControlUI();
96 mappingUI = new MappingUI(mappingTool);
97 logTime("Built overlay UI");
100 for (MidiInputDevice d : RWMidi.getInputDevices()) {
103 SCMidiDevices.initializeStandardDevices(glucose);
104 logTime("Setup MIDI devices");
107 midX = glucose.model.xMax/2 + 20;
108 midY = glucose.model.yMax/2;
109 midZ = glucose.model.zMax/2;
112 eyeX = midX + eyeR*sin(eyeA);
113 eyeZ = midZ + eyeR*cos(eyeA);
115 println("Total setup: " + (millis() - startMillis) + "ms");
116 println("Hit the 'p' key to toggle Panda Board output");
119 void controllerChangeReceived(rwmidi.Controller cc) {
121 println("CC: " + cc.toString());
125 void noteOnReceived(Note note) {
127 println("Note On: " + note.toString());
131 void noteOffReceived(Note note) {
133 println("Note Off: " + note.toString());
137 void logTime(String evt) {
139 println(evt + ": " + (now - lastMillis) + "ms");
144 // Draws the simulation and the 2D UI overlay
146 color[] colors = glucose.getColors();
156 vertex(0, yFloor, 0);
157 vertex(glucose.model.xMax, yFloor, 0);
158 vertex(glucose.model.xMax, yFloor, glucose.model.zMax);
159 vertex(0, yFloor, glucose.model.zMax);
165 for (Point p : glucose.model.points) {
166 stroke(colors[p.index]);
167 vertex(p.fx, p.fy, p.fz);
173 javax.media.opengl.GL gl= ((PGraphicsOpenGL)g).beginGL();
174 gl.glClear(javax.media.opengl.GL.GL_DEPTH_BUFFER_BIT);
175 ((PGraphicsOpenGL)g).endGL();
179 // TODO(mcslee): move into GLucose engine
180 if (pandaBoardsEnabled) {
181 pandaFront.send(colors);
182 pandaRear.send(colors);
196 int restoreToIndex = -1;
200 mappingTool.keyPressed();
205 frameRate(--targetFramerate);
209 frameRate(++targetFramerate);
212 debugMode = !debugMode;
213 println("Debug output: " + (debugMode ? "ON" : "OFF"));
215 mappingMode = !mappingMode;
217 LXPattern pattern = lx.getPattern();
218 for (int i = 0; i < patterns.length; ++i) {
219 if (pattern == patterns[i]) {
225 lx.setPatterns(new LXPattern[] { mappingTool });
228 lx.setPatterns(patterns);
229 lx.goIndex(restoreToIndex);
233 pandaBoardsEnabled = !pandaBoardsEnabled;
234 println("PandaBoard Output: " + (pandaBoardsEnabled ? "ON" : "OFF"));
244 void mousePressed() {
245 if (mouseX > ui.leftPos) {
253 void mouseDragged() {
254 if (mouseX > ui.leftPos) {
257 int dx = mouseX - mx;
258 int dy = mouseY - my;
262 eyeX = midX + eyeR*sin(eyeA);
263 eyeZ = midZ + eyeR*cos(eyeA);
268 void mouseReleased() {
269 if (mouseX > ui.leftPos) {