Can't use ProcessorDuplicator With dsp::Gain?

Hi there, I’m trying to use the Gain from the dsp module in a plugin. Attempted to set it up as a single “stereoGain” using a processorDuplicator as follows:

using stereoGain = ProcessorDuplicator<Gain<float>, Gain<float>>;

but when I build I get an error from the ProcessorDuplicator struct definition

No type named 'Ptr' in 'juce::dsp::Gain<float>'

Which seems to be an issue where ProcessorDuplicator needs to be able to call a processor’s state with the Ptr, and Gain doesn’t have this Ptr?

There are ways around it (I can apply the gain directly to the buffer before output, or something) I just was wondering if this is a known issue or if there’s a better way to duplicate the Gain processor.

Have a look at the documentation: It states:

template<typename MonoProcessorType, typename StateType>
struct dsp::ProcessorDuplicator< MonoProcessorType, StateType >

Converts a mono processor class into a multi-channel version by duplicating it and applying multichannel buffers across an array of instances.

What’s especially interesting here is what the two template parameters mean: typename MonoProcessorType – the first arguments denotes the type of processor you want to duplicate. typename StateType – the second argument holds what kind of object your processor type needs in its constructor. If you have a look at the https://docs.juce.com/master/tutorial_audio_processor_graph.html tutorial, we see an example usage where the ProcessorDuplicator is used to manage multiple IIR filters with the same coefficients. In the tutorial this works by declaring it like dsp::ProcessorDuplicator<dsp::IIR::Filter<float>, dsp::IIR::Coefficients<float>>, you see that the second argument are the filter coefficients which act as the state in this case.
This also works especially because of two reasons:

  • The dsp::IIR::Coefficients struct is a ReferenceCountedObject that declares a Ptr type so that typename StateType::Ptr state; as we find as a public member in the ProcessorDuplicator is a valid expression
  • The dsp::IIR constructor takes such a Ptr as argument, as required here

As dsp::Gain does not have such kind of reference counted state nor a fitting constructor, this simply won’t do. However, I have to admit that this is not obvious from the docs, especially not for newcommers, I had to read a bit of juce code to find that out. Hope this helps you to understand the error a bit better. Regarding your original issue, you can still do it manually by creating an array of Gain objects and looping over them when processing and setting parameters…

2 Likes

Yeah this was silly of me. I actually knew that the duplicator second argument needed to be StateType and brain-farted here. I am a newcomer though and I do appreciate your explanation!