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 final float TRAILER_WIDTH = 240;
38 final float TRAILER_DEPTH = 97;
39 final float TRAILER_HEIGHT = 33;
41 final float BASS_WIDTH = 124;
42 final float BASS_HEIGHT = 31.5;
43 final float BASS_DEPTH = 66;
44 final float BASS_X = (TRAILER_WIDTH - BASS_WIDTH) / 2.;
45 final float BASS_Z = (TRAILER_DEPTH - BASS_DEPTH) / 2.;
47 int targetFramerate = 60;
49 int startMillis, lastMillis;
52 MappingTool mappingTool;
54 LXTransition[] transitions;
59 PandaDriver pandaFront;
60 PandaDriver pandaRear;
61 boolean mappingMode = false;
63 boolean pandaBoardsEnabled = false;
65 boolean debugMode = false;
69 float eyeR, eyeA, eyeX, eyeY, eyeZ, midX, midY, midZ;
71 final float FEET = 12;
74 startMillis = lastMillis = millis();
76 // Initialize the Processing graphics environment
77 size(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, OPENGL);
78 frameRate(targetFramerate);
80 // hint(ENABLE_OPENGL_4X_SMOOTH); // no discernable improvement?
81 logTime("Created viewport");
83 // Create the GLucose engine to run the cubes
84 glucose = new GLucose(this, new SCMapping());
86 lx.enableKeyboardTempo();
87 logTime("Built GLucose engine");
90 glucose.lx.setPatterns(patterns = patterns(glucose));
91 logTime("Built patterns");
92 glucose.lx.addEffects(effects = effects(glucose));
93 logTime("Built effects");
94 glucose.setTransitions(transitions = transitions(glucose));
95 logTime("Built transitions");
97 // Build output driver
98 int[][] frontChannels = glucose.mapping.buildFrontChannelList();
99 int[][] rearChannels = glucose.mapping.buildRearChannelList();
100 int[][] flippedRGB = glucose.mapping.buildFlippedRGBList();
101 mappingTool = new MappingTool(glucose, frontChannels, rearChannels);
102 pandaFront = new PandaDriver(new NetAddress("192.168.1.28", 9001), glucose.model, frontChannels, flippedRGB);
103 pandaRear = new PandaDriver(new NetAddress("192.168.1.29", 9001), glucose.model, rearChannels, flippedRGB);
104 logTime("Build PandaDriver");
107 ui = controlUI = new ControlUI();
108 mappingUI = new MappingUI(mappingTool);
109 debugUI = new DebugUI(frontChannels, rearChannels);
110 logTime("Built overlay UI");
113 for (MidiInputDevice d : RWMidi.getInputDevices()) {
116 SCMidiDevices.initializeStandardDevices(glucose);
117 logTime("Setup MIDI devices");
120 midX = glucose.model.xMax/2 + 20;
121 midY = glucose.model.yMax/2;
122 midZ = glucose.model.zMax/2;
126 eyeX = midX + eyeR*sin(eyeA);
127 eyeZ = midZ + eyeR*cos(eyeA);
128 addMouseWheelListener(new java.awt.event.MouseWheelListener() {
129 public void mouseWheelMoved(java.awt.event.MouseWheelEvent mwe) {
130 mouseWheel(mwe.getWheelRotation());
134 println("Total setup: " + (millis() - startMillis) + "ms");
135 println("Hit the 'p' key to toggle Panda Board output");
138 void controllerChangeReceived(rwmidi.Controller cc) {
140 println("CC: " + cc.toString());
144 void noteOnReceived(Note note) {
146 println("Note On: " + note.toString());
150 void noteOffReceived(Note note) {
152 println("Note Off: " + note.toString());
156 void logTime(String evt) {
158 println(evt + ": " + (now - lastMillis) + "ms");
163 // Draws the simulation and the 2D UI overlay
165 color[] colors = glucose.getColors();
167 debugUI.maskColors(colors);
178 drawBox(0, -TRAILER_HEIGHT, 0, 0, 0, 0, TRAILER_WIDTH, TRAILER_HEIGHT, TRAILER_DEPTH, TRAILER_HEIGHT/2.);
183 vertex(TRAILER_WIDTH, 0, 0);
184 vertex(TRAILER_WIDTH, 0, TRAILER_DEPTH);
185 vertex(0, 0, TRAILER_DEPTH);
190 drawBox(BASS_X, 0, BASS_Z, 0, 0, 0, BASS_WIDTH, BASS_HEIGHT, BASS_DEPTH, Cube.CHANNEL_WIDTH);
191 for (Cube c : glucose.model.cubes) {
198 for (Point p : glucose.model.points) {
199 stroke(colors[p.index]);
200 vertex(p.fx, p.fy, p.fz);
201 // println(p.fx + ":" + p.fy + ":" + p.fz);
207 javax.media.opengl.GL gl= ((PGraphicsOpenGL)g).beginGL();
208 gl.glClear(javax.media.opengl.GL.GL_DEPTH_BUFFER_BIT);
209 ((PGraphicsOpenGL)g).endGL();
217 // TODO(mcslee): move into GLucose engine
218 if (pandaBoardsEnabled) {
219 pandaFront.send(colors);
220 pandaRear.send(colors);
224 void drawCube(Cube c) {
225 drawBox(c.x, c.y, c.z, c.rx, c.ry, c.rz, Cube.EDGE_WIDTH, Cube.EDGE_HEIGHT, Cube.EDGE_WIDTH, Cube.CHANNEL_WIDTH);
228 void drawBox(float x, float y, float z, float rx, float ry, float rz, float xd, float yd, float zd, float sw) {
232 rotate(ry / 180. * PI, 0, -1, 0);
234 for (int i = 0; i < 4; ++i) {
235 float wid = (i % 2 == 0) ? xd : zd;
241 vertex(wid - sw, yd);
242 vertex(wid - sw, sw);
248 vertex(wid - sw, yd);
249 vertex(wid - sw, yd - sw);
254 translate(wid, 0, 0);
255 rotate(HALF_PI, 0, -1, 0);
270 int restoreToIndex = -1;
274 mappingTool.keyPressed();
279 frameRate(--targetFramerate);
283 frameRate(++targetFramerate);
286 debugMode = !debugMode;
287 println("Debug output: " + (debugMode ? "ON" : "OFF"));
290 mappingMode = !mappingMode;
292 LXPattern pattern = lx.getPattern();
293 for (int i = 0; i < patterns.length; ++i) {
294 if (pattern == patterns[i]) {
300 lx.setPatterns(new LXPattern[] { mappingTool });
303 lx.setPatterns(patterns);
304 lx.goIndex(restoreToIndex);
308 pandaBoardsEnabled = !pandaBoardsEnabled;
309 println("PandaBoard Output: " + (pandaBoardsEnabled ? "ON" : "OFF"));
319 void mousePressed() {
320 if (mouseX > ui.leftPos) {
324 debugUI.mousePressed();
331 void mouseDragged() {
332 if (mouseX > ui.leftPos) {
335 int dx = mouseX - mx;
336 int dy = mouseY - my;
340 eyeX = midX + eyeR*sin(eyeA);
341 eyeZ = midZ + eyeR*cos(eyeA);
346 void mouseReleased() {
347 if (mouseX > ui.leftPos) {
352 void mouseWheel(int delta) {
353 eyeR = constrain(eyeR - delta, -500, -80);
354 eyeX = midX + eyeR*sin(eyeA);
355 eyeZ = midZ + eyeR*cos(eyeA);