Max number of MIDI events in processBlock()?

Is there a maximum number of MIDI events that might be expected in the MidiBuffer that is passed to processBlock()?

I’d like to record the MIDI events into my own Note On/Off object list while processing (in certain cases), but can’t allocate them on the fly, so I’d like to pre-allocate a pool of buffers of my objects that the processBlock() function can copy data into (for a background thread to handle).

I suppose I could allocate buffers to the maximum buffer size set in prepareToPlay(), but that seems kind of arbitrary. Is there a reasonable maximum I could use?

Or… is there a better way to capture and remember MIDI data in JUCE (that is safe to capture within the processBlock() function)?

There are no max AFAIK.
I would juste allocate at first 1024 of those and resize (with a lock if required) if it doesn’t fit

Using a lock in the processBlock function is a big no-no, though, right? I don’t know before the function is called if I’ll need more room or not. For now, I’m allocating the number given in prepareToPlay, on the assumption it is highly unlikely that we’d ever get as many MIDI notes as there are samples!

If this happen only one time and only in very rare case I don’t see the fuss.

Right, and if the user is feeding in thousands of MIDI notes for one processBlock call, there’s probably something seriously wrong already that can’t be saved by avoiding the allocation in the audio thread.

2 Likes