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