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;
53 MappingTool mappingTool;
55 LXTransition[] transitions;
60 PandaDriver[] pandaBoards;
61 boolean mappingMode = false;
62 boolean debugMode = false;
66 float eyeR, eyeA, eyeX, eyeY, eyeZ, midX, midY, midZ;
69 startMillis = lastMillis = millis();
71 // Initialize the Processing graphics environment
72 size(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, OPENGL);
73 frameRate(targetFramerate);
75 // hint(ENABLE_OPENGL_4X_SMOOTH); // no discernable improvement?
76 logTime("Created viewport");
78 // Create the GLucose engine to run the cubes
79 mapping = new SCMapping();
80 glucose = new GLucose(this, mapping);
82 lx.enableKeyboardTempo();
83 logTime("Built GLucose engine");
86 glucose.lx.setPatterns(patterns = patterns(glucose));
87 logTime("Built patterns");
88 glucose.lx.addEffects(effects = effects(glucose));
89 logTime("Built effects");
90 glucose.setTransitions(transitions = transitions(glucose));
91 logTime("Built transitions");
93 // Build output driver
94 PandaMapping[] pandaMappings = mapping.buildPandaList();
95 pandaBoards = new PandaDriver[pandaMappings.length];
97 for (PandaMapping pm : pandaMappings) {
98 pandaBoards[pbi++] = new PandaDriver(pm.ip, glucose.model, pm);
100 mappingTool = new MappingTool(glucose, pandaMappings);
101 logTime("Built PandaDriver");
104 ui = controlUI = new ControlUI();
105 mappingUI = new MappingUI(mappingTool);
106 debugUI = new DebugUI(pandaMappings);
107 logTime("Built overlay UI");
110 for (MidiInputDevice d : RWMidi.getInputDevices()) {
113 SCMidiDevices.initializeStandardDevices(glucose);
114 logTime("Setup MIDI devices");
117 midX = TRAILER_WIDTH/2. + 20;
118 midY = glucose.model.yMax/2;
119 midZ = TRAILER_DEPTH/2.;
123 eyeX = midX + eyeR*sin(eyeA);
124 eyeZ = midZ + eyeR*cos(eyeA);
125 addMouseWheelListener(new java.awt.event.MouseWheelListener() {
126 public void mouseWheelMoved(java.awt.event.MouseWheelEvent mwe) {
127 mouseWheel(mwe.getWheelRotation());
131 println("Total setup: " + (millis() - startMillis) + "ms");
132 println("Hit the 'p' key to toggle Panda Board output");
135 void controllerChangeReceived(rwmidi.Controller cc) {
137 println("CC: " + cc.toString());
141 void noteOnReceived(Note note) {
143 println("Note On: " + note.toString());
147 void noteOffReceived(Note note) {
149 println("Note Off: " + note.toString());
153 void logTime(String evt) {
155 println(evt + ": " + (now - lastMillis) + "ms");
160 // Draws the simulation and the 2D UI overlay
162 color[] colors = glucose.getColors();
164 debugUI.maskColors(colors);
175 drawBox(0, -TRAILER_HEIGHT, 0, 0, 0, 0, TRAILER_WIDTH, TRAILER_HEIGHT, TRAILER_DEPTH, TRAILER_HEIGHT/2.);
180 vertex(TRAILER_WIDTH, 0, 0);
181 vertex(TRAILER_WIDTH, 0, TRAILER_DEPTH);
182 vertex(0, 0, TRAILER_DEPTH);
187 drawBox(BASS_X, 0, BASS_Z, 0, 0, 0, BASS_WIDTH, BASS_HEIGHT, BASS_DEPTH, Cube.CHANNEL_WIDTH);
188 for (Cube c : glucose.model.cubes) {
195 for (Point p : glucose.model.points) {
196 stroke(colors[p.index]);
197 vertex(p.fx, p.fy, p.fz);
198 // println(p.fx + ":" + p.fy + ":" + p.fz);
204 javax.media.opengl.GL gl = ((PGraphicsOpenGL)g).beginGL();
205 gl.glClear(javax.media.opengl.GL.GL_DEPTH_BUFFER_BIT);
206 ((PGraphicsOpenGL)g).endGL();
214 // TODO(mcslee): move into GLucose engine
215 for (PandaDriver p : pandaBoards) {
220 void drawCube(Cube c) {
222 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);
225 void drawBox(float x, float y, float z, float rx, float ry, float rz, float xd, float yd, float zd, float sw) {
228 rotate(rx / 180. * PI, -1, 0, 0);
229 rotate(ry / 180. * PI, 0, -1, 0);
230 rotate(rz / 180. * PI, 0, 0, -1);
231 for (int i = 0; i < 4; ++i) {
232 float wid = (i % 2 == 0) ? xd : zd;
238 vertex(wid - sw, yd);
239 vertex(wid - sw, sw);
245 vertex(wid - sw, yd);
246 vertex(wid - sw, yd - sw);
251 translate(wid, 0, 0);
252 rotate(HALF_PI, 0, -1, 0);
267 int restoreToIndex = -1;
271 mappingTool.keyPressed();
276 frameRate(--targetFramerate);
280 frameRate(++targetFramerate);
283 debugMode = !debugMode;
284 println("Debug output: " + (debugMode ? "ON" : "OFF"));
287 mappingMode = !mappingMode;
289 LXPattern pattern = lx.getPattern();
290 for (int i = 0; i < patterns.length; ++i) {
291 if (pattern == patterns[i]) {
297 lx.setPatterns(new LXPattern[] { mappingTool });
300 lx.setPatterns(patterns);
301 lx.goIndex(restoreToIndex);
305 for (PandaDriver p : pandaBoards) {
316 void mousePressed() {
318 if (mouseX < ui.leftPos) {
320 debugUI.mousePressed();
327 void mouseDragged() {
328 if (mouseX > ui.leftPos) {
331 int dx = mouseX - mx;
332 int dy = mouseY - my;
336 eyeX = midX + eyeR*sin(eyeA);
337 eyeZ = midZ + eyeR*cos(eyeA);
342 void mouseReleased() {
346 void mouseWheel(int delta) {
347 if (mouseX > ui.leftPos) {
348 ui.mouseWheel(delta);
350 eyeR = constrain(eyeR - delta, -500, -80);
351 eyeX = midX + eyeR*sin(eyeA);
352 eyeZ = midZ + eyeR*cos(eyeA);