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