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