From: Ben Morrow Date: Sun, 18 Aug 2013 21:23:24 +0000 (-0700) Subject: Dan's apc40 work X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=957d253fcdc00ed1abd91594535a16f2d163f760;p=SugarCubes.git Dan's apc40 work --- diff --git a/DanHorwitz.pde b/DanHorwitz.pde index 64991c2..5435e62 100644 --- a/DanHorwitz.pde +++ b/DanHorwitz.pde @@ -1,24 +1,173 @@ +//---------------------------------------------------------------------------------------------------------------------------------- +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); } - public void updateValue (double value) { super.updateValue(value); } - public float Val () { return getValuef(); } - public int Pick (int b) { return int(Val())==1 ? b-1 : int(b*Val()); } + _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; i0) 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 xMax/2 && (mir == 1 || mir == 3 || mir == 4)) { vx = xMax-vx; } - if (vy > yMax/2 && (mir == 2 || mir == 3 || mir == 4)) { vy = yMax-vy; } -// if (vz > zMax/2 && ( mir == 4)) { vz = zMax-vz; } - float deg = radians(90*(n.dir + pDir.Pick(4))); - float zx = zTime * n.speed * sin(deg); - float zy = zTime * n.speed * cos(deg); - float b = noise(vx/n.xz+zx+n.xoff,vy/n.yz+zy+n.yoff,vz/n.zz+n.zoff)*1.6-.3 + n.den/100 + pDensity.Val() -1; - float con = 1/constrain(2-n.contrast - 2*pContrast.Val(),0,1); - b = b < .5 ? pow(b,con) : 1-pow(1-b,con); - c = blendColor(c,color(n.hue,n.sat,c1c(b * pBright.Val())),ADD); - } - colors[p.index] = c; + color CalcPoint(Point p) { + color c = color(0,0,0); + int symm = pSymm.Cur(); + for (int i=0;i xMax/2) v.x = xMax-v.x; + if ((symm == YSym || symm == XyzSym) && v.y > yMax/2) v.y = yMax-v.y; + if (( symm == XyzSym) && v.z > zMax/2) v.z = zMax-v.z; + + NDat n = (NDat) noises.get(i); + float deg = radians(n.angle + (symm==XyzSym?45:0)); + float zx = zTime * n.speed * sin(deg), + zy = zTime * n.speed * cos(deg), + sharp = 1/constrain(2-n.sharp - 2*pSharp.Val(),0,1); + + float b = (symm==RadSym ? noise(zTime*n.speed+n.xoff-Dist(v,xyzMid)/n.xz) + : noise(v.x/n.xz+zx+n.xoff,v.y/n.yz+zy+n.yoff,v.z/n.zz+n.zoff)) + *1.8-.4 + n.den/100 + pDensity.Val() -1; + + b += n.den/100 + pDensity.Val() -1; + b = b < .5 ? pow(b,sharp) : 1-pow(1-b,sharp); + b += transAdd; + c = blendColor(c,color(n.hue,n.sat,c1c(b)),ADD); } + return c; } } //---------------------------------------------------------------------------------------------------------------------------------- +public class Play extends DPat +{ + int nBeats = 0; + _P pAmp, pRotX, pRotY, pRotZ, pRad; + Pick pTimePattern, pTempoMult, pShape; + + Play(GLucose glucose) { + super(glucose); + addParameter(pAmp = new _P("Amp" , .2 )); + addParameter(pRotX = new _P("RotX", 0 )); + addParameter(pRotY = new _P("RotY", 0 )); + addParameter(pRotZ = new _P("RotZ", 0 )); + addParameter(pRad = new _P("Rad" , .1 )); + + pTimePattern = addPick("TPat", 0 , 5 ); + pTempoMult = addPick("TMul", 5 , 6 ); + pShape = addPick("Shap", 8 , 10 ); + + lx.tempo.setBpm(30); + } + + float t,a; + xyz cPrev = new xyz(), cCur = new xyz(), cMid = new xyz(), cMidNorm; + float LastBeat=3, LastMeasure=3; + int CurRandTempo = 1; + + void StartRun(int deltaMs) { + t = lx.tempo.rampf(); + a = pAmp.Val(); + + if (t (pRad.getValuef()+.1)*100?1:0)) ); // sphere + + case 8: V = new xyz(cMid.x,cMid.y,cMid.z); + return color(0,0,c1c(1 - CalcCone(Px,V,xyzMid) * 0.02 > .5?1:0)); // cone + + } + + return color(0,0,c1c(1 - V.distance(P)/pRad.getValuef() > .5?1:0)); + } +} +//---------------------------------------------------------------------------------------------------------------------------------- \ No newline at end of file