Working through the MIDI queue

I noticed that some note-off events were missing when playing “for real” leaving the note stuck until I hit it again. Now I was wondering if I am working through the MIDI queue correctly?

void OdinAudioProcessor::processBlock(AudioBuffer<float> &buffer,
                                      MidiBuffer &midiMessages) {
  MidiMessage midi_message;
  int midi_message_sample;
  MidiBuffer::Iterator midi_iterator(midiMessages);
  bool midi_message_remaining =
      midi_iterator.getNextEvent(midi_message, midi_message_sample);

  // loop over samples
  for (int sample = 0; sample < buffer.getNumSamples(); ++sample) {
  if (midi_message_remaining) {
    if (midi_message_sample <= sample) {

It looks like you are only pulling one event out of the queue per call to processBlock. There may be more than one in there, and you need to process the ones that fall between the times of the buffer.

1 Like

True, although it’s one per sample. So two events on the last sample will result in one missing :thinking:

Thanks I’ll fix that :slight_smile:

Ok funnyly enough I played and a note got stuck which was literally below the range of my 88 key Midi keyboard.

I further noticed, notes are not getting stuck in my plugin, but in Bitwig studio itself…
I don’t know whats happening, but bitwig is somehow getting confused MIDI messages. Anyway, my plugin is innocent :innocent:

You updated your code to iterate over the midibuffer until it reaches an event past the current buffer time?

Ah yes I did, forgot to mension it. As said the problem persists (which doesn’t say this wasn’t causing problems as well).

I’ll be best off testing in another host now I think! (The notes are getting stuck in Bitwig even without my plugin being loaded in)

Thanks for your input! muchos appreciatos :slight_smile: