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