Breaking change: how to deal with addParameter vs. HostedParameter?

So I wanted to try out the develop fork (Edit: now 6.1.3). I ran into the breaking change explained here:

Functions on AudioPluginInstance that can add parameters have been made

Possible Issues
Code implementing custom plugin formats may stop building if it calls these

When implementing custom plugin formats, ensure that the plugin parameters
derive from AudioPluginInstance::HostedParameter and then use
addHostedParameter, addHostedParameterGroup or setHostedParameterTree to add
the parameters to the plugin instance.

In a plugin host, it is very important to be able to uniquely identify
parameters across different versions of the same plugin. To make this possible,
we needed to introduce a way of retrieving a unique ID for each parameter,
which is now possible using the HostedParameter class. However, we also needed
to enforce that all AudioPluginInstances can only have parameters which are of
the type HostedParameter, which required hiding the old functions.

I can’t really figure out how you’re supposed to fix existing code. There don’t seem to be any examples yet anywhere. And maybe I’m having a brain fart, but…

For example, I have an internal plugin with this in the constructor:

        addParameter (panType = new AudioParameterChoice ("PANTYPE",  "Pan Type",  { "Linear", "-4.5 dB", "Constant Power" },                 2));
        addParameter (smoothing = new AudioParameterBool ("SMOOTHING",  "Smoothing",  true));
        addParameter (postSmoothing = new AudioParameterBool ("POSTSMOOTH",  "Post Smoothing",  false));
        addParameter (smoothSamples = new AudioParameterInt ("SMOOTHSAMPLES",  "Samples To Smooth",  0, 512, 96)); /

The variables are declared as:

    AudioParameterChoice* panType;
    AudioParameterBool* smoothing;
    AudioParameterBool* postSmoothing;
    AudioParameterInt* smoothSamples;

Can anyone provide an example of how you would translate/update this to the new HostedParameter syntax?

You need to use addHostedParameter instead of addParameter there.

Thanks - I read that in the notes. But you can’t just substitute one for the other…

An example would be really helpful. I can’t quite figure out how to get from one to the other. Apologies for being dense.

The new version takes a unique_ptr argument instead of a raw pointer. You can construct the parameter using std::make_unique<AudioParameterChoice>, std::make_unique<AudioParameterBool> etc.

Thank you! I’m starting to get it, but how do you pass the std::make_unique<AudioParameterChoice> to addHostedParameter which expects a std::unique_ptr<HostedParameter> ?

    std::unique_ptr<AudioParameterChoice> panType;

    panType = std::make_unique<AudioParameterChoice>("PANTYPE",  "Pan Type",  StringArray { "Linear", "-4.5 dB", "Constant Power" }, 2);
No viable conversion from 'unique_ptr<juce::AudioParameterChoice>' to 'unique_ptr<juce::AudioPluginInstance::HostedParameter>'

unique_ptr is ‘move only’, which means that it cannot be copied.

I think you’ll need to do something like this:

// Create parameter
auto p = std::make_unique<AudioParameterChoice> ("PANTYPE",  "Pan Type",  StringArray { "Linear", "-4.5 dB", "Constant Power" }, 2);

// Store pointer to parameter, if necessary
panType = p.get();

// Add parameter to processor
addHostedParameter (std::move (p));
1 Like

Thanks a ton! Working.