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;
43 int startMillis, lastMillis;
45 // Core engine variables
49 MappingTool mappingTool;
50 PandaDriver[] pandaBoards;
52 // Display configuration mode
53 boolean mappingMode = false;
54 boolean debugMode = false;
57 // Handles to UI objects
59 UIPatternDeck uiPatternA;
60 UICrossfader uiCrossfader;
62 UIDebugText uiDebugText;
65 float eyeR, eyeA, eyeX, eyeY, eyeZ, midX, midY, midZ;
67 LXPattern[] _patterns(GLucose glucose) {
68 LXPattern[] patterns = patterns(glucose);
69 for (LXPattern p : patterns) {
70 p.setTransition(new DissolveTransition(glucose.lx).setDuration(1000));
76 startMillis = lastMillis = millis();
78 // Initialize the Processing graphics environment
79 size(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, OPENGL);
80 frameRate(targetFramerate);
82 // hint(ENABLE_OPENGL_4X_SMOOTH); // no discernable improvement?
83 logTime("Created viewport");
85 // Create the GLucose engine to run the cubes
86 glucose = new GLucose(this, buildModel());
88 lx.enableKeyboardTempo();
89 logTime("Built GLucose engine");
92 Engine engine = lx.engine;
93 engine.setPatterns(patterns = _patterns(glucose));
94 engine.addDeck(_patterns(glucose));
95 logTime("Built patterns");
96 glucose.setTransitions(transitions(glucose));
97 logTime("Built transitions");
98 glucose.lx.addEffects(effects(glucose));
99 logTime("Built effects");
101 // Build output driver
102 PandaMapping[] pandaMappings = buildPandaList();
103 pandaBoards = new PandaDriver[pandaMappings.length];
105 for (PandaMapping pm : pandaMappings) {
106 pandaBoards[pbi++] = new PandaDriver(pm.ip, glucose.model, pm);
108 mappingTool = new MappingTool(glucose, pandaMappings);
109 logTime("Built PandaDriver");
112 debugUI = new DebugUI(pandaMappings);
113 overlays = new UIContext[] {
114 uiPatternA = new UIPatternDeck(lx.engine.getDeck(0), "PATTERN A", 4, 4, 140, 344),
115 uiCrossfader = new UICrossfader(4, 352, 140, 212),
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),
120 new UIOutput(width-144, 552, 140, 106),
122 uiDebugText = new UIDebugText(4, height-64, width-8, 44),
123 uiMapping = new UIMapping(mappingTool, 4, 4, 140, 344),
125 uiMapping.setVisible(false);
126 logTime("Built overlay UI");
129 for (MidiInputDevice d : RWMidi.getInputDevices()) {
132 SCMidiDevices.initializeStandardDevices(glucose);
133 logTime("Setup MIDI devices");
136 midX = TRAILER_WIDTH/2.;
137 midY = glucose.model.yMax/2;
138 midZ = TRAILER_DEPTH/2.;
142 eyeX = midX + eyeR*sin(eyeA);
143 eyeZ = midZ + eyeR*cos(eyeA);
144 addMouseWheelListener(new java.awt.event.MouseWheelListener() {
145 public void mouseWheelMoved(java.awt.event.MouseWheelEvent mwe) {
146 mouseWheel(mwe.getWheelRotation());
149 println("Total setup: " + (millis() - startMillis) + "ms");
150 println("Hit the 'p' key to toggle Panda Board output");
154 void controllerChangeReceived(rwmidi.Controller cc) {
156 println("CC: " + cc.toString());
160 void noteOnReceived(Note note) {
162 println("Note On: " + note.toString());
166 void noteOffReceived(Note note) {
168 println("Note Off: " + note.toString());
172 void logTime(String evt) {
174 println(evt + ": " + (now - lastMillis) + "ms");
179 // Draws the simulation and the 2D UI overlay
181 color[] colors = glucose.getColors();
183 String displayMode = uiCrossfader.getDisplayMode();
184 if (displayMode == "A") {
185 colors = lx.engine.getDeck(0).getColors();
186 } else if (displayMode == "B") {
187 colors = lx.engine.getDeck(1).getColors();
190 debugUI.maskColors(colors);
203 drawBox(0, -TRAILER_HEIGHT, 0, 0, 0, 0, TRAILER_WIDTH, TRAILER_HEIGHT, TRAILER_DEPTH, TRAILER_HEIGHT/2.);
208 vertex(TRAILER_WIDTH, 0, 0);
209 vertex(TRAILER_WIDTH, 0, TRAILER_DEPTH);
210 vertex(0, 0, TRAILER_DEPTH);
214 // drawBassBox(glucose.model.bassBox);
215 // for (Speaker s : glucose.model.speakers) {
218 for (Cube c : glucose.model.cubes) {
225 // TODO(mcslee): restore when bassBox/speakers are right again
226 // for (Point p : glucose.model.points) {
227 for (Cube cube : glucose.model.cubes) {
228 for (Point p : cube.points) {
229 stroke(colors[p.index]);
230 vertex(p.fx, p.fy, p.fz);
238 // Send output colors
239 color[] sendColors = glucose.getColors();
241 debugUI.maskColors(colors);
244 // Gamma correction here. Apply a cubic to the brightness
245 // for better representation of dynamic range
246 for (int i = 0; i < colors.length; ++i) {
247 float b = brightness(colors[i]) / 100.f;
250 saturation(colors[i]),
255 // TODO(mcslee): move into GLucose engine
256 for (PandaDriver p : pandaBoards) {
261 void drawBassBox(BassBox b) {
267 translate(b.x + BassBox.EDGE_WIDTH/2., b.y + BassBox.EDGE_HEIGHT/2, b.z + BassBox.EDGE_DEPTH/2.);
268 box(BassBox.EDGE_WIDTH-20*in, BassBox.EDGE_HEIGHT-20*in, BassBox.EDGE_DEPTH-20*in);
273 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);
276 translate(b.x+(Cube.CHANNEL_WIDTH-in)/2., b.y + BassBox.EDGE_HEIGHT-in, b.z + BassBox.EDGE_DEPTH/2.);
277 float lastOffset = 0;
278 for (float offset : BoothFloor.STRIP_OFFSETS) {
279 translate(offset - lastOffset, 0, 0);
280 box(Cube.CHANNEL_WIDTH-in, 0, BassBox.EDGE_DEPTH - 2*in);
286 translate(b.x + (Cube.CHANNEL_WIDTH-in)/2., b.y + BassBox.EDGE_HEIGHT/2., b.z + in);
287 for (int j = 0; j < 2; ++j) {
289 for (int i = 0; i < BassBox.NUM_FRONT_STRUTS; ++i) {
290 translate(BassBox.FRONT_STRUT_SPACING, 0, 0);
291 box(Cube.CHANNEL_WIDTH-in, BassBox.EDGE_HEIGHT - in*2, 0);
294 translate(0, 0, BassBox.EDGE_DEPTH - 2*in);
299 translate(b.x + in, b.y + BassBox.EDGE_HEIGHT/2., b.z + BassBox.SIDE_STRUT_SPACING + (Cube.CHANNEL_WIDTH-in)/2.);
300 box(0, BassBox.EDGE_HEIGHT - in*2, Cube.CHANNEL_WIDTH-in);
301 translate(BassBox.EDGE_WIDTH-2*in, 0, 0);
302 box(0, BassBox.EDGE_HEIGHT - in*2, Cube.CHANNEL_WIDTH-in);
307 void drawCube(Cube c) {
311 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);
314 void drawSpeaker(Speaker s) {
320 translate(s.x, s.y, s.z);
321 rotate(s.ry / 180. * PI, 0, -1, 0);
322 translate(Speaker.EDGE_WIDTH/2., Speaker.EDGE_HEIGHT/2., Speaker.EDGE_DEPTH/2.);
323 box(Speaker.EDGE_WIDTH-20*in, Speaker.EDGE_HEIGHT-20*in, Speaker.EDGE_DEPTH-20*in);
324 translate(0, Speaker.EDGE_HEIGHT/2. + Speaker.EDGE_HEIGHT*.8/2, 0);
327 box(Speaker.EDGE_WIDTH*.6, Speaker.EDGE_HEIGHT*.8, Speaker.EDGE_DEPTH*.75);
332 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);
335 void drawBox(float x, float y, float z, float rx, float ry, float rz, float xd, float yd, float zd, float sw) {
338 rotate(rx / 180. * PI, -1, 0, 0);
339 rotate(ry / 180. * PI, 0, -1, 0);
340 rotate(rz / 180. * PI, 0, 0, -1);
341 for (int i = 0; i < 4; ++i) {
342 float wid = (i % 2 == 0) ? xd : zd;
348 vertex(wid - sw, yd);
349 vertex(wid - sw, sw);
355 vertex(wid - sw, yd);
356 vertex(wid - sw, yd - sw);
361 translate(wid, 0, 0);
362 rotate(HALF_PI, 0, -1, 0);
369 javax.media.opengl.GL gl = ((PGraphicsOpenGL)g).beginGL();
370 gl.glClear(javax.media.opengl.GL.GL_DEPTH_BUFFER_BIT);
371 ((PGraphicsOpenGL)g).endGL();
375 for (UIContext context : overlays) {
380 // Always draw FPS meter
383 textAlign(LEFT, BASELINE);
384 text("FPS: " + ((int) (frameRate*10)) / 10. + " / " + targetFramerate + " (-/+)", 4, height-4);
392 LXPattern restoreToPattern = null;
396 mappingTool.keyPressed(uiMapping);
401 frameRate(--targetFramerate);
405 frameRate(++targetFramerate);
408 debugMode = !debugMode;
409 println("Debug output: " + (debugMode ? "ON" : "OFF"));
412 mappingMode = !mappingMode;
413 uiPatternA.setVisible(!mappingMode);
414 uiMapping.setVisible(mappingMode);
416 restoreToPattern = lx.getPattern();
417 lx.setPatterns(new LXPattern[] { mappingTool });
419 lx.setPatterns(patterns);
420 LXTransition pop = restoreToPattern.getTransition();
421 restoreToPattern.setTransition(null);
422 lx.goPattern(restoreToPattern);
423 restoreToPattern.setTransition(pop);
427 for (PandaDriver p : pandaBoards) {
438 void mousePressed() {
439 boolean debugged = false;
441 debugged = debugUI.mousePressed();
444 for (UIContext context : overlays) {
445 context.mousePressed(mouseX, mouseY);
452 void mouseDragged() {
453 boolean dragged = false;
454 for (UIContext context : overlays) {
455 dragged |= context.mouseDragged(mouseX, mouseY);
458 int dx = mouseX - mx;
459 int dy = mouseY - my;
463 eyeX = midX + eyeR*sin(eyeA);
464 eyeZ = midZ + eyeR*cos(eyeA);
469 void mouseReleased() {
470 for (UIContext context : overlays) {
471 context.mouseReleased(mouseX, mouseY);
474 // ui.mouseReleased();
477 void mouseWheel(int delta) {
478 boolean wheeled = false;
479 for (UIContext context : overlays) {
480 wheeled |= context.mouseWheel(mouseX, mouseY, delta);
484 eyeR = constrain(eyeR - delta, -500, -80);
485 eyeX = midX + eyeR*sin(eyeA);
486 eyeZ = midZ + eyeR*cos(eyeA);