Buffering MIDI

I am using a constant buffer size inside my audio plugin (because I will be processing the audio in the frequency domain), and want to do the same buffering with the MIDI, but it doesn’t seem to be working. Does MidiBuffer::addEvents() not allocate memory for the events I want to add? I feel clueless. Here is the code I am trying to use for debugging:

// inside processBlock() :
// ...
    // accumulating midi
    int bufferSize = buffer.getNumSamples();
    MidiAccumulator.addEvents(midiMessages, 0, -1, timeSinceLastBlock);
    timeSinceLastBlock += bufferSize;

    // inside the block of code that processes the constant-size audio buffer
    {
                for (auto event : MidiAccumulator)
                    workBench[(int)event.getMessage().getTimeStamp()] =
                    event.getMessage().isNoteOn(true) ? 0.9f : -0.9f;
    }

    // emptying midiAccumulator
    if (timeSinceLastBlock >= samplesPerBlock)
    {
        timeSinceLastBlock -= samplesPerBlock;
        MidiAccumulator.clear(0, samplesPerBlock);
        for (auto event : MidiAccumulator)
        {
            event.samplePosition -= samplesPerBlock;
        }
    }

MidiAccumulator is a MidiBuffer created with default constructor
timeSinceLastBlock is an int, starting from 0
workBench is a float pointer that marks the beginning of the constant sized audio buffer

This should generate positive spikes on NoteOn and negative on NoteOff, but only generates the NoteOffs in realtime and nothing when playing from piano roll, except a positive when I press play and a negative when I press stop.

Any help would be much appreciated, and sorry for the formatting, I’m new to forums.

I wonder if filtering and transforming the midi messages into another data type and storing that into a different type of buffer would be better? Even the JUCE documentation suggests using other classes (like MidiMessageSequence). I would maybe process the MIDI as it comes in, and just store the 0.9 and -0.9 values that you want (but then I don’t know the full extent of your project)
I also noticed your midi process returns 0.9 for MIDI Note On messages (including those with velocity 0, which is sometimes used as a note off), but it returns -0.9 for all other messages. The host might be sending CC, MIDI timestamps, or who knows what in that buffer. So you’re getting -0.9 for more than just note off messages.

Yes, filtering and processing the midi before buffering is what I will try next. The -0.9 and 0.9 values were only for diagnostical purposes, so I don’t really mind CC and other stuff right now. This is because the way I intend to use the midi is very complicated (for my current experience) and I didn’t want to get into that before I made sure that it has the right input (which is the buffered midi).
It just seemed so intuitive and a good practice to use the classes provided by juce as long as possible in the process chain.

I have been running tests for a while now and it works perfectly fine in the juce AudioPluginHost, but not in FL Studio. My best guess is that it is because of the varying buffer size and that something is wrong with how I buffer my midi, but I have no idea what it is.