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 int targetFramerate = 45;
39 int startMillis, lastMillis;
42 MappingTool mappingTool;
44 LXTransition[] transitions;
49 PandaDriver pandaFront;
50 PandaDriver pandaRear;
51 boolean mappingMode = false;
53 boolean pandaBoardsEnabled = false;
55 boolean debugMode = false;
59 float eyeR, eyeA, eyeX, eyeY, eyeZ, midX, midY, midZ;
62 startMillis = lastMillis = millis();
64 // Initialize the Processing graphics environment
65 size(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, OPENGL);
66 frameRate(targetFramerate);
68 // hint(ENABLE_OPENGL_4X_SMOOTH); // no discernable improvement?
69 logTime("Created viewport");
71 // Create the GLucose engine to run the cubes
72 glucose = new GLucose(this, new SCMapping());
74 lx.enableKeyboardTempo();
75 logTime("Built GLucose engine");
78 glucose.lx.setPatterns(patterns = patterns(glucose));
79 logTime("Built patterns");
80 glucose.lx.addEffects(effects = effects(glucose));
81 logTime("Built effects");
82 glucose.setTransitions(transitions = transitions(glucose));
83 logTime("Built transitions");
85 // Build output driver
86 int[][] frontChannels = glucose.mapping.buildFrontChannelList();
87 int[][] rearChannels = glucose.mapping.buildRearChannelList();
88 int[][] flippedRGB = glucose.mapping.buildFlippedRGBList();
89 mappingTool = new MappingTool(glucose, frontChannels, rearChannels);
90 pandaFront = new PandaDriver(new NetAddress("192.168.1.28", 9001), glucose.model, frontChannels, flippedRGB);
91 pandaRear = new PandaDriver(new NetAddress("192.168.1.29", 9001), glucose.model, rearChannels, flippedRGB);
92 logTime("Build PandaDriver");
95 ui = controlUI = new ControlUI();
96 mappingUI = new MappingUI(mappingTool);
97 debugUI = new DebugUI(frontChannels, rearChannels);
98 logTime("Built overlay UI");
101 for (MidiInputDevice d : RWMidi.getInputDevices()) {
104 SCMidiDevices.initializeStandardDevices(glucose);
105 logTime("Setup MIDI devices");
108 midX = glucose.model.xMax/2 + 20;
109 midY = glucose.model.yMax/2;
110 midZ = glucose.model.zMax/2;
114 eyeX = midX + eyeR*sin(eyeA);
115 eyeZ = midZ + eyeR*cos(eyeA);
116 addMouseWheelListener(new java.awt.event.MouseWheelListener() {
117 public void mouseWheelMoved(java.awt.event.MouseWheelEvent mwe) {
118 mouseWheel(mwe.getWheelRotation());
122 println("Total setup: " + (millis() - startMillis) + "ms");
123 println("Hit the 'p' key to toggle Panda Board output");
126 void controllerChangeReceived(rwmidi.Controller cc) {
128 println("CC: " + cc.toString());
132 void noteOnReceived(Note note) {
134 println("Note On: " + note.toString());
138 void noteOffReceived(Note note) {
140 println("Note Off: " + note.toString());
144 void logTime(String evt) {
146 println(evt + ": " + (now - lastMillis) + "ms");
151 // Draws the simulation and the 2D UI overlay
153 color[] colors = glucose.getColors();
155 debugUI.maskColors(colors);
167 vertex(0, yFloor, 0);
168 vertex(glucose.model.xMax, yFloor, 0);
169 vertex(glucose.model.xMax, yFloor, glucose.model.zMax);
170 vertex(0, yFloor, glucose.model.zMax);
176 for (Point p : glucose.model.points) {
177 stroke(colors[p.index]);
178 vertex(p.fx, p.fy, p.fz);
179 // println(p.fx + ":" + p.fy + ":" + p.fz);
185 javax.media.opengl.GL gl= ((PGraphicsOpenGL)g).beginGL();
186 gl.glClear(javax.media.opengl.GL.GL_DEPTH_BUFFER_BIT);
187 ((PGraphicsOpenGL)g).endGL();
195 // TODO(mcslee): move into GLucose engine
196 if (pandaBoardsEnabled) {
197 pandaFront.send(colors);
198 pandaRear.send(colors);
212 int restoreToIndex = -1;
216 mappingTool.keyPressed();
221 frameRate(--targetFramerate);
225 frameRate(++targetFramerate);
228 debugMode = !debugMode;
229 println("Debug output: " + (debugMode ? "ON" : "OFF"));
232 mappingMode = !mappingMode;
234 LXPattern pattern = lx.getPattern();
235 for (int i = 0; i < patterns.length; ++i) {
236 if (pattern == patterns[i]) {
242 lx.setPatterns(new LXPattern[] { mappingTool });
245 lx.setPatterns(patterns);
246 lx.goIndex(restoreToIndex);
250 pandaBoardsEnabled = !pandaBoardsEnabled;
251 println("PandaBoard Output: " + (pandaBoardsEnabled ? "ON" : "OFF"));
261 void mousePressed() {
262 if (mouseX > ui.leftPos) {
266 debugUI.mousePressed();
273 void mouseDragged() {
274 if (mouseX > ui.leftPos) {
277 int dx = mouseX - mx;
278 int dy = mouseY - my;
282 eyeX = midX + eyeR*sin(eyeA);
283 eyeZ = midZ + eyeR*cos(eyeA);
288 void mouseReleased() {
289 if (mouseX > ui.leftPos) {
294 void mouseWheel(int delta) {
295 eyeR = constrain(eyeR - delta, -500, -80);
296 eyeX = midX + eyeR*sin(eyeA);
297 eyeZ = midZ + eyeR*cos(eyeA);