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[] pandaBoards;
60 boolean mappingMode = false;
61 boolean debugMode = false;
65 float eyeR, eyeA, eyeX, eyeY, eyeZ, midX, midY, midZ;
68 startMillis = lastMillis = millis();
70 // Initialize the Processing graphics environment
71 size(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, OPENGL);
72 frameRate(targetFramerate);
74 // hint(ENABLE_OPENGL_4X_SMOOTH); // no discernable improvement?
75 logTime("Created viewport");
77 // Create the GLucose engine to run the cubes
78 glucose = new GLucose(this, buildModel());
80 lx.enableKeyboardTempo();
81 logTime("Built GLucose engine");
84 glucose.lx.setPatterns(patterns = patterns(glucose));
85 logTime("Built patterns");
86 glucose.lx.addEffects(effects = effects(glucose));
87 logTime("Built effects");
88 glucose.setTransitions(transitions = transitions(glucose));
89 logTime("Built transitions");
91 // Build output driver
92 PandaMapping[] pandaMappings = buildPandaList();
93 pandaBoards = new PandaDriver[pandaMappings.length];
95 for (PandaMapping pm : pandaMappings) {
96 pandaBoards[pbi++] = new PandaDriver(pm.ip, glucose.model, pm);
98 mappingTool = new MappingTool(glucose, pandaMappings);
99 logTime("Built PandaDriver");
102 ui = controlUI = new ControlUI();
103 mappingUI = new MappingUI(mappingTool);
104 debugUI = new DebugUI(pandaMappings);
105 logTime("Built overlay UI");
108 for (MidiInputDevice d : RWMidi.getInputDevices()) {
111 SCMidiDevices.initializeStandardDevices(glucose);
112 logTime("Setup MIDI devices");
115 midX = TRAILER_WIDTH/2. + 20;
116 midY = glucose.model.yMax/2;
117 midZ = TRAILER_DEPTH/2.;
121 eyeX = midX + eyeR*sin(eyeA);
122 eyeZ = midZ + eyeR*cos(eyeA);
123 addMouseWheelListener(new java.awt.event.MouseWheelListener() {
124 public void mouseWheelMoved(java.awt.event.MouseWheelEvent mwe) {
125 mouseWheel(mwe.getWheelRotation());
129 println("Total setup: " + (millis() - startMillis) + "ms");
130 println("Hit the 'p' key to toggle Panda Board output");
133 void controllerChangeReceived(rwmidi.Controller cc) {
135 println("CC: " + cc.toString());
139 void noteOnReceived(Note note) {
141 println("Note On: " + note.toString());
145 void noteOffReceived(Note note) {
147 println("Note Off: " + note.toString());
151 void logTime(String evt) {
153 println(evt + ": " + (now - lastMillis) + "ms");
158 // Draws the simulation and the 2D UI overlay
160 color[] colors = glucose.getColors();
162 debugUI.maskColors(colors);
173 drawBox(0, -TRAILER_HEIGHT, 0, 0, 0, 0, TRAILER_WIDTH, TRAILER_HEIGHT, TRAILER_DEPTH, TRAILER_HEIGHT/2.);
178 vertex(TRAILER_WIDTH, 0, 0);
179 vertex(TRAILER_WIDTH, 0, TRAILER_DEPTH);
180 vertex(0, 0, TRAILER_DEPTH);
185 drawBox(BASS_X, 0, BASS_Z, 0, 0, 0, BASS_WIDTH, BASS_HEIGHT, BASS_DEPTH, Cube.CHANNEL_WIDTH);
186 for (Cube c : glucose.model.cubes) {
193 for (Point p : glucose.model.points) {
194 stroke(colors[p.index]);
195 vertex(p.fx, p.fy, p.fz);
196 // println(p.fx + ":" + p.fy + ":" + p.fz);
202 javax.media.opengl.GL gl = ((PGraphicsOpenGL)g).beginGL();
203 gl.glClear(javax.media.opengl.GL.GL_DEPTH_BUFFER_BIT);
204 ((PGraphicsOpenGL)g).endGL();
212 // TODO(mcslee): move into GLucose engine
213 for (PandaDriver p : pandaBoards) {
218 void drawCube(Cube c) {
220 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);
223 void drawBox(float x, float y, float z, float rx, float ry, float rz, float xd, float yd, float zd, float sw) {
226 rotate(rx / 180. * PI, -1, 0, 0);
227 rotate(ry / 180. * PI, 0, -1, 0);
228 rotate(rz / 180. * PI, 0, 0, -1);
229 for (int i = 0; i < 4; ++i) {
230 float wid = (i % 2 == 0) ? xd : zd;
236 vertex(wid - sw, yd);
237 vertex(wid - sw, sw);
243 vertex(wid - sw, yd);
244 vertex(wid - sw, yd - sw);
249 translate(wid, 0, 0);
250 rotate(HALF_PI, 0, -1, 0);
265 int restoreToIndex = -1;
269 mappingTool.keyPressed();
274 frameRate(--targetFramerate);
278 frameRate(++targetFramerate);
281 debugMode = !debugMode;
282 println("Debug output: " + (debugMode ? "ON" : "OFF"));
285 mappingMode = !mappingMode;
287 LXPattern pattern = lx.getPattern();
288 for (int i = 0; i < patterns.length; ++i) {
289 if (pattern == patterns[i]) {
295 lx.setPatterns(new LXPattern[] { mappingTool });
298 lx.setPatterns(patterns);
299 lx.goIndex(restoreToIndex);
303 for (PandaDriver p : pandaBoards) {
314 void mousePressed() {
316 if (mouseX < ui.leftPos) {
318 debugUI.mousePressed();
325 void mouseDragged() {
326 if (mouseX > ui.leftPos) {
329 int dx = mouseX - mx;
330 int dy = mouseY - my;
334 eyeX = midX + eyeR*sin(eyeA);
335 eyeZ = midZ + eyeR*cos(eyeA);
340 void mouseReleased() {
344 void mouseWheel(int delta) {
345 if (mouseX > ui.leftPos) {
346 ui.mouseWheel(delta);
348 eyeR = constrain(eyeR - delta, -500, -80);
349 eyeX = midX + eyeR*sin(eyeA);
350 eyeZ = midZ + eyeR*cos(eyeA);