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 = 60;
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;
59 float eyeR, eyeA, eyeX, eyeY, eyeZ, midX, midY, midZ;
61 final float FEET = 12;
64 startMillis = lastMillis = millis();
66 // Initialize the Processing graphics environment
67 size(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, OPENGL);
68 frameRate(targetFramerate);
70 // hint(ENABLE_OPENGL_4X_SMOOTH); // no discernable improvement?
71 logTime("Created viewport");
73 // Create the GLucose engine to run the cubes
74 glucose = new GLucose(this, new SCMapping());
76 lx.enableKeyboardTempo();
77 logTime("Built GLucose engine");
80 glucose.lx.setPatterns(patterns = patterns(glucose));
81 logTime("Built patterns");
82 glucose.lx.addEffects(effects = effects(glucose));
83 logTime("Built effects");
84 glucose.setTransitions(transitions = transitions(glucose));
85 logTime("Built transitions");
87 // Build output driver
88 int[][] frontChannels = glucose.mapping.buildFrontChannelList();
89 int[][] rearChannels = glucose.mapping.buildRearChannelList();
90 int[][] flippedRGB = glucose.mapping.buildFlippedRGBList();
91 mappingTool = new MappingTool(glucose, frontChannels, rearChannels);
92 pandaFront = new PandaDriver(new NetAddress("192.168.1.28", 9001), glucose.model, frontChannels, flippedRGB);
93 pandaRear = new PandaDriver(new NetAddress("192.168.1.29", 9001), glucose.model, rearChannels, flippedRGB);
94 logTime("Build PandaDriver");
97 ui = controlUI = new ControlUI();
98 mappingUI = new MappingUI(mappingTool);
99 debugUI = new DebugUI(frontChannels, rearChannels);
100 logTime("Built overlay UI");
103 for (MidiInputDevice d : RWMidi.getInputDevices()) {
106 SCMidiDevices.initializeStandardDevices(glucose);
107 logTime("Setup MIDI devices");
110 midX = glucose.model.xMax/2 + 20;
111 midY = glucose.model.yMax/2;
112 midZ = glucose.model.zMax/2;
116 eyeX = midX + eyeR*sin(eyeA);
117 eyeZ = midZ + eyeR*cos(eyeA);
118 addMouseWheelListener(new java.awt.event.MouseWheelListener() {
119 public void mouseWheelMoved(java.awt.event.MouseWheelEvent mwe) {
120 mouseWheel(mwe.getWheelRotation());
124 println("Total setup: " + (millis() - startMillis) + "ms");
125 println("Hit the 'p' key to toggle Panda Board output");
128 void controllerChangeReceived(rwmidi.Controller cc) {
130 println("CC: " + cc.toString());
134 void noteOnReceived(Note note) {
136 println("Note On: " + note.toString());
140 void noteOffReceived(Note note) {
142 println("Note Off: " + note.toString());
146 void logTime(String evt) {
148 println(evt + ": " + (now - lastMillis) + "ms");
153 // Draws the simulation and the 2D UI overlay
155 color[] colors = glucose.getColors();
157 debugUI.maskColors(colors);
166 float trailerWidth = 20*FEET;
167 float trailerDepth = 8*FEET;
168 float trailerHeight = 2*FEET;
171 drawBox(0, -trailerHeight, 0, 0, 0, 0, trailerWidth, trailerHeight, trailerDepth, trailerHeight/2.);
176 vertex(trailerWidth, 0, 0);
177 vertex(trailerWidth, 0, trailerDepth);
178 vertex(0, 0, trailerDepth);
183 for (Cube c : glucose.model.cubes) {
190 for (Point p : glucose.model.points) {
191 stroke(colors[p.index]);
192 vertex(p.fx, p.fy, p.fz);
193 // println(p.fx + ":" + p.fy + ":" + p.fz);
200 javax.media.opengl.GL gl= ((PGraphicsOpenGL)g).beginGL();
201 gl.glClear(javax.media.opengl.GL.GL_DEPTH_BUFFER_BIT);
202 ((PGraphicsOpenGL)g).endGL();
210 // TODO(mcslee): move into GLucose engine
211 if (pandaBoardsEnabled) {
212 pandaFront.send(colors);
213 pandaRear.send(colors);
217 void drawCube(Cube c) {
218 drawBox(c.x, c.y, c.z, c.rx, c.ry, c.rz, Cube.EDGE_WIDTH, Cube.EDGE_HEIGHT, Cube.EDGE_WIDTH, Strip.CHANNEL_WIDTH);
221 void drawBox(float x, float y, float z, float rx, float ry, float rz, float xd, float yd, float zd, float sw) {
225 rotate(ry / 180. * PI, 0, -1, 0);
227 for (int i = 0; i < 4; ++i) {
228 float wid = (i % 2 == 0) ? xd : zd;
234 vertex(wid - sw, yd);
235 vertex(wid - sw, sw);
241 vertex(wid - sw, yd);
242 vertex(wid - sw, yd - sw);
247 translate(wid, 0, 0);
248 rotate(HALF_PI, 0, -1, 0);
263 int restoreToIndex = -1;
267 mappingTool.keyPressed();
272 frameRate(--targetFramerate);
276 frameRate(++targetFramerate);
279 debugMode = !debugMode;
280 println("Debug output: " + (debugMode ? "ON" : "OFF"));
283 mappingMode = !mappingMode;
285 LXPattern pattern = lx.getPattern();
286 for (int i = 0; i < patterns.length; ++i) {
287 if (pattern == patterns[i]) {
293 lx.setPatterns(new LXPattern[] { mappingTool });
296 lx.setPatterns(patterns);
297 lx.goIndex(restoreToIndex);
301 pandaBoardsEnabled = !pandaBoardsEnabled;
302 println("PandaBoard Output: " + (pandaBoardsEnabled ? "ON" : "OFF"));
312 void mousePressed() {
313 if (mouseX > ui.leftPos) {
317 debugUI.mousePressed();
324 void mouseDragged() {
325 if (mouseX > ui.leftPos) {
328 int dx = mouseX - mx;
329 int dy = mouseY - my;
333 eyeX = midX + eyeR*sin(eyeA);
334 eyeZ = midZ + eyeR*cos(eyeA);
339 void mouseReleased() {
340 if (mouseX > ui.leftPos) {
345 void mouseWheel(int delta) {
346 eyeR = constrain(eyeR - delta, -500, -80);
347 eyeX = midX + eyeR*sin(eyeA);
348 eyeZ = midZ + eyeR*cos(eyeA);