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