FOOTIME.ck

From CSWiki
Jump to: navigation, search

/* FOOTIME!!! Not Foo Time you computer nerd but Foot Time you music nerd!!! The following is a mapping of the 5 footime buttons. pressing a button down plays a sine wav each button renders a different pitch

NOTE: the footime controller is set to hotkey things...annoying things. in MiniAudicle, the A button will add a shred and the B button will remove a shred make sure you run some other program in front of the miniaudicle so as to avoid accidently using hotkeys.

also make sure that the button on the side is pressed in otherwise it will have different messages and you can't distinguish 2 of the buttons

  • /

1 => int deviceNum;

// instantiate a HidIn object HidIn hii; // structure to hold HID messages HidMsg msgi;

// open mouse 0, exit on fail if( !hii.openMouse( deviceNum ) ) me.exit(); // successful! print name of device <<< "mouse '", hii.name(), "' ready" >>>;


int Akey; int Bkey; int Ckey; int Dkey; int Ekey;



MAUI_LED a, b, c, d, e; MAUI_View v;

v.size( 150, 100 );

a.color( a.red ); a.size( 50, 50 ); a.position( 0, 0 ); a.unlight();

b.color( b.green ); b.size( 50, 50 ); b.position( 50, 0 ); b.unlight();

c.color( c.blue ); c.size( 50, 50 ); c.position( 100, 0 ); c.unlight();

d.color( d.red ); d.size( 50, 50 ); d.position( 50, 50 ); d.unlight();


e.color( e.green ); e.size( 50, 50 ); e.position( 100, 50 ); e.unlight();

v.addElement( a ); v.addElement( b ); v.addElement( c ); v.addElement( d ); v.addElement( e );

v.display();





fun void FOOTIME() { // infinite event loop while( true ) {

   // wait on HidIn as event
   hii => now;
   
   // messages received
   while( hii.recv( msgi ) )
   {
             // mouse button down
        if( msgi.isButtonDown() )
       {
           <<<msgi.which>>>;
        
           if	   ( msgi.which == 94 ) 1 => Akey;
           else if( msgi.which == 93 ) 1 => Bkey;
           else if( msgi.which == 92 ) 1 => Ckey;
           
           else if( msgi.which == 91 ) 1 => Dkey;
           else if( msgi.which == 77 ) 1 => Ekey;
 
       }
   
       // mouse button up
       else if( msgi.isButtonUp() )
       {
        
0 => Akey; 0 => Bkey; 0 => Ckey; 0 => Dkey; 0 => Ekey;          
       }
       
   }

}

}


fun void sin(){

   while(true){
       1::ms => now;
       if (Akey ==1) {
       <<<"A">>>;
       SinOsc s => dac;

440 => s.freq; a.light();

       hii => now;
       s =< dac;
       a.unlight();
   }
   if (Bkey ==1) {
       <<<"B">>>;
       SinOsc s => dac;
       550 => s.freq;
       b.light();
       hii => now;
       s =< dac;
       b.unlight();
   }
   if (Ckey ==1) {
       <<<"C">>>;
       SinOsc s => dac;
       660 => s.freq;
       c.light();
       hii => now;
       s =< dac;
       c.unlight();
   }
       if (Dkey ==1) {
           <<<"D">>>;
           SinOsc s => dac;
           770 => s.freq;
           d.light();
           hii => now;
           s =< dac;
           d.unlight();
       }
       if (Ekey ==1) {
           <<<"E">>>;
           SinOsc s => dac;
           880 => s.freq;
           e.light();
           hii => now;
           s =< dac;
           e.unlight();
       }

} }


spork ~FOOTIME(); spork ~sin();


while(true) {

   1::hour => now;

}