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;
58 float eyeR, eyeA, eyeX, eyeY, eyeZ, midX, midY, midZ;
61 startMillis = lastMillis = millis();
63 // Initialize the Processing graphics environment
64 size(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, OPENGL);
65 frameRate(targetFramerate);
67 // hint(ENABLE_OPENGL_4X_SMOOTH); // no discernable improvement?
68 logTime("Created viewport");
70 // Create the GLucose engine to run the cubes
71 glucose = new GLucose(this, new SCMapping());
73 lx.enableKeyboardTempo();
74 logTime("Built GLucose engine");
77 glucose.lx.setPatterns(patterns = patterns(glucose));
78 logTime("Built patterns");
79 glucose.lx.addEffects(effects = effects(glucose));
80 logTime("Built effects");
81 glucose.setTransitions(transitions = transitions(glucose));
82 logTime("Built transitions");
84 // Build output driver
85 int[][] frontChannels = glucose.mapping.buildFrontChannelList();
86 int[][] rearChannels = glucose.mapping.buildRearChannelList();
87 int[][] flippedRGB = glucose.mapping.buildFlippedRGBList();
88 mappingTool = new MappingTool(glucose, frontChannels, rearChannels);
89 pandaFront = new PandaDriver(new NetAddress("192.168.1.28", 9001), glucose.model, frontChannels, flippedRGB);
90 pandaRear = new PandaDriver(new NetAddress("192.168.1.29", 9001), glucose.model, rearChannels, flippedRGB);
91 logTime("Build PandaDriver");
94 ui = controlUI = new ControlUI();
95 mappingUI = new MappingUI(mappingTool);
96 logTime("Built overlay UI");
99 for (MidiInputDevice d : RWMidi.getInputDevices()) {
102 SCMidiDevices.initializeStandardDevices(glucose);
103 logTime("Setup MIDI devices");
106 midX = glucose.model.xMax/2 + 20;
107 midY = glucose.model.yMax/2;
108 midZ = glucose.model.zMax/2;
112 eyeX = midX + eyeR*sin(eyeA);
113 eyeZ = midZ + eyeR*cos(eyeA);
114 addMouseWheelListener(new java.awt.event.MouseWheelListener() {
115 public void mouseWheelMoved(java.awt.event.MouseWheelEvent mwe) {
116 mouseWheel(mwe.getWheelRotation());
120 println("Total setup: " + (millis() - startMillis) + "ms");
121 println("Hit the 'p' key to toggle Panda Board output");
124 void controllerChangeReceived(rwmidi.Controller cc) {
126 println("CC: " + cc.toString());
130 void noteOnReceived(Note note) {
132 println("Note On: " + note.toString());
136 void noteOffReceived(Note note) {
138 println("Note Off: " + note.toString());
142 void logTime(String evt) {
144 println(evt + ": " + (now - lastMillis) + "ms");
149 // Draws the simulation and the 2D UI overlay
151 color[] colors = glucose.getColors();
161 vertex(0, yFloor, 0);
162 vertex(glucose.model.xMax, yFloor, 0);
163 vertex(glucose.model.xMax, yFloor, glucose.model.zMax);
164 vertex(0, yFloor, glucose.model.zMax);
170 for (Point p : glucose.model.points) {
171 stroke(colors[p.index]);
172 vertex(p.fx, p.fy, p.fz);
178 javax.media.opengl.GL gl= ((PGraphicsOpenGL)g).beginGL();
179 gl.glClear(javax.media.opengl.GL.GL_DEPTH_BUFFER_BIT);
180 ((PGraphicsOpenGL)g).endGL();
184 // TODO(mcslee): move into GLucose engine
185 if (pandaBoardsEnabled) {
186 pandaFront.send(colors);
187 pandaRear.send(colors);
201 int restoreToIndex = -1;
205 mappingTool.keyPressed();
210 frameRate(--targetFramerate);
214 frameRate(++targetFramerate);
217 debugMode = !debugMode;
218 println("Debug output: " + (debugMode ? "ON" : "OFF"));
220 mappingMode = !mappingMode;
222 LXPattern pattern = lx.getPattern();
223 for (int i = 0; i < patterns.length; ++i) {
224 if (pattern == patterns[i]) {
230 lx.setPatterns(new LXPattern[] { mappingTool });
233 lx.setPatterns(patterns);
234 lx.goIndex(restoreToIndex);
238 pandaBoardsEnabled = !pandaBoardsEnabled;
239 println("PandaBoard Output: " + (pandaBoardsEnabled ? "ON" : "OFF"));
249 void mousePressed() {
250 if (mouseX > ui.leftPos) {
258 void mouseDragged() {
259 if (mouseX > ui.leftPos) {
262 int dx = mouseX - mx;
263 int dy = mouseY - my;
267 eyeX = midX + eyeR*sin(eyeA);
268 eyeZ = midZ + eyeR*cos(eyeA);
273 void mouseReleased() {
274 if (mouseX > ui.leftPos) {
279 void mouseWheel(int delta) {
280 eyeR = constrain(eyeR - delta, -500, -80);
281 eyeX = midX + eyeR*sin(eyeA);
282 eyeZ = midZ + eyeR*cos(eyeA);