OK, thanks! That would be helpful!
For now, I’m using this as the first thing in my processBlock call:
[code] // Special stuff on first pass
// Add existing messages to our own (big enough) buffer
// Then swap out incoming buffer with ours
// From now on, the midiMessages buffer should be big enough to avoid memory allocation
// in the processBlock call. We won't use m_MIDIBuffer any longer.
m_IsFirstProcessBlockCall = false;
And this in my constructor:
[code] // In order to be able to do special things on the first processBlock call
m_IsFirstProcessBlockCall = true;
// Pre-allocate MIDI event buffer
for (int i = 0; i < kDefaultNumOfEventMessagesPerBlock; i++)
It works fine. But as you say there is no guarantee that the incoming midiMessages buffer will always be the same, it would be best to do this on the wrapper level, indeed.
By the way: I noticed that in juce_VST_Wrapper.cpp (line 789), you are doing:
so at least 64 native VstMidiEvents are pre-allocated.
Probably there (in resume()) is also the place to do the ensureSize() for the midiEvents member variable?
When you add this, could you make it big enough? 64 is ok, but a plugin that sends out 16 calculated values every 128 samples (= 2.9 ms @ 44100 Hz) as MIDI CC’s already needs 128 events for a buffer of 1024 samples. A number like 512 or 1024 might be a better default.
Or perhaps make it so that the developer can change it to whatever he thinks suits the plugin best?