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