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.
