ChucK Program MIDI Headgear

From CSWiki
Jump to: navigation, search
   // Midi interface of ESitar Head Gear Controller
   // Head Gear takes readings from accelerometer
   // more info: ajay@alumni.princeton.edu, www.ajaykapur.com
   // Au: Ajay Kapur
   
   // infinite time-loop
   while( 5::ms => now )
       while( midiin => int min )
       {
           // assign MIDI message to variables
           (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...
                        //    - 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;
                   }
               }
           }
       }