-
Notifications
You must be signed in to change notification settings - Fork 7
/
dome.pde
312 lines (266 loc) · 8.92 KB
/
dome.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/**
* Importing a bunch of stuff.
* Artists, keep scrolling to add your patterns.
*/
import wblut.math.*;
import wblut.processing.*;
import wblut.core.*;
import wblut.hemesh.*;
import wblut.geom.*;
import heronarts.lx.*;
import heronarts.lx.audio.*;
import heronarts.lx.color.*;
import heronarts.lx.effect.*;
import heronarts.lx.midi.*;
import heronarts.lx.model.*;
import heronarts.lx.modulator.*;
import heronarts.lx.output.*;
import heronarts.lx.parameter.*;
import heronarts.lx.pattern.*;
import heronarts.p3lx.*;
import heronarts.p3lx.ui.*;
import heronarts.p3lx.ui.control.*;
import heronarts.p3lx.ui.component.*;
import java.util.Arrays;
import java.util.List;
import java.util.Collections;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Iterator;
import java.util.Random;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.Line;
import javax.sound.sampled.Mixer;
import javax.sound.sampled.TargetDataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.midi.ShortMessage;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiDevice;
import javax.sound.midi.MidiUnavailableException;
/**
* This is the code to be thrown at LEDome!
*
* This Processing sketch is a fun place to build animations, effects, and
* interactions for the LEDome. Most of the ugly modeling and mapping code
* is contained in the LEDome class and setup files.
* artist, you shouldn't need to worry about any of that.
*
* Below, you will find definitions of the Patterns, (and eventually) Effects,
* and Interactions.
*
* If you're an artist, create a new tab in the Processing environment with
* your name. Implement your classes there, and add them to the list below.
*/
// The raspberry pi can't render 3d out of the box.
// Set RENDER_3D to false to avoid using OpenGL.
// TODO: see if this is true any more with processing 3
final static boolean RENDER_3D = true;
final static int AUTO_TRANSITION_SECONDS = 45;
LEDome model;
LXStudio lx;
LXPattern[] patterns(P3LX lx) {
return new LXPattern[] {
// Create New Pattern Instances Below HERE
new ShadyWaffle(lx),
// Slee
new ClockPattern(lx),
// BKudria
new Beachball(lx),
new Breather(lx),
// Heather
new BeatDancers(lx),
new ClapDancers(lx),
// L8on
new L8onMixColor(lx),
new DomeEQ(lx),
new DomeInvertEQ(lx),
new JumpRopes(lx),
new Marbles(lx),
new Explosions(lx),
new Darksplosions(lx),
new AudioBelts(lx),
new Snakes(lx),
new SnakeApple(lx),
new SpotLights(lx),
new DarkLights(lx),
new Life(lx),
new HeartsBeat(lx),
new Balls(lx),
new DarkBalls(lx),
new SurroundWave(lx),
new ThunderStorm(lx),
new SpinEQ(lx),
new SunriseSunsetRainbow(lx),
new SunriseSunsetReal(lx),
new SunriseSunsetStargaze(lx),
// Cackler
new Stargaze(lx),
new ColorSpiral(lx),
new Rings(lx),
// Kristján
//new Disco(lx),
// pld
new Spiral(lx),
// rohan
//new Sunshine(lx),
//new SunshineHalf(lx),
// Test Patterns
new LayerDemoPattern(lx),
// new FaceIteratorTest(lx),
// new EdgeIteratorTest(lx),
// new HueTestPattern(lx),
// new IteratorTestPattern(lx)
};
}
WB_Render render;
LEDomeOutputManager outputManager;
LEDomeAudioParameterManager audioParameterManager;
KorgNanoKontrol2 nanoKontrol2 = null;
LXStudio.UI lxUI = null;
// TODO: get C-Media audio card and create class to manage input
void settings() {
size(1024, 768, P3D);
}
void setup() {
surface.setResizable(true);
if (RENDER_3D) {
surface.setSize(displayWidth, displayHeight);
}
// Create LEDome instance
model = new LEDome();
// Create the LXStudio engine
lx = new LXStudio(this, model) {
@Override
protected void initialize(LXStudio lx, LXStudio.UI ui) {
// Add custom LXComponents or LXOutput objects to the engine here,
// before the UI is constructed
// Create the NDB output manager
outputManager = new LEDomeOutputManager(lx);
outputManager.addLXOutputForNDB();
// Find CableCreation input if available and set by default
String[] deviceNames = lx.engine.audio.input.device.getOptions();
for (int i = 0; i < deviceNames.length; i++) {
if(deviceNames[i].startsWith("CableCreation")) {
lx.engine.audio.input.device.setValue(i);
}
}
}
@Override
protected void onUIReady(LXStudio lx, LXStudio.UI ui) {
// The UI is now ready, can add custom UI components if desired
lxUI = ui;
if (RENDER_3D) {
ui.preview.addComponent(new UIDome());
} else {
ui.removeLayer(ui.preview);
}
}
};
// Create audio parameter manager before setting up patterns so the listner will work out of the box
audioParameterManager = new LEDomeAudioParameterManager(lx, lx.engine.audio.enabled);
setupPatterns();
setupEffects();
setupMidiDevices();
if (RENDER_3D) {
lx.engine.output.enabled.setValue(false);
} else {
// Start up network output immediately if no 3d
lx.engine.output.enabled.setValue(true);
lx.enableAutoTransition(AUTO_TRANSITION_SECONDS);
}
// Set the hue mode of the palette to cycle through all the colors.
lx.palette.hueMode.setValue(2);
LXChannel channel = (LXChannel)lx.engine.getFocusedChannel();
channel.transitionEnabled.setValue(true);
channel.transitionTimeSecs.setValue(3);
// Set the audio input to be on by default
if (lx.engine.audio.input.device.getRange() > 0 || RENDER_3D) {
lx.engine.audio.enabled.setValue(true);
}
}
void setupPatterns() {
LXPattern[] domePatterns = patterns(lx);
LXChannel channel = (LXChannel)lx.engine.getFocusedChannel();
// LXStudio has to load with at least 1 pattern.
// We save it here so we can remove it immediately.
LXPattern initalPattern = channel.getPatterns().get(0);
// Add all patterns from the main list.
for (LXPattern pattern: domePatterns) {
channel.addPattern(pattern);
}
// Remove the initial pattern
channel.removePattern(initalPattern);
}
void setupEffects() {
lx.addEffects(effects(lx));
}
TargetDataLine findCableCreationTargetDataLine(AudioFormat format) {
DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
TargetDataLine.Info cableCreationTargetInfo = null;
Mixer cableCreationMixer = null;
Mixer.Info[] mixers = AudioSystem.getMixerInfo();
for (Mixer.Info mixerInfo : mixers) {
System.out.println("Found Mixer: " + mixerInfo);
System.out.println("Mixer name: " + mixerInfo.getName());
if(mixerInfo.getName().startsWith("CableCreation")) {
System.out.println("Found CableCreation mixer");
cableCreationMixer = AudioSystem.getMixer(mixerInfo);
Line.Info[] lines = cableCreationMixer.getTargetLineInfo(info);
cableCreationTargetInfo = (TargetDataLine.Info) lines[0];
break;
}
}
if(cableCreationTargetInfo == null || cableCreationMixer == null) {
return null;
}
try {
return (TargetDataLine) cableCreationMixer.getLine(cableCreationTargetInfo);
} catch(LineUnavailableException x) {
System.err.println(x.getLocalizedMessage());
return null;
}
}
void setupMidiDevices() {
MidiDevice.Info[] deviceInfos = MidiSystem.getMidiDeviceInfo();
println("There are " + deviceInfos.length + " midi devices");
for (MidiDevice.Info deviceInfo : CoreMidiDeviceProvider.getMidiDeviceInfo()) {
//for (MidiDevice.Info deviceInfo : MidiSystem.getMidiDeviceInfo()) {
println("Here be a midi device: " + deviceInfo.getName());
//try {
// MidiDevice device = MidiSystem.getMidiDevice(deviceInfo);
// println("Here be a midi device: " + deviceInfo);
// //if (device.getMaxTransmitters() != 0) {
// // mutableInputs.add(new LXMidiInput(LXMidiEngine.this, device));
// //}
// //if (device.getMaxReceivers() != 0) {
// // mutableOutputs.add(new LXMidiOutput(LXMidiEngine.this, device));
// //}
//} catch (MidiUnavailableException mux) {
// mux.printStackTrace();
//}
}
LXMidiInput korgNanoControl2Input = lx.engine.midi.matchInput(KorgNanoKontrol2.DEVICE_NAMES);
if (korgNanoControl2Input == null) {
println("Midi Remote not connected");
return;
}
nanoKontrol2 = new KorgNanoKontrol2(korgNanoControl2Input, lx);
korgNanoControl2Input.addListener(new KorgNanoKontrol2MidiListener(lx, nanoKontrol2));
lx.engine.getDefaultChannel().addListener(new KorgNanoKontrol2MidiListener(lx, nanoKontrol2));
nanoKontrol2.getInput().open();
println("The device is connected?");
}
// LXStudio handles all the drawing.
void draw() {
}
LXEffect[] effects(P3LX lx) {
return new LXEffect[] {
new ExplosionEffect(lx),
new FlashEffect(lx),
new DesaturationEffect(lx),
new BlurEffect(lx)
};
}