APC40 is mapped, update UI to reflect that and use GLucose internals
[SugarCubes.git] / _Internals.pde
CommitLineData
49815cc0 1/**
1ecdb44a
MS
2 * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND
3 *
4 * //\\ //\\ //\\ //\\
5 * ///\\\ ///\\\ ///\\\ ///\\\
6 * \\\/// \\\/// \\\/// \\\///
7 * \\// \\// \\// \\//
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
16import glucose.*;
17import glucose.control.*;
3f8be614 18import glucose.effect.*;
f3f5a876 19import glucose.model.*;
49815cc0 20import glucose.pattern.*;
f3f5a876 21import glucose.transform.*;
49815cc0 22import glucose.transition.*;
49815cc0 23import heronarts.lx.*;
3f8be614 24import heronarts.lx.control.*;
49815cc0 25import heronarts.lx.effect.*;
49815cc0 26import heronarts.lx.modulator.*;
f3f5a876 27import heronarts.lx.pattern.*;
49815cc0
MS
28import heronarts.lx.transition.*;
29import ddf.minim.*;
30import ddf.minim.analysis.*;
31import processing.opengl.*;
32import java.lang.reflect.*;
5d70e4d7 33import rwmidi.*;
49815cc0
MS
34
35final int VIEWPORT_WIDTH = 900;
36final int VIEWPORT_HEIGHT = 700;
37final int TARGET_FRAMERATE = 45;
38
39int startMillis, lastMillis;
40GLucose glucose;
41HeronLX lx;
42LXPattern[] patterns;
43LXTransition[] transitions;
44LXEffect[] effects;
45OverlayUI ui;
49815cc0 46
cc9fcf4b
MS
47boolean debugMode = false;
48
49815cc0
MS
49void setup() {
50 startMillis = lastMillis = millis();
51
52 // Initialize the Processing graphics environment
53 size(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, OPENGL);
54 frameRate(TARGET_FRAMERATE);
3f8be614 55 noSmooth();
49815cc0
MS
56 // hint(ENABLE_OPENGL_4X_SMOOTH); // no discernable improvement?
57 logTime("Created viewport");
58
59 // Create the GLucose engine to run the cubes
1ecdb44a 60 glucose = new GLucose(this, new SCMapping());
49815cc0 61 lx = glucose.lx;
cc9fcf4b 62 lx.enableKeyboardTempo();
49815cc0
MS
63 logTime("Built GLucose engine");
64
65 // Set the patterns
66 glucose.lx.setPatterns(patterns = patterns(glucose));
67 logTime("Built patterns");
68 glucose.lx.addEffects(effects = effects(glucose));
69 logTime("Built effects");
cc9fcf4b 70 glucose.setTransitions(transitions = transitions(glucose));
49815cc0
MS
71 logTime("Built transitions");
72
73 // Build overlay UI
74 ui = new OverlayUI();
75 logTime("Built overlay UI");
1ecdb44a 76
49815cc0 77 // MIDI devices
cc9fcf4b
MS
78 for (MidiInputDevice d : RWMidi.getInputDevices()) {
79 d.createInput(this);
80 }
81 SCMidiDevices.initializeStandardDevices(glucose);
3f8be614 82 logTime("Setup MIDI devices");
49815cc0
MS
83
84 println("Total setup: " + (millis() - startMillis) + "ms");
85}
86
cc9fcf4b
MS
87void controllerChangeReceived(rwmidi.Controller cc) {
88 if (debugMode) {
89 println("CC: " + cc.toString());
90 }
91}
92
93void noteOnReceived(Note note) {
94 if (debugMode) {
95 println("Note On: " + note.toString());
96 }
97}
98
99void noteOffReceived(Note note) {
100 if (debugMode) {
101 println("Note Off: " + note.toString());
102 }
103}
104
49815cc0
MS
105void logTime(String evt) {
106 int now = millis();
107 println(evt + ": " + (now - lastMillis) + "ms");
108 lastMillis = now;
109}
110
111void draw() {
112 // The glucose engine deals with the core simulation here, we don't need
113 // to do anything specific. This method just needs to exist.
114}
115
116void drawUI() {
117 if (uiOn) {
118 ui.draw();
119 } else {
120 ui.drawHelpTip();
121 }
122 ui.drawFPS();
123}
124
125boolean uiOn = true;
3f8be614 126boolean knobsOn = true;
49815cc0 127void keyPressed() {
3f8be614 128 switch (key) {
cc9fcf4b
MS
129 case 'd':
130 debugMode = !debugMode;
131 println("Debug output: " + (debugMode ? "ON" : "OFF"));
132 break;
3f8be614
MS
133 case 'u':
134 uiOn = !uiOn;
135 break;
49815cc0
MS
136 }
137}
138
139