ChucK Program MIDI ESitar

From CSWiki
Jump to: navigation, search
   // Midi interface of ESitar Controller
   // Au: Ajay Kapur 
   
   // 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)
                {
                        // replace the following with useful code...
                        chout => "type: " => type => " data1: " => data1 => " data2: " => data2 => endl;
                }
   
                // Fret Sensor 
                else if (data1 == 5.0)
                {
                        // replace the following with useful code...
                        chout => "type: " => type => " data1: " => data1 => " data2: " => data2 => endl;
                }
   
                // 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)
                    {
                        // replace the following with useful code...
                        chout => "type: " => type => " data1: " => data1 => " data2: " => data2 => endl;
                    }
                    // pull switch down
                    else if (data2 == 0.0)
                    {
                        // replace the following with useful code...
                        chout => "type: " => type => " data1: " => data1 => " data2: " => data2 => endl;
                    }
                }
   
                // Switch
                else if (data1 == 9.0)
                {
                    // pull switch up
                    if (data2 == 1.0)
                    {
                        // replace the following with useful code...
                        chout => "type: " => type => " data1: " => data1 => " data2: " => data2 => endl;
                    }
                    // pull switch down
                    else if (data2 == 0.0)
                    {
                        // replace the following with useful code...
                        chout => "type: " => type => " data1: " => data1 => " data2: " => data2 => endl;
                    }
               }
   
               // Switch 3
               else if (data1 == 10.0)
               {
                   // pull switch up
                   if (data2 == 1.0)
                   {
                        // replace the following with useful code...
                        chout => "type: " => type => " data1: " => data1 => " data2: " => data2 => endl;
                   }
                   // pull switch down
                   else if (data2 == 0.0)
                   {
                        // replace the following with useful code...
                        chout => "type: " => type => " data1: " => data1 => " data2: " => data2 => endl;
                   }
               }
           }
       }