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