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