Add a MIDI-responding piano key pattern that lights up cubes based on notes
[SugarCubes.git] / _Internals.pde
1 /**
2 * If you are an artist, you may ignore this file! It just sets
3 * up the framework to run the patterns. Should not need modification
4 * for general animation work.
5 */
6
7 import glucose.*;
8 import glucose.control.*;
9 import glucose.effect.*;
10 import glucose.pattern.*;
11 import glucose.transition.*;
12 import glucose.model.*;
13 import heronarts.lx.*;
14 import heronarts.lx.control.*;
15 import heronarts.lx.effect.*;
16 import heronarts.lx.pattern.*;
17 import heronarts.lx.modulator.*;
18 import heronarts.lx.transition.*;
19 import ddf.minim.*;
20 import ddf.minim.analysis.*;
21 import processing.opengl.*;
22 import java.lang.reflect.*;
23 import rwmidi.*;
24
25 final int VIEWPORT_WIDTH = 900;
26 final int VIEWPORT_HEIGHT = 700;
27 final int TARGET_FRAMERATE = 45;
28
29 int startMillis, lastMillis;
30 GLucose glucose;
31 HeronLX lx;
32 LXPattern[] patterns;
33 LXTransition[] transitions;
34 LXEffect[] effects;
35 OverlayUI ui;
36
37 void setup() {
38 startMillis = lastMillis = millis();
39
40 // Initialize the Processing graphics environment
41 size(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, OPENGL);
42 frameRate(TARGET_FRAMERATE);
43 noSmooth();
44 // hint(ENABLE_OPENGL_4X_SMOOTH); // no discernable improvement?
45 logTime("Created viewport");
46
47 // Create the GLucose engine to run the cubes
48 glucose = new GLucose(this);
49 lx = glucose.lx;
50 logTime("Built GLucose engine");
51
52 // Set the patterns
53 glucose.lx.setPatterns(patterns = patterns(glucose));
54 logTime("Built patterns");
55 glucose.lx.addEffects(effects = effects(glucose));
56 logTime("Built effects");
57 transitions = transitions(glucose);
58 logTime("Built transitions");
59
60 // Build overlay UI
61 ui = new OverlayUI();
62 logTime("Built overlay UI");
63
64 // MIDI devices
65 SCMidiDevices.initializeStandardDevices(glucose, ui.patternKnobs, ui.transitionKnobs, ui.effectKnobs);
66 logTime("Setup MIDI devices");
67
68 println("Total setup: " + (millis() - startMillis) + "ms");
69 }
70
71 void logTime(String evt) {
72 int now = millis();
73 println(evt + ": " + (now - lastMillis) + "ms");
74 lastMillis = now;
75 }
76
77 void draw() {
78 // The glucose engine deals with the core simulation here, we don't need
79 // to do anything specific. This method just needs to exist.
80 }
81
82 void drawUI() {
83 if (uiOn) {
84 ui.draw();
85 } else {
86 ui.drawHelpTip();
87 }
88 ui.drawFPS();
89 }
90
91 boolean uiOn = true;
92 boolean knobsOn = true;
93 void keyPressed() {
94 switch (key) {
95 case 'u':
96 uiOn = !uiOn;
97 break;
98 case 'k':
99 knobsOn = !knobsOn;
100 break;
101 }
102 }
103
104