//Number 22 //Chuck a day 2009 //by Scott Hewitt //www.ablelemon.co.uk/chuckaday //extend event for noteoffs class Zeroevent extends Event{ int pitch; } Zeroevent noteoff; //create midi object MidiIn min; MidiMsg msg; //check if midi present if( !min.open(0) ) { me.exit(); } <<< "midi connected" >>>; //handle midi input function void midiinput(){ while(true){ min => now; while( min.recv(msg) ){ if(msg.data3 == 0){ //send pitch noteoff to child shreds msg.data2 => noteoff.pitch; noteoff.broadcast(); }else{ //new picth spork shred (voice) spork ~ synth(msg.data2, msg.data3); } } } } //synth function void synth(int a, int b){ //synth dsp SinOsc s => Envelope env => dac; 50::ms => env.duration; 1 => env.keyOn; Std.mtof(a) => s.freq; while(true){ //await noteoff event noteoff => now; //match noteoff if(noteoff.pitch == a){ 1 => env.keyOff; 51::ms => now; me.exit(); } } } spork ~ midiinput(); while (true){ 5000::ms => now; }