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;
72 startMillis = lastMillis = millis();
74 // Initialize the Processing graphics environment
75 size(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, OPENGL);
76 frameRate(targetFramerate);
78 // hint(ENABLE_OPENGL_4X_SMOOTH); // no discernable improvement?
79 logTime("Created viewport");
81 // Create the GLucose engine to run the cubes
82 glucose = new GLucose(this, new SCMapping());
84 lx.enableKeyboardTempo();
85 logTime("Built GLucose engine");
88 glucose.lx.setPatterns(patterns = patterns(glucose));
89 logTime("Built patterns");
90 glucose.lx.addEffects(effects = effects(glucose));
91 logTime("Built effects");
92 glucose.setTransitions(transitions = transitions(glucose));
93 logTime("Built transitions");
95 // Build output driver
96 int[][] frontChannels = glucose.mapping.buildFrontChannelList();
97 int[][] rearChannels = glucose.mapping.buildRearChannelList();
98 int[][] flippedRGB = glucose.mapping.buildFlippedRGBList();
99 mappingTool = new MappingTool(glucose, frontChannels, rearChannels);
100 pandaFront = new PandaDriver(new NetAddress("192.168.1.28", 9001), glucose.model, frontChannels, flippedRGB);
101 pandaRear = new PandaDriver(new NetAddress("192.168.1.29", 9001), glucose.model, rearChannels, flippedRGB);
102 logTime("Build PandaDriver");
105 ui = controlUI = new ControlUI();
106 mappingUI = new MappingUI(mappingTool);
107 debugUI = new DebugUI(frontChannels, rearChannels);
108 logTime("Built overlay UI");
111 for (MidiInputDevice d : RWMidi.getInputDevices()) {
114 SCMidiDevices.initializeStandardDevices(glucose);
115 logTime("Setup MIDI devices");
118 midX = TRAILER_WIDTH/2. + 20;
119 midY = glucose.model.yMax/2;
120 midZ = TRAILER_DEPTH/2.;
124 eyeX = midX + eyeR*sin(eyeA);
125 eyeZ = midZ + eyeR*cos(eyeA);
126 addMouseWheelListener(new java.awt.event.MouseWheelListener() {
127 public void mouseWheelMoved(java.awt.event.MouseWheelEvent mwe) {
128 mouseWheel(mwe.getWheelRotation());
132 println("Total setup: " + (millis() - startMillis) + "ms");
133 println("Hit the 'p' key to toggle Panda Board output");
136 void controllerChangeReceived(rwmidi.Controller cc) {
138 println("CC: " + cc.toString());
142 void noteOnReceived(Note note) {
144 println("Note On: " + note.toString());
148 void noteOffReceived(Note note) {
150 println("Note Off: " + note.toString());
154 void logTime(String evt) {
156 println(evt + ": " + (now - lastMillis) + "ms");
161 // Draws the simulation and the 2D UI overlay
163 color[] colors = glucose.getColors();
165 debugUI.maskColors(colors);
176 drawBox(0, -TRAILER_HEIGHT, 0, 0, 0, 0, TRAILER_WIDTH, TRAILER_HEIGHT, TRAILER_DEPTH, TRAILER_HEIGHT/2.);
181 vertex(TRAILER_WIDTH, 0, 0);
182 vertex(TRAILER_WIDTH, 0, TRAILER_DEPTH);
183 vertex(0, 0, TRAILER_DEPTH);
188 drawBox(BASS_X, 0, BASS_Z, 0, 0, 0, BASS_WIDTH, BASS_HEIGHT, BASS_DEPTH, Cube.CHANNEL_WIDTH);
189 for (Cube c : glucose.model.cubes) {
196 for (Point p : glucose.model.points) {
197 stroke(colors[p.index]);
198 vertex(p.fx, p.fy, p.fz);
199 // println(p.fx + ":" + p.fy + ":" + p.fz);
205 javax.media.opengl.GL gl = ((PGraphicsOpenGL)g).beginGL();
206 gl.glClear(javax.media.opengl.GL.GL_DEPTH_BUFFER_BIT);
207 ((PGraphicsOpenGL)g).endGL();
215 // TODO(mcslee): move into GLucose engine
216 if (pandaBoardsEnabled) {
217 pandaFront.send(colors);
218 pandaRear.send(colors);
222 void drawCube(Cube c) {
223 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);
226 void drawBox(float x, float y, float z, float rx, float ry, float rz, float xd, float yd, float zd, float sw) {
229 rotate(rx / 180. * PI, -1, 0, 0);
230 rotate(ry / 180. * PI, 0, -1, 0);
231 rotate(rz / 180. * PI, 0, 0, -1);
232 for (int i = 0; i < 4; ++i) {
233 float wid = (i % 2 == 0) ? xd : zd;
239 vertex(wid - sw, yd);
240 vertex(wid - sw, sw);
246 vertex(wid - sw, yd);
247 vertex(wid - sw, yd - sw);
252 translate(wid, 0, 0);
253 rotate(HALF_PI, 0, -1, 0);
268 int restoreToIndex = -1;
272 mappingTool.keyPressed();
277 frameRate(--targetFramerate);
281 frameRate(++targetFramerate);
284 debugMode = !debugMode;
285 println("Debug output: " + (debugMode ? "ON" : "OFF"));
288 mappingMode = !mappingMode;
290 LXPattern pattern = lx.getPattern();
291 for (int i = 0; i < patterns.length; ++i) {
292 if (pattern == patterns[i]) {
298 lx.setPatterns(new LXPattern[] { mappingTool });
301 lx.setPatterns(patterns);
302 lx.goIndex(restoreToIndex);
306 pandaBoardsEnabled = !pandaBoardsEnabled;
307 println("PandaBoard Output: " + (pandaBoardsEnabled ? "ON" : "OFF"));
317 void mousePressed() {
318 if (mouseX > ui.leftPos) {
322 debugUI.mousePressed();
329 void mouseDragged() {
330 if (mouseX > ui.leftPos) {
333 int dx = mouseX - mx;
334 int dy = mouseY - my;
338 eyeX = midX + eyeR*sin(eyeA);
339 eyeZ = midZ + eyeR*cos(eyeA);
344 void mouseReleased() {
345 if (mouseX > ui.leftPos) {
350 void mouseWheel(int delta) {
351 eyeR = constrain(eyeR - delta, -500, -80);
352 eyeX = midX + eyeR*sin(eyeA);
353 eyeZ = midZ + eyeR*cos(eyeA);