-static MidiOutput midiout;
-int nNumRows = 6, nNumCols = 8;
-boolean btwn (int a,int b,int c) { return a >= b && a <= c; }
-
-public class _P extends BasicParameter {
- _P(String label, double value) { super(label,value); }
- void updateValue (double value) { super.updateValue(value); }
- float Val () { return getValuef(); }
-}
-
-public class Pick {
- Pick (String label, int _Def, int _Max) { Picks=_Max; Default = _Def; tag=label; }
- int Cur() { return (CurCol-StartCol)*nNumRows + CurRow; }
- int Picks, Default, CurRow, CurCol, StartCol, EndCol;
- String tag;
-}
-//----------------------------------------------------------------------------------------------------------------------------------
-float xMax,yMax,zMax;
-public class xyz { float x,y,z;
- xyz() {x=y=z=0;}
- xyz(Point p ) {x=p.fx ; y=p.fy; z=p.fz;}
- xyz(float _x,float _y,float _z) {x=_x ; y=_y ; z=_z ;}
- void set(float _x,float _y,float _z) {x=_x ; y=_y ; z=_z ;}
- float distance(xyz b) {return dist(x,y,z,b.x,b.y,b.z); }
- float dot (xyz b) {return x*b.x + y*b.y + z*b.z; }
- xyz minus (xyz b) {return new xyz(x-b.x,y-b.y,z-b.z); }
- xyz plus (xyz b) {return new xyz(x+b.x,y+b.y,z+b.z); }
- xyz plus (float b) {return new xyz(x+b ,y+b ,z+b ); }
- xyz over (xyz b) {return new xyz(x/b.x,y/b.y,z/b.z); }
- xyz times (float b) {return new xyz(x*b ,y*b ,z*b ); }
-
- xyz RotateX (xyz o, float a) { return new xyz ( x,
- cos(a)*(y-o.y) - sin(a)*(z-o.z) + o.y,
- sin(a)*(y-o.y) + cos(a)*(z-o.z) + o.z); }
-
- xyz RotateY (xyz o, float a) { return new xyz ( cos(a)*(x-o.x) - sin(a)*(z-o.z) + o.x,
- y,
- sin(a)*(x-o.x) + cos(a)*(z-o.z) + o.z); }
-
- xyz RotateZ (xyz o, float a) { return new xyz ( cos(a)*(x-o.x) - sin(a)*(y-o.y) + o.x,
- sin(a)*(x-o.x) + cos(a)*(y-o.y) + o.y,
- z ); }
-
-
- xyz setRand () { return new xyz ( random(xMax), random(yMax), random(zMax)); }
- xyz setNorm () { return new xyz ( x / xMax, y / yMax, z / zMax); }
-
-
- float interp (float a, float b, float c) { return (1-a)*b + a*c; }
- xyz interpolate(float i, xyz d) { return new xyz ( interp(i,x,d.x), interp(i,y,d.y), interp(i,z,d.z)); }
-}
-//----------------------------------------------------------------------------------------------------------------------------------
-public class hsb { float h,s,b;
- hsb(color c) { h=hue(c); s=saturation(c); b=brightness(c); }
- color Out() { return color(h%360.,constrain(s,0,100),constrain(b,0,100)); }
-}
-
-public class DPat extends SCPattern
-{
- float zSpinHue;
- xyz xyzMax, xyz0, xyzMid, xyzHalf;
-
- ArrayList picks = new ArrayList();
- int nMaxCol = 0;
- boolean bIsActive = false;
- float Dist (xyz a, xyz b) { return dist(a.x,a.y,a.z,b.x,b.y,b.z); }
- float c1c (float a) { return 100*constrain(a,0,1); }
- int mapRow (int a) { return a == 52 ? 5 : btwn(a,53,57) ? a-53 : a; }
- int unmapRow (int a) { return a == 5 ? 52 : btwn(a,0 , 4) ? a+53 : a; }
- void SetLight (int row, int col, int clr){ if (midiout != null) midiout.sendNoteOn(col, unmapRow(row), clr); }
- void keypad (int row, int col) {}
- void onInactive() { bIsActive=false; }
- void onActive () { bIsActive=true;
- zSpinHue = 0;
- for (int i=0; i<nNumRows ; i++) for (int j=0; j<nNumCols; j++) SetLight(i, j, 0);
- for (int i=0; i<picks.size(); i++) UpdateLights((Pick)picks.get(i));
- }
- void StartRun(int deltaMs) {}
- color CalcPoint(Point p) { return color(0,0,0); }
- float CalcCone (xyz v1, xyz v2, xyz c) {
- return degrees( acos ( v1.minus(c).dot(v2.minus(c)) / (sqrt(v1.minus(c).dot(v1.minus(c))) * sqrt(v2.minus(c).dot(v2.minus(c))) ) ));
- }
-
-
- void run(int deltaMs) {
- StartRun(deltaMs);
- zSpinHue += s_SpinHue ()*deltaMs*.05;
- for (Point p : model.points) {
- hsb cOld = new hsb(colors[p.index]);
- hsb cNew = new hsb (CalcPoint(p));
- if (s_Trails ()>0) cNew.b = max(cNew.b,cOld.b - (1-s_Trails()) * deltaMs);
- if (s_Dim ()>0) cNew.b *= 1-s_Dim ();
- if (s_Saturate ()>0) cNew.s += s_Saturate()*100;
- if (s_SpinHue ()>0) cNew.h += zSpinHue;
- if (s_ModHue ()>0) cNew.h += s_ModHue()*360;
- colors[p.index] = cNew.Out();
- }
- }
-
- void controllerChangeReceived(rwmidi.Controller cc) {
- if (cc.getCC() == 7 && btwn(cc.getChannel(),0,7)) Sliders[cc.getChannel()] = 1.*cc.getValue()/127.;
- }
-
- float Sliders[] = new float[] {0,0,0,0,0,0,0,0};
- float s_Trails () { return Sliders[0]; }
- float s_Dim () { return Sliders[1]; }
- float s_Saturate () { return Sliders[2]; }
- float s_SpinHue () { return Sliders[3]; }
- float s_ModHue () { return Sliders[4]; }
-
- DPat(GLucose glucose) {
- super(glucose);
- xMax = model.xMax; yMax = model.yMax; zMax = model.zMax;
- xyzMax = new xyz(xMax,yMax,zMax);
- xyzMid = new xyz(xMax/2, yMax/2, zMax/2);
- xyzHalf = new xyz(.5,.5,.5);
- xyz0 = new xyz(0,0,0);
- for (MidiInputDevice input : RWMidi.getInputDevices ()) { if (input.toString().contains("APC")) input .createInput (this);}
- for (MidiOutputDevice output : RWMidi.getOutputDevices()) {
- if (midiout == null && output.toString().contains("APC")) midiout = output.createOutput();
- }
- }
-
- void UpdateLights(Pick P) {
- if (P==null) return;
- for (int i=0; i<nNumRows; i++) for (int j=P.StartCol; j<=P.EndCol; j++) SetLight(i, j, 0);
- SetLight(P.CurRow, P.CurCol, 3);
- }
-
- Pick GetPick(int row, int col) {
- for (int i=0; i<picks.size(); i++) { Pick P = (Pick)picks.get(i);
- if (!btwn(col,P.StartCol,P.EndCol) ) continue;
- if (!btwn(row,0,nNumRows-1) ) continue;
- if (!btwn((col-P.StartCol)*nNumRows + row,0,P.Picks-1) ) continue;
- return P;
- }
- return null;
- }
-
- void noteOffReceived(Note note) { if (!bIsActive) return;
- int row = mapRow(note.getPitch()), col = note.getChannel();
- UpdateLights(GetPick(row,col));
- }
-
- void noteOnReceived (Note note) { if (!bIsActive) return;
- int row = mapRow(note.getPitch()), col = note.getChannel();
- Pick P = GetPick(row,col);
- if (P != null) { P.CurRow=row; P.CurCol=col;} else keypad(row, col);
- }
-
- Pick addPick(String name, int def, int nmax) {
- Pick P = new Pick(name, def, nmax);
- P.StartCol = nMaxCol;
- P.EndCol = P.StartCol + int((nmax-1) / nNumRows);
- nMaxCol = P.EndCol + 1;
- P.CurRow = def % nNumRows;
- P.CurCol = P.StartCol + def/nNumRows;
- picks.add(P);
- return P;
- }
-}
-//----------------------------------------------------------------------------------------------------------------------------------