Difference between revisions of "ChucK Program mididisplay"

From CSWiki
Jump to: navigation, search
 
 
Line 4: Line 4:
 
  // demonstrates how to get specific midi values out of the stream  
 
  // demonstrates how to get specific midi values out of the stream  
 
  // -- art
 
  // -- art
 
+
 
  while( 5::ms => now )
 
  while( 5::ms => now )
 
     while( midiin => int theMidi )
 
     while( midiin => int theMidi )
 
     {
 
     {
 
     // you can watch different midi inputs by changing midiin to
 
     // you can watch different midi inputs by changing midiin to
     // midiin^k where k is the number of the port you want to use
+
     // midiin^k where k is the number of the port you want to use
 
      
 
      
 
     chout => "Raw Message: " => theMidi => endl;
 
     chout => "Raw Message: " => theMidi => endl;
 
+
 
     // bitmasking to get the data out
 
     // bitmasking to get the data out
 
     (theMidi>>16)&0xf => int chan;
 
     (theMidi>>16)&0xf => int chan;
Line 18: Line 18:
 
     (theMidi>>8)&0xff => int data1;
 
     (theMidi>>8)&0xff => int data1;
 
     theMidi&0xff => int data2;  
 
     theMidi&0xff => int data2;  
 
+
 
     chout => "Channel " => chan + 1;
 
     chout => "Channel " => chan + 1;
 
+
 
     if (type == 0)
 
     if (type == 0)
 
         chout => " NoteOff " => data1 => " Velocity " => data2;
 
         chout => " NoteOff " => data1 => " Velocity " => data2;
Line 26: Line 26:
 
     if (type == 1)  
 
     if (type == 1)  
 
         chout => " NoteOn " => data1 => " Velocity " => data2;
 
         chout => " NoteOn " => data1 => " Velocity " => data2;
 
+
 
     if (type == 2)
 
     if (type == 2)
 
         chout => " Aftertouch " => data1 => " Velocity " => data2;
 
         chout => " Aftertouch " => data1 => " Velocity " => data2;
 
+
 
     if (type == 3)
 
     if (type == 3)
 
         chout => " Control Change # " => data1 => " Value " => data2;
 
         chout => " Control Change # " => data1 => " Value " => data2;
 
+
 
     // the following two midi types are two byte messages
 
     // the following two midi types are two byte messages
 
     // ChucK concatenates a blank byte at the end of these messages so  
 
     // ChucK concatenates a blank byte at the end of these messages so  
Line 38: Line 38:
 
     if (type == 4)  
 
     if (type == 4)  
 
         chout => " Patch Change " => data1;
 
         chout => " Patch Change " => data1;
 
+
 
     if (type == 5)  
 
     if (type == 5)  
 
         chout => " PolyPressure " => data1 => " Value ";
 
         chout => " PolyPressure " => data1 => " Value ";
 
+
 
     if (type == 6){
 
     if (type == 6){
 
         // data1 + data2 => int pitchbend;
 
         // data1 + data2 => int pitchbend;
 
         chout => " Pitch Bend -- LSB" => data1 => " MSB " => data2;
 
         chout => " Pitch Bend -- LSB" => data1 => " MSB " => data2;
 
     }
 
     }
 
+
 
     // good luck...
 
     // good luck...
 
     if (type == 7)
 
     if (type == 7)

Latest revision as of 18:59, 21 February 2006

// 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;
      }