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 // The trailer is measured from the outside of the black metal (but not including the higher welded part on the front)
38 final float TRAILER_WIDTH = 240;
39 final float TRAILER_DEPTH = 97;
40 final float TRAILER_HEIGHT = 33;
42 int targetFramerate = 60;
44 int startMillis, lastMillis;
47 MappingTool mappingTool;
49 LXTransition[] transitions;
51 PandaDriver[] pandaBoards;
52 boolean mappingMode = false;
53 boolean debugMode = false;
58 UIPatternDeck uiPatternA;
60 UIDebugText uiDebugText;
63 float eyeR, eyeA, eyeX, eyeY, eyeZ, midX, midY, midZ;
65 LXPattern[] _patterns(GLucose glucose) {
66 LXPattern[] patterns = patterns(glucose);
67 for (LXPattern p : patterns) {
68 p.setTransition(new DissolveTransition(glucose.lx).setDuration(1000));
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, buildModel());
86 lx.enableKeyboardTempo();
87 logTime("Built GLucose engine");
90 Engine engine = lx.engine;
91 glucose.setTransitions(transitions = transitions(glucose));
92 logTime("Built transitions");
93 engine.setPatterns(patterns = _patterns(glucose));
94 engine.addDeck(_patterns(glucose));
95 engine.getDeck(1).setBlendTransition(transitions[0]);
96 logTime("Built patterns");
97 glucose.lx.addEffects(effects = effects(glucose));
98 logTime("Built effects");
100 // Build output driver
101 PandaMapping[] pandaMappings = buildPandaList();
102 pandaBoards = new PandaDriver[pandaMappings.length];
104 for (PandaMapping pm : pandaMappings) {
105 pandaBoards[pbi++] = new PandaDriver(pm.ip, glucose.model, pm);
107 mappingTool = new MappingTool(glucose, pandaMappings);
108 logTime("Built PandaDriver");
111 debugUI = new DebugUI(pandaMappings);
112 overlays = new UIContext[] {
113 uiPatternA = new UIPatternDeck(lx.engine.getDeck(0), "PATTERN A", 4, 4, 140, 344),
114 new UICrossfader(4, 352, 140, 152),
115 new UIOutput(4, 508, 140, 122),
117 new UIPatternDeck(lx.engine.getDeck(1), "PATTERN B", width-144, 4, 140, 344),
118 new UIEffects(width-144, 352, 140, 144),
119 new UITempo(width-144, 498, 140, 50),
121 uiDebugText = new UIDebugText(4, height-64, width-8, 44),
122 uiMapping = new UIMapping(mappingTool, 4, 4, 140, 344),
124 uiMapping.setVisible(false);
125 logTime("Built overlay UI");
128 for (MidiInputDevice d : RWMidi.getInputDevices()) {
131 SCMidiDevices.initializeStandardDevices(glucose);
132 logTime("Setup MIDI devices");
135 midX = TRAILER_WIDTH/2.;
136 midY = glucose.model.yMax/2;
137 midZ = TRAILER_DEPTH/2.;
141 eyeX = midX + eyeR*sin(eyeA);
142 eyeZ = midZ + eyeR*cos(eyeA);
143 addMouseWheelListener(new java.awt.event.MouseWheelListener() {
144 public void mouseWheelMoved(java.awt.event.MouseWheelEvent mwe) {
145 mouseWheel(mwe.getWheelRotation());
148 println("Total setup: " + (millis() - startMillis) + "ms");
149 println("Hit the 'p' key to toggle Panda Board output");
153 void controllerChangeReceived(rwmidi.Controller cc) {
155 println("CC: " + cc.toString());
159 void noteOnReceived(Note note) {
161 println("Note On: " + note.toString());
165 void noteOffReceived(Note note) {
167 println("Note Off: " + note.toString());
171 void logTime(String evt) {
173 println(evt + ": " + (now - lastMillis) + "ms");
178 // Draws the simulation and the 2D UI overlay
180 color[] colors = glucose.getColors();;
181 if (displayMode == "A") {
182 colors = lx.engine.getDeck(0).getColors();
183 } else if (displayMode == "B") {
184 colors = lx.engine.getDeck(1).getColors();
187 debugUI.maskColors(colors);
200 drawBox(0, -TRAILER_HEIGHT, 0, 0, 0, 0, TRAILER_WIDTH, TRAILER_HEIGHT, TRAILER_DEPTH, TRAILER_HEIGHT/2.);
205 vertex(TRAILER_WIDTH, 0, 0);
206 vertex(TRAILER_WIDTH, 0, TRAILER_DEPTH);
207 vertex(0, 0, TRAILER_DEPTH);
211 // drawBassBox(glucose.model.bassBox);
212 // for (Speaker s : glucose.model.speakers) {
215 for (Cube c : glucose.model.cubes) {
222 // TODO(mcslee): restore when bassBox/speakers are right again
223 // for (Point p : glucose.model.points) {
224 for (Cube cube : glucose.model.cubes) {
225 for (Point p : cube.points) {
226 stroke(colors[p.index]);
227 vertex(p.fx, p.fy, p.fz);
235 // Send output colors
236 color[] sendColors = glucose.getColors();
238 debugUI.maskColors(colors);
241 // Gamma correction here. Apply a cubic to the brightness
242 // for better representation of dynamic range
243 for (int i = 0; i < colors.length; ++i) {
244 float b = brightness(colors[i]) / 100.f;
247 saturation(colors[i]),
252 // TODO(mcslee): move into GLucose engine
253 for (PandaDriver p : pandaBoards) {
258 void drawBassBox(BassBox b) {
264 translate(b.x + BassBox.EDGE_WIDTH/2., b.y + BassBox.EDGE_HEIGHT/2, b.z + BassBox.EDGE_DEPTH/2.);
265 box(BassBox.EDGE_WIDTH-20*in, BassBox.EDGE_HEIGHT-20*in, BassBox.EDGE_DEPTH-20*in);
270 drawBox(b.x+in, b.y+in, b.z+in, 0, 0, 0, BassBox.EDGE_WIDTH-in*2, BassBox.EDGE_HEIGHT-in*2, BassBox.EDGE_DEPTH-in*2, Cube.CHANNEL_WIDTH-in);
273 translate(b.x+(Cube.CHANNEL_WIDTH-in)/2., b.y + BassBox.EDGE_HEIGHT-in, b.z + BassBox.EDGE_DEPTH/2.);
274 float lastOffset = 0;
275 for (float offset : BoothFloor.STRIP_OFFSETS) {
276 translate(offset - lastOffset, 0, 0);
277 box(Cube.CHANNEL_WIDTH-in, 0, BassBox.EDGE_DEPTH - 2*in);
283 translate(b.x + (Cube.CHANNEL_WIDTH-in)/2., b.y + BassBox.EDGE_HEIGHT/2., b.z + in);
284 for (int j = 0; j < 2; ++j) {
286 for (int i = 0; i < BassBox.NUM_FRONT_STRUTS; ++i) {
287 translate(BassBox.FRONT_STRUT_SPACING, 0, 0);
288 box(Cube.CHANNEL_WIDTH-in, BassBox.EDGE_HEIGHT - in*2, 0);
291 translate(0, 0, BassBox.EDGE_DEPTH - 2*in);
296 translate(b.x + in, b.y + BassBox.EDGE_HEIGHT/2., b.z + BassBox.SIDE_STRUT_SPACING + (Cube.CHANNEL_WIDTH-in)/2.);
297 box(0, BassBox.EDGE_HEIGHT - in*2, Cube.CHANNEL_WIDTH-in);
298 translate(BassBox.EDGE_WIDTH-2*in, 0, 0);
299 box(0, BassBox.EDGE_HEIGHT - in*2, Cube.CHANNEL_WIDTH-in);
304 void drawCube(Cube c) {
308 drawBox(c.x+in, c.y+in, c.z+in, c.rx, c.ry, c.rz, Cube.EDGE_WIDTH-in*2, Cube.EDGE_HEIGHT-in*2, Cube.EDGE_WIDTH-in*2, Cube.CHANNEL_WIDTH-in);
311 void drawSpeaker(Speaker s) {
317 translate(s.x, s.y, s.z);
318 rotate(s.ry / 180. * PI, 0, -1, 0);
319 translate(Speaker.EDGE_WIDTH/2., Speaker.EDGE_HEIGHT/2., Speaker.EDGE_DEPTH/2.);
320 box(Speaker.EDGE_WIDTH-20*in, Speaker.EDGE_HEIGHT-20*in, Speaker.EDGE_DEPTH-20*in);
321 translate(0, Speaker.EDGE_HEIGHT/2. + Speaker.EDGE_HEIGHT*.8/2, 0);
324 box(Speaker.EDGE_WIDTH*.6, Speaker.EDGE_HEIGHT*.8, Speaker.EDGE_DEPTH*.75);
329 drawBox(s.x+in, s.y+in, s.z+in, 0, s.ry, 0, Speaker.EDGE_WIDTH-in*2, Speaker.EDGE_HEIGHT-in*2, Speaker.EDGE_DEPTH-in*2, Cube.CHANNEL_WIDTH-in);
332 void drawBox(float x, float y, float z, float rx, float ry, float rz, float xd, float yd, float zd, float sw) {
335 rotate(rx / 180. * PI, -1, 0, 0);
336 rotate(ry / 180. * PI, 0, -1, 0);
337 rotate(rz / 180. * PI, 0, 0, -1);
338 for (int i = 0; i < 4; ++i) {
339 float wid = (i % 2 == 0) ? xd : zd;
345 vertex(wid - sw, yd);
346 vertex(wid - sw, sw);
352 vertex(wid - sw, yd);
353 vertex(wid - sw, yd - sw);
358 translate(wid, 0, 0);
359 rotate(HALF_PI, 0, -1, 0);
366 javax.media.opengl.GL gl = ((PGraphicsOpenGL)g).beginGL();
367 gl.glClear(javax.media.opengl.GL.GL_DEPTH_BUFFER_BIT);
368 ((PGraphicsOpenGL)g).endGL();
372 for (UIContext context : overlays) {
377 // Always draw FPS meter
380 textAlign(LEFT, BASELINE);
381 text("FPS: " + ((int) (frameRate*10)) / 10. + " / " + targetFramerate + " (-/+)", 4, height-4);
389 LXPattern restoreToPattern = null;
393 mappingTool.keyPressed(uiMapping);
398 frameRate(--targetFramerate);
402 frameRate(++targetFramerate);
405 debugMode = !debugMode;
406 println("Debug output: " + (debugMode ? "ON" : "OFF"));
409 mappingMode = !mappingMode;
410 uiPatternA.setVisible(!mappingMode);
411 uiMapping.setVisible(mappingMode);
413 restoreToPattern = lx.getPattern();
414 lx.setPatterns(new LXPattern[] { mappingTool });
416 lx.setPatterns(patterns);
417 lx.goPattern(restoreToPattern);
421 for (PandaDriver p : pandaBoards) {
432 void mousePressed() {
433 boolean debugged = false;
435 debugged = debugUI.mousePressed();
438 for (UIContext context : overlays) {
439 context.mousePressed(mouseX, mouseY);
446 void mouseDragged() {
447 boolean dragged = false;
448 for (UIContext context : overlays) {
449 dragged |= context.mouseDragged(mouseX, mouseY);
452 int dx = mouseX - mx;
453 int dy = mouseY - my;
457 eyeX = midX + eyeR*sin(eyeA);
458 eyeZ = midZ + eyeR*cos(eyeA);
463 void mouseReleased() {
464 for (UIContext context : overlays) {
465 context.mouseReleased(mouseX, mouseY);
468 // ui.mouseReleased();
471 void mouseWheel(int delta) {
472 boolean wheeled = false;
473 for (UIContext context : overlays) {
474 wheeled |= context.mouseWheel(mouseX, mouseY, delta);
478 eyeR = constrain(eyeR - delta, -500, -80);
479 eyeX = midX + eyeR*sin(eyeA);
480 eyeZ = midZ + eyeR*cos(eyeA);