Multiple processors in one plugin, swap by choice


If there can only be one plugin processor, If I wanted to implement an audio plugin which had an editor where you could select an effect(e.g distortion, tremolo…) and its processor would run what is the correct way to go about this?


processblock(buffer, midimessages)
if (distortionOn)

if (tremoloOn)


then just make a distortionBox class with a processBlock method and do your number crunching there, no need for multiple processors unless you need the fanciness it offers.


But keep in mind that if you classes have any state (i.e. require memory allocation) then you should do this for both classes before you reach processBlock(). You can do it in the AudioProcessor constructor unless you need to know details like samplerate or expected blocks per sample, in which case you should do it in prepareToPlay().


Yeah thats important

2 approaches:

prepareToPlay(sampleRate, samplesPerBlock)

ProcessorDetails::set(sampleRate, samplesPerBlock); //this should be a static thing

tremoloBox.prepareToPlay(sampleRate, samplesPerBlock); //direct set up


const double sampleRate = ProcessorDetails::getSampleRate();

But your code must also handle changes inside its main process block, so make sure to check details and if necessary re-set the proper values.


Yep, the blocklength may vary in processBlock(), but the sample rate will be fixed.

Also, the number of channels are available in prepareToPlay() by calling getTotalNumImputChannels() or getTotal NumOutputChannels() and that shouldn’t change in processBlock().