Pedantic perf thing, flatten raw int[] list instead of List<Integer> for slightly...
[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.*;
5d70e4d7 32import rwmidi.*;
49815cc0
MS
33
34final int VIEWPORT_WIDTH = 900;
35final int VIEWPORT_HEIGHT = 700;
36final int TARGET_FRAMERATE = 45;
37
38int startMillis, lastMillis;
39GLucose glucose;
40HeronLX lx;
41LXPattern[] patterns;
42LXTransition[] transitions;
43LXEffect[] effects;
44OverlayUI ui;
e73ef85d
MS
45PandaDriver pandaFront;
46PandaDriver pandaRear;
47
48boolean pandaBoardsEnabled = false;
49815cc0
MS
49
50void setup() {
51 startMillis = lastMillis = millis();
52
53 // Initialize the Processing graphics environment
54 size(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, OPENGL);
55 frameRate(TARGET_FRAMERATE);
3f8be614 56 noSmooth();
49815cc0
MS
57 // hint(ENABLE_OPENGL_4X_SMOOTH); // no discernable improvement?
58 logTime("Created viewport");
59
60 // Create the GLucose engine to run the cubes
1ecdb44a 61 glucose = new GLucose(this, new SCMapping());
49815cc0
MS
62 lx = glucose.lx;
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");
70 transitions = transitions(glucose);
71 logTime("Built transitions");
e73ef85d
MS
72
73 // Build output driver
74 int[][] frontChannels = glucose.mapping.buildFrontChannelList();
75 int[][] rearChannels = glucose.mapping.buildRearChannelList();
76 int[][] flippedRGB = glucose.mapping.buildFlippedRGBList();
77 pandaFront = new PandaDriver(new NetAddress("192.168.1.28", 9001), glucose.model, frontChannels, flippedRGB);
78 pandaRear = new PandaDriver(new NetAddress("192.168.1.29", 9001), glucose.model, rearChannels, flippedRGB);
79 logTime("Build PandaDriver");
49815cc0
MS
80
81 // Build overlay UI
82 ui = new OverlayUI();
83 logTime("Built overlay UI");
1ecdb44a 84
49815cc0 85 // MIDI devices
809f3518 86 SCMidiDevices.initializeStandardDevices(glucose, ui.patternKnobs, ui.transitionKnobs, ui.effectKnobs);
3f8be614 87 logTime("Setup MIDI devices");
49815cc0
MS
88
89 println("Total setup: " + (millis() - startMillis) + "ms");
e73ef85d 90 println("Hit the 'p' key to toggle Panda Board output");
49815cc0
MS
91}
92
93void logTime(String evt) {
94 int now = millis();
95 println(evt + ": " + (now - lastMillis) + "ms");
96 lastMillis = now;
97}
98
99void draw() {
100 // The glucose engine deals with the core simulation here, we don't need
101 // to do anything specific. This method just needs to exist.
e73ef85d
MS
102
103 // TODO(mcslee): move into GLucose engine
104 if (pandaBoardsEnabled) {
105 color[] colors = glucose.getColors();
106 pandaFront.send(colors);
107 pandaRear.send(colors);
108 }
49815cc0
MS
109}
110
111void drawUI() {
112 if (uiOn) {
113 ui.draw();
114 } else {
115 ui.drawHelpTip();
116 }
117 ui.drawFPS();
118}
119
120boolean uiOn = true;
3f8be614 121boolean knobsOn = true;
49815cc0 122void keyPressed() {
3f8be614 123 switch (key) {
e73ef85d
MS
124 case 'p':
125 pandaBoardsEnabled = !pandaBoardsEnabled;
126 println("PandaBoard Output: " + (pandaBoardsEnabled ? "ON" : "OFF"));
127 break;
3f8be614
MS
128 case 'u':
129 uiOn = !uiOn;
130 break;
131 case 'k':
132 knobsOn = !knobsOn;
133 break;
49815cc0
MS
134 }
135}
136
137