]>
Commit | Line | Data |
---|---|---|
1 | ||
2 | class SineSphere extends APat { | |
3 | float modelrad = sqrt((model.xMax)*(model.xMax) + (model.yMax)*(model.yMax) + (model.zMax)*(model.zMax)); | |
4 | private BasicParameter yrotspeed = new BasicParameter("yspeed", 3000, 1, 10000); | |
5 | private BasicParameter yrot2speed = new BasicParameter("y2speed", 4000, 1, 15000); | |
6 | private BasicParameter yrot3speed = new BasicParameter("y3speed", 1400, 1, 15000); | |
7 | private BasicParameter vibrationrate = new BasicParameter("vib", 3000, 1, 10000); | |
8 | private SawLFO yrot = new SawLFO(0, TWO_PI, yrotspeed); | |
9 | private SawLFO yrot2 = new SawLFO(0, -TWO_PI, yrot2speed); | |
10 | private SawLFO yrot3 = new SawLFO(0, -TWO_PI, yrot3speed); | |
11 | public BasicParameter huespread = new BasicParameter("Hue", 0, 180); | |
12 | public BasicParameter widthparameter= new BasicParameter("Width", 20, 1, 60); | |
13 | public BasicParameter vibration_magnitude = new BasicParameter("Vmag", 20, 2, modelrad/2); | |
14 | public BasicParameter scale = new BasicParameter("Scale", 1, .1, 5); | |
15 | private int pitch = 0; | |
16 | private int channel = 0; | |
17 | private int velocity = 0; | |
18 | private int cur = 0; | |
19 | public final LXProjection sinespin; | |
20 | public final LXProjection sinespin2; | |
21 | public final LXProjection sinespin3; | |
22 | ||
23 | Pick Galaxy, STime; | |
24 | ||
25 | public BasicParameter rotationx = new BasicParameter("rotx", 0, 0, 1 ); | |
26 | public BasicParameter rotationy = new BasicParameter("roty", 1, 0, 1); | |
27 | public BasicParameter rotationz = new BasicParameter("rotz", 0, 0, 1); | |
28 | ||
29 | public final PVector P = new PVector(); | |
30 | ||
31 | class Sphery { | |
32 | float f1xcenter, f1ycenter, f1zcenter, f2xcenter , f2ycenter, f2zcenter; //second three are for an ellipse with two foci | |
33 | private SinLFO vibration; | |
34 | private SinLFO surfacewave; | |
35 | ||
36 | private SinLFO xbounce; | |
37 | public SinLFO ybounce; | |
38 | private SinLFO zbounce; | |
39 | float vibration_magnitude, vperiod, radius, vibration_min, vibration_max; | |
40 | ||
41 | //public BasicParameter huespread; | |
42 | public BasicParameter bouncerate; | |
43 | public BasicParameter bounceamp; | |
44 | public BasicParameter vibrationrate; | |
45 | public final PVector circlecenter; | |
46 | ||
47 | public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float radius, float vibration_magnitude , float vperiod) | |
48 | { | |
49 | this.f1xcenter = f1xcenter; | |
50 | this.f1ycenter = f1ycenter; | |
51 | this.f1zcenter = f1zcenter; | |
52 | this.radius = radius; | |
53 | this.circlecenter= new PVector(f1xcenter,f1ycenter,f1zcenter); | |
54 | ||
55 | this.vibration_magnitude = vibration_magnitude; | |
56 | ||
57 | this.vperiod = vperiod; | |
58 | //addParameter(bounceamp = new BasicParameter("Amp", .5)); | |
59 | //addParameter(bouncerate = new BasicParameter("Rate", .5)); //ybounce.modulateDurationBy(bouncerate); | |
60 | //addParameter(vibrationrate = new BasicParameter("vibration", 1000, 10000)); | |
61 | //addParameter(widthparameter = new BasicParameter("Width", .2)); | |
62 | //addModulator(xbounce = new SinLFO(model.xMax/3, 2*model.yMax/3, 2000)).trigger(); | |
63 | addModulator(ybounce= new SinLFO(model.yMax/3, 2*model.yMax/3, 240000)).trigger(); //bounce.modulateDurationBy | |
64 | ||
65 | //addModulator(bounceamp); //ybounce.setMagnitude(bouncerate); | |
66 | addModulator( vibration = new SinLFO( this.radius - vibration_magnitude , this.radius + vibration_magnitude, vperiod)).trigger(); //vibration.setPeriod(240000/lx.tempo.bpm()); | |
67 | ||
68 | ||
69 | } | |
70 | ||
71 | // public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float vibration_magnitude, float vperiod) | |
72 | // { | |
73 | // this.f1xcenter = f1xcenter; | |
74 | // this.f1ycenter = f1ycenter; | |
75 | // this.f1zcenter = f1zcenter; | |
76 | // this.vibration_magnitude = vibration_magnitude; | |
77 | // this.vperiod = vperiod; | |
78 | // addModulator(ybounce= new SinLFO(model.yMax/3, 2*model.yMax/3, 240000)).trigger(); //bounce.modulateDurationBy | |
79 | // addModulator( vibration = new SinLFO( modelrad/10 - vibration_magnitude , modelrad/10 + vibration_magnitude, vperiod)).trigger(); //vibration.setPeriod(240000/lx.tempo.bpm()); | |
80 | ||
81 | // } | |
82 | ||
83 | //for an ellipse | |
84 | // public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float f2xcenter, float f2ycenter, float f2zcenter, | |
85 | // float vibration_min, float vibration_max, float vperiod) | |
86 | ||
87 | // { | |
88 | // this.f1xcenter = f1xcenter; | |
89 | // this.f1ycenter = f1ycenter; | |
90 | // this.f1zcenter = f1zcenter; | |
91 | // this.f2xcenter = f2xcenter; | |
92 | // this.f2ycenter = f2ycenter; | |
93 | // this.f2zcenter = f2zcenter; | |
94 | // this.vibration_min = vibration_min; | |
95 | // this.vibration_max = vibration_max; | |
96 | // this.vperiod = vperiod; | |
97 | // //addModulator(xbounce = new SinLFO(model.xMax/3, 2*model.yMax/3, 2000)).trigger(); | |
98 | // addModulator(ybounce).trigger(); | |
99 | // addModulator( vibration = new SinLFO(vibration_min , vibration_max, lx.tempo.rampf())).trigger(); //vibration.modulateDurationBy(vx); | |
100 | // addParameter(widthparameter = new BasicParameter("Width", .1)); | |
101 | // //addParameter(huespread = new BasicParameter("bonk", .2)); | |
102 | ||
103 | // } | |
104 | ||
105 | public int c1c (float a) { return round(100*constrain(a,0,1)); } | |
106 | ||
107 | void setVibrationPeriod(double period){ | |
108 | // to-do: make this conditional upon time signature | |
109 | ||
110 | this.vibration.setPeriod(period); | |
111 | } | |
112 | ||
113 | void setVibrationMagnitude(double mag){ | |
114 | //to-do: make this optionally conditional upon decibel volume, frequency spectrum) | |
115 | this.vibration.setRange(-mag,mag); | |
116 | ||
117 | } | |
118 | ||
119 | ||
120 | float distfromcirclecenter(float px, float py, float pz, float f1x, float f1y, float f1z) | |
121 | { | |
122 | return dist(px, py, pz, f1x, f1y, f1z); | |
123 | } | |
124 | //void updatespherey(deltaMs, ) | |
125 | ||
126 | float quadrant(PVector q) { | |
127 | float qtheta = atan2( (q.x-f1xcenter) , (q.z - f1zcenter) ); | |
128 | float qphi = acos( (q.z-f1zcenter)/(PVector.dist(q,circlecenter)) ); | |
129 | ||
130 | ||
131 | return map(qtheta, -PI/2, PI/2, 200-huespread.getValuef(), 240+huespread.getValuef()); | |
132 | //if (q.x > f1xcenter ) {return 140 ;} | |
133 | //else {return 250;} | |
134 | } | |
135 | ||
136 | // float noisesat(PVector q) { | |
137 | ||
138 | ||
139 | // return noise() | |
140 | ||
141 | // } | |
142 | color spheryvalue (PVector p) { | |
143 | circlecenter.set(this.f1xcenter, this.f1ycenter, this.f1zcenter); | |
144 | ||
145 | ||
146 | //switch(sShpape.cur() ) {} | |
147 | ||
148 | float b = max(0, 100 - widthparameter.getValuef()*abs(p.dist(circlecenter) | |
149 | - vibration.getValuef()) ); | |
150 | ||
151 | if (b <= 0) { | |
152 | return 0; | |
153 | } | |
154 | ||
155 | return lx.hsb( | |
156 | constrain(quadrant(p), 0, 360), | |
157 | // constrain(100*noise(quadrant(p)), 0, 100), | |
158 | 100, | |
159 | b | |
160 | ); | |
161 | } | |
162 | color ellipsevalue(float px, float py, float pz , float f1xc, float f1yc, float f1zc, float f2xc, float f2yc, float f2zc) | |
163 | { | |
164 | //switch(sShpape.cur() ) {} | |
165 | return lx.hsb(huespread.getValuef()*5*px, dist(model.xMax-px, model.yMax-py, model.zMax-pz, f1xc, f1yc, f1zc) , | |
166 | max(0, 100 - 100*widthparameter.getValuef() * | |
167 | abs( (dist(px, py, pz, f1xc, ybounce.getValuef(), f1zc) + | |
168 | (dist(px, py , pz, f2xc, ybounce.getValuef(), f2zc) ) )/2 | |
169 | - 1.2*vibration.getValuef() ) ) ) ; | |
170 | } | |
171 | ||
172 | ||
173 | } | |
174 | ||
175 | boolean noteOn(Note note) { | |
176 | int row = note.getPitch(), col = note.getChannel(); | |
177 | // if (row == 57) {KeyPressed = col; return true; } | |
178 | return super.noteOn(note); | |
179 | } | |
180 | ||
181 | ||
182 | // public boolean noteOn(Note note) { | |
183 | // pitch= note.getPitch(); | |
184 | // velocity=note.getVelocity(); | |
185 | // channel=note.getChannel(); | |
186 | // return true; | |
187 | // } | |
188 | ||
189 | // public boolean gridPressed(int row, int col) { | |
190 | // pitch = row; channel = col; | |
191 | // cur = NumApcCols*(pitch-53)+col; | |
192 | // //setState(row, col, 0 ? 1 : 0); | |
193 | // return true; | |
194 | // } | |
195 | ||
196 | //public grid | |
197 | final Sphery[] spherys; | |
198 | ||
199 | SineSphere(LX lx) | |
200 | { | |
201 | super(lx); | |
202 | println("modelrad " + modelrad); | |
203 | sinespin = new LXProjection(model); | |
204 | sinespin2 = new LXProjection(model); | |
205 | sinespin3= new LXProjection(model); | |
206 | addParameter(huespread); | |
207 | addParameter(vibrationrate); | |
208 | addParameter(widthparameter); | |
209 | addParameter(rotationx); | |
210 | addParameter(rotationy); | |
211 | addParameter(rotationz); | |
212 | addParameter(yrotspeed); | |
213 | addParameter(yrot2speed); | |
214 | addParameter(yrot3speed); | |
215 | addParameter(vibration_magnitude); | |
216 | addParameter(scale); | |
217 | addModulator(yrot).trigger(); | |
218 | addModulator(yrot2).trigger(); | |
219 | addModulator(yrot3).trigger(); | |
220 | //Galaxy = addPick("Galaxy", 1, 3, new String[] {"home", "vertical","single","aquarium"}); | |
221 | STime =addPick("Time", 1, 4, new String[]{"half", "triplet", "beat", "2x", "3x" }); | |
222 | ||
223 | spherys = new Sphery[] { | |
224 | new Sphery(model.xMax/4, model.yMax/2, model.zMax/2, modelrad/12, modelrad/25, 3000), | |
225 | new Sphery(.75*model.xMax, model.yMax/2, model.zMax/2, modelrad/14, modelrad/28, 2000), | |
226 | new Sphery(model.cx, model.cy, model.cz, modelrad/5, modelrad/15, 2300), | |
227 | new Sphery(.7*model.xMax, .65*model.yMax, .5*model.zMax, modelrad/11, modelrad/25, 3500), | |
228 | new Sphery(.75*model.xMax, .8*model.yMax, .7*model.zMax, modelrad/12, modelrad/30, 2000) | |
229 | ||
230 | ||
231 | }; | |
232 | } | |
233 | ||
234 | // public void onParameterChanged(LXParameter parameter) | |
235 | // { | |
236 | ||
237 | ||
238 | // for (Sphery s : spherys) { | |
239 | // if (s == null) continue; | |
240 | // double bampv = s.bounceamp.getValue(); | |
241 | // double brv = s.bouncerate.getValue(); | |
242 | // double tempobounce = lx.tempo.bpm(); | |
243 | // if (parameter == s.bounceamp) | |
244 | // { | |
245 | // s.ybounce.setRange(bampv*model.yMax/3 , bampv*2*model.yMax/3, brv); | |
246 | // } | |
247 | // else if ( parameter == s.bouncerate ) | |
248 | // { | |
249 | // s.ybounce.setDuration(120000./tempobounce); | |
250 | // } | |
251 | // } | |
252 | // } | |
253 | ||
254 | public void run( double deltaMs) { | |
255 | float t = lx.tempo.rampf(); | |
256 | float bpm = lx.tempo.bpmf(); | |
257 | float scalevalue = scale.getValuef(); | |
258 | int spherytime= STime.Cur(); | |
259 | ||
260 | ||
261 | switch (spherytime) { | |
262 | ||
263 | case 0: t = map(.5*t ,0,.5, 0,1); bpm = .5*bpm; break; | |
264 | ||
265 | case 1: t = t; bpm = bpm; break; | |
266 | ||
267 | case 2: t = map(2*t,0,2,0,1); bpm = 2*bpm; break; | |
268 | ||
269 | default: t= t; bpm = bpm; | |
270 | } | |
271 | ||
272 | //switch(sphery.colorscheme) | |
273 | ||
274 | for ( Sphery s: spherys){ | |
275 | s.setVibrationPeriod(vibrationrate.getValuef()); | |
276 | // s.setVibrationMagnitude(vibration_magnitude.getValuef()); | |
277 | ||
278 | } | |
279 | ||
280 | ||
281 | sinespin.reset() | |
282 | // Translate so the center of the car is the origin, offset | |
283 | .center() | |
284 | .scale(scalevalue, scalevalue, scalevalue) | |
285 | // Rotate around the origin (now the center of the car) about an y-vector | |
286 | .rotate(yrot.getValuef(), rotationx.getValuef(), rotationy.getValuef() , rotationz.getValuef()) | |
287 | .translate(model.cx, model.cy, model.cz); | |
288 | ||
289 | ||
290 | ||
291 | ||
292 | ||
293 | for (LXVector p: sinespin) | |
294 | // for (Point p: model.points) | |
295 | { | |
296 | P.set(p.x, p.y, p.z); | |
297 | // PVector P = new PVector(p.x, p.y, p.z); | |
298 | color c = #000000; | |
299 | c = blendIfColor(c, spherys[1].spheryvalue(P), ADD); | |
300 | c = blendIfColor(c, spherys[0].spheryvalue(P), ADD); | |
301 | c = blendIfColor(c, spherys[2].spheryvalue(P),ADD); | |
302 | ||
303 | ||
304 | colors[p.index] = c; | |
305 | ||
306 | ||
307 | } | |
308 | sinespin2.reset() | |
309 | .center() | |
310 | .scale(scalevalue,scalevalue,scalevalue) | |
311 | .rotate(yrot2.getValuef(), rotationx.getValuef(), rotationy.getValuef() , rotationz.getValuef()) | |
312 | .translate(model.cx,model.cy,model.cz); | |
313 | ||
314 | for (LXVector p: sinespin2) | |
315 | { color c = 0; | |
316 | // PVector P = new PVector(p.x, p.y, p.z); | |
317 | P.set(p.x, p.y, p.z); | |
318 | c = blendIfColor(c, spherys[3].spheryvalue(P),ADD); | |
319 | ||
320 | colors[p.index] = blendIfColor(colors[p.index], c , ADD); | |
321 | ||
322 | } | |
323 | sinespin3.reset() | |
324 | .center() | |
325 | .scale(scalevalue,scalevalue,scalevalue) | |
326 | .rotate(yrot3.getValuef(),-1 + rotationx.getValuef(), rotationy.getValuef(), rotationz.getValuef()) | |
327 | .translate(model.cx, model.cy, model.cz); | |
328 | for (LXVector p: sinespin3) | |
329 | { color c = 0; | |
330 | // PVector P = new PVector(p.x, p.y, p.z); | |
331 | P.set(p.x, p.y, p.z); | |
332 | c = blendIfColor(c, spherys[4].spheryvalue(P),ADD); | |
333 | ||
334 | colors[p.index] = blendIfColor(colors[p.index], c , ADD); | |
335 | ||
336 | } | |
337 | ||
338 | ||
339 | ||
340 | ||
341 | ||
342 | ||
343 | ||
344 | } | |
345 | ||
346 | color blendIfColor(color c1, color c2, int mode) { | |
347 | if (c2 != 0) { | |
348 | return blendColor(c1, c2, mode); | |
349 | } | |
350 | return c1; | |
351 | } | |
352 | ||
353 | ||
354 | // color c = 0; | |
355 | // c = blendColor(c, spherys[3].ellipsevalue(Px.x, Px.y, Px.z, model.xMax/4, model.yMax/4, model.zMax/4, 3*model.xMax/4, 3*model.yMax/4, 3*model.zMax/4),ADD); | |
356 | // return c; | |
357 | // } | |
358 | // return lx.hsb(0,0,0); | |
359 | // // else if(spheremode ==2) | |
360 | // { color c = 0; | |
361 | // return lx.hsb(CalcCone( (xyz by = new xyz(0,spherys[2].ybounce.getValuef(),0) ), Px, mid) ); | |
362 | ||
363 | // } | |
364 | ||
365 | ||
366 | // } | |
367 | ||
368 | } | |
369 | /*This just takes all of Dan Horwitz's code that I want to inherit and leaves the rest behind. | |
370 | A work in progress. */ | |
371 | ||
372 | public class APat extends SCPattern | |
373 | ||
374 | ||
375 | { | |
376 | ArrayList<Pick> picks = new ArrayList<Pick> (); | |
377 | ArrayList<DBool> bools = new ArrayList<DBool> (); | |
378 | ||
379 | PVector mMax, mCtr, mHalf; | |
380 | ||
381 | MidiOutput APCOut; | |
382 | int nMaxRow = 53; | |
383 | float LastJog = -1; | |
384 | float[] xWaveNz, yWaveNz; | |
385 | int nPoint , nPoints; | |
386 | PVector xyzJog = new PVector(), modmin; | |
387 | ||
388 | float NoiseMove = random(10000); | |
389 | BasicParameter pSpark, pWave, pRotX, pRotY, pRotZ, pSpin, pTransX, pTransY; | |
390 | DBool pXsym, pYsym, pRsym, pXdup, pXtrip, pJog, pGrey; | |
391 | ||
392 | float lxh () { return lx.getBaseHuef(); } | |
393 | int c1c (float a) { return round(100*constrain(a,0,1)); } | |
394 | float interpWv(float i, float[] vals) { return interp(i-floor(i), vals[floor(i)], vals[ceil(i)]); } | |
395 | void setNorm (PVector vec) { vec.set(vec.x/mMax.x, vec.y/mMax.y, vec.z/mMax.z); } | |
396 | void setRand (PVector vec) { vec.set(random(mMax.x), random(mMax.y), random(mMax.z)); } | |
397 | void setVec (PVector vec, LXPoint p) { vec.set(p.x, p.y, p.z); } | |
398 | void interpolate(float i, PVector a, PVector b) { a.set(interp(i,a.x,b.x), interp(i,a.y,b.y), interp(i,a.z,b.z)); } | |
399 | void StartRun(double deltaMs) { } | |
400 | float val (BasicParameter p) { return p.getValuef(); } | |
401 | color CalcPoint(PVector p) { return lx.hsb(0,0,0); } | |
402 | color blend3(color c1, color c2, color c3) { return blendColor(c1,blendColor(c2,c3,ADD),ADD); } | |
403 | ||
404 | void rotateZ (PVector p, PVector o, float nSin, float nCos) { p.set( nCos*(p.x-o.x) - nSin*(p.y-o.y) + o.x , nSin*(p.x-o.x) + nCos*(p.y-o.y) + o.y,p.z); } | |
405 | void rotateX (PVector p, PVector o, float nSin, float nCos) { p.set(p.x,nCos*(p.y-o.y) - nSin*(p.z-o.z) + o.y , nSin*(p.y-o.y) + nCos*(p.z-o.z) + o.z ); } | |
406 | void rotateY (PVector p, PVector o, float nSin, float nCos) { p.set( nSin*(p.z-o.z) + nCos*(p.x-o.x) + o.x,p.y, nCos*(p.z-o.z) - nSin*(p.x-o.x) + o.z ); } | |
407 | ||
408 | BasicParameter addParam(String label, double value) { BasicParameter p = new BasicParameter(label, value); addParameter(p); return p; } | |
409 | ||
410 | PVector vT1 = new PVector(), vT2 = new PVector(); | |
411 | float calcCone (PVector v1, PVector v2, PVector c) { vT1.set(v1); vT2.set(v2); vT1.sub(c); vT2.sub(c); | |
412 | return degrees(PVector.angleBetween(vT1,vT2)); } | |
413 | ||
414 | Pick addPick(String name, int def, int _max, String[] desc) { | |
415 | Pick P = new Pick(name, def, _max+1, nMaxRow, desc); | |
416 | nMaxRow = P.EndRow + 1; | |
417 | picks.add(P); | |
418 | return P; | |
419 | } | |
420 | ||
421 | boolean noteOff(Note note) { | |
422 | int row = note.getPitch(), col = note.getChannel(); | |
423 | for (int i=0; i<bools.size(); i++) if (bools.get(i).set(row, col, false)) { presetManager.dirty(this); return true; } | |
424 | updateLights(); return false; | |
425 | } | |
426 | ||
427 | boolean noteOn(Note note) { | |
428 | int row = note.getPitch(), col = note.getChannel(); | |
429 | for (int i=0; i<picks.size(); i++) if (picks.get(i).set(row, col)) { presetManager.dirty(this); return true; } | |
430 | for (int i=0; i<bools.size(); i++) if (bools.get(i).set(row, col, true)) { presetManager.dirty(this); return true; } | |
431 | println("row: " + row + " col: " + col); return false; | |
432 | } | |
433 | ||
434 | void onInactive() { uiDebugText.setText(""); } | |
435 | void onReset() { | |
436 | for (int i=0; i<bools .size(); i++) bools.get(i).reset(); | |
437 | for (int i=0; i<picks .size(); i++) picks.get(i).reset(); | |
438 | presetManager.dirty(this); | |
439 | updateLights(); | |
440 | } | |
441 | ||
442 | APat(LX lx) { | |
443 | super(lx); | |
444 | ||
445 | ||
446 | ||
447 | nPoints = model.points.size(); | |
448 | pXsym = new DBool("X-SYM", false, 48, 0); bools.add(pXsym ); | |
449 | pYsym = new DBool("Y-SYM", false, 48, 1); bools.add(pYsym ); | |
450 | pRsym = new DBool("R-SYM", false, 48, 2); bools.add(pRsym ); | |
451 | pXdup = new DBool("X-DUP", false, 48, 3); bools.add(pXdup ); | |
452 | pJog = new DBool("JOG" , false, 48, 4); bools.add(pJog ); | |
453 | pGrey = new DBool("GREY" , false, 48, 5); bools.add(pGrey ); | |
454 | ||
455 | modmin = new PVector(model.xMin, model.yMin, model.zMin); | |
456 | mMax = new PVector(model.xMax, model.yMax, model.zMax); mMax.sub(modmin); | |
457 | mCtr = new PVector(); mCtr.set(mMax); mCtr.mult(.5); | |
458 | mHalf = new PVector(.5,.5,.5); | |
459 | xWaveNz = new float[ceil(mMax.y)+1]; | |
460 | yWaveNz = new float[ceil(mMax.x)+1]; | |
461 | ||
462 | //println (model.xMin + " " + model.yMin + " " + model.zMin); | |
463 | //println (model.xMax + " " + model.yMax + " " + model.zMax); | |
464 | //for (MidiOutputDevice o: RWMidi.getOutputDevices()) { if (o.toString().contains("APC")) { APCOut = o.createOutput(); break;}} | |
465 | } | |
466 | ||
467 | float spin() { | |
468 | float raw = val(pSpin); | |
469 | if (raw <= 0.45) { | |
470 | return raw + 0.05; | |
471 | } else if (raw >= 0.55) { | |
472 | return raw - 0.05; | |
473 | } | |
474 | return 0.5; | |
475 | } | |
476 | ||
477 | void setAPCOutput(MidiOutput output) { | |
478 | APCOut = output; | |
479 | } | |
480 | ||
481 | void updateLights() { if (APCOut == null) return; | |
482 | for (int i = 0; i < NumApcRows; ++i) | |
483 | for (int j = 0; j < 8; ++j) APCOut.sendNoteOn(j, 53+i, 0); | |
484 | for (int i=0; i<picks .size(); i++) APCOut.sendNoteOn(picks.get(i).CurCol, picks.get(i).CurRow, 3); | |
485 | for (int i=0; i<bools .size(); i++) if (bools.get(i).b) APCOut.sendNoteOn (bools.get(i).col, bools.get(i).row, 1); | |
486 | else APCOut.sendNoteOff (bools.get(i).col, bools.get(i).row, 0); | |
487 | } | |
488 | ||
489 | void run(double deltaMs) | |
490 | { | |
491 | if (deltaMs > 100) return; | |
492 | ||
493 | if (this == midiEngine.getFocusedDeck().getActivePattern()) { | |
494 | String Text1="", Text2=""; | |
495 | for (int i=0; i<bools.size(); i++) if (bools.get(i).b) Text1 += " " + bools.get(i).tag + " "; | |
496 | for (int i=0; i<picks.size(); i++) Text1 += picks.get(i).tag + ": " + picks.get(i).CurDesc() + " "; | |
497 | uiDebugText.setText(Text1, Text2); | |
498 | } | |
499 | ||
500 | NoiseMove += deltaMs; NoiseMove = NoiseMove % 1e7; | |
501 | StartRun (deltaMs); | |
502 | PVector P = new PVector(), tP = new PVector(), pSave = new PVector(); | |
503 | PVector pTrans = new PVector(val(pTransX)*200-100, val(pTransY)*100-50,0); | |
504 | nPoint = 0; | |
505 | ||
506 | if (pJog.b) { | |
507 | float tRamp = (lx.tempo.rampf() % .25); | |
508 | if (tRamp < LastJog) xyzJog.set(randctr(mMax.x*.2), randctr(mMax.y*.2), randctr(mMax.z*.2)); | |
509 | LastJog = tRamp; | |
510 | } | |
511 | ||
512 | // precalculate this stuff | |
513 | float wvAmp = val(pWave), sprk = val(pSpark); | |
514 | if (wvAmp > 0) { | |
515 | for (int i=0; i<ceil(mMax.x)+1; i++) | |
516 | yWaveNz[i] = wvAmp * (noise(i/(mMax.x*.3)-(2e3+NoiseMove)/1500.) - .5) * (mMax.y/2.); | |
517 | ||
518 | for (int i=0; i<ceil(mMax.y)+1; i++) | |
519 | xWaveNz[i] = wvAmp * (noise(i/(mMax.y*.3)-(1e3+NoiseMove)/1500.) - .5) * (mMax.x/2.); | |
520 | } | |
521 | ||
522 | for (LXPoint p : model.points) { nPoint++; | |
523 | setVec(P,p); | |
524 | P.sub(modmin); | |
525 | P.sub(pTrans); | |
526 | if (sprk > 0) {P.y += sprk*randctr(50); P.x += sprk*randctr(50); P.z += sprk*randctr(50); } | |
527 | if (wvAmp > 0) P.y += interpWv(p.x-modmin.x, yWaveNz); | |
528 | if (wvAmp > 0) P.x += interpWv(p.y-modmin.y, xWaveNz); | |
529 | if (pJog.b) P.add(xyzJog); | |
530 | ||
531 | ||
532 | color cNew, cOld = colors[p.index]; | |
533 | { tP.set(P); cNew = CalcPoint(tP); } | |
534 | if (pXsym.b) { tP.set(mMax.x-P.x,P.y,P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); } | |
535 | if (pYsym.b) { tP.set(P.x,mMax.y-P.y,P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); } | |
536 | if (pRsym.b) { tP.set(mMax.x-P.x,mMax.y-P.y,mMax.z-P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); } | |
537 | if (pXdup.b) { tP.set((P.x+mMax.x*.5)%mMax.x,P.y,P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); } | |
538 | if (pGrey.b) { cNew = lx.hsb(0, 0, lx.b(cNew)); } | |
539 | colors[p.index] = cNew; | |
540 | } | |
541 | } | |
542 | } | |
543 | ||
544 | class CubeCurl extends SCPattern{ | |
545 | float CH, CW, diag; | |
546 | ArrayList<PVector> cubeorigin = new ArrayList<PVector>(); | |
547 | ArrayList<PVector> centerlist = new ArrayList<PVector>(); | |
548 | private SinLFO curl = new SinLFO(0, Cube.EDGE_HEIGHT, 5000 ); | |
549 | ||
550 | private SinLFO bg = new SinLFO(180, 220, 3000); | |
551 | ||
552 | CubeCurl(LX lx){ | |
553 | super(lx); | |
554 | addModulator(curl).trigger(); | |
555 | addModulator(bg).trigger(); | |
556 | this.CH = Cube.EDGE_HEIGHT; | |
557 | this.CW = Cube.EDGE_WIDTH; | |
558 | this.diag = sqrt(CW*CW + CW*CW); | |
559 | ||
560 | ||
561 | ArrayList<PVector> centerlistrelative = new ArrayList<PVector>(); | |
562 | for (int i = 0; i < model.cubes.size(); i++){ | |
563 | Cube a = model.cubes.get(i); | |
564 | cubeorigin.add(new PVector(a.x, a.y, a.z)); | |
565 | centerlist.add(new PVector(a.cx, a.cy, a.cz) ); | |
566 | ||
567 | } | |
568 | ||
569 | } | |
570 | //there is definitely a better way of doing this! | |
571 | PVector centerofcube(int i) { | |
572 | Cube c = model.cubes.get(i); | |
573 | PVector cubecenter = new PVector(c.cx, c.cy, c.cz); | |
574 | ||
575 | return cubecenter; | |
576 | } | |
577 | ||
578 | ||
579 | void run(double deltaMs){ | |
580 | for (int i =0; i < model.cubes.size(); i++) { | |
581 | Cube c = model.cubes.get(i); | |
582 | float cfloor = c.y; | |
583 | ||
584 | // if (i%3 == 0){ | |
585 | ||
586 | // for (LXPoint p : c.points ){ | |
587 | // // colors[p.index]=color(0,0,0); | |
588 | // //float dif = (p.y - c.y); | |
589 | // //colors[p.index] = color( bg.getValuef() , 80 , dif < curl.getValuef() ? 80 : 0, ADD); | |
590 | // } | |
591 | // } | |
592 | ||
593 | // else if (i%3 == 1) { | |
594 | ||
595 | // for (LXPoint p: c.points){ | |
596 | // colors[p.index]=color(0,0,0); | |
597 | // float dif = (p.y - c.y); | |
598 | // // colors[p.index] = | |
599 | // // color(bg.getValuef(), | |
600 | // // map(curl.getValuef(), 0, Cube.EDGE_HEIGHT, 20, 100), | |
601 | // // 100 - 10*abs(dif - curl.getValuef()), ADD ); | |
602 | // } | |
603 | // } | |
604 | // else if (i%3 == 2){ | |
605 | // centerlist[i].sub(cubeorigin(i); | |
606 | for (LXPoint p: c.points) { | |
607 | PVector pv = new PVector(p.x, p.y, p.z); | |
608 | colors[p.index] =color( constrain(4* pv.dist(centerlist.get(i)), 0, 360) , 50, 100 ); | |
609 | // colors[p.index] =color(constrain(centerlist[i].x, 0, 360), constrain(centerlist[i].y, 0, 100), ); | |
610 | ||
611 | ||
612 | } | |
613 | ||
614 | ||
615 | //} | |
616 | ||
617 | } | |
618 | } | |
619 | } | |
620 | JGraphAdapterDemo graph1; | |
621 | ||
622 | ||
623 | // class SpinningCube extends SCPattern{ | |
624 | // LXProjection spin1, spin2, spin3; | |
625 | // SawLFO | |
626 | ||
627 | //} | |
628 | ||
629 | ||
630 | ||
631 | ||
632 | ||
633 | class PixelGraph implements EdgeFactory<dPixel, dVertex> { | |
634 | ||
635 | dPixel p0; dPixel p1; dVertex v0; | |
636 | ||
637 | public dVertex createEdge(dPixel p0, dPixel p1) { | |
638 | ||
639 | return v0; | |
640 | ||
641 | } | |
642 | ||
643 | ||
644 | } | |
645 | ||
646 | class GraphTest extends SCPattern { | |
647 | JGraphAdapterDemo graph1; | |
648 | ||
649 | GraphTest( LX lx) {super(lx); JGraphAdapterDemo graph1 = new JGraphAdapterDemo();} | |
650 | ||
651 | void run(double deltaMs){ | |
652 | } | |
653 | } | |
654 | ||
655 | class SpinningCube extends SCPattern{ | |
656 | ||
657 | LXProjection spin1, spin2, spin3; | |
658 | SawLFO spinx, spiny, spinz; | |
659 | SinLFO spinx1, spiny1, spinz1, cubesize; | |
660 | BasicParameter xoff = new BasicParameter("xoff", 10, 0, 100); | |
661 | BasicParameter toff = new BasicParameter("toff", 10,0,1000); | |
662 | BasicParameter huev = new BasicParameter("hue", 200, 0, 360); | |
663 | BasicParameter density = new BasicParameter("density", 0, 0, 1); | |
664 | BasicParameter Vsize = new BasicParameter("size", model.xMax/3,0, model.xMax); | |
665 | VirtualCube V1, V2, V3; | |
666 | PVector P = new PVector(); | |
667 | float noisetime=0.; | |
668 | class VirtualCube { | |
669 | float x,y,z,d; | |
670 | PVector center; | |
671 | ||
672 | VirtualCube(float x, float y, float z, float d) { | |
673 | this.x=x; | |
674 | this.y= y; | |
675 | this.z=z; | |
676 | this.d=d; | |
677 | this.center=new PVector(x,y,z); | |
678 | } | |
679 | ||
680 | color getcolor(LXVector q) { | |
681 | if ( q.x > this.x + d/2 || q.x < this.x - d/2 || q.y > this.y + d/2 || q.y < this.y - d/2 || q.z > this.z + d/2 || q.z < this.z - d/2 ) | |
682 | {return 0;} | |
683 | else { | |
684 | return lx.hsb(huev.getValuef()*noise(xoff.getValuef()*.001*noisetime ) , constrain(100*noise(xoff.getValuef()*.001*q.x*noisetime), 0, 100), max(100*(noise(xoff.getValuef()*.001*q.x*noisetime)-density.getValuef()), 0) ); | |
685 | } | |
686 | } | |
687 | void setcenter(float x, float y, float z) {this.x=x; this.y = y; this.z=z; } | |
688 | void setsize(float din){ this.d=din ; } | |
689 | ||
690 | } | |
691 | ||
692 | SpinningCube(LX lx) { | |
693 | super(lx); | |
694 | addParameter(xoff); | |
695 | addParameter(toff); | |
696 | addParameter(Vsize); | |
697 | addParameter(huev); | |
698 | addParameter(density); | |
699 | //addModulator() | |
700 | V1 = new VirtualCube(model.cx, model.cy, model.cz, model.xMax/2); | |
701 | spinx= new SawLFO(0, TWO_PI, 8000); | |
702 | spin1 = new LXProjection(model); | |
703 | ||
704 | } | |
705 | ||
706 | ||
707 | void run(double deltaMs) { | |
708 | ||
709 | noisetime+= deltaMs*.0001*toff.getValuef(); | |
710 | ||
711 | spin1.reset() | |
712 | .center() | |
713 | //.scale () | |
714 | .rotate(spinx.getValuef(),0, 1, 0) | |
715 | .translate(model.cx, model.cy, model.cz); | |
716 | ||
717 | for (LXVector p: spin1) { | |
718 | P.set(p.x, p.y, p.z); | |
719 | ||
720 | colors[p.index] = V1.getcolor(p); | |
721 | ||
722 | } | |
723 | ||
724 | V1.setsize(Vsize.getValuef()); | |
725 | ||
726 | ||
727 | }; | |
728 | ||
729 | ||
730 | } | |
731 | ||
732 | ||
733 | ||
734 | ||
735 | ||
736 | ||
737 | class HueTestHSB extends SCPattern{ | |
738 | BasicParameter HueT = new BasicParameter("Hue", .5); | |
739 | BasicParameter SatT = new BasicParameter("Sat", .5); | |
740 | BasicParameter BriT = new BasicParameter("Bright", .5); | |
741 | ||
742 | HueTestHSB(LX lx) { | |
743 | super(lx); | |
744 | addParameter(HueT); | |
745 | addParameter(SatT); | |
746 | addParameter(BriT); | |
747 | } | |
748 | void run(double deltaMs){ | |
749 | ||
750 | for (LXPoint p : model.points) { | |
751 | color c = 0; | |
752 | c = blendColor(c, lx.hsb(360*HueT.getValuef(), 100*SatT.getValuef(), 100*BriT.getValuef()), ADD); | |
753 | colors[p.index]= c; | |
754 | } | |
755 | int now= millis(); | |
756 | if (now % 1000 <= 20) | |
757 | { | |
758 | println("Hue: " + 360*HueT.getValuef() + "Sat: " + 100*SatT.getValuef() + "Bright: " + 100*BriT.getValuef()); | |
759 | } | |
760 | } | |
761 | ||
762 | } |