Difference between revisions of "Poly demo.ck"
From CSWiki
(2 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
// open midi receiver, exit on fail | // open midi receiver, exit on fail | ||
// need to set this argument depending on your MIDI config | // need to set this argument depending on your MIDI config | ||
− | // try chuck --probe in the Terminal to see what MIDI devices are present | + | // try "chuck --probe" in the Terminal to see what MIDI devices are present |
if ( !min.open(1) ) me.exit(); | if ( !min.open(1) ) me.exit(); | ||
Line 20: | Line 20: | ||
// print content | // print content | ||
<<< msg.data1, msg.data2, msg.data3 >>>; | <<< msg.data1, msg.data2, msg.data3 >>>; | ||
+ | //message type + channel number, noteNumber (if note message), noteVelocity (if note message) | ||
+ | //this will work if your MIDI device sends noteOff messages as noteOn messages with velocity (msg.data3) = 0. | ||
if(msg.data3 > 0) spork ~ mand_note(Std.mtof(msg.data2), msg.data3/127., noteoffs[msg.data2]); | if(msg.data3 > 0) spork ~ mand_note(Std.mtof(msg.data2), msg.data3/127., noteoffs[msg.data2]); | ||
else noteoffs[msg.data2].signal(); | else noteoffs[msg.data2].signal(); | ||
+ | |||
+ | //however, many MIDI devices use proper noteOff messages (msg.data1 = 128 + channel number) as well as | ||
+ | //noteOn messages (msg.data1 = 144 + channel number), so the if/else structure above would have to be | ||
+ | //modified accordingly; an exercise left for the ChucKer. | ||
} | } | ||
} | } |
Latest revision as of 12:53, 26 February 2008
MidiIn min; MidiMsg msg; Event noteoffs[127]; // open midi receiver, exit on fail // need to set this argument depending on your MIDI config // try "chuck --probe" in the Terminal to see what MIDI devices are present if ( !min.open(1) ) me.exit(); while( true ) { // wait on midi event min => now; // receive midimsg(s) while( min.recv( msg ) ) { // print content <<< msg.data1, msg.data2, msg.data3 >>>; //message type + channel number, noteNumber (if note message), noteVelocity (if note message) //this will work if your MIDI device sends noteOff messages as noteOn messages with velocity (msg.data3) = 0. if(msg.data3 > 0) spork ~ mand_note(Std.mtof(msg.data2), msg.data3/127., noteoffs[msg.data2]); else noteoffs[msg.data2].signal(); //however, many MIDI devices use proper noteOff messages (msg.data1 = 128 + channel number) as well as //noteOn messages (msg.data1 = 144 + channel number), so the if/else structure above would have to be //modified accordingly; an exercise left for the ChucKer. } } fun void mand_note(float freq, float amplitude, Event mynoteoff) { Mandolin mand => dac; mand.freq(freq); mand.pluck(amplitude); mynoteoff => now; mand =< dac; //think about how to make this better with an envelope or ADSR }