ChucK Program MIDI ESitar TT

From CSWiki
Revision as of 19:01, 21 February 2006 by Art (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
   // Midi interface of ESitar Controller with Trimpin TT
   // Au: Ajay Kapur 


   0x90007f => int on;
   0x80007f => int off;
   1 => int TTselect;
   1.0 => float thumbdata2_t;
   1 => int midiout_t;
   1 => int thumbdir_t;
   0 => int thumbTTflag;

   1 => int fretdir_t;
   54.0 => float fretdata2_t;

   // Pre define ID numbers
   16 => int beg;


   // Define Turntable Functions
   3 => int thumbTT;
   5 => int thumbTT2;
   8 => int sthreeTT;


   function int direction(float nw, float bef)
   {
      nw - bef => float k;
      if (k < 0.)
         return 0; // left
      return 1; //right
   }


   function void TrimpTT(int TT, int note) 
   {
       // interface to Trimpins TT Robots
       // TT = turntable number number (1-8), and 0 for all the TTs
       // note = 0 - start     C
       //        1 - stop      C#
       //        2 - forward   D
       //        3 - reverse   D#
       //        4 - 33 rpm    E
       //        5 - 45 rpm    F
       //        6 - 78 rpm    F#
       //        7 - faster    G
       //        8 - slower    G#
       TT*0x000c00 => int hTT;
       note*0x000100 => int hnote; 
       if (TT > 4)
           hTT + 0x000c00 => hTT;
       if (TT == 0)
       {
           5*0x000c00 => hTT;
       }
   
       on + hnote + hTT => int msgo;
       if (msgo != midiout_t)
       {
           msgo => midiout; 
           msgo => midiout_t;    
       }   
   }

   // infinite time-loop
   while( 5::ms => now )
       while( midiin => int min )
       {
           (min>>16)&0xff => int type;
           (float)((min>>8)&0xff) => float data1;
           (float)(min&0xff) => float data2;
    
           // control change message (176)
           if (type == 176)
           {
               // headgear signal x
               if (data1 == 1.0)
               {
                   //signal conditioning for y axis
                   if ((data2 > 0.0) && (data2 < 100.0))
                   {
                       //**********************************************************************************
                       // replace the following with useful code...
                       //    - change ugen parameter(s),
                       //    - connect / disconnect ugens
                       //    - spork a shred,
                       //    - or machine.add() a new program on the on-the-fly
                       //    - something else
                       //********************************************************************************** 
                       chout => "type: " => type => " data1: " => data1 => " data2: " => data2 => endl;
                   }
               }

               // headgear signal y
               else if (data1 == 2.0)
               {
                   //signal conditioning for y axis
                   if ((data2 > 0.0) && (data2 < 50.0))
                   {
                       // replace the following with useful code...
                       chout => "type: " => type => " data1: " => data1 => " data2: " => data2 => endl;
                   }   
               }
        
               // Thumb FSR Sensor 
               else if (data1 == 4.0)
               {
                   if (data2 == 0.0)
                   {
                       if (thumbTTflag == 1)
                       {
                           // turn off table
                           TrimpTT(thumbTT, 1);
                           TrimpTT(thumbTT2, 1);
                           0 => thumbTTflag;
                           chout => "Thumb Off" => endl;
                       }
                   }
                   else 
                   {
                       if (thumbTTflag == 0)
                       {   
                           // turn on table at 60 rpm
                           TrimpTT(thumbTT, 5);
                           TrimpTT(thumbTT, 0);
                           TrimpTT(thumbTT2, 5);
                           TrimpTT(thumbTT2, 0);
                           1 => thumbTTflag;
                           chout => "Thumb On" => endl;
                       }
                       else
                       {
                           direction(data2, thumbdata2_t) => int thumbdir;
                           if (thumbdir_t != thumbdir)
                           {
                               if (thumbdir == 0)
                               {
                                   TrimpTT(thumbTT, 3); //reverse
                                   TrimpTT(thumbTT2, 3); //reverse
                                   chout => "Thumb Reverse" => endl;
                               }
                               else 
                               {
                                   TrimpTT(thumbTT, 2); //forward
                                   TrimpTT(thumbTT, 2); //forward
                                   chout => "Thumb Forward" => endl;
                               }
                               thumbdir => thumbdir_t;
                           }                                   
                           data2 => thumbdata2_t;
                       }
                   }
               }

               // Fret Sensor 
               else if (data1 == 5.0)
               {
                   direction(data2, fretdata2_t) => int fretdir;
                   if (fretdir_t != fretdir)
                   {
                       if (fretdir == 0)
                       {
                           TrimpTT(thumbTT, 7); //reverse
                           TrimpTT(thumbTT2, 7); //reverse
                           chout => "Thumb Slow" => endl;
                       }
                       else 
                       {
                           TrimpTT(thumbTT, 8); //forward
                           TrimpTT(thumbTT, 8); //forward
                           chout => "Thumb Fast" => endl;
                       }
                       fretdir => fretdir_t;
                   }                                   
                   data2 => fretdata2_t;
               }

               // Encoder
               else if (data1 == 6.0)
               {
                   // replace the following with useful code...
                   chout => "type: " => type => " data1: " => data1 => " data2: " => data2 => endl;
               }

               // Potentiometer  
               else if (data1 == 7.0)
               {
                   // replace the following with useful code...
                   chout => "type: " => type => " data1: " => data1 => " data2: " => data2 => endl;
               }

               // Switch 1
               else if (data1 == 8.0)
               {
                   // pull switch up
                   if (data2 == 1.0)
                   {
                       TrimpTT(0,2); 
                       TrimpTT(0, 4);
                       TrimpTT(0, 0);
                       chout => "SwitchOne On" => endl;
                   }
                   // pull switch down
                   else if (data2 == 0.0)
                   {
                       TrimpTT(0, 1);
                       chout => "SwitchOne Off (Master)" => endl;
                   }
               }

               // Switch 2
               else if (data1 == 9.0)
               {
                   // pull switch up
                   if (data2 == 1.0)
                   {
                       machine.add("a01_trimpinTT.ck") => beg;
                   }
                   // pull switch down
                   else if (data2 == 0.0)
                   {
                       machine.remove(beg);
                   }
               }

               // Switch 3
               else if (data1 == 10.0)
               {
                   // pull switch up
                   if (data2 == 1.0)
                   {
                       TrimpTT(sthreeTT,2); 
                       TrimpTT(sthreeTT, 4);
                       TrimpTT(sthreeTT, 0);
                       chout => "SwitchThree On" => endl;
                   }
                   // pull switch down
                   else if (data2 == 0.0)
                   {
                       TrimpTT(sthreeTT, 1);
                       chout => "SwitchThree Off" => endl;
                   }
               }
           }
       }