//----------------------------------------------------------------------------- // name: miditest.cpp // desc: basic RtMidi input example // // Music 256a, Fall 2009, Stanford University // http://ccrma.stanford.edu/courses/256a-fall-2009/ //----------------------------------------------------------------------------- #include #include using namespace std; #include "RtMidi.h" // the callback void callme( double deltatime, std::vector< unsigned char > *message, void *userData ) { unsigned int nBytes = message->size(); // only care about 3-byte messages if( nBytes == 3 ) { // look at first byte in message switch( (int)message->at(0) ) { case 144: // note on cerr << "NOTEON: " << (int)message->at(1) << " v: " << (int)message->at(2) << endl; break; default: break; } } } // entry point int main() { RtMidiIn * midiin = new RtMidiIn(); // Check available ports. unsigned int nPorts = midiin->getPortCount(); if ( nPorts == 0 ) { std::cout << "No ports available!\n"; goto cleanup; } midiin->openPort( 0 ); // Set our callback function. This should be done immediately after // opening the port to avoid having incoming messages written to the // queue. midiin->setCallback( &callme ); // Don't ignore sysex, timing, or active sensing messages. midiin->ignoreTypes( false, false, false ); std::cout << "reading MIDI input ... press to quit.\n"; char input; std::cin.get(input); // Clean up cleanup: delete midiin; return 0; }