Can't make sequencer plugin host to send note messages reliably


#1

I have a plugin host sequencer software sending notes to a plugin, but for some reason, the notes sometimes don’t get to their destination, resulting with unheard notes, and stuck notes.
I checked through the console and it appears all the appropriate note messages are getting out from the sequencer, Meaning it must be something in the way I fill the MidiBuffer of the plugin.

void PluginInstrument::noteIn(int note, int velocity)
{
MidiMessage event;
event = MidiMessage::noteOn(1, note, ((float)velocity)/127);

m_midiBuffer.addEvent(event, m_midiMessagePosition);

m_midiMessagePosition += 10;

}

void PluginInstrument::getNextAudioBlock (const AudioSourceChannelInfo &bufferToFill)

{
if (currentPlugin== nullptr)
bufferToFill.clearActiveBufferRegion();
else
{
m_midiBufferOutput = m_midiBuffer;
currentPlugin->processBlock(*bufferToFill.buffer, m_midiBufferOutput);
m_midiBuffer.clear();
m_midiMessagePosition = 0;
}
};

I tried different things including raising each incoming note message timing by 10 samples interval, separating the input buffer and output buffer, and try different plugins… The only thing worked out when I filled the MidiBuffer of the plugin with one note message for each processBlock function. But then, the delay time between each note was highly perceivable.

Truly appreciate any kind of help.


#2

Problem Solved!

literally just jumped the MidiBuffer.clear() function two rows up.

the sequencer thread just sent note messages while the plugin was processing the current midi buffer and the buffer was cleared after all the plugin process was finished, removing all the notes messages that came while the plugin was processing. Anyway, I’m relieved as hell.


#3

Umm… no, you’ve not solved your problem, just reduced the frequency at which it will crash. Two threads modifying and reading the same array is a massive race condition. (If you don’t know what that is then you probably need to do some homework about multi-threading!)

Maybe look at the MidiMessageCollector class, which is designed for this kind of midi queuing.


#4

Yes you are right, I am making some compromises for the moment, but I will get there.
Thanks! I’ll check out this class