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