merged slee's lx changes
[SugarCubes.git] / _Internals.pde
CommitLineData
49815cc0 1/**
1ecdb44a
MS
2 * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND
3 *
4 * //\\ //\\ //\\ //\\
5 * ///\\\ ///\\\ ///\\\ ///\\\
6 * \\\/// \\\/// \\\/// \\\///
d12e46b6 7 * \\// \\// \\// \\//H
1ecdb44a
MS
8 *
9 * EXPERTS ONLY!! EXPERTS ONLY!!
10 *
49815cc0
MS
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.
14 */
15
16import glucose.*;
f3f5a876 17import glucose.model.*;
49815cc0
MS
18import heronarts.lx.*;
19import heronarts.lx.effect.*;
49815cc0 20import heronarts.lx.modulator.*;
b8bb2748 21import heronarts.lx.parameter.*;
f3f5a876 22import heronarts.lx.pattern.*;
9fa29818 23import heronarts.lx.transform.*;
49815cc0
MS
24import heronarts.lx.transition.*;
25import ddf.minim.*;
26import ddf.minim.analysis.*;
27import processing.opengl.*;
5d70e4d7 28import rwmidi.*;
24fc0330 29import java.lang.reflect.*;
49815cc0
MS
30
31final int VIEWPORT_WIDTH = 900;
32final int VIEWPORT_HEIGHT = 700;
0e3c5542 33
92c06c97 34// The trailer is measured from the outside of the black metal (but not including the higher welded part on the front)
87998ff3
MS
35final float TRAILER_WIDTH = 240;
36final float TRAILER_DEPTH = 97;
37final float TRAILER_HEIGHT = 33;
38
3fa45e9e
AG
39final int MaxCubeHeight = 7;
40final int NumBackTowers = 18;
7e3329d2 41
51d0d59a 42int targetFramerate = 60;
49815cc0 43int startMillis, lastMillis;
a898d79b
MS
44
45// Core engine variables
49815cc0 46GLucose glucose;
d12e46b6 47LX lx;
49815cc0 48LXPattern[] patterns;
24fc0330 49Effects effects;
a898d79b 50MappingTool mappingTool;
79ae8245 51PandaDriver[] pandaBoards;
e0794d3a 52PresetManager presetManager;
1f974cbc 53MidiEngine midiEngine;
a898d79b
MS
54
55// Display configuration mode
bf551144 56boolean mappingMode = false;
cc9fcf4b 57boolean debugMode = false;
554e38ff 58DebugUI debugUI;
34327c96 59boolean uiOn = true;
7974acd6 60boolean simulationOn = true;
73678c57 61boolean diagnosticsOn = false;
34327c96 62LXPattern restoreToPattern = null;
4c640acc 63PImage logo;
a41f334c 64float[] hsb = new float[3];
d626bc9b 65
a898d79b 66// Handles to UI objects
d626bc9b
MS
67UIContext[] overlays;
68UIPatternDeck uiPatternA;
a898d79b 69UICrossfader uiCrossfader;
a8d55ade 70UIMidi uiMidi;
d626bc9b
MS
71UIMapping uiMapping;
72UIDebugText uiDebugText;
fa4f822d 73UISpeed uiSpeed;
cc9fcf4b 74
0a9f99cc 75// Camera variables
bda5421d 76float eyeR, eyeA, eyeX, eyeY, eyeZ, midX, midY, midZ;
0a9f99cc 77
34327c96
MS
78/**
79 * Engine construction and initialization.
80 */
d1dcc4b5
MS
81
82LXTransition _transition(GLucose glucose) {
83 return new DissolveTransition(glucose.lx).setDuration(1000);
84}
85
86LXPattern[] _leftPatterns(GLucose glucose) {
d626bc9b
MS
87 LXPattern[] patterns = patterns(glucose);
88 for (LXPattern p : patterns) {
d1dcc4b5 89 p.setTransition(_transition(glucose));
d626bc9b
MS
90 }
91 return patterns;
92}
93
d1dcc4b5
MS
94LXPattern[] _rightPatterns(GLucose glucose) {
95 LXPattern[] patterns = _leftPatterns(glucose);
96 LXPattern[] rightPatterns = new LXPattern[patterns.length+1];
97 int i = 0;
98 rightPatterns[i++] = new BlankPattern(glucose).setTransition(_transition(glucose));
99 for (LXPattern p : patterns) {
100 rightPatterns[i++] = p;
101 }
102 return rightPatterns;
103}
24fc0330
MS
104
105LXEffect[] _effectsArray(Effects effects) {
106 List<LXEffect> effectList = new ArrayList<LXEffect>();
107 for (Field f : effects.getClass().getDeclaredFields()) {
108 try {
109 Object val = f.get(effects);
110 if (val instanceof LXEffect) {
111 effectList.add((LXEffect)val);
112 }
113 } catch (IllegalAccessException iax) {}
114 }
115 return effectList.toArray(new LXEffect[]{});
116}
d1dcc4b5 117
34327c96
MS
118void logTime(String evt) {
119 int now = millis();
120 println(evt + ": " + (now - lastMillis) + "ms");
121 lastMillis = now;
122}
123
49815cc0
MS
124void setup() {
125 startMillis = lastMillis = millis();
126
127 // Initialize the Processing graphics environment
128 size(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, OPENGL);
0e3c5542 129 frameRate(targetFramerate);
3f8be614 130 noSmooth();
49815cc0
MS
131 // hint(ENABLE_OPENGL_4X_SMOOTH); // no discernable improvement?
132 logTime("Created viewport");
133
134 // Create the GLucose engine to run the cubes
186bc4d3 135 glucose = new GLucose(this, buildModel());
49815cc0 136 lx = glucose.lx;
cc9fcf4b 137 lx.enableKeyboardTempo();
49815cc0 138 logTime("Built GLucose engine");
2bb56822 139
49815cc0 140 // Set the patterns
42a424d7 141 LXEngine engine = lx.engine;
d1dcc4b5
MS
142 engine.setPatterns(patterns = _leftPatterns(glucose));
143 engine.addDeck(_rightPatterns(glucose));
49815cc0 144 logTime("Built patterns");
a898d79b
MS
145 glucose.setTransitions(transitions(glucose));
146 logTime("Built transitions");
24fc0330 147 glucose.lx.addEffects(_effectsArray(effects = new Effects()));
49815cc0 148 logTime("Built effects");
4214e9a2 149
e0794d3a
MS
150 // Preset manager
151 presetManager = new PresetManager();
152 logTime("Loaded presets");
4214e9a2 153
1f974cbc
MS
154 // MIDI devices
155 midiEngine = new MidiEngine();
1f974cbc
MS
156 logTime("Setup MIDI devices");
157
e73ef85d 158 // Build output driver
186bc4d3 159 PandaMapping[] pandaMappings = buildPandaList();
45f43cc2
MS
160 pandaBoards = new PandaDriver[pandaMappings.length];
161 int pbi = 0;
162 for (PandaMapping pm : pandaMappings) {
44b8de9c 163 pandaBoards[pbi++] = new PandaDriver(pm.ip, glucose.model, pm);
45f43cc2
MS
164 }
165 mappingTool = new MappingTool(glucose, pandaMappings);
166 logTime("Built PandaDriver");
a8d55ade 167
49815cc0 168 // Build overlay UI
45f43cc2 169 debugUI = new DebugUI(pandaMappings);
d626bc9b 170 overlays = new UIContext[] {
42a424d7 171 uiPatternA = new UIPatternDeck(lx.engine.getDeck(GLucose.LEFT_DECK), "PATTERN A", 4, 4, 140, 324),
a8d55ade
MS
172 new UIBlendMode(4, 332, 140, 86),
173 new UIEffects(4, 422, 140, 144),
174 new UITempo(4, 570, 140, 50),
fa4f822d 175 uiSpeed = new UISpeed(4, 624, 140, 50),
a8d55ade 176
42a424d7 177 new UIPatternDeck(lx.engine.getDeck(GLucose.RIGHT_DECK), "PATTERN B", width-144, 4, 140, 324),
d6ac1ee8 178 uiMidi = new UIMidi(midiEngine, width-144, 332, 140, 158),
4df91daf 179 new UIOutput(width-144, 494, 140, 106),
d626bc9b 180
a8d55ade 181 uiCrossfader = new UICrossfader(width/2-90, height-90, 180, 86),
d626bc9b 182
a8d55ade
MS
183 uiDebugText = new UIDebugText(148, height-138, width-304, 44),
184 uiMapping = new UIMapping(mappingTool, 4, 4, 140, 324),
d626bc9b
MS
185 };
186 uiMapping.setVisible(false);
49815cc0 187 logTime("Built overlay UI");
4c640acc
MS
188
189 // Load logo image
190 logo = loadImage("data/logo.png");
191
0a9f99cc 192 // Setup camera
d626bc9b 193 midX = TRAILER_WIDTH/2.;
0a9f99cc 194 midY = glucose.model.yMax/2;
e0cea600
MS
195 midZ = TRAILER_DEPTH/2.;
196 eyeR = -290;
0a9f99cc 197 eyeA = .15;
d626bc9b 198 eyeY = midY + 70;
0a9f99cc
MS
199 eyeX = midX + eyeR*sin(eyeA);
200 eyeZ = midZ + eyeR*cos(eyeA);
d6ac1ee8
MS
201
202 // Add mouse scrolling event support
bda5421d
MS
203 addMouseWheelListener(new java.awt.event.MouseWheelListener() {
204 public void mouseWheelMoved(java.awt.event.MouseWheelEvent mwe) {
205 mouseWheel(mwe.getWheelRotation());
206 }});
207
49815cc0 208 println("Total setup: " + (millis() - startMillis) + "ms");
e73ef85d 209 println("Hit the 'p' key to toggle Panda Board output");
49815cc0
MS
210}
211
34327c96
MS
212/**
213 * Core render loop and drawing functionality.
214 */
49815cc0 215void draw() {
73678c57
MS
216 long drawStart = System.nanoTime();
217
0a9f99cc
MS
218 // Draws the simulation and the 2D UI overlay
219 background(40);
a898d79b 220
19d16a16
MS
221 color[] simulationColors;
222 color[] sendColors;
223 simulationColors = sendColors = glucose.getColors();
a898d79b 224 String displayMode = uiCrossfader.getDisplayMode();
d626bc9b 225 if (displayMode == "A") {
6b3d53ca 226 simulationColors = lx.engine.getDeck(GLucose.LEFT_DECK).getColors();
d626bc9b 227 } else if (displayMode == "B") {
6b3d53ca 228 simulationColors = lx.engine.getDeck(GLucose.RIGHT_DECK).getColors();
d626bc9b 229 }
554e38ff 230 if (debugMode) {
19d16a16
MS
231 debugUI.maskColors(simulationColors);
232 debugUI.maskColors(sendColors);
554e38ff 233 }
51d0d59a 234
73678c57 235 long simulationStart = System.nanoTime();
7974acd6
MS
236 if (simulationOn) {
237 drawSimulation(simulationColors);
238 }
73678c57 239 long simulationNanos = System.nanoTime() - simulationStart;
7974acd6
MS
240
241 // 2D Overlay UI
73678c57 242 long uiStart = System.nanoTime();
7974acd6 243 drawUI();
73678c57
MS
244 long uiNanos = System.nanoTime() - uiStart;
245
246 long gammaStart = System.nanoTime();
7974acd6
MS
247 // Gamma correction here. Apply a cubic to the brightness
248 // for better representation of dynamic range
249 for (int i = 0; i < sendColors.length; ++i) {
250 lx.RGBtoHSB(sendColors[i], hsb);
251 float b = hsb[2];
252 sendColors[i] = lx.hsb(360.*hsb[0], 100.*hsb[1], 100.*(b*b*b));
253 }
73678c57 254 long gammaNanos = System.nanoTime() - gammaStart;
7974acd6 255
73678c57 256 long sendStart = System.nanoTime();
7974acd6
MS
257 for (PandaDriver p : pandaBoards) {
258 p.send(sendColors);
259 }
73678c57
MS
260 long sendNanos = System.nanoTime() - sendStart;
261
262 long drawNanos = System.nanoTime() - drawStart;
263
264 if (diagnosticsOn) {
ef7118ad 265 drawDiagnostics(drawNanos, simulationNanos, uiNanos, gammaNanos, sendNanos);
73678c57
MS
266 }
267}
268
ef7118ad 269void drawDiagnostics(long drawNanos, long simulationNanos, long uiNanos, long gammaNanos, long sendNanos) {
73678c57
MS
270 float ws = 4 / 1000000.;
271 int thirtyfps = 1000000000 / 30;
272 int sixtyfps = 1000000000 / 60;
273 int x = width - 138;
274 int y = height - 14;
275 int h = 10;
276 noFill();
277 stroke(#999999);
278 rect(x, y, thirtyfps * ws, h);
279 noStroke();
280 int xp = x;
281 float hv = 0;
ef7118ad 282 for (long val : new long[] {lx.timer.drawNanos, simulationNanos, uiNanos, gammaNanos, sendNanos }) {
73678c57
MS
283 fill(lx.hsb(hv % 360, 100, 80));
284 rect(xp, y, val * ws, h-1);
285 hv += 140;
286 xp += val * ws;
287 }
288 noFill();
289 stroke(#333333);
290 line(x+sixtyfps*ws, y+1, x+sixtyfps*ws, y+h-1);
ef7118ad
MS
291
292 y = y - 14;
293 xp = x;
294 float tw = thirtyfps * ws;
295 noFill();
296 stroke(#999999);
297 rect(x, y, tw, h);
bae2197a 298 h = 5;
ef7118ad
MS
299 noStroke();
300 for (long val : new long[] {
301 lx.engine.timer.deckNanos,
bae2197a 302 lx.engine.timer.copyNanos,
ef7118ad
MS
303 lx.engine.timer.fxNanos}) {
304 float amt = val / (float) lx.timer.drawNanos;
305 fill(lx.hsb(hv % 360, 100, 80));
306 rect(xp, y, amt * tw, h-1);
307 hv += 140;
308 xp += amt * tw;
bae2197a
MS
309 }
310
311 xp = x;
312 y += h;
313 hv = 120;
314 for (long val : new long[] {
315 lx.engine.getDeck(0).timer.runNanos,
316 lx.engine.getDeck(1).timer.runNanos,
317 lx.engine.getDeck(1).getFaderTransition().timer.blendNanos}) {
318 float amt = val / (float) lx.timer.drawNanos;
319 fill(lx.hsb(hv % 360, 100, 80));
320 rect(xp, y, amt * tw, h-1);
321 hv += 140;
322 xp += amt * tw;
323 }
7974acd6
MS
324}
325
326void drawSimulation(color[] simulationColors) {
2bb56822 327 camera(
0a9f99cc
MS
328 eyeX, eyeY, eyeZ,
329 midX, midY, midZ,
330 0, -1, 0
331 );
51d0d59a 332
a8d55ade 333 translate(0, 40, 0);
d626bc9b 334
51d0d59a
MS
335 noStroke();
336 fill(#141414);
87998ff3 337 drawBox(0, -TRAILER_HEIGHT, 0, 0, 0, 0, TRAILER_WIDTH, TRAILER_HEIGHT, TRAILER_DEPTH, TRAILER_HEIGHT/2.);
51d0d59a
MS
338 fill(#070707);
339 stroke(#222222);
0a9f99cc 340 beginShape();
51d0d59a 341 vertex(0, 0, 0);
87998ff3
MS
342 vertex(TRAILER_WIDTH, 0, 0);
343 vertex(TRAILER_WIDTH, 0, TRAILER_DEPTH);
344 vertex(0, 0, TRAILER_DEPTH);
51d0d59a 345 endShape();
4c640acc
MS
346
347 // Draw the logo on the front of platform
348 pushMatrix();
349 translate(0, 0, -1);
350 float s = .07;
351 scale(s, -s, s);
352 image(logo, TRAILER_WIDTH/2/s-logo.width/2, TRAILER_HEIGHT/2/s-logo.height/2-2/s);
353 popMatrix();
0a9f99cc 354
51d0d59a 355 noStroke();
e89eda9f
MS
356 if (glucose.model.bassBox.exists) {
357 drawBassBox(glucose.model.bassBox, false);
358 }
359 for (Speaker speaker : glucose.model.speakers) {
360 drawSpeaker(speaker);
361 }
51d0d59a
MS
362 for (Cube c : glucose.model.cubes) {
363 drawCube(c);
364 }
365
0a9f99cc
MS
366 noFill();
367 strokeWeight(2);
368 beginShape(POINTS);
2bb56822 369 for (LXPoint p : glucose.model.points) {
19d16a16 370 stroke(simulationColors[p.index]);
190d91c2 371 vertex(p.x, p.y, p.z);
0a9f99cc
MS
372 }
373 endShape();
49815cc0
MS
374}
375
e89eda9f
MS
376void drawBassBox(BassBox b, boolean hasSub) {
377
92c06c97 378 float in = .15;
e89eda9f
MS
379
380 if (hasSub) {
381 noStroke();
382 fill(#191919);
383 pushMatrix();
384 translate(b.x + BassBox.EDGE_WIDTH/2., b.y + BassBox.EDGE_HEIGHT/2, b.z + BassBox.EDGE_DEPTH/2.);
385 box(BassBox.EDGE_WIDTH-20*in, BassBox.EDGE_HEIGHT-20*in, BassBox.EDGE_DEPTH-20*in);
386 popMatrix();
387 }
e76480d4
MS
388
389 noStroke();
390 fill(#393939);
92c06c97
MS
391 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);
392
39011e7e
MS
393 pushMatrix();
394 translate(b.x+(Cube.CHANNEL_WIDTH-in)/2., b.y + BassBox.EDGE_HEIGHT-in, b.z + BassBox.EDGE_DEPTH/2.);
395 float lastOffset = 0;
396 for (float offset : BoothFloor.STRIP_OFFSETS) {
397 translate(offset - lastOffset, 0, 0);
398 box(Cube.CHANNEL_WIDTH-in, 0, BassBox.EDGE_DEPTH - 2*in);
399 lastOffset = offset;
400 }
401 popMatrix();
402
92c06c97
MS
403 pushMatrix();
404 translate(b.x + (Cube.CHANNEL_WIDTH-in)/2., b.y + BassBox.EDGE_HEIGHT/2., b.z + in);
405 for (int j = 0; j < 2; ++j) {
406 pushMatrix();
407 for (int i = 0; i < BassBox.NUM_FRONT_STRUTS; ++i) {
408 translate(BassBox.FRONT_STRUT_SPACING, 0, 0);
409 box(Cube.CHANNEL_WIDTH-in, BassBox.EDGE_HEIGHT - in*2, 0);
410 }
411 popMatrix();
412 translate(0, 0, BassBox.EDGE_DEPTH - 2*in);
413 }
414 popMatrix();
415
416 pushMatrix();
417 translate(b.x + in, b.y + BassBox.EDGE_HEIGHT/2., b.z + BassBox.SIDE_STRUT_SPACING + (Cube.CHANNEL_WIDTH-in)/2.);
418 box(0, BassBox.EDGE_HEIGHT - in*2, Cube.CHANNEL_WIDTH-in);
419 translate(BassBox.EDGE_WIDTH-2*in, 0, 0);
420 box(0, BassBox.EDGE_HEIGHT - in*2, Cube.CHANNEL_WIDTH-in);
ab77005f 421 popMatrix();
e76480d4 422
92c06c97
MS
423}
424
51d0d59a 425void drawCube(Cube c) {
254d34c0 426 float in = .15;
e76480d4
MS
427 noStroke();
428 fill(#393939);
254d34c0 429 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);
51d0d59a
MS
430}
431
e76480d4
MS
432void drawSpeaker(Speaker s) {
433 float in = .15;
434
435 noStroke();
436 fill(#191919);
437 pushMatrix();
438 translate(s.x, s.y, s.z);
439 rotate(s.ry / 180. * PI, 0, -1, 0);
440 translate(Speaker.EDGE_WIDTH/2., Speaker.EDGE_HEIGHT/2., Speaker.EDGE_DEPTH/2.);
441 box(Speaker.EDGE_WIDTH-20*in, Speaker.EDGE_HEIGHT-20*in, Speaker.EDGE_DEPTH-20*in);
254fbb68
MS
442 translate(0, Speaker.EDGE_HEIGHT/2. + Speaker.EDGE_HEIGHT*.8/2, 0);
443
444 fill(#222222);
445 box(Speaker.EDGE_WIDTH*.6, Speaker.EDGE_HEIGHT*.8, Speaker.EDGE_DEPTH*.75);
e76480d4
MS
446 popMatrix();
447
e76480d4
MS
448 noStroke();
449 fill(#393939);
450 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);
ab77005f 451}
e76480d4 452
51d0d59a
MS
453void drawBox(float x, float y, float z, float rx, float ry, float rz, float xd, float yd, float zd, float sw) {
454 pushMatrix();
455 translate(x, y, z);
e0cea600 456 rotate(rx / 180. * PI, -1, 0, 0);
51d0d59a 457 rotate(ry / 180. * PI, 0, -1, 0);
e0cea600 458 rotate(rz / 180. * PI, 0, 0, -1);
51d0d59a
MS
459 for (int i = 0; i < 4; ++i) {
460 float wid = (i % 2 == 0) ? xd : zd;
461
462 beginShape();
463 vertex(0, 0);
464 vertex(wid, 0);
465 vertex(wid, yd);
466 vertex(wid - sw, yd);
467 vertex(wid - sw, sw);
468 vertex(0, sw);
469 endShape();
470 beginShape();
471 vertex(0, sw);
472 vertex(0, yd);
473 vertex(wid - sw, yd);
474 vertex(wid - sw, yd - sw);
475 vertex(sw, yd - sw);
476 vertex(sw, sw);
477 endShape();
478
479 translate(wid, 0, 0);
480 rotate(HALF_PI, 0, -1, 0);
481 }
482 popMatrix();
483}
484
49815cc0 485void drawUI() {
d626bc9b
MS
486 camera();
487 javax.media.opengl.GL gl = ((PGraphicsOpenGL)g).beginGL();
488 gl.glClear(javax.media.opengl.GL.GL_DEPTH_BUFFER_BIT);
489 ((PGraphicsOpenGL)g).endGL();
490 strokeWeight(1);
491
49815cc0 492 if (uiOn) {
d626bc9b
MS
493 for (UIContext context : overlays) {
494 context.draw();
495 }
496 }
497
498 // Always draw FPS meter
499 fill(#555555);
500 textSize(9);
501 textAlign(LEFT, BASELINE);
502 text("FPS: " + ((int) (frameRate*10)) / 10. + " / " + targetFramerate + " (-/+)", 4, height-4);
503
504 if (debugMode) {
505 debugUI.draw();
49815cc0 506 }
49815cc0
MS
507}
508
4c640acc 509
34327c96
MS
510/**
511 * Top-level keyboard event handling
512 */
49815cc0 513void keyPressed() {
bf551144 514 if (mappingMode) {
d626bc9b 515 mappingTool.keyPressed(uiMapping);
bf551144 516 }
3f8be614 517 switch (key) {
2b068dd5
MS
518 case '1':
519 case '2':
520 case '3':
521 case '4':
522 case '5':
523 case '6':
524 case '7':
525 case '8':
526 if (!midiEngine.isQwertyEnabled()) {
527 presetManager.select(midiEngine.getFocusedDeck(), key - '1');
528 }
529 break;
530
531 case '!':
532 if (!midiEngine.isQwertyEnabled()) presetManager.store(midiEngine.getFocusedDeck(), 0);
533 break;
534 case '@':
535 if (!midiEngine.isQwertyEnabled()) presetManager.store(midiEngine.getFocusedDeck(), 1);
536 break;
537 case '#':
538 if (!midiEngine.isQwertyEnabled()) presetManager.store(midiEngine.getFocusedDeck(), 2);
539 break;
540 case '$':
541 if (!midiEngine.isQwertyEnabled()) presetManager.store(midiEngine.getFocusedDeck(), 3);
542 break;
543 case '%':
544 if (!midiEngine.isQwertyEnabled()) presetManager.store(midiEngine.getFocusedDeck(), 4);
545 break;
546 case '^':
547 if (!midiEngine.isQwertyEnabled()) presetManager.store(midiEngine.getFocusedDeck(), 5);
548 break;
549 case '&':
550 if (!midiEngine.isQwertyEnabled()) presetManager.store(midiEngine.getFocusedDeck(), 6);
551 break;
552 case '*':
553 if (!midiEngine.isQwertyEnabled()) presetManager.store(midiEngine.getFocusedDeck(), 7);
554 break;
555
0e3c5542
MS
556 case '-':
557 case '_':
558 frameRate(--targetFramerate);
559 break;
560 case '=':
561 case '+':
562 frameRate(++targetFramerate);
75e1ddde
MS
563 break;
564 case 'b':
24fc0330 565 effects.boom.trigger();
75e1ddde 566 break;
cc9fcf4b 567 case 'd':
d6ac1ee8 568 if (!midiEngine.isQwertyEnabled()) {
a8d55ade
MS
569 debugMode = !debugMode;
570 println("Debug output: " + (debugMode ? "ON" : "OFF"));
571 }
554e38ff 572 break;
bf551144 573 case 'm':
d6ac1ee8 574 if (!midiEngine.isQwertyEnabled()) {
a8d55ade
MS
575 mappingMode = !mappingMode;
576 uiPatternA.setVisible(!mappingMode);
577 uiMapping.setVisible(mappingMode);
578 if (mappingMode) {
579 restoreToPattern = lx.getPattern();
580 lx.setPatterns(new LXPattern[] { mappingTool });
581 } else {
582 lx.setPatterns(patterns);
583 LXTransition pop = restoreToPattern.getTransition();
584 restoreToPattern.setTransition(null);
585 lx.goPattern(restoreToPattern);
586 restoreToPattern.setTransition(pop);
587 }
bf551144
MS
588 }
589 break;
19d16a16
MS
590 case 't':
591 if (!midiEngine.isQwertyEnabled()) {
592 lx.engine.setThreaded(!lx.engine.isThreaded());
593 }
594 break;
e73ef85d 595 case 'p':
79ae8245
MS
596 for (PandaDriver p : pandaBoards) {
597 p.toggle();
598 }
cc9fcf4b 599 break;
73678c57
MS
600 case 'q':
601 if (!midiEngine.isQwertyEnabled()) {
602 diagnosticsOn = !diagnosticsOn;
603 }
604 break;
7974acd6
MS
605 case 's':
606 if (!midiEngine.isQwertyEnabled()) {
607 simulationOn = !simulationOn;
608 }
609 break;
3f8be614 610 case 'u':
d6ac1ee8 611 if (!midiEngine.isQwertyEnabled()) {
4df91daf
MS
612 uiOn = !uiOn;
613 }
3f8be614 614 break;
49815cc0
MS
615 }
616}
617
34327c96
MS
618/**
619 * Top-level mouse event handling
620 */
0a9f99cc 621int mx, my;
0a9f99cc 622void mousePressed() {
d626bc9b
MS
623 boolean debugged = false;
624 if (debugMode) {
625 debugged = debugUI.mousePressed();
626 }
627 if (!debugged) {
628 for (UIContext context : overlays) {
629 context.mousePressed(mouseX, mouseY);
630 }
0a9f99cc 631 }
d626bc9b
MS
632 mx = mouseX;
633 my = mouseY;
0a9f99cc
MS
634}
635
636void mouseDragged() {
d626bc9b
MS
637 boolean dragged = false;
638 for (UIContext context : overlays) {
639 dragged |= context.mouseDragged(mouseX, mouseY);
640 }
641 if (!dragged) {
0a9f99cc
MS
642 int dx = mouseX - mx;
643 int dy = mouseY - my;
644 mx = mouseX;
645 my = mouseY;
646 eyeA += dx*.003;
647 eyeX = midX + eyeR*sin(eyeA);
648 eyeZ = midZ + eyeR*cos(eyeA);
649 eyeY += dy;
650 }
651}
652
653void mouseReleased() {
d626bc9b
MS
654 for (UIContext context : overlays) {
655 context.mouseReleased(mouseX, mouseY);
656 }
0a9f99cc 657}
73687629 658
a0140e21 659void mouseWheel(int delta) {
d626bc9b
MS
660 boolean wheeled = false;
661 for (UIContext context : overlays) {
662 wheeled |= context.mouseWheel(mouseX, mouseY, delta);
663 }
664
665 if (!wheeled) {
0ba6ac44
MS
666 eyeR = constrain(eyeR - delta, -500, -80);
667 eyeX = midX + eyeR*sin(eyeA);
668 eyeZ = midZ + eyeR*cos(eyeA);
669 }
bda5421d 670}