So, I just tried my hand at compiling this latest 0.02 version of ofxMidi on Mac OS 10.5.8. Here’s how I got it to work:
First, before anything, make sure you’ve added both the ofxMidi addon’s source to your project and that you’ve added CoreMIDI.Framework to your project as well (http://forum.openframeworks.cc/t/ofxmidi-questions/2520/4).
Next, I made a class to act as my listener. I just got an M-Audio X-Session Pro controller and wanted to hook it up to my project. You’ll want to make a class of your own. We’ll pretend it’s called MyMidiListener. You’ll stick the .h and .cpp files in your project’s src folder.
First the header file (called MyMidiListener.h):
#pragma once
#include "ofxMidi.h"
class MyMidiListener : public ofxMidiListener {
public:
MyMidiListener();
~MyMidiListener();
void newMidiMessage(ofxMidiEventArgs& eventArgs);
};
And now the actual cpp file (called MyMidiListener.cpp):
#include "MyMidiListener.h"
// Constructor
MyMidiListener::MyMidiListener(){
}
// Destructor
MyMidiListener::~MyMidiListener(){
}
// Method that receives MIDI event messages.
void MyMidiListener::newMidiMessage(ofxMidiEventArgs& eventArgs){
cout << "byteOne = " << eventArgs.byteOne << endl;
cout << "byteTwo[" << eventArgs. byteTwo << endl;
// Do the stuff you need to do with
// the ofxMidiEventArgs instance.
}
Now in your testapp.h header file, you’ll need to declare a couple member variables. One for the ofxMidiIn instance, and one for the MyMidiListener instance. Make sure you have the #include directives at the top of your header file for both “ofxMidi.h” and “MyMidiListener.h”.
ofxMidiIn midiIn;
MyMidiListener midiListener;
Now in your testapp.cpp file, in the setup() method, add these lines:
// This outputs the various ports
// and their respective IDs.
midiIn.listPorts();
// Now open a port to whatever
// port ID your MIDI controller is on.
midiIn.openPort(0);
// Add your MyMidiListener instance
// as a listener.
midiIn.addListener(&midiListener);
Now, when your computer receives MIDI events, your listener’s newMidiMessage method will get called. You can (and should) add some additional methods to your MyMidiListener class so that your main testapp application can actually get data from it.