I miss AudioBuffer.numSamples for midieffects in VST3

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.

How would you be using the resulting VST3 plug-in? In Cubase I don’t think it’s possible to use MIDI plug-ins as MIDI inserts (I think Steinberg is trying to encourage people to use the VST Module SDK, which JUCE doesn’t support), so I would suggest that you just stick with VST2.

And what about other daws? If it’s a generally accepted belief that vst3 souldn’t be used for midi inserts, maybe you could gray ut that option in the producer or put an assert/warning somewhere in the code for pure vst3 midiplugins without any audio?

Yeah, midi inserts won’t work for vst3 currently. We are working on supporting this in the future. It’s in our backlog.