I noticed when porting the Arpeggiator midi sample from VST(2) to VST3 that it doesn’t work.
When implemented as a midi effect, it has no audio connections so AudioSampleBuffer.numSamples in processBlock will always be zero. Although this might sound logical to some, it makes it hard to calculate the proper position of outgoing the midimessages. Like how it’s being done in the Arpeggiator e.g.
In the old VST-implementation you still get a valid numSamples value even if the channel count is zero. Can’t we have that also for the VST3?
In VST_wrapper the crucial code at line 461 looks like
const int numChannels = jmax (numIn, numOut); AudioBuffer<FloatType> chans (tmpBuffers.channels, isMidiEffect ? 0 : numChannels, numSamples);
whereas in VST3_wrapper (line 1934) it’s
if (int totalChans = jmax (totalOutputChans, totalInputChans)) buffer.setDataToReferTo (channelList.getRawDataPointer(), totalChans, (int) data.numSamples);
See the difference?
If we change this to
int totalChans = jmax(totalOutputChans, totalInputChans); buffer.setDataToReferTo (channelList.getRawDataPointer(), totalChans, (int) data.numSamples);
the existing midi code base depending on numsamples in AudioSampleBuffer will continue to work. (To be fair I haven’t checked the above change for every possible drawback, there might be better ways to set numSamples to the right value, but it works for those plugins I’ve tested anyway)
While it might look… heretical to some to have a sample count but no samples, at least the channel count will be zero, so properly designed code (looping over no of channels) will still work.
The other solution, to have one or more dummy audio channels looks even more awful to me, and after all, if it worked having a non-zero sample count even when there were zero real samples in the old VST, why wouldn’t it work for VST3?
All code is from the developer branch as of yesterday.