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