Commit | Line | Data |
---|---|---|
cc9e8c8b | 1 | import java.util.Stack; |
616d4f9e MS |
2 | class Cathedrals extends SCPattern { |
3 | ||
4 | private final BasicParameter xpos = new BasicParameter("XPOS", 0.5); | |
5 | private final BasicParameter wid = new BasicParameter("WID", 0.5); | |
6 | private final BasicParameter arms = new BasicParameter("ARMS", 0.5); | |
7 | private final BasicParameter sat = new BasicParameter("SAT", 0.5); | |
8 | private GraphicEQ eq; | |
9 | ||
dde75983 MS |
10 | Cathedrals(LX lx) { |
11 | super(lx); | |
616d4f9e MS |
12 | addParameter(xpos); |
13 | addParameter(wid); | |
14 | addParameter(arms); | |
15 | addParameter(sat); | |
16 | } | |
17 | ||
4e6626a9 | 18 | void onActive() { |
616d4f9e MS |
19 | if (eq == null) { |
20 | eq = new GraphicEQ(lx, 16); | |
21 | eq.slope.setValue(0.7); | |
22 | eq.range.setValue(0.4); | |
23 | eq.attack.setValue(0.4); | |
24 | eq.release.setValue(0.4); | |
25 | addParameter(eq.level); | |
26 | addParameter(eq.range); | |
27 | addParameter(eq.attack); | |
28 | addParameter(eq.release); | |
29 | addParameter(eq.slope); | |
30 | } | |
31 | } | |
32 | ||
33 | ||
34 | public void run(double deltaMs) { | |
35 | eq.run(deltaMs); | |
36 | float bassLevel = eq.getAverageLevel(0, 4); | |
37 | float trebleLevel = eq.getAverageLevel(8, 6); | |
38 | ||
39 | float falloff = 100 / (2 + 14*wid.getValuef()); | |
40 | float cx = model.xMin + (model.xMax-model.xMin) * xpos.getValuef(); | |
41 | float barm = 12 + 60*arms.getValuef()*max(0, 2*(bassLevel-0.1)); | |
42 | float tarm = 12 + 60*arms.getValuef()*max(0, 2*(trebleLevel-0.1)); | |
43 | ||
44 | float arm = 0; | |
45 | float middle = 0; | |
46 | ||
47 | float sf = 100. / (70 - 69.9*sat.getValuef()); | |
48 | ||
2bb56822 | 49 | for (LXPoint p : model.points) { |
616d4f9e MS |
50 | float d = MAX_FLOAT; |
51 | if (p.y > model.cy) { | |
52 | arm = tarm; | |
53 | middle = model.yMax * 3/5.; | |
54 | } else { | |
55 | arm = barm; | |
56 | middle = model.yMax * 1/5.; | |
57 | } | |
58 | if (abs(p.x - cx) < arm) { | |
59 | d = min(abs(p.x - cx), abs(p.y - middle)); | |
60 | } | |
67847b06 | 61 | colors[p.index] = lx.hsb( |
616d4f9e MS |
62 | (lx.getBaseHuef() + .2*abs(p.y - model.cy)) % 360, |
63 | min(100, sf*dist(abs(p.x - cx), p.y, arm, middle)), | |
67847b06 | 64 | constrain(120 - d*falloff, 0, 100)); |
616d4f9e MS |
65 | } |
66 | } | |
67 | } | |
68 | ||
4214e9a2 MS |
69 | class MidiMusic extends SCPattern { |
70 | ||
09068c4e | 71 | private final Stack<LXLayer> newLayers = new Stack<LXLayer>(); |
4214e9a2 | 72 | |
09068c4e MS |
73 | private final Map<Integer, LightUp> lightMap = new HashMap<Integer, LightUp>(); |
74 | private final List<LightUp> lights = new ArrayList<LightUp>(); | |
d93c968f | 75 | private final BasicParameter lightSize = new BasicParameter("SIZE", 0.5); |
cfb7de01 | 76 | |
09068c4e MS |
77 | private final List<Sweep> sweeps = new ArrayList<Sweep>(); |
78 | ||
d93c968f | 79 | private final LinearEnvelope sparkle = new LinearEnvelope(0, 1, 500); |
09068c4e | 80 | private boolean sparkleDirection = true; |
d93c968f | 81 | private float sparkleBright = 100; |
09068c4e MS |
82 | |
83 | private final BasicParameter wave = new BasicParameter("WAVE", 0); | |
4214e9a2 | 84 | |
dde75983 MS |
85 | MidiMusic(LX lx) { |
86 | super(lx); | |
d93c968f | 87 | addParameter(lightSize); |
09068c4e | 88 | addParameter(wave); |
d93c968f | 89 | addModulator(sparkle).setValue(1); |
09068c4e MS |
90 | } |
91 | ||
29d8acbb MS |
92 | void onReset() { |
93 | for (LightUp light : lights) { | |
94 | light.noteOff(null); | |
95 | } | |
96 | } | |
97 | ||
09068c4e MS |
98 | class Sweep extends LXLayer { |
99 | ||
100 | final LinearEnvelope position = new LinearEnvelope(0, 1, 1000); | |
101 | float bright = 100; | |
102 | float falloff = 10; | |
103 | ||
104 | Sweep() { | |
105 | addModulator(position); | |
106 | } | |
107 | ||
108 | public void run(double deltaMs, color[] colors) { | |
109 | if (!position.isRunning()) { | |
110 | return; | |
111 | } | |
112 | float posf = position.getValuef(); | |
2bb56822 | 113 | for (LXPoint p : model.points) { |
67847b06 | 114 | colors[p.index] = blendColor(colors[p.index], lx.hsb( |
09068c4e MS |
115 | (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360, |
116 | 100, | |
117 | max(0, bright - posf*100 - falloff*abs(p.y - posf*model.yMax)) | |
118 | ), ADD); | |
119 | } | |
120 | } | |
4214e9a2 MS |
121 | } |
122 | ||
123 | class LightUp extends LXLayer { | |
124 | ||
09068c4e MS |
125 | private final LinearEnvelope brt = new LinearEnvelope(0, 0, 0); |
126 | private final Accelerator yPos = new Accelerator(0, 0, 0); | |
4214e9a2 MS |
127 | private float xPos; |
128 | ||
129 | LightUp() { | |
130 | addModulator(brt); | |
131 | addModulator(yPos); | |
132 | } | |
133 | ||
134 | boolean isAvailable() { | |
135 | return brt.getValuef() <= 0; | |
136 | } | |
137 | ||
138 | void noteOn(Note note) { | |
09068c4e MS |
139 | xPos = lerp(0, model.xMax, constrain(0.5 + (note.getPitch() - 60) / 28., 0, 1)); |
140 | yPos.setValue(lerp(20, model.yMax*.72, note.getVelocity() / 127.)).stop(); | |
4214e9a2 MS |
141 | brt.setRangeFromHereTo(lerp(40, 100, note.getVelocity() / 127.), 20).start(); |
142 | } | |
143 | ||
144 | void noteOff(Note note) { | |
145 | yPos.setVelocity(0).setAcceleration(-380).start(); | |
146 | brt.setRangeFromHereTo(0, 1000).start(); | |
147 | } | |
148 | ||
149 | public void run(double deltaMs, color[] colors) { | |
150 | float bVal = brt.getValuef(); | |
151 | if (bVal <= 0) { | |
152 | return; | |
153 | } | |
154 | float yVal = yPos.getValuef(); | |
2bb56822 | 155 | for (LXPoint p : model.points) { |
d93c968f MS |
156 | float falloff = 6 - 5*lightSize.getValuef(); |
157 | float b = max(0, bVal - falloff*dist(p.x, p.y, xPos, yVal)); | |
4214e9a2 | 158 | if (b > 0) { |
19d16a16 | 159 | colors[p.index] = blendColor(colors[p.index], lx.hsb( |
d93c968f | 160 | (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360, |
4214e9a2 MS |
161 | 100, |
162 | b | |
163 | ), ADD); | |
164 | } | |
165 | } | |
166 | } | |
167 | } | |
168 | ||
09068c4e MS |
169 | private LightUp getLight() { |
170 | for (LightUp light : lights) { | |
171 | if (light.isAvailable()) { | |
172 | return light; | |
4214e9a2 | 173 | } |
09068c4e MS |
174 | } |
175 | LightUp newLight = new LightUp(); | |
176 | lights.add(newLight); | |
177 | synchronized(newLayers) { | |
178 | newLayers.push(newLight); | |
179 | } | |
180 | return newLight; | |
181 | } | |
182 | ||
183 | private Sweep getSweep() { | |
184 | for (Sweep s : sweeps) { | |
185 | if (!s.position.isRunning()) { | |
186 | return s; | |
4214e9a2 | 187 | } |
09068c4e MS |
188 | } |
189 | Sweep newSweep = new Sweep(); | |
190 | sweeps.add(newSweep); | |
191 | synchronized(newLayers) { | |
192 | newLayers.push(newSweep); | |
193 | } | |
194 | return newSweep; | |
195 | } | |
196 | ||
197 | public synchronized boolean noteOn(Note note) { | |
198 | if (note.getChannel() == 0) { | |
199 | LightUp light = getLight(); | |
200 | lightMap.put(note.getPitch(), light); | |
201 | light.noteOn(note); | |
4214e9a2 | 202 | } else if (note.getChannel() == 1) { |
d93c968f | 203 | } else if (note.getChannel() == 9) { |
cfb7de01 MS |
204 | if (note.getVelocity() > 0) { |
205 | switch (note.getPitch()) { | |
206 | case 36: | |
09068c4e MS |
207 | Sweep s = getSweep(); |
208 | s.bright = 50 + note.getVelocity() / 127. * 50; | |
209 | s.falloff = 20 - note.getVelocity() / 127. * 17; | |
210 | s.position.trigger(); | |
211 | break; | |
212 | case 37: | |
d93c968f | 213 | sparkleBright = note.getVelocity() / 127. * 100; |
09068c4e | 214 | sparkleDirection = true; |
cfb7de01 MS |
215 | sparkle.trigger(); |
216 | break; | |
09068c4e MS |
217 | case 38: |
218 | sparkleBright = note.getVelocity() / 127. * 100; | |
219 | sparkleDirection = false; | |
220 | sparkle.trigger(); | |
cfb7de01 | 221 | break; |
29d8acbb MS |
222 | case 39: |
223 | effects.boom.trigger(); | |
224 | break; | |
225 | case 40: | |
cc9e8c8b | 226 | //effects.flash.trigger(); |
29d8acbb | 227 | break; |
cfb7de01 | 228 | } |
d93c968f | 229 | } |
4214e9a2 MS |
230 | } |
231 | return true; | |
232 | } | |
233 | ||
242b19ad | 234 | public synchronized boolean noteOff(Note note) { |
4214e9a2 MS |
235 | if (note.getChannel() == 0) { |
236 | LightUp light = lightMap.get(note.getPitch()); | |
237 | if (light != null) { | |
238 | light.noteOff(note); | |
239 | } | |
240 | } | |
241 | return true; | |
242 | } | |
243 | ||
09068c4e MS |
244 | final float[] wval = new float[16]; |
245 | float wavoff = 0; | |
246 | ||
4214e9a2 | 247 | public synchronized void run(double deltaMs) { |
09068c4e MS |
248 | wavoff += deltaMs * .001; |
249 | for (int i = 0; i < wval.length; ++i) { | |
250 | wval[i] = model.cy + 0.2 * model.yMax/2. * sin(wavoff + i / 1.9); | |
251 | } | |
252 | float sparklePos = (sparkleDirection ? sparkle.getValuef() : (1 - sparkle.getValuef())) * (Cube.POINTS_PER_STRIP)/2.; | |
d93c968f MS |
253 | float maxBright = sparkleBright * (1 - sparkle.getValuef()); |
254 | for (Strip s : model.strips) { | |
255 | int i = 0; | |
2bb56822 | 256 | for (LXPoint p : s.points) { |
09068c4e MS |
257 | int wavi = (int) constrain(p.x / model.xMax * wval.length, 0, wval.length-1); |
258 | float wavb = max(0, wave.getValuef()*100. - 8.*abs(p.y - wval[wavi])); | |
67847b06 | 259 | colors[p.index] = lx.hsb( |
d93c968f MS |
260 | (lx.getBaseHuef() + .2*abs(p.x - model.cx) + .2*abs(p.y - model.cy)) % 360, |
261 | 100, | |
09068c4e | 262 | constrain(wavb + max(0, maxBright - 40.*abs(sparklePos - abs(i - (Cube.POINTS_PER_STRIP-1)/2.))), 0, 100) |
d93c968f MS |
263 | ); |
264 | ++i; | |
265 | } | |
266 | } | |
09068c4e | 267 | |
4214e9a2 MS |
268 | if (!newLayers.isEmpty()) { |
269 | synchronized(newLayers) { | |
270 | while (!newLayers.isEmpty()) { | |
271 | addLayer(newLayers.pop()); | |
272 | } | |
273 | } | |
274 | } | |
275 | } | |
276 | } | |
277 | ||
0137237d MS |
278 | class Pulley extends SCPattern { |
279 | ||
280 | final int NUM_DIVISIONS = 16; | |
281 | private final Accelerator[] gravity = new Accelerator[NUM_DIVISIONS]; | |
282 | private final Click[] delays = new Click[NUM_DIVISIONS]; | |
283 | ||
284 | private final Click reset = new Click(9000); | |
285 | private boolean isRising = false; | |
286 | ||
0e6f37cf | 287 | private BasicParameter sz = new BasicParameter("SIZE", 0.5); |
a41f334c | 288 | private BasicParameter beatAmount = new BasicParameter("BEAT", 0); |
eb0d5167 | 289 | |
dde75983 MS |
290 | Pulley(LX lx) { |
291 | super(lx); | |
0137237d MS |
292 | for (int i = 0; i < NUM_DIVISIONS; ++i) { |
293 | addModulator(gravity[i] = new Accelerator(0, 0, 0)); | |
294 | addModulator(delays[i] = new Click(0)); | |
295 | } | |
296 | addModulator(reset).start(); | |
0e6f37cf | 297 | addParameter(sz); |
eb0d5167 | 298 | addParameter(beatAmount); |
0137237d | 299 | trigger(); |
242b19ad | 300 | |
0137237d MS |
301 | } |
302 | ||
303 | private void trigger() { | |
304 | isRising = !isRising; | |
305 | int i = 0; | |
306 | for (Accelerator g : gravity) { | |
307 | if (isRising) { | |
a41f334c | 308 | g.setSpeed(random(20, 33), 0).start(); |
0137237d MS |
309 | } else { |
310 | g.setVelocity(0).setAcceleration(-420); | |
311 | delays[i].setDuration(random(0, 500)).trigger(); | |
312 | } | |
313 | ++i; | |
314 | } | |
315 | } | |
316 | ||
317 | public void run(double deltaMs) { | |
318 | if (reset.click()) { | |
319 | trigger(); | |
320 | } | |
242b19ad | 321 | |
a41f334c MS |
322 | if (isRising) { |
323 | // Fucking A, had to comment this all out because of that bizarre | |
324 | // Processing bug where some simple loop takes an absurd amount of | |
325 | // time, must be some pre-processor bug | |
326 | // for (Accelerator g : gravity) { | |
327 | // if (g.getValuef() > model.yMax) { | |
328 | // g.stop(); | |
329 | // } else if (g.getValuef() > model.yMax*.55) { | |
330 | // if (g.getVelocityf() > 10) { | |
331 | // g.setAcceleration(-16); | |
332 | // } else { | |
333 | // g.setAcceleration(0); | |
334 | // } | |
335 | // } | |
336 | // } | |
337 | } else { | |
338 | int j = 0; | |
339 | for (Click d : delays) { | |
340 | if (d.click()) { | |
341 | gravity[j].start(); | |
342 | d.stop(); | |
0137237d | 343 | } |
a41f334c MS |
344 | ++j; |
345 | } | |
346 | for (Accelerator g : gravity) { | |
0137237d MS |
347 | if (g.getValuef() < 0) { |
348 | g.setValue(-g.getValuef()); | |
349 | g.setVelocity(-g.getVelocityf() * random(0.74, 0.84)); | |
350 | } | |
351 | } | |
352 | } | |
242b19ad MS |
353 | |
354 | // A little silliness to test the grid API | |
66067e53 MS |
355 | if (midiEngine != null && midiEngine.getFocusedPattern() == this) { |
356 | for (int i = 0; i < 5; ++i) { | |
357 | for (int j = 0; j < 8; ++j) { | |
358 | int gi = (int) constrain(j * NUM_DIVISIONS / 8, 0, NUM_DIVISIONS-1); | |
359 | float b = 1 - 4.*abs((6-i)/6. - gravity[gi].getValuef() / model.yMax); | |
360 | midiEngine.grid.setState(i, j, (b < 0) ? 0 : 3); | |
361 | } | |
242b19ad MS |
362 | } |
363 | } | |
0137237d | 364 | |
eb0d5167 MS |
365 | float fPos = 1 - lx.tempo.rampf(); |
366 | if (fPos < .2) { | |
367 | fPos = .2 + 4 * (.2 - fPos); | |
368 | } | |
0e6f37cf | 369 | float falloff = 100. / (3 + sz.getValuef() * 36 + fPos * beatAmount.getValuef()*48); |
2bb56822 | 370 | for (LXPoint p : model.points) { |
a41f334c | 371 | int gi = (int) constrain((p.x - model.xMin) * NUM_DIVISIONS / (model.xMax - model.xMin), 0, NUM_DIVISIONS-1); |
19d16a16 | 372 | colors[p.index] = lx.hsb( |
0137237d MS |
373 | (lx.getBaseHuef() + abs(p.x - model.cx)*.8 + p.y*.4) % 360, |
374 | constrain(130 - p.y*.8, 0, 100), | |
a41f334c | 375 | max(0, 100 - abs(p.y - gravity[gi].getValuef())*falloff) |
0137237d MS |
376 | ); |
377 | } | |
378 | } | |
379 | } | |
380 | ||
4760e696 MS |
381 | class ViolinWave extends SCPattern { |
382 | ||
383 | BasicParameter level = new BasicParameter("LVL", 0.45); | |
384 | BasicParameter range = new BasicParameter("RNG", 0.5); | |
385 | BasicParameter edge = new BasicParameter("EDG", 0.5); | |
386 | BasicParameter release = new BasicParameter("RLS", 0.5); | |
387 | BasicParameter speed = new BasicParameter("SPD", 0.5); | |
388 | BasicParameter amp = new BasicParameter("AMP", 0.25); | |
389 | BasicParameter period = new BasicParameter("WAVE", 0.5); | |
390 | BasicParameter pSize = new BasicParameter("PSIZE", 0.5); | |
391 | BasicParameter pSpeed = new BasicParameter("PSPD", 0.5); | |
392 | BasicParameter pDensity = new BasicParameter("PDENS", 0.25); | |
393 | ||
394 | LinearEnvelope dbValue = new LinearEnvelope(0, 0, 10); | |
395 | ||
dde75983 MS |
396 | ViolinWave(LX lx) { |
397 | super(lx); | |
4760e696 MS |
398 | addParameter(level); |
399 | addParameter(edge); | |
400 | addParameter(range); | |
401 | addParameter(release); | |
402 | addParameter(speed); | |
403 | addParameter(amp); | |
404 | addParameter(period); | |
405 | addParameter(pSize); | |
406 | addParameter(pSpeed); | |
407 | addParameter(pDensity); | |
408 | ||
409 | addModulator(dbValue); | |
410 | } | |
411 | ||
412 | final List<Particle> particles = new ArrayList<Particle>(); | |
413 | ||
414 | class Particle { | |
415 | ||
416 | LinearEnvelope x = new LinearEnvelope(0, 0, 0); | |
417 | LinearEnvelope y = new LinearEnvelope(0, 0, 0); | |
418 | ||
419 | Particle() { | |
420 | addModulator(x); | |
421 | addModulator(y); | |
422 | } | |
423 | ||
424 | Particle trigger(boolean direction) { | |
425 | float xInit = random(model.xMin, model.xMax); | |
426 | float time = 3000 - 2500*pSpeed.getValuef(); | |
427 | x.setRange(xInit, xInit + random(-40, 40), time).trigger(); | |
428 | y.setRange(model.cy + 10, direction ? model.yMax + 50 : model.yMin - 50, time).trigger(); | |
429 | return this; | |
430 | } | |
431 | ||
432 | boolean isActive() { | |
433 | return x.isRunning() || y.isRunning(); | |
434 | } | |
435 | ||
436 | public void run(double deltaMs) { | |
437 | if (!isActive()) { | |
438 | return; | |
439 | } | |
440 | ||
441 | float pFalloff = (30 - 27*pSize.getValuef()); | |
2bb56822 | 442 | for (LXPoint p : model.points) { |
4760e696 MS |
443 | float b = 100 - pFalloff * (abs(p.x - x.getValuef()) + abs(p.y - y.getValuef())); |
444 | if (b > 0) { | |
343875e3 | 445 | colors[p.index] = blendColor(colors[p.index], lx.hsb( |
4760e696 MS |
446 | lx.getBaseHuef(), 20, b |
447 | ), ADD); | |
448 | } | |
449 | } | |
450 | } | |
451 | } | |
452 | ||
453 | float[] centers = new float[30]; | |
454 | double accum = 0; | |
455 | boolean rising = true; | |
456 | ||
457 | void fireParticle(boolean direction) { | |
458 | boolean gotOne = false; | |
459 | for (Particle p : particles) { | |
460 | if (!p.isActive()) { | |
461 | p.trigger(direction); | |
462 | return; | |
463 | } | |
464 | } | |
465 | particles.add(new Particle().trigger(direction)); | |
466 | } | |
467 | ||
468 | public void run(double deltaMs) { | |
469 | accum += deltaMs / (1000. - 900.*speed.getValuef()); | |
470 | for (int i = 0; i < centers.length; ++i) { | |
471 | centers[i] = model.cy + 30*amp.getValuef()*sin((float) (accum + (i-centers.length/2.)/(1. + 9.*period.getValuef()))); | |
472 | } | |
473 | ||
474 | float zeroDBReference = pow(10, (50 - 190*level.getValuef())/20.); | |
616d4f9e | 475 | float dB = 20*GraphicEQ.log10(lx.audioInput().mix.level() / zeroDBReference); |
4760e696 MS |
476 | if (dB > dbValue.getValuef()) { |
477 | rising = true; | |
478 | dbValue.setRangeFromHereTo(dB, 10).trigger(); | |
479 | } else { | |
480 | if (rising) { | |
481 | for (int j = 0; j < pDensity.getValuef()*3; ++j) { | |
482 | fireParticle(true); | |
483 | fireParticle(false); | |
484 | } | |
485 | } | |
486 | rising = false; | |
487 | dbValue.setRangeFromHereTo(max(dB, -96), 50 + 1000*release.getValuef()).trigger(); | |
488 | } | |
489 | float edg = 1 + edge.getValuef() * 40; | |
490 | float rng = (78 - 64 * range.getValuef()) / (model.yMax - model.cy); | |
491 | float val = max(2, dbValue.getValuef()); | |
492 | ||
2bb56822 | 493 | for (LXPoint p : model.points) { |
4760e696 MS |
494 | int ci = (int) lerp(0, centers.length-1, (p.x - model.xMin) / (model.xMax - model.xMin)); |
495 | float rFactor = 1.0 - 0.9 * abs(p.x - model.cx) / (model.xMax - model.cx); | |
343875e3 | 496 | colors[p.index] = lx.hsb( |
4760e696 MS |
497 | (lx.getBaseHuef() + abs(p.x - model.cx)) % 360, |
498 | min(100, 20 + 8*abs(p.y - centers[ci])), | |
499 | constrain(edg*(val*rFactor - rng * abs(p.y-centers[ci])), 0, 100) | |
500 | ); | |
501 | } | |
502 | ||
503 | for (Particle p : particles) { | |
504 | p.run(deltaMs); | |
505 | } | |
506 | } | |
507 | } | |
508 | ||
d1dcc4b5 | 509 | class BouncyBalls extends SCPattern { |
cc8b3f82 | 510 | |
d1dcc4b5 | 511 | static final int NUM_BALLS = 6; |
cc8b3f82 | 512 | |
d1dcc4b5 | 513 | class BouncyBall { |
cc8b3f82 MS |
514 | |
515 | Accelerator yPos; | |
516 | TriangleLFO xPos = new TriangleLFO(0, model.xMax, random(8000, 19000)); | |
d1dcc4b5 | 517 | float zPos; |
cc8b3f82 | 518 | |
d1dcc4b5 | 519 | BouncyBall(int i) { |
d12e46b6 | 520 | addModulator(xPos.setBasis(random(0, TWO_PI)).start()); |
cc8b3f82 | 521 | addModulator(yPos = new Accelerator(0, 0, 0)); |
d1dcc4b5 | 522 | zPos = lerp(model.zMin, model.zMax, (i+2.) / (NUM_BALLS + 4.)); |
cc8b3f82 MS |
523 | } |
524 | ||
525 | void bounce(float midiVel) { | |
526 | float v = 100 + 8*midiVel; | |
527 | yPos.setSpeed(v, getAccel(v, 60 / lx.tempo.bpmf())).start(); | |
528 | } | |
529 | ||
530 | float getAccel(float v, float oneBeat) { | |
531 | return -2*v / oneBeat; | |
532 | } | |
533 | ||
534 | void run(double deltaMs) { | |
535 | float flrLevel = flr.getValuef() * model.xMax/2.; | |
536 | if (yPos.getValuef() < flrLevel) { | |
537 | if (yPos.getVelocity() < -50) { | |
538 | yPos.setValue(2*flrLevel-yPos.getValuef()); | |
539 | float v = -yPos.getVelocityf() * bounce.getValuef(); | |
540 | yPos.setSpeed(v, getAccel(v, 60 / lx.tempo.bpmf())); | |
541 | } else { | |
542 | yPos.setValue(flrLevel).stop(); | |
543 | } | |
544 | } | |
545 | float falloff = 130.f / (12 + blobSize.getValuef() * 36); | |
d1dcc4b5 MS |
546 | float xv = xPos.getValuef(); |
547 | float yv = yPos.getValuef(); | |
548 | ||
2bb56822 | 549 | for (LXPoint p : model.points) { |
d1dcc4b5 | 550 | float d = sqrt((p.x-xv)*(p.x-xv) + (p.y-yv)*(p.y-yv) + .1*(p.z-zPos)*(p.z-zPos)); |
cc8b3f82 MS |
551 | float b = constrain(130 - falloff*d, 0, 100); |
552 | if (b > 0) { | |
19d16a16 | 553 | colors[p.index] = blendColor(colors[p.index], lx.hsb( |
cc8b3f82 MS |
554 | (lx.getBaseHuef() + p.y*.5 + abs(model.cx - p.x) * .5) % 360, |
555 | max(0, 100 - .45*(p.y - flrLevel)), | |
556 | b | |
557 | ), ADD); | |
558 | } | |
559 | } | |
560 | } | |
561 | } | |
562 | ||
d1dcc4b5 | 563 | final BouncyBall[] balls = new BouncyBall[NUM_BALLS]; |
cc8b3f82 MS |
564 | |
565 | final BasicParameter bounce = new BasicParameter("BNC", .8); | |
566 | final BasicParameter flr = new BasicParameter("FLR", 0); | |
567 | final BasicParameter blobSize = new BasicParameter("SIZE", 0.5); | |
568 | ||
dde75983 MS |
569 | BouncyBalls(LX lx) { |
570 | super(lx); | |
d1dcc4b5 MS |
571 | for (int i = 0; i < balls.length; ++i) { |
572 | balls[i] = new BouncyBall(i); | |
cc8b3f82 MS |
573 | } |
574 | addParameter(bounce); | |
575 | addParameter(flr); | |
576 | addParameter(blobSize); | |
577 | } | |
578 | ||
579 | public void run(double deltaMs) { | |
580 | setColors(#000000); | |
d1dcc4b5 MS |
581 | for (BouncyBall b : balls) { |
582 | b.run(deltaMs); | |
cc8b3f82 MS |
583 | } |
584 | } | |
585 | ||
242b19ad | 586 | public boolean noteOn(Note note) { |
d1dcc4b5 MS |
587 | int pitch = (note.getPitch() + note.getChannel()) % NUM_BALLS; |
588 | balls[pitch].bounce(note.getVelocity()); | |
cc8b3f82 MS |
589 | return true; |
590 | } | |
591 | } | |
592 | ||
49815cc0 MS |
593 | class SpaceTime extends SCPattern { |
594 | ||
3e8e60d8 | 595 | SinLFO pos = new SinLFO(0, 1, 3000); |
49815cc0 MS |
596 | SinLFO rate = new SinLFO(1000, 9000, 13000); |
597 | SinLFO falloff = new SinLFO(10, 70, 5000); | |
3f8be614 MS |
598 | float angle = 0; |
599 | ||
600 | BasicParameter rateParameter = new BasicParameter("RATE", 0.5); | |
601 | BasicParameter sizeParameter = new BasicParameter("SIZE", 0.5); | |
49815cc0 | 602 | |
3e8e60d8 | 603 | |
dde75983 MS |
604 | public SpaceTime(LX lx) { |
605 | super(lx); | |
3e8e60d8 | 606 | |
49815cc0 MS |
607 | addModulator(pos).trigger(); |
608 | addModulator(rate).trigger(); | |
609 | addModulator(falloff).trigger(); | |
610 | pos.modulateDurationBy(rate); | |
3f8be614 MS |
611 | addParameter(rateParameter); |
612 | addParameter(sizeParameter); | |
49815cc0 | 613 | } |
3f8be614 MS |
614 | |
615 | public void onParameterChanged(LXParameter parameter) { | |
616 | if (parameter == rateParameter) { | |
617 | rate.stop().setValue(9000 - 8000*parameter.getValuef()); | |
618 | } else if (parameter == sizeParameter) { | |
619 | falloff.stop().setValue(70 - 60*parameter.getValuef()); | |
49815cc0 MS |
620 | } |
621 | } | |
622 | ||
34327c96 | 623 | void run(double deltaMs) { |
3f8be614 | 624 | angle += deltaMs * 0.0007; |
87f6fa39 MS |
625 | float sVal1 = model.strips.size() * (0.5 + 0.5*sin(angle)); |
626 | float sVal2 = model.strips.size() * (0.5 + 0.5*cos(angle)); | |
49815cc0 MS |
627 | |
628 | float pVal = pos.getValuef(); | |
629 | float fVal = falloff.getValuef(); | |
630 | ||
631 | int s = 0; | |
cfc57fca | 632 | for (Strip strip : model.strips) { |
49815cc0 | 633 | int i = 0; |
2bb56822 | 634 | for (LXPoint p : strip.points) { |
19d16a16 | 635 | colors[p.index] = lx.hsb( |
190d91c2 | 636 | (lx.getBaseHuef() + 360 - p.x*.2 + p.y * .3) % 360, |
3e8e60d8 MS |
637 | constrain(.4 * min(abs(s - sVal1), abs(s - sVal2)), 20, 100), |
638 | max(0, 100 - fVal*abs(i - pVal*(strip.metrics.numPoints - 1))) | |
639 | ); | |
49815cc0 MS |
640 | ++i; |
641 | } | |
3f8be614 | 642 | ++s; |
49815cc0 MS |
643 | } |
644 | } | |
645 | } | |
646 | ||
647 | class Swarm extends SCPattern { | |
d12e46b6 | 648 | |
3e8e60d8 | 649 | SawLFO offset = new SawLFO(0, 1, 1000); |
49815cc0 MS |
650 | SinLFO rate = new SinLFO(350, 1200, 63000); |
651 | SinLFO falloff = new SinLFO(15, 50, 17000); | |
2bb56822 MS |
652 | SinLFO fX = new SinLFO(model.xMin, model.xMax, 19000); |
653 | SinLFO fY = new SinLFO(model.yMin, model.yMax, 11000); | |
654 | SinLFO hOffX = new SinLFO(model.xMin, model.xMax, 13000); | |
49815cc0 | 655 | |
dde75983 MS |
656 | public Swarm(LX lx) { |
657 | super(lx); | |
3e8e60d8 | 658 | |
49815cc0 MS |
659 | addModulator(offset).trigger(); |
660 | addModulator(rate).trigger(); | |
661 | addModulator(falloff).trigger(); | |
2b6688e8 | 662 | addModulator(fX).trigger(); |
49815cc0 | 663 | addModulator(fY).trigger(); |
2b6688e8 | 664 | addModulator(hOffX).trigger(); |
49815cc0 MS |
665 | offset.modulateDurationBy(rate); |
666 | } | |
667 | ||
668 | float modDist(float v1, float v2, float mod) { | |
669 | v1 = v1 % mod; | |
670 | v2 = v2 % mod; | |
671 | if (v2 > v1) { | |
672 | return min(v2-v1, v1+mod-v2); | |
673 | } | |
674 | else { | |
675 | return min(v1-v2, v2+mod-v1); | |
676 | } | |
677 | } | |
678 | ||
34327c96 | 679 | void run(double deltaMs) { |
49815cc0 | 680 | float s = 0; |
2bb56822 | 681 | for (Strip strip : model.strips) { |
49815cc0 | 682 | int i = 0; |
2bb56822 | 683 | for (LXPoint p : strip.points) { |
190d91c2 | 684 | float fV = max(-1, 1 - dist(p.x/2., p.y, fX.getValuef()/2., fY.getValuef()) / 64.); |
19d16a16 | 685 | colors[p.index] = lx.hsb( |
190d91c2 | 686 | (lx.getBaseHuef() + 0.3 * abs(p.x - hOffX.getValuef())) % 360, |
49815cc0 | 687 | constrain(80 + 40 * fV, 0, 100), |
1d414e45 AG |
688 | constrain(100 - |
689 | (30 - fV * falloff.getValuef()) * modDist(i + (s*63)%61, offset.getValuef() * strip.metrics.numPoints, strip.metrics.numPoints), 0, 100) | |
49815cc0 MS |
690 | ); |
691 | ++i; | |
1d414e45 | 692 | } |
49815cc0 MS |
693 | ++s; |
694 | } | |
695 | } | |
696 | } | |
697 | ||
a22015f4 | 698 | class SwipeTransition extends LXTransition { |
3f8be614 MS |
699 | |
700 | final BasicParameter bleed = new BasicParameter("WIDTH", 0.5); | |
701 | ||
a22015f4 MS |
702 | SwipeTransition(LX lx) { |
703 | super(lx); | |
49815cc0 | 704 | setDuration(5000); |
3f8be614 | 705 | addParameter(bleed); |
49815cc0 MS |
706 | } |
707 | ||
708 | void computeBlend(int[] c1, int[] c2, double progress) { | |
3f8be614 | 709 | float bleedf = 10 + bleed.getValuef() * 200.; |
c39f7a04 | 710 | float xPos = (float) (-bleedf + progress * (model.xMax + bleedf)); |
2bb56822 | 711 | for (LXPoint p : model.points) { |
190d91c2 | 712 | float d = (p.x - xPos) / bleedf; |
49815cc0 MS |
713 | if (d < 0) { |
714 | colors[p.index] = c2[p.index]; | |
2b6688e8 | 715 | } else if (d > 1) { |
49815cc0 | 716 | colors[p.index] = c1[p.index]; |
2b6688e8 | 717 | } else { |
49815cc0 MS |
718 | colors[p.index] = lerpColor(c2[p.index], c1[p.index], d, RGB); |
719 | } | |
720 | } | |
721 | } | |
722 | } | |
723 | ||
4c006f7b MS |
724 | class BassPod extends SCPattern { |
725 | ||
726 | private GraphicEQ eq = null; | |
727 | ||
32467992 MS |
728 | private final BasicParameter clr = new BasicParameter("CLR", 0.5); |
729 | ||
dde75983 MS |
730 | public BassPod(LX lx) { |
731 | super(lx); | |
32467992 | 732 | addParameter(clr); |
4c006f7b MS |
733 | } |
734 | ||
4e6626a9 | 735 | void onActive() { |
4c006f7b MS |
736 | if (eq == null) { |
737 | eq = new GraphicEQ(lx, 16); | |
32467992 MS |
738 | eq.range.setValue(0.4); |
739 | eq.level.setValue(0.4); | |
4c006f7b MS |
740 | eq.slope.setValue(0.6); |
741 | addParameter(eq.level); | |
742 | addParameter(eq.range); | |
743 | addParameter(eq.attack); | |
744 | addParameter(eq.release); | |
745 | addParameter(eq.slope); | |
746 | } | |
747 | } | |
748 | ||
34327c96 | 749 | public void run(double deltaMs) { |
4c006f7b MS |
750 | eq.run(deltaMs); |
751 | ||
752 | float bassLevel = eq.getAverageLevel(0, 5); | |
753 | ||
32467992 MS |
754 | float satBase = bassLevel*480*clr.getValuef(); |
755 | ||
2bb56822 | 756 | for (LXPoint p : model.points) { |
32467992 | 757 | int avgIndex = (int) constrain(1 + abs(p.x-model.cx)/(model.cx)*(eq.numBands-5), 0, eq.numBands-5); |
4c006f7b MS |
758 | float value = 0; |
759 | for (int i = avgIndex; i < avgIndex + 5; ++i) { | |
760 | value += eq.getLevel(i); | |
761 | } | |
762 | value /= 5.; | |
763 | ||
190d91c2 | 764 | float b = constrain(8 * (value*model.yMax - abs(p.y-model.yMax/2.)), 0, 100); |
19d16a16 | 765 | colors[p.index] = lx.hsb( |
190d91c2 | 766 | (lx.getBaseHuef() + abs(p.y - model.cy) + abs(p.x - model.cx)) % 360, |
32467992 | 767 | constrain(satBase - .6*dist(p.x, p.y, model.cx, model.cy), 0, 100), |
4c006f7b MS |
768 | b |
769 | ); | |
770 | } | |
771 | } | |
772 | } | |
773 | ||
774 | ||
49815cc0 MS |
775 | class CubeEQ extends SCPattern { |
776 | ||
4c006f7b | 777 | private GraphicEQ eq = null; |
49815cc0 | 778 | |
3f8be614 | 779 | private final BasicParameter edge = new BasicParameter("EDGE", 0.5); |
3f8be614 | 780 | private final BasicParameter clr = new BasicParameter("CLR", 0.5); |
4c006f7b | 781 | private final BasicParameter blockiness = new BasicParameter("BLK", 0.5); |
49815cc0 | 782 | |
dde75983 MS |
783 | public CubeEQ(LX lx) { |
784 | super(lx); | |
49815cc0 | 785 | } |
3f8be614 | 786 | |
4e6626a9 | 787 | void onActive() { |
4c006f7b MS |
788 | if (eq == null) { |
789 | eq = new GraphicEQ(lx, 16); | |
790 | addParameter(eq.level); | |
791 | addParameter(eq.range); | |
792 | addParameter(eq.attack); | |
793 | addParameter(eq.release); | |
794 | addParameter(eq.slope); | |
795 | addParameter(edge); | |
796 | addParameter(clr); | |
797 | addParameter(blockiness); | |
49815cc0 MS |
798 | } |
799 | } | |
800 | ||
34327c96 | 801 | public void run(double deltaMs) { |
4c006f7b | 802 | eq.run(deltaMs); |
3f8be614 | 803 | |
4c006f7b | 804 | float edgeConst = 2 + 30*edge.getValuef(); |
49815cc0 MS |
805 | float clrConst = 1.1 + clr.getValuef(); |
806 | ||
2bb56822 | 807 | for (LXPoint p : model.points) { |
190d91c2 | 808 | float avgIndex = constrain(2 + p.x / model.xMax * (eq.numBands-4), 0, eq.numBands-4); |
49815cc0 | 809 | int avgFloor = (int) avgIndex; |
3f8be614 | 810 | |
4c006f7b MS |
811 | float leftVal = eq.getLevel(avgFloor); |
812 | float rightVal = eq.getLevel(avgFloor+1); | |
813 | float smoothValue = lerp(leftVal, rightVal, avgIndex-avgFloor); | |
814 | ||
815 | float chunkyValue = ( | |
816 | eq.getLevel(avgFloor/4*4) + | |
817 | eq.getLevel(avgFloor/4*4 + 1) + | |
818 | eq.getLevel(avgFloor/4*4 + 2) + | |
819 | eq.getLevel(avgFloor/4*4 + 3) | |
820 | ) / 4.; | |
821 | ||
822 | float value = lerp(smoothValue, chunkyValue, blockiness.getValuef()); | |
823 | ||
190d91c2 | 824 | float b = constrain(edgeConst * (value*model.yMax - p.y), 0, 100); |
19d16a16 | 825 | colors[p.index] = lx.hsb( |
190d91c2 | 826 | (480 + lx.getBaseHuef() - min(clrConst*p.y, 120)) % 360, |
4c006f7b MS |
827 | 100, |
828 | b | |
829 | ); | |
3f8be614 MS |
830 | } |
831 | } | |
832 | } | |
833 | ||
a22015f4 | 834 | class BoomEffect extends LXEffect { |
3f8be614 MS |
835 | |
836 | final BasicParameter falloff = new BasicParameter("WIDTH", 0.5); | |
837 | final BasicParameter speed = new BasicParameter("SPD", 0.5); | |
838 | final BasicParameter bright = new BasicParameter("BRT", 1.0); | |
839 | final BasicParameter sat = new BasicParameter("SAT", 0.2); | |
840 | List<Layer> layers = new ArrayList<Layer>(); | |
c39f7a04 | 841 | final float maxr = sqrt(model.xMax*model.xMax + model.yMax*model.yMax + model.zMax*model.zMax) + 10; |
3f8be614 MS |
842 | |
843 | class Layer { | |
844 | LinearEnvelope boom = new LinearEnvelope(-40, 500, 1300); | |
845 | ||
846 | Layer() { | |
847 | addModulator(boom); | |
848 | trigger(); | |
849 | } | |
850 | ||
851 | void trigger() { | |
852 | float falloffv = falloffv(); | |
2b6688e8 | 853 | boom.setRange(-100 / falloffv, maxr + 100/falloffv, 4000 - speed.getValuef() * 3300); |
3f8be614 MS |
854 | boom.trigger(); |
855 | } | |
856 | ||
d12e46b6 | 857 | void apply(int[] colors) { |
3f8be614 MS |
858 | float brightv = 100 * bright.getValuef(); |
859 | float falloffv = falloffv(); | |
860 | float satv = sat.getValuef() * 100; | |
861 | float huev = lx.getBaseHuef(); | |
2bb56822 | 862 | for (LXPoint p : model.points) { |
3f8be614 MS |
863 | colors[p.index] = blendColor( |
864 | colors[p.index], | |
19d16a16 | 865 | lx.hsb(huev, satv, constrain(brightv - falloffv*abs(boom.getValuef() - dist(p.x, 2*p.y, 3*p.z, model.xMax/2, model.yMax, model.zMax*1.5)), 0, 100)), |
3f8be614 MS |
866 | ADD); |
867 | } | |
868 | } | |
869 | } | |
870 | ||
a22015f4 MS |
871 | BoomEffect(LX lx) { |
872 | super(lx, true); | |
3f8be614 MS |
873 | addParameter(falloff); |
874 | addParameter(speed); | |
875 | addParameter(bright); | |
876 | addParameter(sat); | |
877 | } | |
878 | ||
879 | public void onEnable() { | |
880 | for (Layer l : layers) { | |
881 | if (!l.boom.isRunning()) { | |
882 | l.trigger(); | |
883 | return; | |
884 | } | |
885 | } | |
886 | layers.add(new Layer()); | |
887 | } | |
888 | ||
889 | private float falloffv() { | |
890 | return 20 - 19 * falloff.getValuef(); | |
891 | } | |
892 | ||
893 | public void onTrigger() { | |
894 | onEnable(); | |
895 | } | |
896 | ||
d12e46b6 | 897 | public void apply(int[] colors) { |
3f8be614 MS |
898 | for (Layer l : layers) { |
899 | if (l.boom.isRunning()) { | |
d12e46b6 | 900 | l.apply(colors); |
3f8be614 | 901 | } |
49815cc0 MS |
902 | } |
903 | } | |
904 | } | |
905 | ||
5d70e4d7 MS |
906 | public class PianoKeyPattern extends SCPattern { |
907 | ||
908 | final LinearEnvelope[] cubeBrt; | |
909 | final SinLFO base[]; | |
910 | final BasicParameter attack = new BasicParameter("ATK", 0.1); | |
911 | final BasicParameter release = new BasicParameter("REL", 0.5); | |
912 | final BasicParameter level = new BasicParameter("AMB", 0.6); | |
913 | ||
dde75983 MS |
914 | PianoKeyPattern(LX lx) { |
915 | super(lx); | |
a8d55ade | 916 | |
5d70e4d7 MS |
917 | addParameter(attack); |
918 | addParameter(release); | |
919 | addParameter(level); | |
87f6fa39 | 920 | cubeBrt = new LinearEnvelope[model.cubes.size() / 4]; |
5d70e4d7 MS |
921 | for (int i = 0; i < cubeBrt.length; ++i) { |
922 | addModulator(cubeBrt[i] = new LinearEnvelope(0, 0, 100)); | |
923 | } | |
87f6fa39 | 924 | base = new SinLFO[model.cubes.size() / 12]; |
5d70e4d7 MS |
925 | for (int i = 0; i < base.length; ++i) { |
926 | addModulator(base[i] = new SinLFO(0, 1, 7000 + 1000*i)).trigger(); | |
927 | } | |
928 | } | |
929 | ||
930 | private float getAttackTime() { | |
931 | return 15 + attack.getValuef()*attack.getValuef() * 2000; | |
932 | } | |
933 | ||
934 | private float getReleaseTime() { | |
935 | return 15 + release.getValuef() * 3000; | |
936 | } | |
937 | ||
938 | private LinearEnvelope getEnvelope(int index) { | |
939 | return cubeBrt[index % cubeBrt.length]; | |
940 | } | |
941 | ||
942 | private SinLFO getBase(int index) { | |
943 | return base[index % base.length]; | |
944 | } | |
945 | ||
242b19ad | 946 | public boolean noteOn(Note note) { |
5d70e4d7 MS |
947 | LinearEnvelope env = getEnvelope(note.getPitch()); |
948 | env.setEndVal(min(1, env.getValuef() + (note.getVelocity() / 127.)), getAttackTime()).start(); | |
d6ac1ee8 | 949 | return true; |
5d70e4d7 MS |
950 | } |
951 | ||
242b19ad | 952 | public boolean noteOff(Note note) { |
5d70e4d7 | 953 | getEnvelope(note.getPitch()).setEndVal(0, getReleaseTime()).start(); |
d6ac1ee8 | 954 | return true; |
5d70e4d7 MS |
955 | } |
956 | ||
34327c96 | 957 | public void run(double deltaMs) { |
5d70e4d7 MS |
958 | int i = 0; |
959 | float huef = lx.getBaseHuef(); | |
960 | float levelf = level.getValuef(); | |
87f6fa39 | 961 | for (Cube c : model.cubes) { |
5d70e4d7 | 962 | float v = max(getBase(i).getValuef() * levelf/4., getEnvelope(i++).getValuef()); |
19d16a16 | 963 | setColor(c, lx.hsb( |
e0cea600 | 964 | (huef + 20*v + abs(c.cx-model.xMax/2.)*.3 + c.cy) % 360, |
5d70e4d7 MS |
965 | min(100, 120*v), |
966 | 100*v | |
967 | )); | |
968 | } | |
969 | } | |
970 | } | |
971 | ||
0106b29c MS |
972 | class CrossSections extends SCPattern { |
973 | ||
c39f7a04 MS |
974 | final SinLFO x = new SinLFO(0, model.xMax, 5000); |
975 | final SinLFO y = new SinLFO(0, model.yMax, 6000); | |
976 | final SinLFO z = new SinLFO(0, model.zMax, 7000); | |
0106b29c MS |
977 | |
978 | final BasicParameter xw = new BasicParameter("XWID", 0.3); | |
979 | final BasicParameter yw = new BasicParameter("YWID", 0.3); | |
980 | final BasicParameter zw = new BasicParameter("ZWID", 0.3); | |
2b6688e8 | 981 | final BasicParameter xr = new BasicParameter("XRAT", 0.7); |
0106b29c | 982 | final BasicParameter yr = new BasicParameter("YRAT", 0.6); |
2b6688e8 MS |
983 | final BasicParameter zr = new BasicParameter("ZRAT", 0.5); |
984 | final BasicParameter xl = new BasicParameter("XLEV", 1); | |
0106b29c | 985 | final BasicParameter yl = new BasicParameter("YLEV", 1); |
2b6688e8 | 986 | final BasicParameter zl = new BasicParameter("ZLEV", 0.5); |
0106b29c MS |
987 | |
988 | ||
dde75983 MS |
989 | CrossSections(LX lx) { |
990 | super(lx); | |
0106b29c MS |
991 | addModulator(x).trigger(); |
992 | addModulator(y).trigger(); | |
993 | addModulator(z).trigger(); | |
b12bca62 MS |
994 | addParams(); |
995 | } | |
996 | ||
997 | protected void addParams() { | |
0106b29c MS |
998 | addParameter(xr); |
999 | addParameter(yr); | |
1000 | addParameter(zr); | |
2b6688e8 | 1001 | addParameter(xw); |
0106b29c MS |
1002 | addParameter(xl); |
1003 | addParameter(yl); | |
1004 | addParameter(zl); | |
2b6688e8 MS |
1005 | addParameter(yw); |
1006 | addParameter(zw); | |
0106b29c | 1007 | } |
3e8e60d8 MS |
1008 | |
1009 | void onParameterChanged(LXParameter p) { | |
0106b29c | 1010 | if (p == xr) { |
2b6688e8 | 1011 | x.setDuration(10000 - 8800*p.getValuef()); |
0106b29c | 1012 | } else if (p == yr) { |
2b6688e8 | 1013 | y.setDuration(10000 - 9000*p.getValuef()); |
0106b29c MS |
1014 | } else if (p == zr) { |
1015 | z.setDuration(10000 - 9000*p.getValuef()); | |
1016 | } | |
0106b29c | 1017 | } |
b12bca62 MS |
1018 | |
1019 | float xv, yv, zv; | |
1020 | ||
1021 | protected void updateXYZVals() { | |
1022 | xv = x.getValuef(); | |
1023 | yv = y.getValuef(); | |
1024 | zv = z.getValuef(); | |
1025 | } | |
0106b29c | 1026 | |
34327c96 | 1027 | public void run(double deltaMs) { |
f1c74267 MS |
1028 | updateXYZVals(); |
1029 | ||
0106b29c MS |
1030 | float xlv = 100*xl.getValuef(); |
1031 | float ylv = 100*yl.getValuef(); | |
1032 | float zlv = 100*zl.getValuef(); | |
1033 | ||
1034 | float xwv = 100. / (10 + 40*xw.getValuef()); | |
1035 | float ywv = 100. / (10 + 40*yw.getValuef()); | |
1036 | float zwv = 100. / (10 + 40*zw.getValuef()); | |
1037 | ||
2bb56822 | 1038 | for (LXPoint p : model.points) { |
0106b29c | 1039 | color c = 0; |
19d16a16 | 1040 | c = blendColor(c, lx.hsb( |
190d91c2 MS |
1041 | (lx.getBaseHuef() + p.x/10 + p.y/3) % 360, |
1042 | constrain(140 - 1.1*abs(p.x - model.xMax/2.), 0, 100), | |
1043 | max(0, xlv - xwv*abs(p.x - xv)) | |
0106b29c | 1044 | ), ADD); |
19d16a16 | 1045 | c = blendColor(c, lx.hsb( |
190d91c2 MS |
1046 | (lx.getBaseHuef() + 80 + p.y/10) % 360, |
1047 | constrain(140 - 2.2*abs(p.y - model.yMax/2.), 0, 100), | |
1048 | max(0, ylv - ywv*abs(p.y - yv)) | |
0106b29c | 1049 | ), ADD); |
19d16a16 | 1050 | c = blendColor(c, lx.hsb( |
190d91c2 MS |
1051 | (lx.getBaseHuef() + 160 + p.z / 10 + p.y/2) % 360, |
1052 | constrain(140 - 2.2*abs(p.z - model.zMax/2.), 0, 100), | |
1053 | max(0, zlv - zwv*abs(p.z - zv)) | |
0106b29c MS |
1054 | ), ADD); |
1055 | colors[p.index] = c; | |
1056 | } | |
1057 | } | |
1058 | } | |
1059 | ||
1060 | class Blinders extends SCPattern { | |
1061 | ||
aa54c1ca | 1062 | final SinLFO[] m; |
0106b29c MS |
1063 | final TriangleLFO r; |
1064 | final SinLFO s; | |
1065 | final TriangleLFO hs; | |
1066 | ||
dde75983 MS |
1067 | public Blinders(LX lx) { |
1068 | super(lx); | |
aa54c1ca MS |
1069 | m = new SinLFO[12]; |
1070 | for (int i = 0; i < m.length; ++i) { | |
1071 | addModulator(m[i] = new SinLFO(0.5, 120, (120000. / (3+i)))).trigger(); | |
1072 | } | |
1073 | addModulator(r = new TriangleLFO(9000, 15000, 29000)).trigger(); | |
1074 | addModulator(s = new SinLFO(-20, 275, 11000)).trigger(); | |
0106b29c | 1075 | addModulator(hs = new TriangleLFO(0.1, 0.5, 15000)).trigger(); |
aa54c1ca | 1076 | s.modulateDurationBy(r); |
0106b29c MS |
1077 | } |
1078 | ||
34327c96 | 1079 | public void run(double deltaMs) { |
0106b29c | 1080 | float hv = lx.getBaseHuef(); |
aa54c1ca | 1081 | int si = 0; |
87f6fa39 | 1082 | for (Strip strip : model.strips) { |
0106b29c | 1083 | int i = 0; |
aa54c1ca | 1084 | float mv = m[si % m.length].getValuef(); |
2bb56822 | 1085 | for (LXPoint p : strip.points) { |
19d16a16 | 1086 | colors[p.index] = lx.hsb( |
190d91c2 MS |
1087 | (hv + p.z + p.y*hs.getValuef()) % 360, |
1088 | min(100, abs(p.x - s.getValuef())/2.), | |
254fbb68 | 1089 | max(0, 100 - mv/2. - mv * abs(i - (strip.metrics.length-1)/2.)) |
0106b29c MS |
1090 | ); |
1091 | ++i; | |
1092 | } | |
aa54c1ca | 1093 | ++si; |
0106b29c MS |
1094 | } |
1095 | } | |
1096 | } | |
1097 | ||
87f6fa39 MS |
1098 | class Psychedelia extends SCPattern { |
1099 | ||
1100 | final int NUM = 3; | |
1101 | SinLFO m = new SinLFO(-0.5, NUM-0.5, 9000); | |
1102 | SinLFO s = new SinLFO(-20, 147, 11000); | |
1103 | TriangleLFO h = new TriangleLFO(0, 240, 19000); | |
1104 | SinLFO c = new SinLFO(-.2, .8, 31000); | |
1105 | ||
dde75983 MS |
1106 | Psychedelia(LX lx) { |
1107 | super(lx); | |
87f6fa39 MS |
1108 | addModulator(m).trigger(); |
1109 | addModulator(s).trigger(); | |
1110 | addModulator(h).trigger(); | |
1111 | addModulator(c).trigger(); | |
1112 | } | |
0106b29c | 1113 | |
34327c96 | 1114 | void run(double deltaMs) { |
87f6fa39 MS |
1115 | float huev = h.getValuef(); |
1116 | float cv = c.getValuef(); | |
1117 | float sv = s.getValuef(); | |
1118 | float mv = m.getValuef(); | |
1119 | int i = 0; | |
1120 | for (Strip strip : model.strips) { | |
2bb56822 | 1121 | for (LXPoint p : strip.points) { |
19d16a16 | 1122 | colors[p.index] = lx.hsb( |
190d91c2 MS |
1123 | (huev + i*constrain(cv, 0, 2) + p.z/2. + p.x/4.) % 360, |
1124 | min(100, abs(p.y-sv)), | |
87f6fa39 MS |
1125 | max(0, 100 - 50*abs((i%NUM) - mv)) |
1126 | ); | |
1127 | } | |
1128 | ++i; | |
1129 | } | |
1130 | } | |
1131 | } | |
5129affb MS |
1132 | |
1133 | class AskewPlanes extends SCPattern { | |
1134 | ||
1135 | class Plane { | |
1136 | private final SinLFO a; | |
1137 | private final SinLFO b; | |
1138 | private final SinLFO c; | |
775d3394 MS |
1139 | float av = 1; |
1140 | float bv = 1; | |
1141 | float cv = 1; | |
1142 | float denom = 0.1; | |
5129affb MS |
1143 | |
1144 | Plane(int i) { | |
1145 | addModulator(a = new SinLFO(-1, 1, 4000 + 1029*i)).trigger(); | |
1146 | addModulator(b = new SinLFO(-1, 1, 11000 - 1104*i)).trigger(); | |
1147 | addModulator(c = new SinLFO(-50, 50, 4000 + 1000*i * ((i % 2 == 0) ? 1 : -1))).trigger(); | |
1148 | } | |
1149 | ||
34327c96 | 1150 | void run(double deltaMs) { |
5129affb MS |
1151 | av = a.getValuef(); |
1152 | bv = b.getValuef(); | |
1153 | cv = c.getValuef(); | |
1154 | denom = sqrt(av*av + bv*bv); | |
1155 | } | |
1156 | } | |
1157 | ||
1158 | final Plane[] planes; | |
1159 | final int NUM_PLANES = 3; | |
1160 | ||
dde75983 MS |
1161 | AskewPlanes(LX lx) { |
1162 | super(lx); | |
5129affb MS |
1163 | planes = new Plane[NUM_PLANES]; |
1164 | for (int i = 0; i < planes.length; ++i) { | |
1165 | planes[i] = new Plane(i); | |
1166 | } | |
1167 | } | |
5129affb | 1168 | |
34327c96 | 1169 | public void run(double deltaMs) { |
5129affb | 1170 | float huev = lx.getBaseHuef(); |
775d3394 MS |
1171 | |
1172 | // This is super fucking bizarre. But if this is a for loop, the framerate | |
1173 | // tanks to like 30FPS, instead of 60. Call them manually and it works fine. | |
1174 | // Doesn't make ANY sense... there must be some weird side effect going on | |
1175 | // with the Processing internals perhaps? | |
1176 | // for (Plane plane : planes) { | |
1177 | // plane.run(deltaMs); | |
1178 | // } | |
1179 | planes[0].run(deltaMs); | |
1180 | planes[1].run(deltaMs); | |
1181 | planes[2].run(deltaMs); | |
1182 | ||
2bb56822 | 1183 | for (LXPoint p : model.points) { |
775d3394 MS |
1184 | float d = MAX_FLOAT; |
1185 | for (Plane plane : planes) { | |
1186 | if (plane.denom != 0) { | |
190d91c2 | 1187 | d = min(d, abs(plane.av*(p.x-model.cx) + plane.bv*(p.y-model.cy) + plane.cv) / plane.denom); |
775d3394 MS |
1188 | } |
1189 | } | |
19d16a16 | 1190 | colors[p.index] = lx.hsb( |
190d91c2 MS |
1191 | (huev + abs(p.x-model.cx)*.3 + p.y*.8) % 360, |
1192 | max(0, 100 - .8*abs(p.x - model.cx)), | |
775d3394 MS |
1193 | constrain(140 - 10.*d, 0, 100) |
1194 | ); | |
5129affb MS |
1195 | } |
1196 | } | |
1197 | } | |
1198 | ||
1199 | class ShiftingPlane extends SCPattern { | |
1200 | ||
1201 | final SinLFO a = new SinLFO(-.2, .2, 5300); | |
1202 | final SinLFO b = new SinLFO(1, -1, 13300); | |
1203 | final SinLFO c = new SinLFO(-1.4, 1.4, 5700); | |
1204 | final SinLFO d = new SinLFO(-10, 10, 9500); | |
1205 | ||
dde75983 MS |
1206 | ShiftingPlane(LX lx) { |
1207 | super(lx); | |
5129affb MS |
1208 | addModulator(a).trigger(); |
1209 | addModulator(b).trigger(); | |
1210 | addModulator(c).trigger(); | |
1211 | addModulator(d).trigger(); | |
1212 | } | |
1213 | ||
34327c96 | 1214 | public void run(double deltaMs) { |
5129affb MS |
1215 | float hv = lx.getBaseHuef(); |
1216 | float av = a.getValuef(); | |
1217 | float bv = b.getValuef(); | |
1218 | float cv = c.getValuef(); | |
1219 | float dv = d.getValuef(); | |
1220 | float denom = sqrt(av*av + bv*bv + cv*cv); | |
2bb56822 | 1221 | for (LXPoint p : model.points) { |
190d91c2 | 1222 | float d = abs(av*(p.x-model.cx) + bv*(p.y-model.cy) + cv*(p.z-model.cz) + dv) / denom; |
19d16a16 | 1223 | colors[p.index] = lx.hsb( |
190d91c2 | 1224 | (hv + abs(p.x-model.cx)*.6 + abs(p.y-model.cy)*.9 + abs(p.z - model.cz)) % 360, |
5129affb MS |
1225 | constrain(110 - d*6, 0, 100), |
1226 | constrain(130 - 7*d, 0, 100) | |
1227 | ); | |
1228 | } | |
1229 | } | |
1230 | } | |
f3f5a876 | 1231 | |
4c006f7b MS |
1232 | class Traktor extends SCPattern { |
1233 | ||
1234 | final int FRAME_WIDTH = 60; | |
1235 | ||
1236 | final BasicParameter speed = new BasicParameter("SPD", 0.5); | |
1237 | ||
1238 | private float[] bass = new float[FRAME_WIDTH]; | |
1239 | private float[] treble = new float[FRAME_WIDTH]; | |
1240 | ||
1241 | private int index = 0; | |
1242 | private GraphicEQ eq = null; | |
1243 | ||
dde75983 MS |
1244 | public Traktor(LX lx) { |
1245 | super(lx); | |
4c006f7b MS |
1246 | for (int i = 0; i < FRAME_WIDTH; ++i) { |
1247 | bass[i] = 0; | |
1248 | treble[i] = 0; | |
1249 | } | |
1250 | addParameter(speed); | |
1251 | } | |
1252 | ||
1253 | public void onActive() { | |
1254 | if (eq == null) { | |
1255 | eq = new GraphicEQ(lx, 16); | |
1256 | eq.slope.setValue(0.6); | |
1257 | eq.level.setValue(0.65); | |
1258 | eq.range.setValue(0.35); | |
1259 | eq.release.setValue(0.4); | |
1260 | addParameter(eq.level); | |
1261 | addParameter(eq.range); | |
1262 | addParameter(eq.attack); | |
1263 | addParameter(eq.release); | |
1264 | addParameter(eq.slope); | |
1265 | } | |
1266 | } | |
1267 | ||
1268 | int counter = 0; | |
1269 | ||
34327c96 | 1270 | public void run(double deltaMs) { |
4c006f7b MS |
1271 | eq.run(deltaMs); |
1272 | ||
1273 | int stepThresh = (int) (40 - 39*speed.getValuef()); | |
1274 | counter += deltaMs; | |
1275 | if (counter < stepThresh) { | |
1276 | return; | |
1277 | } | |
1278 | counter = counter % stepThresh; | |
1279 | ||
1280 | index = (index + 1) % FRAME_WIDTH; | |
1281 | ||
1282 | float rawBass = eq.getAverageLevel(0, 4); | |
1283 | float rawTreble = eq.getAverageLevel(eq.numBands-7, 7); | |
1284 | ||
1285 | bass[index] = rawBass * rawBass * rawBass * rawBass; | |
1286 | treble[index] = rawTreble * rawTreble; | |
1287 | ||
2bb56822 | 1288 | for (LXPoint p : model.points) { |
4c006f7b MS |
1289 | int i = (int) constrain((model.xMax - p.x) / model.xMax * FRAME_WIDTH, 0, FRAME_WIDTH-1); |
1290 | int pos = (index + FRAME_WIDTH - i) % FRAME_WIDTH; | |
1291 | ||
19d16a16 | 1292 | colors[p.index] = lx.hsb( |
4c006f7b MS |
1293 | (360 + lx.getBaseHuef() + .8*abs(p.x-model.cx)) % 360, |
1294 | 100, | |
29d8acbb | 1295 | constrain(9 * (bass[pos]*model.cy - abs(p.y - model.cy + 5)), 0, 100) |
4c006f7b | 1296 | ); |
19d16a16 | 1297 | colors[p.index] = blendColor(colors[p.index], lx.hsb( |
4c006f7b MS |
1298 | (400 + lx.getBaseHuef() + .5*abs(p.x-model.cx)) % 360, |
1299 | 60, | |
190d91c2 | 1300 | constrain(5 * (treble[pos]*.6*model.cy - abs(p.y - model.cy)), 0, 100) |
4c006f7b MS |
1301 | |
1302 | ), ADD); | |
1303 | } | |
1304 | } | |
1305 | } | |
6702151a | 1306 | |
a22015f4 | 1307 | class ColorFuckerEffect extends LXEffect { |
6702151a | 1308 | |
e5308763 | 1309 | final BasicParameter level = new BasicParameter("BRT", 1); |
1310 | final BasicParameter desat = new BasicParameter("DSAT", 0); | |
29d8acbb | 1311 | final BasicParameter hueShift = new BasicParameter("HSHFT", 0); |
e5308763 | 1312 | final BasicParameter sharp = new BasicParameter("SHARP", 0); |
1313 | final BasicParameter soft = new BasicParameter("SOFT", 0); | |
1314 | final BasicParameter mono = new BasicParameter("MONO", 0); | |
1315 | final BasicParameter invert = new BasicParameter("INVERT", 0); | |
29d8acbb | 1316 | |
e5308763 | 1317 | |
4214e9a2 | 1318 | float[] hsb = new float[3]; |
6702151a | 1319 | |
a22015f4 MS |
1320 | ColorFuckerEffect(LX lx) { |
1321 | super(lx); | |
e5308763 | 1322 | addParameter(level); |
1323 | addParameter(desat); | |
1324 | addParameter(sharp); | |
29d8acbb | 1325 | addParameter(hueShift); |
e5308763 | 1326 | addParameter(soft); |
1327 | addParameter(mono); | |
1328 | addParameter(invert); | |
6702151a MS |
1329 | } |
1330 | ||
d12e46b6 | 1331 | public void apply(int[] colors) { |
4749563e | 1332 | if (!isEnabled()) { |
d626bc9b MS |
1333 | return; |
1334 | } | |
e5308763 | 1335 | float bMod = level.getValuef(); |
1336 | float sMod = 1 - desat.getValuef(); | |
6702151a | 1337 | float hMod = hueShift.getValuef(); |
ef7118ad | 1338 | float fSharp = sharp.getValuef(); |
e5308763 | 1339 | float fSoft = soft.getValuef(); |
1340 | boolean mon = mono.getValuef() > 0.5; | |
1341 | boolean ivt = invert.getValuef() > 0.5; | |
1342 | if (bMod < 1 || sMod < 1 || hMod > 0 || fSharp > 0 || ivt || mon || fSoft > 0) { | |
6702151a | 1343 | for (int i = 0; i < colors.length; ++i) { |
4214e9a2 | 1344 | lx.RGBtoHSB(colors[i], hsb); |
e5308763 | 1345 | if (mon) { |
1346 | hsb[0] = lx.getBaseHuef() / 360.; | |
1347 | } | |
1348 | if (ivt) { | |
1349 | hsb[2] = 1 - hsb[2]; | |
1350 | } | |
1351 | if (fSharp > 0) { | |
ef7118ad | 1352 | fSharp = 1/(1-fSharp); |
bae2197a MS |
1353 | if (hsb[2] < .5) { |
1354 | hsb[2] = pow(hsb[2],fSharp); | |
1355 | } else { | |
1356 | hsb[2] = 1-pow(1-hsb[2],fSharp); | |
1357 | } | |
e5308763 | 1358 | } |
1359 | if (fSoft > 0) { | |
1360 | if (hsb[2] > 0.5) { | |
1361 | hsb[2] = lerp(hsb[2], 0.5 + 2 * (hsb[2]-0.5)*(hsb[2]-0.5), fSoft); | |
1362 | } else { | |
1363 | hsb[2] = lerp(hsb[2], 0.5 * sqrt(2*hsb[2]), fSoft); | |
1364 | } | |
1365 | } | |
4214e9a2 | 1366 | colors[i] = lx.hsb( |
e5308763 | 1367 | (360. * hsb[0] + hMod*360.) % 360, |
1368 | 100. * hsb[1] * sMod, | |
1369 | 100. * hsb[2] * bMod | |
6702151a MS |
1370 | ); |
1371 | } | |
1372 | } | |
1373 | } | |
1374 | } | |
348fed66 | 1375 | |
a22015f4 | 1376 | class QuantizeEffect extends LXEffect { |
e5308763 | 1377 | |
1378 | color[] quantizedFrame; | |
1379 | float lastQuant; | |
1380 | final BasicParameter amount = new BasicParameter("AMT", 0); | |
1381 | ||
a22015f4 MS |
1382 | QuantizeEffect(LX lx) { |
1383 | super(lx); | |
0c7bfdb5 | 1384 | quantizedFrame = new color[lx.total]; |
e5308763 | 1385 | lastQuant = 0; |
1386 | } | |
1387 | ||
d12e46b6 | 1388 | public void apply(int[] colors) { |
e5308763 | 1389 | float fQuant = amount.getValuef(); |
1390 | if (fQuant > 0) { | |
1391 | float tRamp = (lx.tempo.rampf() % (1./pow(2,floor((1-fQuant) * 4)))); | |
1392 | float f = lastQuant; | |
1393 | lastQuant = tRamp; | |
1394 | if (tRamp > f) { | |
1395 | for (int i = 0; i < colors.length; ++i) { | |
1396 | colors[i] = quantizedFrame[i]; | |
1397 | } | |
1398 | return; | |
1399 | } | |
1400 | } | |
1401 | for (int i = 0; i < colors.length; ++i) { | |
1402 | quantizedFrame[i] = colors[i]; | |
1403 | } | |
1404 | } | |
1405 | } | |
1406 | ||
a22015f4 | 1407 | class BlurEffect extends LXEffect { |
348fed66 | 1408 | |
05ebfd15 | 1409 | final BasicParameter amount = new BasicParameter("AMT", 0); |
348fed66 MS |
1410 | final int[] frame; |
1411 | final LinearEnvelope env = new LinearEnvelope(0, 1, 100); | |
1412 | ||
a22015f4 MS |
1413 | BlurEffect(LX lx) { |
1414 | super(lx); | |
348fed66 MS |
1415 | addParameter(amount); |
1416 | addModulator(env); | |
1417 | frame = new int[lx.total]; | |
1418 | for (int i = 0; i < frame.length; ++i) { | |
1419 | frame[i] = #000000; | |
1420 | } | |
1421 | } | |
1422 | ||
1423 | public void onEnable() { | |
1424 | env.setRangeFromHereTo(1, 400).start(); | |
1425 | for (int i = 0; i < frame.length; ++i) { | |
1426 | frame[i] = #000000; | |
1427 | } | |
1428 | } | |
1429 | ||
1430 | public void onDisable() { | |
1431 | env.setRangeFromHereTo(0, 1000).start(); | |
1432 | } | |
1433 | ||
d12e46b6 | 1434 | public void apply(int[] colors) { |
348fed66 MS |
1435 | float amt = env.getValuef() * amount.getValuef(); |
1436 | if (amt > 0) { | |
1437 | amt = (1 - amt); | |
1438 | amt = 1 - (amt*amt*amt); | |
1439 | for (int i = 0; i < colors.length; ++i) { | |
1440 | // frame[i] = colors[i] = blendColor(colors[i], lerpColor(#000000, frame[i], amt, RGB), SCREEN); | |
1441 | frame[i] = colors[i] = lerpColor(colors[i], blendColor(colors[i], frame[i], SCREEN), amt, RGB); | |
1442 | } | |
1443 | } | |
1444 | ||
1445 | } | |
1446 | } | |
2bb56822 | 1447 |