// name: map-osc.ck // desc: sampling oscillators, mapping (scale+offset) to pitches // (this outputs MIDI) // midi msg MidiMsg msg; // midi out MidiOut mout; // try to open if( !mout.open( 0 ) ) me.exit(); // send message fun void sendMsg( int data1, int data2, int data3 ) { // set data bytes data1 => msg.data1; data2 => msg.data2; data3 => msg.data3; // send msg => mout.send; } // overloaded play note fun void play( int pitch, float velocity ) { // play with recaled velocity play2( pitch, (velocity*127+.5) $ int ); } // play note fun void play2( int pitch, int velocity ) { // send note on message sendMsg( 0x90, pitch, velocity ); } // oscillator (also try TriOsc and SawOsc) SinOsc foo => blackhole; // set frequency (try experimenting with other numbers) 1030./5000 => foo.freq; // play something while( true ) { // sample the signal, scale + offset to MIDI note number play( (48 + (foo.last()/2+.5)*50) $ int, .5 ); // how often 113.1::ms => now; }