dpat fixes
authorbb3dan <gitdan@citopia.com>
Fri, 27 Sep 2013 17:09:47 +0000 (13:09 -0400)
committerbb3dan <gitdan@citopia.com>
Fri, 27 Sep 2013 17:09:47 +0000 (13:09 -0400)
DanHorwitz.pde
DanUtil.pde
SugarCubes.pde

index 96101809f59680b0bf91b23f0d156db0f04ddc2f..a8c013618783f5cd8f62bb934c9268b51a0b9238 100755 (executable)
@@ -15,7 +15,7 @@ public class Pong extends DPat {
                addModulator(y  = new SinLFO(cRad, mMax.y - cRad, 0)).trigger();        y.modulateDurationBy(dy);\r
                addModulator(z  = new SinLFO(cRad, mMax.z - cRad, 0)).trigger();        z.modulateDurationBy(dz);\r
            pSize       = addParam      ("Size"                 , 0.4   );\r
-           pChoose = addPick   ("Animiation"   , 0     , 3, new String[] {"Pong", "Ball", "Cone"}      );\r
+           pChoose = addPick   ("Animiation"   , 0, 2, new String[] {"Pong", "Ball", "Cone"}   );\r
        }\r
 \r
        void    StartRun(double deltaMs)        { cRad = mMax.x*pSize.Val()/6; }\r
@@ -50,8 +50,7 @@ public class Noise extends DPat
 {\r
        int                     CurAnim, iSymm;\r
        int             XSym=1,YSym=2,RadSym=3;\r
-       float           zTime   = random(10000), zTheta=0, zSin, zCos;\r
-       float           rtime   = 0, ttime      = 0, transAdd=0;\r
+       float           zTime , zTheta=0, zSin, zCos, rtime, ttime, transAdd;\r
        DParam          pSpeed , pDensity, pRotZ;\r
        Pick            pChoose, pSymm;\r
        int                     _ND = 4;\r
@@ -61,11 +60,12 @@ public class Noise extends DPat
                super(glucose);\r
                pRotZ   = addParam("RotZ"        , .5 );        pSpeed          = addParam("Fast", .55);\r
                pDensity= addParam("Dens"        , .5);\r
-               pSymm   = addPick("Symmetry" , 0, 4, new String[] {"None", "X", "Y", "Radial"}  );\r
-               pChoose = addPick("Animation", 1, 6, new String[] {"Drip", "Cloud", "Rain", "Fire", "Machine", "Spark"} );\r
+               pSymm   = addPick("Symmetry" , 0, 3, new String[] {"None", "X", "Y", "Radial"}  );\r
+               pChoose = addPick("Animation", 1, 5, new String[] {"Drip", "Cloud", "Rain", "Fire", "Machine", "Spark"} );\r
                for (int i=0; i<_ND; i++) N[i] = new NDat();\r
        }\r
 \r
+       void StartPattern() { zTime = random(500); zTheta=0; rtime = 0; ttime = 0; transAdd=0; }\r
        void StartRun(double deltaMs) {\r
                zTime   += deltaMs*(pSpeed.Val()-.5)*.002       ;\r
                zTheta  += deltaMs*(pRotZ .Val()-.5)*.01        ;\r
@@ -150,10 +150,10 @@ public class Play extends DPat
                                                                        prvR    = dstR;         dstR    = random(mCtr.y);                                                                       }\r
        }\r
        int             nBeats  =       0;\r
-       DParam  pAmp, pRad;\r
+       DParam  pAmp, pRadius, pBounce;\r
        DParam  pRotX, pRotY, pRotZ;\r
 \r
-       float   t,amp;\r
+       float   t,amp,rad,bnc;\r
        rAngle  a1 = new rAngle(), a2 = new rAngle(),\r
                        a3 = new rAngle(), a4 = new rAngle();\r
        xyz             cPrev   = new xyz(), cRand      = new xyz(),\r
@@ -173,17 +173,25 @@ public class Play extends DPat
                pRotX           = addParam("RotX", .5);\r
                pRotY           = addParam("RotY", .5);\r
                pRotZ           = addParam("RotZ", .5);\r
-           pAmp                = addParam("Amp" , .2);\r
-           pRad                = addParam("Rad"        , .1            );\r
-               pTempoMult      = addPick ("TMult"      , 0 , 6         , new String[] {"1x", "2x", "4x", "8x", "16x", "Rand"   }       );\r
-               pTimePattern= addPick ("TPat"   , 6 , 8         , new String[] {"Bounce", "Sin", "Roll", "Quant", "Accel", "Deccel", "Slide", "Rand"}   );\r             pShape          = addPick ("Shape"      , 8 , 12        , new String[] {"Line", "Tap", "V", "RandV", "Pyramid", "Wings", "W2", "Clock",\r
-                                                                                                                                       "RSphere", "Sphere", "Cone", "Noise" }                                  );\r
-               pForm           = addPick ("Form"       , 0 , 3         , new String[] {"Bar", "Volume", "Fade"}                                                                );\r
+           pRadius             = addParam("Rad"        , .1    );\r
+               pBounce         = addParam("Bnc"        , .2    );\r
+           pAmp                = addParam("Amp"        , .2    );\r
+               pTempoMult      = addPick ("TMult"      , 0 , 5         , new String[] {"1x", "2x", "4x", "8x", "16x", "Rand"   }       );\r
+               pTimePattern= addPick ("TPat"   , 6 , 7         , new String[] {"Bounce", "Sin", "Roll", "Quant", "Accel", "Deccel", "Slide", "Rand"}   );\r             pShape          = addPick ("Shape"      , 13, 15        , new String[] {"Line", "Tap", "V", "RandV",\r
+                                                                                                                                       "Pyramid", "Wings", "W2", "Clock",\r
+                                                                                                                                       "Triangle", "Quad", "Sphere", "Cone",\r
+                                                                                                                                       "Noise", "Wave", "?", "?"}                                              );\r
+               pForm           = addPick ("Form"       , 2 , 2         , new String[] {"Bar", "Volume", "Fade"}                                                                                                );\r
        }\r
 \r
+\r
+float zTime = random(1000);\r
        void StartRun(double deltaMs) {\r
+               zTime += deltaMs*.001; zTime = zTime % 1000.;\r
                t       = lx.tempo.rampf();\r
                amp = pAmp.Val();\r
+               rad     = pRadius.getValuef();\r
+               bnc     = pBounce.getValuef();          \r
 \r
                Theta   .set(pRotX.Val()*PI*2, pRotY.Val()*PI*2, pRotZ.Val()*PI*2);\r
                TSin    .set(sin(Theta.x), sin(Theta.y), sin(Theta.z));\r
@@ -220,7 +228,6 @@ public class Play extends DPat
                        case 6:         t = .5*(1-cos(PI*t));                                   break;  // slide\r
                }\r
                \r
-               \r
                cMid.set                (cPrev);        cMid.interpolate        (t,cRand);\r
                cMidNorm.set    (cMid);         cMidNorm.setNorm();\r
 \r
@@ -235,46 +242,60 @@ public class Play extends DPat
                Pn.set(Px); Pn.setNorm();\r
 \r
                float mp        = min(Pn.x, Pn.z);\r
-               float yt        = map(t,0,1,.5-amp/2,.5+amp/2);\r
-               float rad       = pRad.getValuef();\r
+               float yt        = map(t,0,1,.5-bnc/2,.5+bnc/2);\r
+               float r;\r
 \r
                switch (pShape.Cur()) {\r
                case 0:         V.set(Pn.x, yt                                                          , Pn.z);                                                        break;  // bouncing line\r
                case 1:         V.set(Pn.x, map(cos(PI*t * Pn.x),-1,1,0,1)  , Pn.z);                                                    break;  // top tap\r
-               case 2:         V.set(Pn.x, amp*map(Pn.x<.5?Pn.x:1-Pn.x,0,.5 ,0,t-.5)+.5, Pn.z);                                break;  // V shape\r
+               case 2:         V.set(Pn.x, bnc*map(Pn.x<.5?Pn.x:1-Pn.x,0,.5 ,0,t-.5)+.5, Pn.z);                                break;  // V shape\r
                case 3:         V.set(Pn.x, Pn.x < cMidNorm.x ? map(Pn.x,0,cMidNorm.x, .5,yt) :\r
                                                                                                map(Pn.x,cMidNorm.x,1, yt,.5), Pn.z);                           break;  //  Random V shape\r
 \r
                case 4:         V.set(Pn.x,     .5*(Pn.x < cMidNorm.x ?         map(Pn.x,0,cMidNorm.x, .5,yt) :\r
                                                                                                                map(Pn.x,cMidNorm.x,1, yt,.5)) +\r
                                                        .5*(Pn.z < cMidNorm.z ?         map(Pn.z,0,cMidNorm.z, .5,yt) :\r
-                                                                                                               map(Pn.z,cMidNorm.z,1, yt,.5)), Pn.z);  break;  //  Random Pyramid shape\r
+                                                                                                               map(Pn.z,cMidNorm.z,1, yt,.5)), Pn.z);          break;  //  Random Pyramid shape\r
                                                                                                        \r
-               case 5:         V.set(Pn.x, amp*map((Pn.x-.5)*(Pn.x-.5),0,.25,0,t-.5)+.5, Pn.z);                                break;  // wings\r
-               case 6:         V.set(Pn.x, amp*map((mp  -.5)*(mp  -.5),0,.25,0,t-.5)+.5, Pn.z);                                break;  // wings\r
+               case 5:         V.set(Pn.x, bnc*map((Pn.x-.5)*(Pn.x-.5),0,.25,0,t-.5)+.5, Pn.z);                                break;  // wings\r
+               case 6:         V.set(Pn.x, bnc*map((mp  -.5)*(mp  -.5),0,.25,0,t-.5)+.5, Pn.z);                                break;  // wings\r
+\r
+\r
 \r
                case 7:         return color(0,0, min(\r
                                                distToSeg(Px.x, Px.y, a1.getX(70),a1.getY(70), mCtr.x, mCtr.y),\r
                                                distToSeg(Px.x, Px.y, a2.getX(40),a2.getY(40), mCtr.x, mCtr.y)) <rad*40?100:0); // clock\r
 \r
-//             case 8:         return color(0,0,c1c(.9+2*pRad.getValuef() - Px.distance(a1.x,a1.y)*.03) );             // sphere - radial\r
-\r
-               case 8:         float r = amp*200;\r
-                                       return color(0,0, min(\r
+               case 8:         r = amp*200 * map(bnc,0,1,1,sin(PI*t)); return color(0,0, min(\r
+                                               distToSeg(Px.x, Px.y, a1.getX(r),a1.getY(r), a2.getX(r),a2.getY(r)),\r
+                                               distToSeg(Px.x, Px.y, a2.getX(r),a2.getY(r), a3.getX(r),a3.getY(r)),\r
+                                               distToSeg(Px.x, Px.y, a3.getX(r),a3.getY(r), a1.getX(r),a1.getY(r))                             // triangle\r
+                                               ) <rad*40?100:0);\r
+                                               \r
+               case 9:         r = amp*200 * map(bnc,0,1,1,sin(PI*t)); return color(0,0, min(\r
                                                distToSeg(Px.x, Px.y, a1.getX(r),a1.getY(r), a2.getX(r),a2.getY(r)),\r
                                                distToSeg(Px.x, Px.y, a2.getX(r),a2.getY(r), a3.getX(r),a3.getY(r)),\r
                                                distToSeg(Px.x, Px.y, a3.getX(r),a3.getY(r), a4.getX(r),a4.getY(r)),\r
-                                               distToSeg(Px.x, Px.y, a4.getX(r),a4.getY(r), a1.getX(r),a1.getY(r))\r
+                                               distToSeg(Px.x, Px.y, a4.getX(r),a4.getY(r), a1.getX(r),a1.getY(r))                             // quad\r
                                                ) <rad*40?100:0); // shape\r
 \r
+                                               \r
+               case 10:        r = map(bnc,0,1,a1.r,amp*200*sin(PI*t)); \r
+                                       return color(0,0,c1c(.9+2*rad - dist(Px.x,Px.y,a1.getX(r),a1.getY(r))*.03) );           // sphere\r
 \r
-               case 9:         return color(0,0,c1c(.9+2*pRad.getValuef() - cMid.distance(Px)*.03) );          // sphere - radial\r
-\r
-               case 10:        return color(0,0,c1c(1 - CalcCone(Px,cMid,mCtr) * 0.02 > .5?1:0));                              // cone\r
+               case 11:        return color(0,0,c1c(1 - CalcCone(Px,cMid,mCtr) * 0.02 > .5?1:0));                              // cone\r
 \r
-               case 11:        return color(100 + noise(Pn.x,Pn.y,Pn.z + (NoiseMove+50000)/1000.)*200,\r
+               case 12:        return color(100 + noise(Pn.x,Pn.y,Pn.z + (NoiseMove+50000)/1000.)*200,\r
                                                85,c1c(Pn.y < noise(Pn.x + NoiseMove/2000.,Pn.z)*(1+amp)-amp/2.-.1 ? 1 : 0));   // noise\r
 \r
+               case 13:        V.set(Pn.x, map(\r
+                                                                       sin( zTime*3.7  + Pn.x*2.0*PI)\r
+                                                               +       sin( zTime*4.2  + Pn.x*1.7*PI)\r
+                                                               +       sin( -zTime*4.7  + Pn.x*2.1*PI)\r
+                                                               +       sin( -zTime*5.2  + Pn.x*1.5*PI)\r
+                                                               ,-2,2,.2,.8), Pn.z); break;\r
+                                               \r
+                                               \r
                default:        return color(0,0,0);\r
                }\r
 \r
index 7b0c17d5e5ad911521bde23fad5d2975085f4df6..f6b3a815814e66af1cdfc4882eb9cecfc30c6005 100644 (file)
@@ -28,9 +28,9 @@ public class Pick {
                        StartRow, EndRow        ;
        String  tag             , Desc[]        ;
        
-       Pick    (String label, int _Def, int _Max,      int nStart, String d[]) {
-               NumPicks        = _Max;         Default = _Def; 
-               StartRow        = nStart;       EndRow  = StartRow + int((NumPicks-1) / NumApcCols);
+       Pick    (String label, int _Def, int _Num,      int nStart, String d[]) {
+               NumPicks        = _Num;         Default = _Def; 
+               StartRow        = nStart;       EndRow  = StartRow + floor((NumPicks-1) / NumApcCols);
                tag                     = label;        Desc    = d;
                reset();
        }
@@ -115,7 +115,7 @@ public class DGlobals {
        DPat            CurPat                  = null;
 
        float           Sliders[]               = new float [] {1,0,0,0,0,0,0,0};
-       String          SliderText[]    = new String[] {"Level", "SpinHue", "Spark", "Wiggle", "Trails", "??", "??", "??"};
+       String          SliderText[]    = new String[] {"Level", "SpinHue", "Spark", "Xwave", "Ywave", "Trails", "??", "??", "??"};
        
        void            SetNoteOn       (int row, int col, int clr){ if (APCOut != null) APCOut.sendNoteOn              (col, row, clr);        }
        void            SetNoteOff      (int row, int col, int clr){ if (APCOut != null) APCOut.sendNoteOff             (col, row, clr);        }
@@ -128,8 +128,9 @@ public class DGlobals {
        float           _Dim            ()                                              { return Sliders[0]; }
        float           _SpinHue        ()                                              { return Sliders[1]; }
        float           _Spark          ()                                              { return Sliders[2]; }
-       float           _Wiggle         ()                                              { return Sliders[3]; }
-       float           _Trails         ()                                              { return Sliders[4]; }
+       float           _XWave          ()                                              { return Sliders[3]; }
+       float           _YWave          ()                                              { return Sliders[4]; }
+       float           _Trails         ()                                              { return Sliders[5]; }
 
        void            Init            () {
                if (bInit) return; bInit=true;
@@ -153,7 +154,7 @@ public class DGlobals {
                String Text1="", Text2="";
                for (int i=0; i<CurPat.bools.size(); i++) if (GetBool(i).b) Text1 += " " + GetBool(i).tag       + "   ";
                for (int i=0; i<CurPat.picks.size(); i++) Text1 += GetPick(i).tag + ": " + GetPick(i).CurDesc() + "   ";
-               for (int i=0; i<5; i++)                                   Text2 += SliderText[i]  + ": " + int(100*Sliders[i])  + "   ";
+               for (int i=0; i<5; i++)                                   Text2 += SliderText[i]  + ": " + round(100*Sliders[i])  + "   ";
                uiDebugText.setText(Text1, Text2);
        }
 
@@ -163,7 +164,7 @@ public class DGlobals {
                for (int i=48;i< 56; i++) SetKnob(0, i, 0);
                for (int i=16;i< 20; i++) SetKnob(0, i, 0);
 
-               for (int i=0; i<CurPat.params.size(); i++) SetKnob              ( 0, i<8 ? 48+i : 16 + i - 8, int(GetParam(i).Val()*127) );
+               for (int i=0; i<CurPat.params.size(); i++) SetKnob              ( 0, i<8 ? 48+i : 16 + i - 8, round(GetParam(i).Val()*127) );
                for (int i=0; i<CurPat.picks .size(); i++) SetNoteOn    (GetPick(i).CurRow, GetPick(i).CurCol, 3);
                for (int i=0; i<CurPat.bools .size(); i++) if (GetBool(i).b)    SetNoteOn       (GetBool(i).row, GetBool(i).col, 1);
                                                                                                        else                            SetNoteOff      (GetBool(i).row, GetBool(i).col, 0);
@@ -195,6 +196,7 @@ public class DPat extends SCPattern
        int                     nMaxRow         = 53;
        float           zSpinHue        = 0;
        float           LastQuant       = -1, LastJog = -1;
+       float[]         xWaveNz, yWaveNz;
        int             nPoint  , nPoints;
        xyz                     xyzJog = new xyz(), vT1 = new xyz(), vT2 = new xyz();
        xyz                     modmin;
@@ -203,15 +205,19 @@ public class DPat extends SCPattern
        DParam          pSharp, pQuantize, pSaturate;
        DBool           pXsym, pYsym, pRsym, pXdup, pXtrip, pJog;
        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                     c1c              (float a)                                      { return round(100*constrain(a,0,1));           }
+       float           interpWv(float i, float[] vals)         { return interp(i-floor(i), vals[floor(i)], vals[ceil(i)]); }
+
        float           CalcCone (xyz v1, xyz v2, xyz c)        { vT1.set(v1); vT2.set(v2); vT1.subtract(c); vT2.subtract(c);
                                                                                                                return degrees( acos ( vT1.dot(vT2) / (sqrt(vT1.dot(vT1)) * sqrt(vT2.dot(vT2)) ) ));    }
+
+       void            StartPattern()                                          {                                                               }
        void            StartRun(double deltaMs)                        {                                                               }
        color           CalcPoint(xyz p)                                        { return color(0,0,0);                  }
        boolean         IsActive()                                                      { return this == DG.CurPat;                                                                                             }
        boolean         IsFocused()                                                     { return this == midiEngine.getFocusedDeck().getActivePattern();                }
        void            onInactive()                                            { UpdateState(); }
-       void            onActive  ()                                            { UpdateState(); }
+       void            onActive  ()                                            { UpdateState(); StartPattern(); }
        void            UpdateState()                                           { if (IsFocused() != IsActive()) { if (IsFocused()) DG.Activate(this); else DG.Deactivate(this); } }
        color           blend3(color c1, color c2, color c3){ return blendColor(c1,blendColor(c2,c3,ADD),ADD);                                          }
 
@@ -220,9 +226,8 @@ public class DPat extends SCPattern
                super.addParameter(P);
                params.add(P); return P;
        }
-
-       Pick addPick(String name, int def, int nmax, String[] desc) {
-               Pick P          = new Pick(name, def, nmax, nMaxRow, desc); 
+       Pick addPick(String name, int def, int _max, String[] desc) {
+               Pick P          = new Pick(name, def, _max+1, nMaxRow, desc); 
                nMaxRow         = P.EndRow + 1;
                picks.add(P);
                return P;
@@ -243,6 +248,9 @@ public class DPat extends SCPattern
                mMax            =       new xyz(model.xMax, model.yMax, model.zMax); mMax.subtract(modmin);
                mCtr            =       new xyz(mMax); mCtr.scale(.5);
                mHalf           =       new xyz(.5,.5,.5);
+               xWaveNz         =       new float[ceil(mMax.y)+1];
+               yWaveNz         =       new float[ceil(mMax.x)+1];
+               
                //println (model.xMin + " " + model.yMin + " " +  model.zMin);
                //println (model.xMax + " " + model.yMax + " " +  model.zMax);
                DG.Init();
@@ -251,9 +259,9 @@ public class DPat extends SCPattern
        void run(double deltaMs)
        {
                UpdateState();
-               NoiseMove       += deltaMs;
+               NoiseMove       += deltaMs; NoiseMove = NoiseMove % 1e7;
                StartRun                (deltaMs);
-               zSpinHue                += DG._SpinHue ()*deltaMs*.05;
+               zSpinHue                += DG._SpinHue ()*deltaMs*.05; zSpinHue = zSpinHue % 5000.;
                xyz P                   = new xyz(), tP = new xyz(), pSave = new xyz();
                float fSharp    = 1/(1.0001-pSharp.Val());
                float fQuant    = pQuantize.Val();
@@ -263,7 +271,7 @@ public class DPat extends SCPattern
                nPoint  = 0;
                
                if (fQuant > 0) {
-                       float tRamp     = (lx.tempo.rampf() % (1./pow(2,int((1-fQuant) * 4))));
+                       float tRamp     = (lx.tempo.rampf() % (1./pow(2,floor((1-fQuant) * 4))));
                        float f = LastQuant; LastQuant = tRamp; if (tRamp > f) return;
                }
        
@@ -273,12 +281,22 @@ public class DPat extends SCPattern
                        LastJog = tRamp; 
                }
 
-               for (Point p : model.points)    { nPoint++;
+               // precalculate this stuff
+               float yWv = DG._YWave(), xWv = DG._XWave(), sprk = DG._Spark();
+               if (yWv > 0) for (int i=0; i<ceil(mMax.x)+1; i++)
+                       yWaveNz[i] = yWv * (noise(i/(mMax.x*.3)-(2e3+NoiseMove)/1500.) - .5) * (mMax.y/2.);
+
+               if (xWv > 0) for (int i=0; i<ceil(mMax.y)+1; i++)
+                       xWaveNz[i] = xWv * (noise(i/(mMax.y*.3)-(1e3+NoiseMove)/1500.) - .5) * (mMax.x/2.);
+                       
+               for (Point p : model.points) { nPoint++;
                        P.set(p);
                        P.subtract(modmin);
-                       if (pJog.b)     P.add(xyzJog);
-                       if (DG._Spark () > 0)   P.y += DG._Spark () * (noise(P.x,P.y+NoiseMove/30  ,P.z)*mMax.y - mMax.y/2.);
-                       if (DG._Wiggle() > 0)   P.y += DG._Wiggle() * (noise(P.x/(mMax.x*.3)-NoiseMove/1500.) - .5) * (mMax.y/2.);
+                       if (sprk > 0) { P.y += sprk*randctr(50); P.x += sprk*randctr(50); P.z += sprk*randctr(50); }
+                       if (yWv > 0)    P.y += interpWv(p.x-modmin.x, yWaveNz);
+                       if (xWv > 0)    P.x += interpWv(p.y-modmin.y, xWaveNz);
+                       if (pJog.b)             P.add(xyzJog);
+
 
                        color cNew, cOld = colors[p.index];
                                                        { tP.set(P);                                                                    cNew = CalcPoint(tP);                                                   }
index 42817a6b0ead39692be310c41a22d2e04a7f5903..656d7c4f60c4254ad662dd97bde76de4a1f4b33c 100644 (file)
@@ -108,16 +108,16 @@ LXPattern[] patterns(GLucose glucose) {
 LXTransition[] transitions(GLucose glucose) {
   return new LXTransition[] {
     new DissolveTransition(lx),
+    new AddTransition(glucose),
     new MultiplyTransition(glucose),
-    new ScreenTransition(glucose),
-    new BurnTransition(glucose),
-    new DodgeTransition(glucose),
     new OverlayTransition(glucose),
-    new AddTransition(glucose),
-    new SubtractTransition(glucose),
-    new SoftLightTransition(glucose),
+    new DodgeTransition(glucose),
     new SwipeTransition(glucose),
     new FadeTransition(lx),
+//  new SubtractTransition(glucose),   // similar to multiply - dh
+//  new BurnTransition(glucose),               // similar to multiply - dh
+//  new ScreenTransition(glucose),             // same as add -dh
+//  new SoftLightTransition(glucose),  // same as overlay -dh
   };
 }