sinesphere extending APat derived from Dpat, no lights working but not broken
[SugarCubes.git] / AlexGreen.pde
CommitLineData
610db5fe 1class SineSphere extends APat {
251dcf21 2 float modelrad = sqrt((model.xMax)*(model.xMax) + (model.yMax)*(model.yMax) + (model.zMax)*(model.zMax));
e88f9c30 3 private BasicParameter yrotspeed = new BasicParameter("yspeed", 3000, 1, 10000);
251dcf21 4 private BasicParameter yrot2speed = new BasicParameter("y2speed", 4000, 1, 15000);
e88f9c30 5 private BasicParameter yrot3speed = new BasicParameter("y3speed", 1400, 1, 15000);
251dcf21 6 private BasicParameter vibrationrate = new BasicParameter("vib", 3000, 1, 10000);
e88f9c30
AG
7 private SawLFO yrot = new SawLFO(0, TWO_PI, yrotspeed);
8 private SawLFO yrot2 = new SawLFO(0, -TWO_PI, yrot2speed);
9 private SawLFO yrot3 = new SawLFO(0, -TWO_PI, yrot3speed);
610db5fe 10 public BasicParameter huespread = new BasicParameter("Hue", 0, 180);
251dcf21
AG
11 public BasicParameter widthparameter= new BasicParameter("Width", 20, 1, 60);
12 public BasicParameter vibration_magnitude = new BasicParameter("Vmag", 20, 2, modelrad/2);
13 public BasicParameter scale = new BasicParameter("Scale", 1, .1, 5);
1c44211b
AG
14 private int pitch = 0;
15 private int channel = 0;
16 private int velocity = 0;
df18145f 17 private int cur = 0;
9fa29818 18 public final LXProjection sinespin;
09437b3e 19 public final LXProjection sinespin2;
1a92d73a 20 public final LXProjection sinespin3;
251dcf21 21
610db5fe 22 Pick Galaxy, SpheryTime;
09437b3e 23
09437b3e
AG
24 public BasicParameter rotationx = new BasicParameter("rotx", 0, 0, 1 );
25 public BasicParameter rotationy = new BasicParameter("roty", 1, 0, 1);
26 public BasicParameter rotationz = new BasicParameter("rotz", 0, 0, 1);
27
7974acd6 28 public final PVector P = new PVector();
a9aad043 29
0b1785e3 30 class Sphery {
a9aad043 31 float f1xcenter, f1ycenter, f1zcenter, f2xcenter , f2ycenter, f2zcenter; //second three are for an ellipse with two foci
0b1785e3 32 private SinLFO vibration;
251dcf21
AG
33 private SinLFO surfacewave;
34
a9aad043
AG
35 private SinLFO xbounce;
36 public SinLFO ybounce;
37 private SinLFO zbounce;
610db5fe 38 float vibration_magnitude, vperiod, radius, vibration_min, vibration_max;
1c44211b
AG
39
40 //public BasicParameter huespread;
a9aad043
AG
41 public BasicParameter bouncerate;
42 public BasicParameter bounceamp;
a62bf8ad 43 public BasicParameter vibrationrate;
7974acd6 44 public final PVector circlecenter = new PVector();
a9aad043 45
610db5fe 46 public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float radius, float vibration_magnitude , float vperiod)
a9aad043 47 {
0b1785e3
AG
48 this.f1xcenter = f1xcenter;
49 this.f1ycenter = f1ycenter;
50 this.f1zcenter = f1zcenter;
610db5fe 51 this.radius = radius;
251dcf21
AG
52
53 this.vibration_magnitude = vibration_magnitude;
54
0b1785e3 55 this.vperiod = vperiod;
1d414e45
AG
56 //addParameter(bounceamp = new BasicParameter("Amp", .5));
57 //addParameter(bouncerate = new BasicParameter("Rate", .5)); //ybounce.modulateDurationBy(bouncerate);
e3da2932 58 //addParameter(vibrationrate = new BasicParameter("vibration", 1000, 10000));
1c44211b 59 //addParameter(widthparameter = new BasicParameter("Width", .2));
251dcf21 60 //addModulator(xbounce = new SinLFO(model.xMax/3, 2*model.yMax/3, 2000)).trigger();
df18145f 61 addModulator(ybounce= new SinLFO(model.yMax/3, 2*model.yMax/3, 240000)).trigger(); //bounce.modulateDurationBy
a9aad043
AG
62
63 //addModulator(bounceamp); //ybounce.setMagnitude(bouncerate);
610db5fe 64 addModulator( vibration = new SinLFO( this.radius - vibration_magnitude , this.radius + vibration_magnitude, vperiod)).trigger(); //vibration.setPeriod(240000/lx.tempo.bpm());
251dcf21 65
7974acd6 66
a9aad043 67 }
a62bf8ad 68
251dcf21
AG
69 // public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float vibration_magnitude, float vperiod)
70 // {
71 // this.f1xcenter = f1xcenter;
72 // this.f1ycenter = f1ycenter;
73 // this.f1zcenter = f1zcenter;
74 // this.vibration_magnitude = vibration_magnitude;
75 // this.vperiod = vperiod;
76 // addModulator(ybounce= new SinLFO(model.yMax/3, 2*model.yMax/3, 240000)).trigger(); //bounce.modulateDurationBy
77 // addModulator( vibration = new SinLFO( modelrad/10 - vibration_magnitude , modelrad/10 + vibration_magnitude, vperiod)).trigger(); //vibration.setPeriod(240000/lx.tempo.bpm());
78
79 // }
80
a62bf8ad 81 //for an ellipse
1c44211b
AG
82// public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float f2xcenter, float f2ycenter, float f2zcenter,
83// float vibration_min, float vibration_max, float vperiod)
38712136 84
1c44211b
AG
85// {
86// this.f1xcenter = f1xcenter;
87// this.f1ycenter = f1ycenter;
88// this.f1zcenter = f1zcenter;
89// this.f2xcenter = f2xcenter;
90// this.f2ycenter = f2ycenter;
91// this.f2zcenter = f2zcenter;
92// this.vibration_min = vibration_min;
93// this.vibration_max = vibration_max;
94// this.vperiod = vperiod;
95// //addModulator(xbounce = new SinLFO(model.xMax/3, 2*model.yMax/3, 2000)).trigger();
96// addModulator(ybounce).trigger();
97// addModulator( vibration = new SinLFO(vibration_min , vibration_max, lx.tempo.rampf())).trigger(); //vibration.modulateDurationBy(vx);
98// addParameter(widthparameter = new BasicParameter("Width", .1));
99// //addParameter(huespread = new BasicParameter("bonk", .2));
a9aad043 100
1c44211b
AG
101// }
102
570ba27d 103public int c1c (float a) { return round(100*constrain(a,0,1)); }
a9aad043 104
e3da2932
AG
105void setVibrationPeriod(double period){
106// to-do: make this conditional upon time signature
a9aad043 107
1a92d73a 108this.vibration.setPeriod(period);
e3da2932 109}
a9aad043 110
251dcf21
AG
111void setVibrationMagnitude(double mag){
112//to-do: make this optionally conditional upon decibel volume, frequency spectrum)
113this.vibration.setRange(-mag,mag);
114
115}
116
a9aad043
AG
117
118float distfromcirclecenter(float px, float py, float pz, float f1x, float f1y, float f1z)
119{
0b1785e3
AG
120 return dist(px, py, pz, f1x, f1y, f1z);
121 }
c2f643bd 122 //void updatespherey(deltaMs, )
55a56424 123
e0cfbe20 124 float quadrant(PVector q) {
7b2faded 125 float qtheta = atan2( (q.x-f1xcenter) , (q.z - f1zcenter) );
7b2faded 126
a62bf8ad 127
610db5fe 128 return map(qtheta, -PI/2, PI/2, 200-huespread.getValuef(), 240+huespread.getValuef());
e0cfbe20
AG
129 //if (q.x > f1xcenter ) {return 140 ;}
130 //else {return 250;}
55a56424 131 }
570ba27d
AG
132
133 // float noisesat(PVector q) {
134
135
136 // return noise()
137
138 // }
1a92d73a
AG
139 color spheryvalue (PVector p) {
140 circlecenter.set(this.f1xcenter, this.f1ycenter, this.f1zcenter);
7974acd6 141
a62bf8ad 142
a9aad043 143//switch(sShpape.cur() ) {}
7974acd6 144
251dcf21
AG
145 float b = max(0, 100 - widthparameter.getValuef()*abs(p.dist(circlecenter)
146 - vibration.getValuef()) );
7974acd6
MS
147
148 if (b <= 0) {
149 return 0;
150 }
151
152 return lx.hsb(
a62bf8ad 153 constrain(quadrant(p), 0, 360),
251dcf21
AG
154 // constrain(100*noise(quadrant(p)), 0, 100),
155 100,
156 b
7974acd6 157 );
0b1785e3 158 }
a9aad043
AG
159 color ellipsevalue(float px, float py, float pz , float f1xc, float f1yc, float f1zc, float f2xc, float f2yc, float f2zc)
160 {
161//switch(sShpape.cur() ) {}
a41f334c 162 return lx.hsb(huespread.getValuef()*5*px, dist(model.xMax-px, model.yMax-py, model.zMax-pz, f1xc, f1yc, f1zc) ,
a9aad043
AG
163 max(0, 100 - 100*widthparameter.getValuef() *
164 abs( (dist(px, py, pz, f1xc, ybounce.getValuef(), f1zc) +
165 (dist(px, py , pz, f2xc, ybounce.getValuef(), f2zc) ) )/2
166 - 1.2*vibration.getValuef() ) ) ) ;
0b1785e3 167 }
a9aad043 168
0b1785e3 169
a9aad043
AG
170}
171
1c44211b
AG
172
173public boolean noteOn(Note note) {
174pitch= note.getPitch();
175velocity=note.getVelocity();
176channel=note.getChannel();
177return true;
178}
a9aad043 179
df18145f
AG
180public boolean gridPressed(int row, int col) {
181 pitch = row; channel = col;
182 cur = NumApcCols*(pitch-53)+col;
183//setState(row, col, 0 ? 1 : 0);
184return true;
185}
186
187//public grid
0b1785e3 188final Sphery[] spherys;
1d414e45 189
a9aad043
AG
190 SineSphere(GLucose glucose)
191 {
0b1785e3 192 super(glucose);
251dcf21 193 println("modelrad " + modelrad);
9fa29818 194 sinespin = new LXProjection(model);
09437b3e 195 sinespin2 = new LXProjection(model);
1a92d73a 196 sinespin3= new LXProjection(model);
1c44211b 197 addParameter(huespread);
1a92d73a 198 addParameter(vibrationrate);
251dcf21 199 addParameter(widthparameter);
e3da2932
AG
200 addParameter(rotationx);
201 addParameter(rotationy);
202 addParameter(rotationz);
1a92d73a
AG
203 addParameter(yrotspeed);
204 addParameter(yrot2speed);
205 addParameter(yrot3speed);
251dcf21
AG
206 addParameter(vibration_magnitude);
207 addParameter(scale);
d8239019 208 addModulator(yrot).trigger();
e0cfbe20 209 addModulator(yrot2).trigger();
1a92d73a 210 addModulator(yrot3).trigger();
610db5fe
AG
211 Galaxy = addPick("Galaxy", 1, 3, new String[] {"home", "vertical","single","aquarium"});
212 SpheryTime =addPick("Time", 3, 4, new String[]{"half", "triplet", "beat", "2x", "3x" });
e3da2932 213
a9aad043 214 spherys = new Sphery[] {
610db5fe
AG
215 new Sphery(model.xMax/4, model.yMax/2, model.zMax/2, modelrad/12, modelrad/25, 3000),
216 new Sphery(.75*model.xMax, model.yMax/2, model.zMax/2, modelrad/14, modelrad/28, 2000),
217 new Sphery(model.cx, model.cy, model.cz, modelrad/5, modelrad/15, 2300),
218 new Sphery(.7*model.xMax, .65*model.yMax, .5*model.zMax, modelrad/11, modelrad/25, 3500),
219 new Sphery(.75*model.xMax, .8*model.yMax, .7*model.zMax, modelrad/12, modelrad/30, 2000)
220
251dcf21 221
e0cfbe20 222
251dcf21
AG
223
224
225 // new Sphery(model.xMax/4, model.yMax/2, model.zMax/2, modelrad/16, modelrad/8, 3000),
226 // new Sphery(.75*model.xMax, model.yMax/2, model.zMax/2, modelrad/20, modelrad/10, 2000),
227 // new Sphery(model.xMax/2, model.yMax/2, model.zMax/2, modelrad/4, modelrad/8, 2300),
228
229 // new Sphery(.7*model.xMax, .65*model.yMax, .5*model.zMax, modelrad/14, modelrad/7, 3500),
230 // new Sphery(.75*model.xMax, .8*model.yMax, .7*model.zMax, modelrad/20, modelrad/10, 2000),
231 // new Sphery(model.xMax/2, model.yMax/2, model.zMax/2, modelrad/4, modelrad/8, 2300),
e0cfbe20 232
7974acd6 233 };
0b1785e3
AG
234 }
235
a9aad043
AG
236// public void onParameterChanged(LXParameter parameter)
237// {
e28f168c 238
e28f168c 239
a9aad043
AG
240// for (Sphery s : spherys) {
241// if (s == null) continue;
242// double bampv = s.bounceamp.getValue();
243// double brv = s.bouncerate.getValue();
244// double tempobounce = lx.tempo.bpm();
245// if (parameter == s.bounceamp)
246// {
247// s.ybounce.setRange(bampv*model.yMax/3 , bampv*2*model.yMax/3, brv);
248// }
249// else if ( parameter == s.bouncerate )
250// {
251// s.ybounce.setDuration(120000./tempobounce);
252// }
253// }
254// }
e28f168c 255
1d414e45 256 public void run( double deltaMs) {
1a92d73a
AG
257 float t = lx.tempo.rampf();
258 float bpm = lx.tempo.bpmf();
251dcf21 259 float scalevalue = scale.getValuef();
1a92d73a 260
df18145f 261
1a92d73a
AG
262 // switch (cur) {
263
264 // case 1: t = map(.5*t ,0,.5, 0,1); bpm = .5*bpm; break;
df18145f 265
1a92d73a 266 // case 2: t = t; bpm = bpm; break;
1c44211b 267
1a92d73a 268 // case 3: t = map(2*t,0,2,0,1); bpm = 2*bpm; break;
1c44211b 269
1a92d73a
AG
270 // default: t= t; bpm = bpm;
271 // }
1c44211b 272
1a92d73a 273 //switch(sphery.colorscheme)
df18145f 274
1c44211b 275 for ( Sphery s: spherys){
1a92d73a
AG
276
277 //s.vibration.setBasis(t);
278 s.setVibrationPeriod(vibrationrate.getValuef());
251dcf21 279 // s.setVibrationMagnitude(vibration_magnitude.getValuef());
df18145f 280
1c44211b 281 }
1a92d73a
AG
282
283
284 sinespin.reset()
285 // Translate so the center of the car is the origin, offset
09437b3e 286 .center()
251dcf21 287 .scale(scalevalue, scalevalue, scalevalue)
1d414e45 288 // Rotate around the origin (now the center of the car) about an y-vector
e3da2932 289 .rotate(yrot.getValuef(), rotationx.getValuef(), rotationy.getValuef() , rotationz.getValuef())
38712136 290 .translate(model.cx, model.cy, model.cz);
1d414e45 291
d8239019 292
e0cfbe20 293
1d414e45 294
d8239019 295
09437b3e 296 for (LXVector p: sinespin)
1a92d73a 297 // for (Point p: model.points)
1d414e45 298 {
7974acd6
MS
299 P.set(p.x, p.y, p.z);
300 // PVector P = new PVector(p.x, p.y, p.z);
301 color c = #000000;
1a92d73a
AG
302 c = blendIfColor(c, spherys[1].spheryvalue(P), ADD);
303 c = blendIfColor(c, spherys[0].spheryvalue(P), ADD);
304 c = blendIfColor(c, spherys[2].spheryvalue(P),ADD);
e0cfbe20 305
d8239019 306
7974acd6 307 colors[p.index] = c;
e0cfbe20 308
d8239019 309
e0cfbe20 310 }
09437b3e
AG
311 sinespin2.reset()
312 .center()
251dcf21 313 .scale(scalevalue,scalevalue,scalevalue)
1a92d73a 314 .rotate(yrot2.getValuef(), rotationx.getValuef(), rotationy.getValuef() , rotationz.getValuef())
09437b3e 315 .translate(model.cx,model.cy,model.cz);
e0cfbe20 316
09437b3e 317 for (LXVector p: sinespin2)
e0cfbe20 318 { color c = 0;
7974acd6
MS
319 // PVector P = new PVector(p.x, p.y, p.z);
320 P.set(p.x, p.y, p.z);
1a92d73a 321 c = blendIfColor(c, spherys[3].spheryvalue(P),ADD);
7b2faded 322
7974acd6 323 colors[p.index] = blendIfColor(colors[p.index], c , ADD);
e0cfbe20
AG
324
325 }
1a92d73a
AG
326 sinespin3.reset()
327 .center()
251dcf21 328 .scale(scalevalue,scalevalue,scalevalue)
e88f9c30 329 .rotate(yrot3.getValuef(),-1 + rotationx.getValuef(), rotationy.getValuef(), rotationz.getValuef())
1a92d73a
AG
330 .translate(model.cx, model.cy, model.cz);
331 for (LXVector p: sinespin3)
332 { color c = 0;
333 // PVector P = new PVector(p.x, p.y, p.z);
334 P.set(p.x, p.y, p.z);
335 c = blendIfColor(c, spherys[4].spheryvalue(P),ADD);
336
337 colors[p.index] = blendIfColor(colors[p.index], c , ADD);
338
339 }
340
341
e0cfbe20 342
610db5fe
AG
343
344
345
346
7974acd6
MS
347 }
348
349 color blendIfColor(color c1, color c2, int mode) {
350 if (c2 != 0) {
351 return blendColor(c1, c2, mode);
352 }
353 return c1;
a9aad043 354 }
e27a8652 355
a9aad043
AG
356
357 // color c = 0;
358 // 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);
359 // return c;
360 // }
a41f334c 361 // return lx.hsb(0,0,0);
a9aad043
AG
362 // // else if(spheremode ==2)
363 // { color c = 0;
a41f334c 364 // return lx.hsb(CalcCone( (xyz by = new xyz(0,spherys[2].ybounce.getValuef(),0) ), Px, mid) );
a9aad043
AG
365
366 // }
367
368
d8239019 369 // }
a9aad043
AG
370
371 }
372
610db5fe
AG
373public class APat extends SCPattern
374{
375 ArrayList<Pick> picks = new ArrayList<Pick> ();
376 ArrayList<DBool> bools = new ArrayList<DBool> ();
377
378 PVector mMax, mCtr, mHalf;
379
380 MidiOutput APCOut;
381 int nMaxRow = 53;
382 float LastJog = -1;
383 float[] xWaveNz, yWaveNz;
384 int nPoint , nPoints;
385 PVector xyzJog = new PVector(), modmin;
386
387 float NoiseMove = random(10000);
388 BasicParameter pSpark, pWave, pRotX, pRotY, pRotZ, pSpin, pTransX, pTransY;
389 DBool pXsym, pYsym, pRsym, pXdup, pXtrip, pJog, pGrey;
390
391 float lxh () { return lx.getBaseHuef(); }
392 int c1c (float a) { return round(100*constrain(a,0,1)); }
393 float interpWv(float i, float[] vals) { return interp(i-floor(i), vals[floor(i)], vals[ceil(i)]); }
394 void setNorm (PVector vec) { vec.set(vec.x/mMax.x, vec.y/mMax.y, vec.z/mMax.z); }
395 void setRand (PVector vec) { vec.set(random(mMax.x), random(mMax.y), random(mMax.z)); }
396 void setVec (PVector vec, LXPoint p) { vec.set(p.x, p.y, p.z); }
397 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)); }
398 //void StartRun(double deltaMs) { }
399 float val (BasicParameter p) { return p.getValuef(); }
400 //color CalcPoint(PVector p) { return lx.hsb(0,0,0); }
401 color blend3(color c1, color c2, color c3) { return blendColor(c1,blendColor(c2,c3,ADD),ADD); }
402
403 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); }
404 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 ); }
405 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 ); }
406
407 BasicParameter addParam(String label, double value) { BasicParameter p = new BasicParameter(label, value); addParameter(p); return p; }
408
409 PVector vT1 = new PVector(), vT2 = new PVector();
410 float calcCone (PVector v1, PVector v2, PVector c) { vT1.set(v1); vT2.set(v2); vT1.sub(c); vT2.sub(c);
411 return degrees(PVector.angleBetween(vT1,vT2)); }
412
413 Pick addPick(String name, int def, int _max, String[] desc) {
414 Pick P = new Pick(name, def, _max+1, nMaxRow, desc);
415 nMaxRow = P.EndRow + 1;
416 picks.add(P);
417 return P;
418 }
419
420 boolean noteOff(Note note) {
421 int row = note.getPitch(), col = note.getChannel();
422 for (int i=0; i<bools.size(); i++) if (bools.get(i).set(row, col, false)) { presetManager.dirty(this); return true; }
423 updateLights(); return false;
424 }
425
426 boolean noteOn(Note note) {
427 int row = note.getPitch(), col = note.getChannel();
428 for (int i=0; i<picks.size(); i++) if (picks.get(i).set(row, col)) { presetManager.dirty(this); return true; }
429 for (int i=0; i<bools.size(); i++) if (bools.get(i).set(row, col, true)) { presetManager.dirty(this); return true; }
430 println("row: " + row + " col: " + col); return false;
431 }
432
433 void onInactive() { uiDebugText.setText(""); }
434 void onReset() {
435 for (int i=0; i<bools .size(); i++) bools.get(i).reset();
436 for (int i=0; i<picks .size(); i++) picks.get(i).reset();
437 presetManager.dirty(this);
438 updateLights();
439 }
440
441 APat(GLucose glucose) {
442 super(glucose);
443
444
445
446 nPoints = model.points.size();
447 pXsym = new DBool("X-SYM", false, 48, 0); bools.add(pXsym );
448 pYsym = new DBool("Y-SYM", false, 48, 1); bools.add(pYsym );
449 pRsym = new DBool("R-SYM", false, 48, 2); bools.add(pRsym );
450 pXdup = new DBool("X-DUP", false, 48, 3); bools.add(pXdup );
451 pJog = new DBool("JOG" , false, 48, 4); bools.add(pJog );
452 pGrey = new DBool("GREY" , false, 48, 5); bools.add(pGrey );
453
454 modmin = new PVector(model.xMin, model.yMin, model.zMin);
455 mMax = new PVector(model.xMax, model.yMax, model.zMax); mMax.sub(modmin);
456 mCtr = new PVector(); mCtr.set(mMax); mCtr.mult(.5);
457 mHalf = new PVector(.5,.5,.5);
458 xWaveNz = new float[ceil(mMax.y)+1];
459 yWaveNz = new float[ceil(mMax.x)+1];
460
461 //println (model.xMin + " " + model.yMin + " " + model.zMin);
462 //println (model.xMax + " " + model.yMax + " " + model.zMax);
463 //for (MidiOutputDevice o: RWMidi.getOutputDevices()) { if (o.toString().contains("APC")) { APCOut = o.createOutput(); break;}}
464 }
465
466 float spin() {
467 float raw = val(pSpin);
468 if (raw <= 0.45) {
469 return raw + 0.05;
470 } else if (raw >= 0.55) {
471 return raw - 0.05;
472 }
473 return 0.5;
474 }
475
476 void setAPCOutput(MidiOutput output) {
477 APCOut = output;
478 }
479
480 void updateLights() { if (APCOut == null) return;
481 for (int i = 0; i < NumApcRows; ++i)
482 for (int j = 0; j < 8; ++j) APCOut.sendNoteOn(j, 53+i, 0);
483 for (int i=0; i<picks .size(); i++) APCOut.sendNoteOn(picks.get(i).CurCol, picks.get(i).CurRow, 3);
484 for (int i=0; i<bools .size(); i++) if (bools.get(i).b) APCOut.sendNoteOn (bools.get(i).col, bools.get(i).row, 1);
485 else APCOut.sendNoteOff (bools.get(i).col, bools.get(i).row, 0);
486 }
487
488 void run(double deltaMs)
489 {
490 if (deltaMs > 100) return;
491
492 if (this == midiEngine.getFocusedDeck().getActivePattern()) {
493 String Text1="", Text2="";
494 for (int i=0; i<bools.size(); i++) if (bools.get(i).b) Text1 += " " + bools.get(i).tag + " ";
495 for (int i=0; i<picks.size(); i++) Text1 += picks.get(i).tag + ": " + picks.get(i).CurDesc() + " ";
496 uiDebugText.setText(Text1, Text2);
497 }
498
499
500 }
501}
502
5bc92bc2 503class CubeCurl extends SCPattern{
b30f14fd
AG
504float CH, CW, diag;
505ArrayList<PVector> cubeorigin = new ArrayList<PVector>();
506ArrayList<PVector> centerlist = new ArrayList<PVector>();
5bc92bc2
AG
507private SinLFO curl = new SinLFO(0, Cube.EDGE_HEIGHT, 5000 );
508
509private SinLFO bg = new SinLFO(180, 220, 3000);
510
511CubeCurl(GLucose glucose){
512super(glucose);
513addModulator(curl).trigger();
514addModulator(bg).trigger();
7c7625ec
AG
515 this.CH = Cube.EDGE_HEIGHT;
516 this.CW = Cube.EDGE_WIDTH;
f1370a0b 517 this.diag = sqrt(CW*CW + CW*CW);
b30f14fd 518
7c7625ec 519
b30f14fd 520ArrayList<PVector> centerlistrelative = new ArrayList<PVector>();
7c7625ec 521for (int i = 0; i < model.cubes.size(); i++){
b30f14fd
AG
522 Cube a = model.cubes.get(i);
523 cubeorigin.add(new PVector(a.x, a.y, a.z));
e0cfbe20 524 centerlist.add(new PVector(a.cx, a.cy, a.cz) );
b30f14fd
AG
525
526}
5bc92bc2
AG
527
528}
7c7625ec
AG
529//there is definitely a better way of doing this!
530PVector centerofcube(int i) {
531Cube c = model.cubes.get(i);
df18145f 532PVector cubecenter = new PVector(c.cx, c.cy, c.cz);
f1370a0b 533
b30f14fd 534return cubecenter;
7c7625ec
AG
535}
536
5bc92bc2
AG
537
538void run(double deltaMs){
539for (int i =0; i < model.cubes.size(); i++) {
540Cube c = model.cubes.get(i);
541float cfloor = c.y;
542
f1370a0b 543// if (i%3 == 0){
5bc92bc2 544
2bb56822 545// for (LXPoint p : c.points ){
f1370a0b
AG
546// // colors[p.index]=color(0,0,0);
547// //float dif = (p.y - c.y);
548// //colors[p.index] = color( bg.getValuef() , 80 , dif < curl.getValuef() ? 80 : 0, ADD);
549// }
550// }
5bc92bc2 551
f1370a0b 552// else if (i%3 == 1) {
5bc92bc2 553
2bb56822 554// for (LXPoint p: c.points){
f1370a0b
AG
555// colors[p.index]=color(0,0,0);
556// float dif = (p.y - c.y);
557// // colors[p.index] =
558// // color(bg.getValuef(),
559// // map(curl.getValuef(), 0, Cube.EDGE_HEIGHT, 20, 100),
560// // 100 - 10*abs(dif - curl.getValuef()), ADD );
561// }
562// }
563// else if (i%3 == 2){
b30f14fd 564 // centerlist[i].sub(cubeorigin(i);
2bb56822 565 for (LXPoint p: c.points) {
b30f14fd 566 PVector pv = new PVector(p.x, p.y, p.z);
f1370a0b 567 colors[p.index] =color( constrain(4* pv.dist(centerlist.get(i)), 0, 360) , 50, 100 );
b30f14fd 568 // colors[p.index] =color(constrain(centerlist[i].x, 0, 360), constrain(centerlist[i].y, 0, 100), );
5bc92bc2
AG
569
570
b30f14fd 571 }
5bc92bc2
AG
572
573
f1370a0b 574 //}
5bc92bc2
AG
575
576 }
577 }
578 }
579
a9aad043
AG
580 class HueTestHSB extends SCPattern{
581 BasicParameter HueT = new BasicParameter("Hue", .5);
582 BasicParameter SatT = new BasicParameter("Sat", .5);
583 BasicParameter BriT = new BasicParameter("Bright", .5);
584
585HueTestHSB(GLucose glucose) {
586 super(glucose);
587 addParameter(HueT);
588 addParameter(SatT);
589 addParameter(BriT);
590}
591 void run(double deltaMs){
592
2bb56822 593 for (LXPoint p : model.points) {
a9aad043 594 color c = 0;
a41f334c 595 c = blendColor(c, lx.hsb(360*HueT.getValuef(), 100*SatT.getValuef(), 100*BriT.getValuef()), ADD);
a9aad043
AG
596 colors[p.index]= c;
597 }
598 int now= millis();
599 if (now % 1000 <= 20)
600 {
601 println("Hue: " + 360*HueT.getValuef() + "Sat: " + 100*SatT.getValuef() + "Bright: " + 100*BriT.getValuef());
602 }
603 }
0b1785e3 604
a41f334c 605 }