Commit | Line | Data |
---|---|---|
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 | ||
16 | import glucose.*; | |
17 | import glucose.control.*; | |
3f8be614 | 18 | import glucose.effect.*; |
f3f5a876 | 19 | import glucose.model.*; |
49815cc0 | 20 | import glucose.pattern.*; |
f3f5a876 | 21 | import glucose.transform.*; |
49815cc0 | 22 | import glucose.transition.*; |
49815cc0 | 23 | import heronarts.lx.*; |
3f8be614 | 24 | import heronarts.lx.control.*; |
49815cc0 | 25 | import heronarts.lx.effect.*; |
49815cc0 | 26 | import heronarts.lx.modulator.*; |
f3f5a876 | 27 | import heronarts.lx.pattern.*; |
49815cc0 MS |
28 | import heronarts.lx.transition.*; |
29 | import ddf.minim.*; | |
30 | import ddf.minim.analysis.*; | |
31 | import processing.opengl.*; | |
5d70e4d7 | 32 | import rwmidi.*; |
49815cc0 MS |
33 | |
34 | final int VIEWPORT_WIDTH = 900; | |
35 | final int VIEWPORT_HEIGHT = 700; | |
0e3c5542 MS |
36 | |
37 | int targetFramerate = 30; | |
49815cc0 MS |
38 | |
39 | int startMillis, lastMillis; | |
40 | GLucose glucose; | |
41 | HeronLX lx; | |
bf551144 | 42 | MappingTool mappingTool; |
49815cc0 MS |
43 | LXPattern[] patterns; |
44 | LXTransition[] transitions; | |
45 | LXEffect[] effects; | |
46 | OverlayUI ui; | |
bf551144 MS |
47 | ControlUI controlUI; |
48 | MappingUI mappingUI; | |
e73ef85d MS |
49 | PandaDriver pandaFront; |
50 | PandaDriver pandaRear; | |
bf551144 | 51 | boolean mappingMode = false; |
e73ef85d MS |
52 | |
53 | boolean pandaBoardsEnabled = false; | |
49815cc0 | 54 | |
cc9fcf4b MS |
55 | boolean debugMode = false; |
56 | ||
49815cc0 MS |
57 | void setup() { |
58 | startMillis = lastMillis = millis(); | |
59 | ||
60 | // Initialize the Processing graphics environment | |
61 | size(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, OPENGL); | |
0e3c5542 | 62 | frameRate(targetFramerate); |
3f8be614 | 63 | noSmooth(); |
49815cc0 MS |
64 | // hint(ENABLE_OPENGL_4X_SMOOTH); // no discernable improvement? |
65 | logTime("Created viewport"); | |
66 | ||
67 | // Create the GLucose engine to run the cubes | |
1ecdb44a | 68 | glucose = new GLucose(this, new SCMapping()); |
49815cc0 | 69 | lx = glucose.lx; |
cc9fcf4b | 70 | lx.enableKeyboardTempo(); |
49815cc0 MS |
71 | logTime("Built GLucose engine"); |
72 | ||
73 | // Set the patterns | |
74 | glucose.lx.setPatterns(patterns = patterns(glucose)); | |
75 | logTime("Built patterns"); | |
76 | glucose.lx.addEffects(effects = effects(glucose)); | |
77 | logTime("Built effects"); | |
cc9fcf4b | 78 | glucose.setTransitions(transitions = transitions(glucose)); |
49815cc0 | 79 | logTime("Built transitions"); |
e73ef85d MS |
80 | |
81 | // Build output driver | |
82 | int[][] frontChannels = glucose.mapping.buildFrontChannelList(); | |
83 | int[][] rearChannels = glucose.mapping.buildRearChannelList(); | |
84 | int[][] flippedRGB = glucose.mapping.buildFlippedRGBList(); | |
2bae07c9 | 85 | mappingTool = new MappingTool(glucose, frontChannels, rearChannels); |
e73ef85d MS |
86 | pandaFront = new PandaDriver(new NetAddress("192.168.1.28", 9001), glucose.model, frontChannels, flippedRGB); |
87 | pandaRear = new PandaDriver(new NetAddress("192.168.1.29", 9001), glucose.model, rearChannels, flippedRGB); | |
88 | logTime("Build PandaDriver"); | |
49815cc0 MS |
89 | |
90 | // Build overlay UI | |
bf551144 MS |
91 | ui = controlUI = new ControlUI(); |
92 | mappingUI = new MappingUI(mappingTool); | |
49815cc0 | 93 | logTime("Built overlay UI"); |
1ecdb44a | 94 | |
49815cc0 | 95 | // MIDI devices |
cc9fcf4b MS |
96 | for (MidiInputDevice d : RWMidi.getInputDevices()) { |
97 | d.createInput(this); | |
98 | } | |
99 | SCMidiDevices.initializeStandardDevices(glucose); | |
3f8be614 | 100 | logTime("Setup MIDI devices"); |
49815cc0 MS |
101 | |
102 | println("Total setup: " + (millis() - startMillis) + "ms"); | |
e73ef85d | 103 | println("Hit the 'p' key to toggle Panda Board output"); |
49815cc0 MS |
104 | } |
105 | ||
cc9fcf4b MS |
106 | void controllerChangeReceived(rwmidi.Controller cc) { |
107 | if (debugMode) { | |
108 | println("CC: " + cc.toString()); | |
109 | } | |
110 | } | |
111 | ||
112 | void noteOnReceived(Note note) { | |
113 | if (debugMode) { | |
114 | println("Note On: " + note.toString()); | |
115 | } | |
116 | } | |
117 | ||
118 | void noteOffReceived(Note note) { | |
119 | if (debugMode) { | |
120 | println("Note Off: " + note.toString()); | |
121 | } | |
122 | } | |
123 | ||
49815cc0 MS |
124 | void logTime(String evt) { |
125 | int now = millis(); | |
126 | println(evt + ": " + (now - lastMillis) + "ms"); | |
127 | lastMillis = now; | |
128 | } | |
129 | ||
130 | void draw() { | |
131 | // The glucose engine deals with the core simulation here, we don't need | |
132 | // to do anything specific. This method just needs to exist. | |
e73ef85d MS |
133 | |
134 | // TODO(mcslee): move into GLucose engine | |
135 | if (pandaBoardsEnabled) { | |
136 | color[] colors = glucose.getColors(); | |
137 | pandaFront.send(colors); | |
138 | pandaRear.send(colors); | |
139 | } | |
49815cc0 MS |
140 | } |
141 | ||
142 | void drawUI() { | |
143 | if (uiOn) { | |
144 | ui.draw(); | |
145 | } else { | |
146 | ui.drawHelpTip(); | |
147 | } | |
148 | ui.drawFPS(); | |
149 | } | |
150 | ||
151 | boolean uiOn = true; | |
bf551144 MS |
152 | int restoreToIndex = -1; |
153 | ||
49815cc0 | 154 | void keyPressed() { |
bf551144 MS |
155 | if (mappingMode) { |
156 | mappingTool.keyPressed(); | |
157 | } | |
3f8be614 | 158 | switch (key) { |
0e3c5542 MS |
159 | case '-': |
160 | case '_': | |
161 | frameRate(--targetFramerate); | |
162 | break; | |
163 | case '=': | |
164 | case '+': | |
165 | frameRate(++targetFramerate); | |
166 | break; | |
cc9fcf4b MS |
167 | case 'd': |
168 | debugMode = !debugMode; | |
169 | println("Debug output: " + (debugMode ? "ON" : "OFF")); | |
bf551144 MS |
170 | case 'm': |
171 | mappingMode = !mappingMode; | |
172 | if (mappingMode) { | |
173 | LXPattern pattern = lx.getPattern(); | |
174 | for (int i = 0; i < patterns.length; ++i) { | |
175 | if (pattern == patterns[i]) { | |
176 | restoreToIndex = i; | |
177 | break; | |
178 | } | |
179 | } | |
180 | ui = mappingUI; | |
181 | lx.setPatterns(new LXPattern[] { mappingTool }); | |
182 | } else { | |
183 | ui = controlUI; | |
184 | lx.setPatterns(patterns); | |
185 | lx.goIndex(restoreToIndex); | |
186 | } | |
187 | break; | |
e73ef85d MS |
188 | case 'p': |
189 | pandaBoardsEnabled = !pandaBoardsEnabled; | |
190 | println("PandaBoard Output: " + (pandaBoardsEnabled ? "ON" : "OFF")); | |
cc9fcf4b | 191 | break; |
3f8be614 MS |
192 | case 'u': |
193 | uiOn = !uiOn; | |
194 | break; | |
49815cc0 MS |
195 | } |
196 | } | |
197 | ||
198 |