danomatika / ofxMidi

(maintained) Midi addon for openFrameworks
Other
262 stars 73 forks source link

receiving chords #57

Closed stephanschulz closed 6 years ago

stephanschulz commented 6 years ago

I had good success making your add-on work for a project. But I am struggling understanding how to receive chords due to the serial nature of midi. Theoretically I should be receiving all the notes of a chord quickly one after the other, but using your input example I only see some of the chord's notes.

Do I have to put the code on it's own thread to get faster read times?

I modified your input example to print in the console when messages change. https://gist.github.com/stephanschulz/c72930fcd69096b8d1f9e573100a615f

Here is a screenshot using a virtual midi keyboard showing how 3 notes are pressed but only 2 get printed out. I have noticed this on a real keyboard too.

What am I doing wrong?

screen shot 2018-05-28 at 9 21 43 pm
danomatika commented 6 years ago

Do the chord check in the newMidiMessage() function.

The example basically just makes a copy of the latest message which is used to draw the status info each frame. As you've noticed, sometimes MIDI messages come in quickly and essentially the copied message gets overwritten before it can be drawn.

Start by adding a print to the newMidiMessage() function ala:

ofLog() << "Received: " << ofxMidiMessage::getStatusString(midiMessage.status);

One thing to know is that you generally don't want to do GUI logic here (ie. don't draw to the screen) as it's being called on the high priority MIDI thread which is why the example makes a copy. Either do your chord checks in newMidiMessage(), which has a higher call rate than update() or draw() which is locked to the frame rate, or push copies of the incoming messages to a vector which you can then process on every frame in update().

danomatika commented 6 years ago

Any update on this?

stephanschulz commented 6 years ago

sorry did not have time yet. I'm sure you are right and all I need to do was use newMidiMessage()

danomatika commented 6 years ago

With ofxMidi 1.1.0, I updated the midiInputExample to queue the incoming messages. This would be easiest way to check for multiple note onset the same time.