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.model.*;
18 import heronarts.lx.*;
19 import heronarts.lx.effect.*;
20 import heronarts.lx.modulator.*;
21 import heronarts.lx.parameter.*;
22 import heronarts.lx.pattern.*;
23 import heronarts.lx.transform.*;
24 import heronarts.lx.transition.*;
25 import heronarts.lx.ui.*;
26 import heronarts.lx.ui.component.*;
27 import heronarts.lx.ui.control.*;
29 import ddf.minim.analysis.*;
30 import processing.opengl.*;
32 import java.lang.reflect.*;
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;
43 int startMillis, lastMillis;
45 // Core engine variables
51 MappingTool mappingTool;
52 GrizzlyOutput[] grizzlies;
53 PresetManager presetManager;
54 MidiEngine midiEngine;
56 // Display configuration mode
57 boolean mappingMode = false;
58 boolean debugMode = false;
59 boolean simulationOn = true;
60 boolean diagnosticsOn = false;
61 LXPattern restoreToPattern = null;
63 float[] hsb = new float[3];
65 // Handles to UI objects
66 UIPatternDeck uiPatternA;
67 UICrossfader uiCrossfader;
70 UIDebugText uiDebugText;
74 * Engine construction and initialization.
77 LXTransition _transition(GLucose glucose) {
78 return new DissolveTransition(glucose.lx).setDuration(1000);
81 LXPattern[] _leftPatterns(GLucose glucose) {
82 LXPattern[] patterns = patterns(glucose);
83 for (LXPattern p : patterns) {
84 p.setTransition(_transition(glucose));
89 LXPattern[] _rightPatterns(GLucose glucose) {
90 LXPattern[] patterns = _leftPatterns(glucose);
91 LXPattern[] rightPatterns = new LXPattern[patterns.length+1];
93 rightPatterns[i++] = new BlankPattern(glucose).setTransition(_transition(glucose));
94 for (LXPattern p : patterns) {
95 rightPatterns[i++] = p;
100 LXEffect[] _effectsArray(Effects effects) {
101 List<LXEffect> effectList = new ArrayList<LXEffect>();
102 for (Field f : effects.getClass().getDeclaredFields()) {
104 Object val = f.get(effects);
105 if (val instanceof LXEffect) {
106 effectList.add((LXEffect)val);
108 } catch (IllegalAccessException iax) {}
110 return effectList.toArray(new LXEffect[]{});
113 void logTime(String evt) {
115 println(evt + ": " + (now - lastMillis) + "ms");
120 startMillis = lastMillis = millis();
122 // Initialize the Processing graphics environment
123 size(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, OPENGL);
124 frameRate(targetFramerate);
126 // hint(ENABLE_OPENGL_4X_SMOOTH); // no discernable improvement?
127 logTime("Created viewport");
129 // Create the GLucose engine to run the cubes
130 glucose = new GLucose(this, model = buildModel());
132 lx.enableKeyboardTempo();
133 logTime("Built GLucose engine");
136 LXEngine engine = lx.engine;
137 engine.setPatterns(patterns = _leftPatterns(glucose));
138 engine.addDeck(_rightPatterns(glucose));
139 logTime("Built patterns");
140 glucose.setTransitions(transitions(glucose));
141 logTime("Built transitions");
142 glucose.lx.addEffects(_effectsArray(effects = new Effects()));
143 logTime("Built effects");
146 presetManager = new PresetManager();
147 logTime("Loaded presets");
150 midiEngine = new MidiEngine();
151 logTime("Setup MIDI devices");
153 // Build output driver
154 grizzlies = new GrizzlyOutput[]{};
156 grizzlies = buildGrizzlies();
157 for (LXOutput output : grizzlies) {
158 lx.addOutput(output);
160 } catch (Exception x) {
163 logTime("Built Grizzly Outputs");
166 mappingTool = new MappingTool(glucose);
169 UILayer[] layers = new UILayer[] {
171 new UICameraLayer(lx.ui)
172 .setCenter(TRAILER_WIDTH/2., glucose.model.yMax/2, TRAILER_DEPTH/2.)
173 .setRadius(290).addComponent(new UICubesLayer()),
176 uiPatternA = new UIPatternDeck(lx.ui, lx.engine.getDeck(GLucose.LEFT_DECK), "PATTERN A", 4, 4, 140, 324),
177 new UIBlendMode(4, 332, 140, 86),
178 new UIEffects(4, 422, 140, 144),
179 new UITempo(4, 570, 140, 50),
180 uiSpeed = new UISpeed(4, 624, 140, 50),
183 new UIPatternDeck(lx.ui, lx.engine.getDeck(GLucose.RIGHT_DECK), "PATTERN B", width-144, 4, 140, 324),
184 uiMidi = new UIMidi(midiEngine, width-144, 332, 140, 158),
185 new UIOutput(grizzlies, width-144, 494, 140, 106),
188 uiCrossfader = new UICrossfader(width/2-90, height-90, 180, 86),
191 uiDebugText = new UIDebugText(148, height-138, width-304, 44),
192 uiMapping = new UIMapping(mappingTool, 4, 4, 140, 324)
194 uiMapping.setVisible(false);
195 for (UILayer layer : layers) {
196 lx.ui.addLayer(layer);
201 logo = loadImage("data/logo.png");
202 logTime("Loaded logo image");
204 println("Total setup: " + (millis() - startMillis) + "ms");
205 println("Hit the 'o' key to toggle live output");
209 * Core render loop and drawing functionality.
212 long drawStart = System.nanoTime();
218 color[] sendColors = glucose.getColors();
219 long gammaStart = System.nanoTime();
220 // Gamma correction here. Apply a cubic to the brightness
221 // for better representation of dynamic range
222 for (int i = 0; i < sendColors.length; ++i) {
223 lx.RGBtoHSB(sendColors[i], hsb);
225 sendColors[i] = lx.hsb(360.*hsb[0], 100.*hsb[1], 100.*(b*b*b));
227 long gammaNanos = System.nanoTime() - gammaStart;
229 // Always draw FPS meter
233 long drawNanos = System.nanoTime() - drawStart;
235 long simulationNanos = 0, uiNanos = 0;
237 drawDiagnostics(drawNanos, simulationNanos, uiNanos, gammaNanos);
241 class UICubesLayer extends UICameraComponent {
243 color[] simulationColors = glucose.getColors();
244 String displayMode = uiCrossfader.getDisplayMode();
245 if (displayMode == "A") {
246 simulationColors = lx.engine.getDeck(GLucose.LEFT_DECK).getColors();
247 } else if (displayMode == "B") {
248 simulationColors = lx.engine.getDeck(GLucose.RIGHT_DECK).getColors();
251 long simulationStart = System.nanoTime();
253 drawSimulation(simulationColors);
255 long simulationNanos = System.nanoTime() - simulationStart;
258 javax.media.opengl.GL gl = ((PGraphicsOpenGL)g).beginGL();
259 gl.glClear(javax.media.opengl.GL.GL_DEPTH_BUFFER_BIT);
260 ((PGraphicsOpenGL)g).endGL();
265 void drawDiagnostics(long drawNanos, long simulationNanos, long uiNanos, long gammaNanos) {
266 float ws = 4 / 1000000.;
267 int thirtyfps = 1000000000 / 30;
268 int sixtyfps = 1000000000 / 60;
274 rect(x, y, thirtyfps * ws, h);
278 for (long val : new long[] {lx.timer.drawNanos, simulationNanos, uiNanos, gammaNanos, lx.timer.outputNanos }) {
279 fill(lx.hsb(hv % 360, 100, 80));
280 rect(xp, y, val * ws, h-1);
286 line(x+sixtyfps*ws, y+1, x+sixtyfps*ws, y+h-1);
290 float tw = thirtyfps * ws;
296 for (long val : new long[] {
297 lx.engine.timer.deckNanos,
298 lx.engine.timer.copyNanos,
299 lx.engine.timer.fxNanos}) {
300 float amt = val / (float) lx.timer.drawNanos;
301 fill(lx.hsb(hv % 360, 100, 80));
302 rect(xp, y, amt * tw, h-1);
310 for (long val : new long[] {
311 lx.engine.getDeck(0).timer.runNanos,
312 lx.engine.getDeck(1).timer.runNanos,
313 lx.engine.getDeck(1).getFaderTransition().timer.blendNanos}) {
314 float amt = val / (float) lx.timer.drawNanos;
315 fill(lx.hsb(hv % 360, 100, 80));
316 rect(xp, y, amt * tw, h-1);
322 void drawSimulation(color[] simulationColors) {
327 drawBox(0, -TRAILER_HEIGHT, 0, 0, 0, 0, TRAILER_WIDTH, TRAILER_HEIGHT, TRAILER_DEPTH, TRAILER_HEIGHT/2.);
332 vertex(TRAILER_WIDTH, 0, 0);
333 vertex(TRAILER_WIDTH, 0, TRAILER_DEPTH);
334 vertex(0, 0, TRAILER_DEPTH);
337 // Draw the logo on the front of platform
342 image(logo, TRAILER_WIDTH/2/s-logo.width/2, TRAILER_HEIGHT/2/s-logo.height/2-2/s);
346 if (glucose.model.bassBox.exists) {
347 drawBassBox(glucose.model.bassBox, false);
349 for (Speaker speaker : glucose.model.speakers) {
350 drawSpeaker(speaker);
352 for (Cube c : glucose.model.cubes) {
359 for (LXPoint p : glucose.model.points) {
360 stroke(simulationColors[p.index]);
361 vertex(p.x, p.y, p.z);
366 void drawBassBox(BassBox b, boolean hasSub) {
374 translate(b.x + BassBox.EDGE_WIDTH/2., b.y + BassBox.EDGE_HEIGHT/2, b.z + BassBox.EDGE_DEPTH/2.);
375 box(BassBox.EDGE_WIDTH-20*in, BassBox.EDGE_HEIGHT-20*in, BassBox.EDGE_DEPTH-20*in);
381 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);
384 translate(b.x+(Cube.CHANNEL_WIDTH-in)/2., b.y + BassBox.EDGE_HEIGHT-in, b.z + BassBox.EDGE_DEPTH/2.);
385 float lastOffset = 0;
386 for (float offset : BoothFloor.STRIP_OFFSETS) {
387 translate(offset - lastOffset, 0, 0);
388 box(Cube.CHANNEL_WIDTH-in, 0, BassBox.EDGE_DEPTH - 2*in);
394 translate(b.x + (Cube.CHANNEL_WIDTH-in)/2., b.y + BassBox.EDGE_HEIGHT/2., b.z + in);
395 for (int j = 0; j < 2; ++j) {
397 for (int i = 0; i < BassBox.NUM_FRONT_STRUTS; ++i) {
398 translate(BassBox.FRONT_STRUT_SPACING, 0, 0);
399 box(Cube.CHANNEL_WIDTH-in, BassBox.EDGE_HEIGHT - in*2, 0);
402 translate(0, 0, BassBox.EDGE_DEPTH - 2*in);
407 translate(b.x + in, b.y + BassBox.EDGE_HEIGHT/2., b.z + BassBox.SIDE_STRUT_SPACING + (Cube.CHANNEL_WIDTH-in)/2.);
408 box(0, BassBox.EDGE_HEIGHT - in*2, Cube.CHANNEL_WIDTH-in);
409 translate(BassBox.EDGE_WIDTH-2*in, 0, 0);
410 box(0, BassBox.EDGE_HEIGHT - in*2, Cube.CHANNEL_WIDTH-in);
415 void drawCube(Cube c) {
419 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);
422 void drawSpeaker(Speaker s) {
428 translate(s.x, s.y, s.z);
429 rotate(s.ry / 180. * PI, 0, -1, 0);
430 translate(Speaker.EDGE_WIDTH/2., Speaker.EDGE_HEIGHT/2., Speaker.EDGE_DEPTH/2.);
431 box(Speaker.EDGE_WIDTH-20*in, Speaker.EDGE_HEIGHT-20*in, Speaker.EDGE_DEPTH-20*in);
432 translate(0, Speaker.EDGE_HEIGHT/2. + Speaker.EDGE_HEIGHT*.8/2, 0);
435 box(Speaker.EDGE_WIDTH*.6, Speaker.EDGE_HEIGHT*.8, Speaker.EDGE_DEPTH*.75);
440 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);
443 void drawBox(float x, float y, float z, float rx, float ry, float rz, float xd, float yd, float zd, float sw) {
446 rotate(rx / 180. * PI, -1, 0, 0);
447 rotate(ry / 180. * PI, 0, -1, 0);
448 rotate(rz / 180. * PI, 0, 0, -1);
449 for (int i = 0; i < 4; ++i) {
450 float wid = (i % 2 == 0) ? xd : zd;
456 vertex(wid - sw, yd);
457 vertex(wid - sw, sw);
463 vertex(wid - sw, yd);
464 vertex(wid - sw, yd - sw);
469 translate(wid, 0, 0);
470 rotate(HALF_PI, 0, -1, 0);
476 // Always draw FPS meter
479 textAlign(LEFT, BASELINE);
480 text("FPS: " + ((int) (frameRate*10)) / 10. + " / " + targetFramerate + " (-/+)", 4, height-4);
485 * Top-level keyboard event handling
489 mappingTool.keyPressed(uiMapping);
500 if (!midiEngine.isQwertyEnabled()) {
501 presetManager.select(midiEngine.getFocusedDeck(), key - '1');
506 if (!midiEngine.isQwertyEnabled()) presetManager.store(midiEngine.getFocusedDeck(), 0);
509 if (!midiEngine.isQwertyEnabled()) presetManager.store(midiEngine.getFocusedDeck(), 1);
512 if (!midiEngine.isQwertyEnabled()) presetManager.store(midiEngine.getFocusedDeck(), 2);
515 if (!midiEngine.isQwertyEnabled()) presetManager.store(midiEngine.getFocusedDeck(), 3);
518 if (!midiEngine.isQwertyEnabled()) presetManager.store(midiEngine.getFocusedDeck(), 4);
521 if (!midiEngine.isQwertyEnabled()) presetManager.store(midiEngine.getFocusedDeck(), 5);
524 if (!midiEngine.isQwertyEnabled()) presetManager.store(midiEngine.getFocusedDeck(), 6);
527 if (!midiEngine.isQwertyEnabled()) presetManager.store(midiEngine.getFocusedDeck(), 7);
532 frameRate(--targetFramerate);
536 frameRate(++targetFramerate);
539 effects.boom.trigger();
542 if (!midiEngine.isQwertyEnabled()) {
543 debugMode = !debugMode;
544 println("Debug output: " + (debugMode ? "ON" : "OFF"));
548 if (!midiEngine.isQwertyEnabled()) {
549 mappingMode = !mappingMode;
550 uiPatternA.setVisible(!mappingMode);
551 uiMapping.setVisible(mappingMode);
553 restoreToPattern = lx.getPattern();
554 lx.setPatterns(new LXPattern[] { mappingTool });
556 lx.setPatterns(patterns);
557 LXTransition pop = restoreToPattern.getTransition();
558 restoreToPattern.setTransition(null);
559 lx.goPattern(restoreToPattern);
560 restoreToPattern.setTransition(pop);
565 if (!midiEngine.isQwertyEnabled()) {
566 lx.engine.setThreaded(!lx.engine.isThreaded());
571 for (LXOutput output : grizzlies) {
572 output.enabled.toggle();
576 if (!midiEngine.isQwertyEnabled()) {
577 diagnosticsOn = !diagnosticsOn;
581 if (!midiEngine.isQwertyEnabled()) {
582 simulationOn = !simulationOn;