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