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