I want to create a MIDI-to-MIDI plugin that accepts a sequence of chords and outputs just the
lowest note in each chord. I have studied the following MIDI plugin example and got the example working too:
JUCE/ Tutorial/ Create a basic Audio/MIDI plugin, Part 2/ Coding your plug-in
However, I’m puzzled by one aspect of what I am trying to achieve. I’d like my plugin to be able to accept 2-note chords, 3-note chords, 4-note chords, and, in general, N-note chords. Each chord will arrive as a cluster of MIDI events but all with the same timestamp (I assume). My code will read the chord by reading MIDI events from a MIDI input buffer, as does the code in
the above example.
My question is: How can my code determine that it has read all the MIDI events in the chord?More technically, if it reads one or more notes at time T, how can it be sure that it has read ALL the notes at time T, given that the plugin does not know how many notes are in the arriving chords?
The obvious solution is to wait until a MIDI event arrives that has a LATER time. But this will probably be the first note in the NEXT chord at the start of the next bar. By the time my plugin has seen this event, it will be way too late in real time to output the lowest note of the previous chord.
Should I somehow wait until the next AUDIO time unit passes, and then check the MIDI buffer?
Is there a JUCE call I can make to say “I’ve received one MIDI event. Please give me ALL the other MIDI events that are arriving at this exact same time”?
If this problem is NOT solvable, I guess I’ll have to add a setting to my plugin so that they
user can specify how many notes are going to arrive in each chord, and then the code can
simply wait for that many events to arrive in each round.
Another approach is for the code to observe the arriving chords and count how many notes are in each chord and wait for only that many each round. However, this will mean that the plugin will fumble the very first chord.
Can anyone help me address this issue?