From CSWiki
// mididisplay.ck
// ---------------------------------------
// Displays Midi data
// demonstrates how to get specific midi values out of the stream
// -- art
while( 5::ms => now )
while( midiin => int theMidi )
{
// you can watch different midi inputs by changing midiin to
// midiin^k where k is the number of the port you want to use
chout => "Raw Message: " => theMidi => endl;
// bitmasking to get the data out
(theMidi>>16)&0xf => int chan;
(theMidi>>20)&0x7 => int type;
(theMidi>>8)&0xff => int data1;
theMidi&0xff => int data2;
chout => "Channel " => chan + 1;
if (type == 0)
chout => " NoteOff " => data1 => " Velocity " => data2;
if (type == 1)
chout => " NoteOn " => data1 => " Velocity " => data2;
if (type == 2)
chout => " Aftertouch " => data1 => " Velocity " => data2;
if (type == 3)
chout => " Control Change # " => data1 => " Value " => data2;
// the following two midi types are two byte messages
// ChucK concatenates a blank byte at the end of these messages so
// that your parsing doesn't blow up
if (type == 4)
chout => " Patch Change " => data1;
if (type == 5)
chout => " PolyPressure " => data1 => " Value ";
if (type == 6){
// data1 + data2 => int pitchbend;
chout => " Pitch Bend -- LSB" => data1 => " MSB " => data2;
}
// good luck...
if (type == 7)
chout => " Sysex " => "Data " => data1 => " " =>data2;
// Prints out the now time so that it each message is time-stamped
chout => " " => now => endl;
// You can take the time-stamp out by commenting the previous line
// and uncommenting the following the line
//chout => endl;
}