AudioProcessorPlayer: pre-allocate MIDI buffer

The callback of AudioProcessorPlayer::audioDeviceIOCallbackWithContext causes re-allocations on the realtime thread when there are a lot of MIDI messages. The callback copies MIDI messages from the messageCollector. If the incomingMidi buffer capacity is exceeded a re-alloc has to happen.

A solution would be to call incomingMidi.ensureSize() with an appropriate size. Please note that this is not the same as calling player.getMidiMessageCollector().ensureStorageAllocated()

What would you say is “an appropriate size”? I think it is fair to say that this HIGHLY depends on the use case, which is why this is not pre-allocated. It is also noteworthy, that MidiBuffer does not allocate every time when there happens to be a lot of MIDI messages in one block. It’s gonna allocate more space once, and stick with that space until another block does not fit. You might only experience memory being allocated in the first five blocks.

Lastly, I think the class AudioProcessorPlayer is more of a PoC than something designed to use in an highly optimised environment. There are a lot of system calls and memory allocations hidden in there, not just the MIDI buffer being enlarged if necessary.