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;
54 PandaDriver[] pandaBoards;
55 boolean mappingMode = false;
56 boolean debugMode = false;
60 float eyeR, eyeA, eyeX, eyeY, eyeZ, midX, midY, midZ;
63 startMillis = lastMillis = millis();
65 // Initialize the Processing graphics environment
66 size(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, OPENGL);
67 frameRate(targetFramerate);
69 // hint(ENABLE_OPENGL_4X_SMOOTH); // no discernable improvement?
70 logTime("Created viewport");
72 // Create the GLucose engine to run the cubes
73 glucose = new GLucose(this, buildModel());
75 lx.enableKeyboardTempo();
76 logTime("Built GLucose engine");
79 glucose.lx.setPatterns(patterns = patterns(glucose));
80 logTime("Built patterns");
81 glucose.lx.addEffects(effects = effects(glucose));
82 logTime("Built effects");
83 glucose.setTransitions(transitions = transitions(glucose));
84 logTime("Built transitions");
86 // Build output driver
87 PandaMapping[] pandaMappings = buildPandaList();
88 pandaBoards = new PandaDriver[pandaMappings.length];
90 for (PandaMapping pm : pandaMappings) {
91 pandaBoards[pbi++] = new PandaDriver(pm.ip, glucose.model, pm);
93 mappingTool = new MappingTool(glucose, pandaMappings);
94 logTime("Built PandaDriver");
97 ui = controlUI = new ControlUI();
98 mappingUI = new MappingUI(mappingTool);
99 debugUI = new DebugUI(pandaMappings);
100 logTime("Built overlay UI");
103 for (MidiInputDevice d : RWMidi.getInputDevices()) {
106 SCMidiDevices.initializeStandardDevices(glucose);
107 logTime("Setup MIDI devices");
110 midX = TRAILER_WIDTH/2. + 20;
111 midY = glucose.model.yMax/2;
112 midZ = TRAILER_DEPTH/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());
123 println("Total setup: " + (millis() - startMillis) + "ms");
124 println("Hit the 'p' key to toggle Panda Board output");
127 boolean[] noteState = new boolean[16];
129 void controllerChangeReceived(rwmidi.Controller cc) {
131 println("CC: " + cc.toString());
133 //println(cc.getInput().getName());
136 for(int i=0; i<16; i++){
137 if(noteState[i] && i<8) { LXParameter p = glucose.patternKnobs.get(i); p.setValue(cc.getValue()/127.0); }
138 else if(noteState[i] && i<16) { try { LXParameter p = gparams.get(i-8); p.setValue(cc.getValue()/127.0); } catch(Exception e) {} }
142 for(int i=0; i<16; i++){
143 //sif(noteState[i] && i<8) { println( gplay.Sliders ); }
144 //else if(noteState[i] && i<16) { try { LXParameter p = gparams.get(i-8); p.setValue(cc.getValue()/127.0); } catch(Exception e) {} }
149 //if(c>=16 || c<16+8){
150 // LXParameter p = gparams.get(c-16);
151 // p.setValue(c/127.0);
156 void noteOnReceived(Note note) {
158 println("Note On: " + note.toString());
160 int pitch = note.getPitch();
161 if(pitch>=36 && pitch <36+16){
162 noteState[pitch-36]=true;
166 void noteOffReceived(Note note) {
168 println("Note Off: " + note.toString());
170 int pitch = note.getPitch();
171 if(pitch>=36 && pitch <36+16){
172 noteState[pitch-36]=false;
177 void logTime(String evt) {
179 println(evt + ": " + (now - lastMillis) + "ms");
184 // Draws the simulation and the 2D UI overlay
186 color[] colors = glucose.getColors();
188 debugUI.maskColors(colors);
199 drawBox(0, -TRAILER_HEIGHT, 0, 0, 0, 0, TRAILER_WIDTH, TRAILER_HEIGHT, TRAILER_DEPTH, TRAILER_HEIGHT/2.);
204 vertex(TRAILER_WIDTH, 0, 0);
205 vertex(TRAILER_WIDTH, 0, TRAILER_DEPTH);
206 vertex(0, 0, TRAILER_DEPTH);
210 drawBassBox(glucose.model.bassBox);
211 for (Speaker s : glucose.model.speakers) {
214 for (Cube c : glucose.model.cubes) {
221 for (Point p : glucose.model.points) {
222 stroke(colors[p.index]);
223 vertex(p.fx, p.fy, p.fz);
229 javax.media.opengl.GL gl = ((PGraphicsOpenGL)g).beginGL();
230 gl.glClear(javax.media.opengl.GL.GL_DEPTH_BUFFER_BIT);
231 ((PGraphicsOpenGL)g).endGL();
239 // Gamma correction here. Apply a cubic to the brightness
240 // for better representation of dynamic range
241 for (int i = 0; i < colors.length; ++i) {
242 float b = brightness(colors[i]) / 100.f;
245 saturation(colors[i]),
250 // TODO(mcslee): move into GLucose engine
251 for (PandaDriver p : pandaBoards) {
256 void drawBassBox(BassBox b) {
263 translate(b.x + BassBox.EDGE_WIDTH/2., b.y + BassBox.EDGE_HEIGHT/2, b.z + BassBox.EDGE_DEPTH/2.);
264 box(BassBox.EDGE_WIDTH-20*in, BassBox.EDGE_HEIGHT-20*in, BassBox.EDGE_DEPTH-20*in);
269 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);
272 translate(b.x+(Cube.CHANNEL_WIDTH-in)/2., b.y + BassBox.EDGE_HEIGHT-in, b.z + BassBox.EDGE_DEPTH/2.);
273 float lastOffset = 0;
274 for (float offset : BoothFloor.STRIP_OFFSETS) {
275 translate(offset - lastOffset, 0, 0);
276 box(Cube.CHANNEL_WIDTH-in, 0, BassBox.EDGE_DEPTH - 2*in);
282 translate(b.x + (Cube.CHANNEL_WIDTH-in)/2., b.y + BassBox.EDGE_HEIGHT/2., b.z + in);
283 for (int j = 0; j < 2; ++j) {
285 for (int i = 0; i < BassBox.NUM_FRONT_STRUTS; ++i) {
286 translate(BassBox.FRONT_STRUT_SPACING, 0, 0);
287 box(Cube.CHANNEL_WIDTH-in, BassBox.EDGE_HEIGHT - in*2, 0);
290 translate(0, 0, BassBox.EDGE_DEPTH - 2*in);
295 translate(b.x + in, b.y + BassBox.EDGE_HEIGHT/2., b.z + BassBox.SIDE_STRUT_SPACING + (Cube.CHANNEL_WIDTH-in)/2.);
296 box(0, BassBox.EDGE_HEIGHT - in*2, Cube.CHANNEL_WIDTH-in);
297 translate(BassBox.EDGE_WIDTH-2*in, 0, 0);
298 box(0, BassBox.EDGE_HEIGHT - in*2, Cube.CHANNEL_WIDTH-in);
303 void drawCube(Cube c) {
307 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);
310 void drawSpeaker(Speaker s) {
316 translate(s.x, s.y, s.z);
317 rotate(s.ry / 180. * PI, 0, -1, 0);
318 translate(Speaker.EDGE_WIDTH/2., Speaker.EDGE_HEIGHT/2., Speaker.EDGE_DEPTH/2.);
319 box(Speaker.EDGE_WIDTH-20*in, Speaker.EDGE_HEIGHT-20*in, Speaker.EDGE_DEPTH-20*in);
320 translate(0, Speaker.EDGE_HEIGHT/2. + Speaker.EDGE_HEIGHT*.8/2, 0);
323 box(Speaker.EDGE_WIDTH*.6, Speaker.EDGE_HEIGHT*.8, Speaker.EDGE_DEPTH*.75);
328 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);
375 int restoreToIndex = -1;
377 boolean doDual = false;
380 mappingTool.keyPressed();
388 frameRate(--targetFramerate);
392 frameRate(++targetFramerate);
395 debugMode = !debugMode;
396 println("Debug output: " + (debugMode ? "ON" : "OFF"));
399 mappingMode = !mappingMode;
401 LXPattern pattern = lx.getPattern();
402 for (int i = 0; i < patterns.length; ++i) {
403 if (pattern == patterns[i]) {
409 lx.setPatterns(new LXPattern[] { mappingTool });
412 lx.setPatterns(patterns);
413 lx.goIndex(restoreToIndex);
417 for (PandaDriver p : pandaBoards) {
428 void mousePressed() {
430 if (mouseX < ui.leftPos) {
432 debugUI.mousePressed();
439 void mouseDragged() {
440 if (mouseX > ui.leftPos) {
443 int dx = mouseX - mx;
444 int dy = mouseY - my;
448 eyeX = midX + eyeR*sin(eyeA);
449 eyeZ = midZ + eyeR*cos(eyeA);
454 void mouseReleased() {
458 void mouseWheel(int delta) {
459 if (mouseX > ui.leftPos) {
460 ui.mouseWheel(delta);
462 eyeR = constrain(eyeR - delta, -500, -80);
463 eyeX = midX + eyeR*sin(eyeA);
464 eyeZ = midZ + eyeR*cos(eyeA);