Fixed DPat to work with crossfader
authorbb3dan <gitdan@citopia.com>
Tue, 24 Sep 2013 19:24:39 +0000 (15:24 -0400)
committerbb3dan <gitdan@citopia.com>
Tue, 24 Sep 2013 19:24:39 +0000 (15:24 -0400)
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

DanHorwitz.pde
DanUtil.pde

index b15bad9d1b6a801a8fd6ebe84610043f3248f8c0..51b22cd22ee015a122e71b4f86d69c042aadd9a3 100755 (executable)
@@ -113,7 +113,10 @@ public class Play extends DPat
        int             nBeats  =       0;\r
        _DhP    pAmp, pRad;\r
        _DhP    pRotX, pRotY, pRotZ;\r
-       xyz             Theta = new xyz();\r
+       xyz             Theta   = new xyz();\r
+       xyz             TSin    = new xyz();\r
+       xyz             TCos    = new xyz();\r
+       \r
        Pick    pTimePattern, pTempoMult, pShape, pForm;\r
        int             RandCube;\r
 \r
@@ -139,9 +142,9 @@ public class Play extends DPat
                t = lx.tempo.rampf();\r
                a = pAmp.Val();\r
 \r
-               Theta.x = pRotX.ZeroOrOne() ? 0 :(pRotX.Val()-.5)*10;\r
-               Theta.y = pRotY.ZeroOrOne() ? 0 :(pRotY.Val()-.5)*10;\r
-               Theta.z = pRotZ.ZeroOrOne() ? 0 :(pRotZ.Val()-.5)*10;\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
+               TCos    .set(cos(Theta.x), cos(Theta.y), cos(Theta.z));\r
 \r
                if (t<LastMeasure) { CurRandTempo = int(random(4)); } LastMeasure = t;\r
                \r
@@ -169,38 +172,36 @@ public class Play extends DPat
        }\r
 \r
        color CalcPoint(xyz Px) {\r
-               xyz V           = new xyz();\r
-               xyz P           = Px.setNorm();\r
-               if (Theta.x>0)  P = P.RotateZ(xyzHalf, Theta.x);\r
-               if (Theta.y>0)  P = P.RotateZ(xyzHalf, Theta.y);\r
-               if (Theta.z>0)  P = P.RotateZ(xyzHalf, Theta.z);\r
+               xyz V           =       new xyz();\r
+               xyz P           =       Px.setNorm();\r
+                                               P.RotateXYZ(xyzHalf, Theta, TSin, TCos);\r
 \r
                float mp        = min(P.x, P.z);\r
                float yt        = map(t,0,1,.5-a/2,.5+a/2);\r
 \r
                switch (pShape.Cur()) {\r
-                       case 0:         V = new xyz(P.x, yt                                                             , P.z);                                         break;  // bouncing line\r
-                       case 1:         V = new xyz(P.x, map(cos(PI*t * P.x),-1,1,0,1)  , P.z);                                         break;  // top tap\r
-                       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\r
-                       case 3:         V = new xyz(P.x, P.x < cMidNorm.x ? map(P.x,0,cMidNorm.x, .5,yt) :\r
-                                                                                                                       map(P.x,cMidNorm.x,1, yt,.5), P.z);             break;  //  Random V shape\r
-\r
-                       case 4:         V = new xyz(P.x, .5*(P.x < cMidNorm.x ? map(P.x,0,cMidNorm.x, .5,yt) :\r
-                                                                                                                        map(P.x,cMidNorm.x,1, yt,.5)) +\r
-                                                                                .5*(P.z < cMidNorm.z ? map(P.z,0,cMidNorm.z, .5,yt) :\r
-                                                                                                                        map(P.z,cMidNorm.z,1, yt,.5)), P.z);   break;  //  Random Pyramid shape\r
+                       case 0:         V.set(P.x, yt                                                     , P.z);                                                       break;  // bouncing line\r
+                       case 1:         V.set(P.x, map(cos(PI*t * P.x),-1,1,0,1)  , P.z);                                                       break;  // top tap\r
+                       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\r
+                       case 3:         V.set(P.x, P.x < cMidNorm.x ? map(P.x,0,cMidNorm.x, .5,yt) :\r
+                                                                                                         map(P.x,cMidNorm.x,1, yt,.5), P.z);                   break;  //  Random V shape\r
+\r
+                       case 4:         V.set(P.x,      .5*(P.x < cMidNorm.x ?  map(P.x,0,cMidNorm.x, .5,yt) :\r
+                                                                                                                       map(P.x,cMidNorm.x,1, yt,.5)) +\r
+                                                                       .5*(P.z < cMidNorm.z ?  map(P.z,0,cMidNorm.z, .5,yt) :\r
+                                                                                                                       map(P.z,cMidNorm.z,1, yt,.5)), P.z);    break;  //  Random Pyramid shape\r
                                                                                                                        \r
-                       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\r
-                       case 6:         V = new xyz(P.x, a*map((mp -.5)*(mp -.5),0,.25,0,t-.5)+.5, P.z);                        break;  // wings\r
+                       case 5:         V.set(P.x, a*map((P.x-.5)*(P.x-.5),0,.25,0,t-.5)+.5, P.z);                                      break;  // wings\r
+                       case 6:         V.set(P.x, a*map((mp -.5)*(mp -.5),0,.25,0,t-.5)+.5, P.z);                                      break;  // wings\r
 \r
-                       case 7:         V = new xyz(cMid.x,cMid.y,cMid.z);\r
+                       case 7:         V.set(cMid.x,cMid.y,cMid.z);\r
                                                return color(0,0,c1c(1 - (V.distance(Px) > (pRad.getValuef()+.1)*150?1:0)) );           // sphere\r
 \r
-                       case 8:         V = new xyz(cMid.x,cMid.y,cMid.z);\r
+                       case 8:         V.set(cMid.x,cMid.y,cMid.z);\r
                                                return color(0,0,c1c(1 - CalcCone(Px,V,xyzMid) * 0.02 > .5?1:0));                                       // cone\r
 \r
                        case 9:         return color(100 + noise(P.x,P.y,P.z + (NoiseMove+50000)/1000.)*200,\r
-                                                                       85,c1c(P.y < noise(P.x + NoiseMove/2000.,P.z)*(1+a)-a/2.-.1 ? 1 : 0));          //\r
+                                                       85,c1c(P.y < noise(P.x + NoiseMove/2000.,P.z)*(1+a)-a/2.-.1 ? 1 : 0));                  //\r
                }\r
 \r
 \r
index 7bcd56a2bfda9e15050d72db8baec6d33d45016c..16e19359ed4c2412fd2e54621b1f84c2c2a2f397 100644 (file)
@@ -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<paramlist.size(); i++) ((_DhP)paramlist.get(i)).reset();
-               while (lx.tempo.bpm() > 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<picklist.size() ; i++) { Pick P = (Pick)picklist.get(i); DanTextLine1 += P.tag + ": " + P.Cur() + "    "; }
-               DanTextLine1  += " X-Symm:   " + (_XSym   ? "ON" : "OFF") + "    ";
-               DanTextLine1  += " Y-Symm:   " + (_YSym   ? "ON" : "OFF") + "    ";
-               DanTextLine1  += " Z-Symm:   " + (_ZSym   ? "ON" : "OFF") + "    ";
-               DanTextLine1  += " Rad-Sym:  " + (_RadSym ? "ON" : "OFF") + "    ";
-//             DanTextLine1  += " Horiz:    " + (_Horiz  ? "ON" : "OFF") + "    ";
-//             DanTextLine1  += " Vert:     " + (_Vert   ? "ON" : "OFF") + "    ";
+       float           Sliders[]               = new float[] {0,0,0,0,0,0,0,0};
+       String          SliderText[]    = new String[] {"Trails", "Dim", "Saturate", "SpinHue", "Hue", "NoiseHue", "Spark", "Wiggle"};
 
-               DanTextLine2  = "SLIDERS: ";
-               for (int i=0; i<8; i++) if (SliderText[i] != "") { DanTextLine2 += SliderText[i] + ": " + Sliders[i] + "     "; }
-
-               uiDebugText.setText(DanTextLine1, DanTextLine2);
-       }
-
-       void    run(double deltaMs) {
-               NoiseMove   += deltaMs;
-               xdMax           =  model.xMax;
-               ydMax           =  model.yMax;
-               zdMax           =  model.zMax;
-               xyzdMax         =  new xyz(xdMax,ydMax,zdMax);
-               xyzMid          =  new xyz(xdMax/2, ydMax/2, zdMax/2);
-               StartRun                (deltaMs);
-               zSpinHue        += s_SpinHue ()*deltaMs*.05;
-               float fSharp = 1/(1.01-pSharp.Val());
-               AddDanText();
-               iCur.reset();                                                   iCur.nPoints = model.points.size();
-//             iCur.nTowers = model.towers.size();             iCur.nCubes  = model.cubes .size();
-//             iCur.nFaces  = model.faces .size();             iCur.nStrips = model.strips.size();
-
-//             for (Tower t : model.towers)    {       iCur.tower++;
-//             for (Cube  c : t.cubes)                 {       iCur.cube ++; 
-//             for (Face  f : c.faces)                 {       iCur.face ++; 
-//             for (Strip s : f.strips)                {       iCur.strip++; iCur.isHoriz= (iCur.strip % 2 == 1 || iCur.strip < 5) ? true : false;
-               for (Point p : model.points)    {       iCur.point++; 
-                       xyz P           = new xyz(p);
-
-                       if (s_Spark () > 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; i<CurPat.picks.size(); i++) {
+                       Pick P = (Pick)CurPat.picks.get(i); Text1 += P.tag + ": " + P.Cur() + "    ";
+               }
 
-                       float noizhue = s_NoiseHue()>0 ? 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<nNumRows                ; i++) for (int j=0; j<nNumCols; j++) SetLight(i, j, 0);
-               for (int i=0; i<picklist.size() ; i++) {
-                       Pick P = (Pick)picklist.get(i); SetLight(P.CurRow, P.CurCol, 3);
-               }
-               SetLight(82, 0, _XSym   ? 3 : 0);
-               SetLight(83, 0, _YSym   ? 3 : 0);
-               SetLight(84, 0, _ZSym   ? 3 : 0);
-               SetLight(85, 0, _RadSym ? 3 : 0);
-//             SetLight(86, 0, _Horiz  ? 3 : 0);
-//             SetLight(87, 0, _Vert   ? 3 : 0);
+               //else { println(cc.getCC() + " " + cc.getChannel() + " " + cc.getValue()); }
+       }
+       
+       void    Deactivate (DPat p) { if (p == CurPat) { uiDebugText.setText(""); CurPat = NextPat; } NextPat = null; }
+       void    Activate   (DPat p) {
+               NextPat = CurPat; CurPat = p;
+               while (lx.tempo.bpm() > 40) lx.tempo.setBpm(lx.tempo.bpm()/2);
+               for (int i=0; i<p.paramlist.size(); i++) ((_DhP)p.paramlist.get(i)).reset();
+               UpdateLights();
        }
 
-       Pick GetPick(int row, int col) {
-               for (int i=0; i<picklist.size(); i++) { Pick P = (Pick)picklist.get(i);
-                       if (!btwn(row,P.StartRow,P.EndRow)                                                      ) continue;
-                       if (!btwn(col,0,nNumCols-1)                                                             ) continue;
-                       if (!btwn((row-P.StartRow)*nNumCols + col,0,P.NumPicks-1)       ) continue;
-                       return P;
+       void    UpdateLights() {
+               for (int i=0; i<NumApcRows      ; i++) for (int j=0; j<NumApcCols; j++) SetLight(i, j, 0);
+               for (int i=0; i<CurPat.picks.size()     ; i++) {
+                       Pick P = (Pick)CurPat.picks.get(i); SetLight(P.CurRow, P.CurCol, 3);
                }
-               return null;
+               SetLight(82, 0, _XSym ? 3 : 0);
+               SetLight(83, 0, _YSym ? 3 : 0);
+               SetLight(84, 0, _ZSym ? 3 : 0);
+               SetLight(85, 0, _RSym ? 3 : 0);
        }
        
        double Tap1 = 0;
        double getNow() { return millis() + 1000*second() + 60*1000*minute() + 3600*1000*hour(); }
-       
-       void noteOffReceived(Note note) { if (!bIsActive) return;
-               int row = mapRow(note.getPitch()), col = note.getChannel();
+
+       void noteOffReceived(Note note) {
+               if (CurPat == null) return;
+               int row = DG.mapRow(note.getPitch()), col = note.getChannel();
 
                if (row == 50 && col == 0 && btwn(getNow() - Tap1,5000,300*1000)) {     // hackish tapping mechanism
                        double bpm = 32.*60000./(getNow()-Tap1);
@@ -230,19 +164,50 @@ public class DPat extends SCPattern
                UpdateLights();
        }
 
-       boolean _XSym=false, _YSym=false, _ZSym=false, _RadSym=false; //, _Horiz=false, _Vert=false;
-       
-       void noteOnReceived (Note note) { if (!bIsActive) return;
+       void noteOnReceived (Note note) {
+               if (CurPat == null) return;
                int row = mapRow(note.getPitch()), col = note.getChannel();
-               Pick P = GetPick(row,col);
-                        if (P != null)                                 { P.CurRow=row; P.CurCol=col;                   }
-               else if (row == 50 && col == 0)         { lx.tempo.trigger(); Tap1 = getNow();  }
-               else if (row == 82 && col == 0)         _XSym   = !_XSym        ;
-               else if (row == 83 && col == 0)         _YSym   = !_YSym        ;
-               else if (row == 84 && col == 0)         _ZSym   = !_ZSym        ;
-               else if (row == 85 && col == 0)         _RadSym = !_RadSym      ;
-               else                                                            keypad(row, col)        ;
+               
+                        if (row == 50 && col == 0)     { lx.tempo.trigger(); Tap1 = getNow();  }
+               else if (row == 82 && col == 0)         _XSym = !_XSym  ;
+               else if (row == 83 && col == 0)         _YSym = !_YSym  ;
+               else if (row == 84 && col == 0)         _ZSym = !_ZSym  ;
+               else if (row == 85 && col == 0)         _RSym = !_RSym  ;
+               else {
+                       for (int i=0; i<CurPat.picks.size(); i++) { Pick P = (Pick)CurPat.picks.get(i);
+                               if (!btwn(row,P.StartRow,P.EndRow)                                                      ) continue;
+                               if (!btwn(col,0,NumApcCols-1)                                                           ) continue;
+                               if (!btwn((row-P.StartRow)*NumApcCols + col,0,P.NumPicks-1)     ) continue;
+                               P.CurRow=row; P.CurCol=col; return;
+                       }
+                       println(row + " " + col);                       
+               }
        }
+}
+//----------------------------------------------------------------------------------------------------------------------------------
+public class DPat extends SCPattern
+{
+       ArrayList       picks           = new ArrayList();
+       ArrayList       paramlist       = new ArrayList();
+       int                     nMaxRow         = 0;
+       float           zSpinHue        = 0;
+       int             nPoint  , nPoints;
+       xyz                     xyzHalf          = new xyz(.5,.5,.5),
+                               xyzdMax,
+                               xyzMid;
+       
+       float           NoiseMove       = random(10000);
+       _DhP            pSharp;
+
+       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));                     }
+       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            StartRun(double deltaMs)                        {                                                               }
+       color           CalcPoint(xyz p)                                        { return color(0,0,0);                  }
+       boolean         IsActive()                                                      { return this == DG.CurPat;             }
+       void            onInactive()                                            { DG.Deactivate(this);  }
+       void            onActive  ()                                            { DG.Activate(this);    }
 
        _DhP addParam(String label, double value) {
                _DhP P = new _DhP(label, value);                
@@ -253,12 +218,68 @@ public class DPat extends SCPattern
        Pick addPick(String name, int def, int nmax) {
                Pick P          = new Pick(name, def, nmax); 
                P.StartRow      = nMaxRow;
-               P.EndRow        = P.StartRow + int((nmax-1) / nNumCols);
+               P.EndRow        = P.StartRow + int((nmax-1) / NumApcCols);
                nMaxRow         = P.EndRow + 1;
-               P.CurCol        = def % nNumCols;
-               P.CurRow        = P.StartRow + def/nNumCols;
-               picklist.add(P);
+               P.CurCol        = def % NumApcCols;
+               P.CurRow        = P.StartRow + def / NumApcCols;
+               picks.add(P);
                return P;
        }
+
+       DPat(GLucose glucose) {
+               super(glucose);
+               DG.Init();
+               pSharp          =  addParam("Shrp", 0);
+               nPoints         =  model.points.size();
+               xdMax           =  model.xMax;
+               ydMax           =  model.yMax;
+               zdMax           =  model.zMax;
+               xyzdMax         =  new xyz(xdMax,ydMax,zdMax);
+               xyzMid          =  new xyz(xdMax/2, ydMax/2, zdMax/2);
+       }
+
+       void run(double deltaMs)
+       {
+               NoiseMove       += deltaMs;
+               StartRun                (deltaMs);
+               zSpinHue                += DG._SpinHue ()*deltaMs*.05;
+               xyz P                   = new xyz();
+               float modhue    = DG._ModHue  ()==0 ? 0 : DG._ModHue  ()*360;
+               float fSharp    = 1/(1.01-pSharp.Val());
+               
+               DG.SetText();
+               nPoint  = 0;
+               for (Point p : model.points)    { nPoint++;
+                       if (!IsActive()) { colors[p.index] = color(0,0,0); continue; }
+
+                       P.set(p);
+
+                       if (DG._Spark () > 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;
+               }
+       }
 }
 //----------------------------------------------------------------------------------------------------------------------------------