Keyin topitch

From CSWiki
Revision as of 21:37, 1 October 2008 by Dtrueman (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Hid hi;
HidMsg msg;

0 => int deviceNum;
hi.openKeyboard( deviceNum ) => int deviceAvailable;
if ( deviceAvailable == 0 ) me.exit();
<<< "keyboard '", hi.name(), "' ready" >>>;

SinOsc sine => ADSR envelope => dac;

envelope.set(20::ms, 250::ms, 0.1, 150::ms);

while( true )
{
       
    hi => now;
    
    while( hi.recv( msg ) )
    {
        if( msg.isButtonDown() )
        {
			<<< "down:", msg.which >>>;
			
			//set the pitch, based on key value
			msg.which + 50 => Std.mtof => sine.freq;
			<<<sine.freq()>>>;
			//ok this is kinda random; would be nice to have 
			//a table that would convert these random ASCII
			//values to useful pitch values....
			
			//turn the note on, wait 1.5 seconds, turn it off
			envelope.keyOn();
			1500::ms => now;
			envelope.keyOff();
        }
        
        else
        {
			<<< "up:", msg.which >>>;
	}
    }
}