Trying to access notes in ofxMidi

Hi, just wondering if anyone could help me get this figured out.

I am just trying the ofxMidi library. It compiles fine and I get a stream of messages from my controller. But for some reason I can’t capture notes like I can see them in my MIDI Monitor app. I am trying to use the following line. I have had a few “note_on” appear in my debug window but not nearly what I should be getting.

Any ideas?
Many thanks

Simon

void ofApp::update() {

if(midiMessage.status == MIDI_NOTE_ON) {
    cout << "note_on" << endl;

}

}

Ah I think the function doesn’t get called fast enough to catch the note ons… If
I put it inside here I get them. Anyone else using this? I am not finding that many examples to work from.

Cheers

Simon

//--------------------------------------------------------------
void ofApp::newMidiMessage(ofxMidiMessage& msg) {

	// make a copy of the latest message
	midiMessage = msg;
    
    if(msg.status == MIDI_NOTE_ON) {
        cout << "note_on" << endl;
        
    }
}

What I did was to have a vector, and I push all the arriving notes into that vector, then process those messages one by one inside update.
Otherwise, if you get 5 messages between two animation frames, you would only see the latest one stored in midiMessage.

Note: I was using the ofxThreadedMidiPlayer so I had to use .lock() and .unlock() with the vector, otherwise it would crash. I don’t know if that would be necessary with newMidiMessage() (does it run on the same thread or a different one?).