From: bb3dan Date: Tue, 24 Sep 2013 19:24:39 +0000 (-0400) Subject: Fixed DPat to work with crossfader X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=dd00b10f32e4512228dade7200a0da56741db327;p=SugarCubes.git Fixed DPat to work with crossfader New behavior. * only one DPat works at a time (bc dpat is slooooow). the latest one you choose is the current one * apc40 horizontal slider always updates crossfader * there is one global dpat. vertical slider changes are persistent across dpats and always update the internal values. * pong works again * many bug fixes --- diff --git a/DanHorwitz.pde b/DanHorwitz.pde index b15bad9..51b22cd 100755 --- a/DanHorwitz.pde +++ b/DanHorwitz.pde @@ -113,7 +113,10 @@ public class Play extends DPat int nBeats = 0; _DhP pAmp, pRad; _DhP pRotX, pRotY, pRotZ; - xyz Theta = new xyz(); + xyz Theta = new xyz(); + xyz TSin = new xyz(); + xyz TCos = new xyz(); + Pick pTimePattern, pTempoMult, pShape, pForm; int RandCube; @@ -139,9 +142,9 @@ public class Play extends DPat t = lx.tempo.rampf(); a = pAmp.Val(); - Theta.x = pRotX.ZeroOrOne() ? 0 :(pRotX.Val()-.5)*10; - Theta.y = pRotY.ZeroOrOne() ? 0 :(pRotY.Val()-.5)*10; - Theta.z = pRotZ.ZeroOrOne() ? 0 :(pRotZ.Val()-.5)*10; + Theta .set(pRotX.Val()*PI*2, pRotY.Val()*PI*2, pRotZ.Val()*PI*2); + TSin .set(sin(Theta.x), sin(Theta.y), sin(Theta.z)); + TCos .set(cos(Theta.x), cos(Theta.y), cos(Theta.z)); if (t0) P = P.RotateZ(xyzHalf, Theta.x); - if (Theta.y>0) P = P.RotateZ(xyzHalf, Theta.y); - if (Theta.z>0) P = P.RotateZ(xyzHalf, Theta.z); + xyz V = new xyz(); + xyz P = Px.setNorm(); + P.RotateXYZ(xyzHalf, Theta, TSin, TCos); float mp = min(P.x, P.z); float yt = map(t,0,1,.5-a/2,.5+a/2); switch (pShape.Cur()) { - case 0: V = new xyz(P.x, yt , P.z); break; // bouncing line - case 1: V = new xyz(P.x, map(cos(PI*t * P.x),-1,1,0,1) , P.z); break; // top tap - case 2: V = new xyz(P.x, a*map(P.x<.5?P.x:1-P.x,0,.5 ,0,t-.5)+.5, P.z); break; // V shape - case 3: V = new xyz(P.x, P.x < cMidNorm.x ? map(P.x,0,cMidNorm.x, .5,yt) : - map(P.x,cMidNorm.x,1, yt,.5), P.z); break; // Random V shape - - case 4: V = new xyz(P.x, .5*(P.x < cMidNorm.x ? map(P.x,0,cMidNorm.x, .5,yt) : - map(P.x,cMidNorm.x,1, yt,.5)) + - .5*(P.z < cMidNorm.z ? map(P.z,0,cMidNorm.z, .5,yt) : - map(P.z,cMidNorm.z,1, yt,.5)), P.z); break; // Random Pyramid shape + case 0: V.set(P.x, yt , P.z); break; // bouncing line + case 1: V.set(P.x, map(cos(PI*t * P.x),-1,1,0,1) , P.z); break; // top tap + case 2: V.set(P.x, a*map(P.x<.5?P.x:1-P.x,0,.5 ,0,t-.5)+.5, P.z); break; // V shape + case 3: V.set(P.x, P.x < cMidNorm.x ? map(P.x,0,cMidNorm.x, .5,yt) : + map(P.x,cMidNorm.x,1, yt,.5), P.z); break; // Random V shape + + case 4: V.set(P.x, .5*(P.x < cMidNorm.x ? map(P.x,0,cMidNorm.x, .5,yt) : + map(P.x,cMidNorm.x,1, yt,.5)) + + .5*(P.z < cMidNorm.z ? map(P.z,0,cMidNorm.z, .5,yt) : + map(P.z,cMidNorm.z,1, yt,.5)), P.z); break; // Random Pyramid shape - case 5: V = new xyz(P.x, a*map((P.x-.5)*(P.x-.5),0,.25,0,t-.5)+.5, P.z); break; // wings - case 6: V = new xyz(P.x, a*map((mp -.5)*(mp -.5),0,.25,0,t-.5)+.5, P.z); break; // wings + case 5: V.set(P.x, a*map((P.x-.5)*(P.x-.5),0,.25,0,t-.5)+.5, P.z); break; // wings + case 6: V.set(P.x, a*map((mp -.5)*(mp -.5),0,.25,0,t-.5)+.5, P.z); break; // wings - case 7: V = new xyz(cMid.x,cMid.y,cMid.z); + case 7: V.set(cMid.x,cMid.y,cMid.z); return color(0,0,c1c(1 - (V.distance(Px) > (pRad.getValuef()+.1)*150?1:0)) ); // sphere - case 8: V = new xyz(cMid.x,cMid.y,cMid.z); + case 8: V.set(cMid.x,cMid.y,cMid.z); return color(0,0,c1c(1 - CalcCone(Px,V,xyzMid) * 0.02 > .5?1:0)); // cone case 9: return color(100 + noise(P.x,P.y,P.z + (NoiseMove+50000)/1000.)*200, - 85,c1c(P.y < noise(P.x + NoiseMove/2000.,P.z)*(1+a)-a/2.-.1 ? 1 : 0)); // + 85,c1c(P.y < noise(P.x + NoiseMove/2000.,P.z)*(1+a)-a/2.-.1 ? 1 : 0)); // } diff --git a/DanUtil.pde b/DanUtil.pde index 7bcd56a..16e1935 100644 --- a/DanUtil.pde +++ b/DanUtil.pde @@ -1,15 +1,14 @@ //---------------------------------------------------------------------------------------------------------------------------------- -static MidiOutput midiout; -int nNumRows = 5, nNumCols = 8; -float xdMax,ydMax,zdMax; -String DanTextLine1 = "", DanTextLine2 = ""; +float xdMax,ydMax,zdMax; +int NumApcRows = 5, NumApcCols = 8; +DGlobals DG = new DGlobals(); boolean btwn (int a,int b,int c) { return a >= b && a <= c; } boolean btwn (double a,double b,double c) { return a >= b && a <= c; } public class Pick { - Pick (String label, int _Def, int _Max) { NumPicks=_Max; Default = _Def; tag=label; } - int Cur() { return (CurRow-StartRow)*nNumCols + CurCol; } + Pick (String label, int _Def, int _Max) { NumPicks=_Max; Default = _Def; tag=label; } + int Cur() { return (CurRow-StartRow)*NumApcCols + CurCol; } int NumPicks, Default, CurRow, CurCol, StartRow, EndRow; String tag; } @@ -22,19 +21,12 @@ public class _DhP extends BasicParameter { float Val () { return getValuef(); } boolean ZeroOrOne () { return Val()==0 || Val() == 1; } } - -public class IndexNums { - int point ;//, cube , tower , face , strip ; - int nPoints ;//, nCubes, nTowers, nFaces, nStrips ; -// boolean isHoriz; - void reset() { point=0;}//cube=tower=face=strip=0; } -} -IndexNums iCur = new IndexNums(); //---------------------------------------------------------------------------------------------------------------------------------- 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(Point p ) {x=p.fx ; y=p.fy; z=p.fz;} 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; } @@ -46,16 +38,26 @@ public class xyz { float x,y,z; 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); } + 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); } + 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 ); } + z ); } + + void RotateXYZ (xyz o, xyz t, xyz tsin, xyz tcos) { + { x -= o.x; y -= o.y; z -= o.z; } + if (t.x != 0) { y = y*tcos.x - z*tsin.x; z = y*tsin.x + z*tcos.x; } + if (t.y != 0) { z = z*tcos.y - x*tsin.y; x = z*tsin.y + x*tcos.y; } + if (t.z != 0) { x = x*tcos.z - y*tsin.z; y = x*tsin.z + y*tcos.z; } + { x += o.x; y += o.y; z += o.z; } + + } + xyz setRand () { return new xyz ( random(xdMax), random(ydMax), random(zdMax)); } xyz setNorm () { return new xyz ( x / xdMax, y / ydMax, z / zdMax); } @@ -63,162 +65,94 @@ public class xyz { float x,y,z; 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 DPat extends SCPattern -{ - float zSpinHue; - xyz xyzdMax, xyz0, xyzMid, xyzHalf; - PFont itemFont = createFont("Lucida Grande", 11); - ArrayList picklist = new ArrayList(); - ArrayList paramlist = new ArrayList(); - int nMaxRow = 0; - boolean bIsActive = false; - float NoiseMove = random(10000); - - float Dist (xyz a, xyz b) { return dist(a.x,a.y,a.z,b.x,b.y,b.z); } - int c1c (float a) { return int(100*constrain(a,0,1)); } - int mapRow (int a) { return btwn(a,53,57) ? a-53 : a; } - int unmapRow (int a) { return 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) { println(row + " " + col); } - void onInactive() { bIsActive=false; DanTextLine1 = ""; DanTextLine2 = ""; uiDebugText.setText(""); } - void onActive () { bIsActive=true; - zSpinHue = 0; - for (int i=0; i 40) lx.tempo.setBpm(lx.tempo.bpm()/2); - UpdateLights(); - } - void StartRun(double deltaMs) { } - color CalcPoint(xyz 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))) ) )); - } +public class DGlobals { + boolean bInit = false; + MidiOutput APCOut = null; + MidiInput APCIn = null, OxygenIn = null; + DPat CurPat = null, NextPat = null; + boolean _XSym = false, _YSym = false, + _ZSym = false, _RSym = false; + String Text1 = "", Text2 = ""; - void AddDanText() { - DanTextLine1 = "APC40: "; - for (int i=0; i 0) P.y += s_Spark () * (noise(P.x,P.y+NoiseMove/30 ,P.z)*ydMax - ydMax/2.); - if (s_Wiggle() > 0) P.y += s_Wiggle() * (noise(P.x/(xdMax*.3)-NoiseMove/1500.) - .5) * (ydMax/2.); + int mapRow (int a) { return btwn(a,53,57) ? a-53 : a; } + int unmapRow (int a) { return btwn(a,0 , 4) ? a+53 : a; } + void SetLight (int row, int col, int clr){ if (APCOut != null) APCOut.sendNoteOn(col, unmapRow(row), clr); } - color cOld = colors[p.index]; - color cNew = CalcPoint(P); + float _Trails () { return Sliders[0]; } + float _Dim () { return Sliders[1]; } + float _Saturate () { return Sliders[2]; } + float _SpinHue () { return Sliders[3]; } + float _ModHue () { return Sliders[4]; } + float _NoiseHue () { return Sliders[5]; } + float _Spark () { return Sliders[6]; } + float _Wiggle () { return Sliders[7]; } -// if (_Horiz && !iCur.isHoriz) { colors[p.index] = 0; continue; } -// if (_Vert && iCur.isHoriz) { colors[p.index] = 0; continue; } - if (_XSym) cNew = blendColor(cNew, CalcPoint(new xyz(xdMax-P.x,P.y,P.z)), ADD); - if (_YSym) cNew = blendColor(cNew, CalcPoint(new xyz(P.x,ydMax-P.y,P.z)), ADD); - if (_ZSym) cNew = blendColor(cNew, CalcPoint(new xyz(P.x,P.y,zdMax-P.z)), ADD); + void Init () { + if (bInit) return; bInit=true; + for (MidiOutputDevice output : RWMidi.getOutputDevices()) { + if (APCOut == null && output.toString().contains("APC")) APCOut = output.createOutput(); + } - float b = brightness(cNew)/100.; - b = b < .5 ? pow(b,fSharp) : 1-pow(1-b,fSharp); + for (MidiInputDevice input : RWMidi.getInputDevices ()) { + if (input.toString().contains("APC")) input.createInput (this); + } + } - float modhue = s_ModHue ()>0 ? s_ModHue ()*360:0; + void SetText() + { + Text1 = ""; Text2 = ""; + Text1 += " XSym: " + (_XSym ? "ON" : "OFF") + " "; + Text1 += " YSym: " + (_YSym ? "ON" : "OFF") + " "; + Text1 += " ZSym: " + (_ZSym ? "ON" : "OFF") + " "; + Text1 += " RSym: " + (_RSym ? "ON" : "OFF") + " "; + for (int i=0; i0 ? s_NoiseHue()*360*noise( P.x/(xdMax*.3)+NoiseMove/3000., - P.y/(ydMax*.3)+NoiseMove/4000., - P.z/(zdMax*.3)+NoiseMove/5000.) : 0; + Text2 = "SLIDERS: "; + for (int i=0; i<8; i++) if (SliderText[i] != "") { Text2 += SliderText[i] + ": " + Sliders[i] + " "; } - cNew = color( (hue(cNew) + modhue + zSpinHue - noizhue) % 360, - saturation(cNew) + 100*s_Saturate(), - 100 * (s_Trails()==0 ? b : max(b, (float) (brightness(cOld)/100. - (1-s_Trails()) * deltaMs/200.))) - * (s_Dim ()==0 ? 1 : 1-s_Dim()) - ); - - colors[p.index] = cNew; - } -// }}}} + uiDebugText.setText(Text1, Text2); } void controllerChangeReceived(rwmidi.Controller cc) { - if (cc.getCC() == 7 && btwn(cc.getChannel(),0,7)) Sliders[cc.getChannel()] = 1.*cc.getValue()/127.; - } - - public float Sliders[] = new float[] {0,0,0,0,0,0,0,0}; - String SliderText[]= new String[] {"Trails", "Dim", "Saturate", "SpinHue", "Hue", "NoiseHue", "Spark", "Wiggle"}; - 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]; } - float s_NoiseHue () { return Sliders[5]; } - float s_Spark () { return Sliders[6]; } - float s_Wiggle () { return Sliders[7]; } - _DhP pSharp; + if (cc.getCC() == 7 && btwn(cc.getChannel(),0,7)) { Sliders[cc.getChannel()] = 1.*cc.getValue()/127.; } - DPat(GLucose glucose) { - super(glucose); - xyzHalf = new xyz(.5,.5,.5); - xyz0 = new xyz(0,0,0); - pSharp = addParam("Shrp", 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(); + else if (cc.getCC() == 15 && cc.getChannel() == 0) { + lx.engine.getDeck(1).getCrossfader().setValue( 1.*cc.getValue()/127.); } - } - void UpdateLights() { - for (int i=0; i 40) lx.tempo.setBpm(lx.tempo.bpm()/2); + for (int i=0; i 0) P.y += DG._Spark () * (noise(P.x,P.y+NoiseMove/30 ,P.z)*ydMax - ydMax/2.); + if (DG._Wiggle() > 0) P.y += DG._Wiggle() * (noise(P.x/(xdMax*.3)-NoiseMove/1500.) - .5) * (ydMax/2.); + + color cOld = colors[p.index]; + + color cNew = CalcPoint(P); + if (DG._XSym) cNew = blendColor(cNew, CalcPoint(new xyz(xdMax-P.x,P.y,P.z)), ADD); + if (DG._YSym) cNew = blendColor(cNew, CalcPoint(new xyz(P.x,ydMax-P.y,P.z)), ADD); + if (DG._ZSym) cNew = blendColor(cNew, CalcPoint(new xyz(P.x,P.y,zdMax-P.z)), ADD); + + float b = brightness(cNew)/100.; + b = b < .5 ? pow(b,fSharp) : 1-pow(1-b,fSharp); + + float noizhue = DG._NoiseHue()==0 ? 0 : DG._NoiseHue()*360*noise( + P.x/(xdMax*.3)+NoiseMove*.0003, + P.y/(ydMax*.3)+NoiseMove*.00025, + P.z/(zdMax*.3)+NoiseMove*.0002 ); + + cNew = color( (hue(cNew) + modhue + zSpinHue - noizhue) % 360, + saturation(cNew) + 100*DG._Saturate(), + 100 * (DG._Trails()==0 ? b : max(b, (float) (brightness(cOld)/100. - (1-DG._Trails()) * deltaMs/200.))) + * (DG._Dim ()==0 ? 1 : 1-DG._Dim()) + ); + + colors[p.index] = cNew; + } + } } //----------------------------------------------------------------------------------------------------------------------------------