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