How to use paramterID in the host?


The host needs access to plugin’s parameters for automation/modulation.
What is proper way to get parameter ID for that and therefore save it in the session state?
We can use the index of parameter, but indices aren’t stable and it’s recommended to use pluginID for that.
Another problem that some plugins have thousands of params, walking through them for mapping takes long time.

But I don’t understand how to get the parameterID and how to store it properly.
And how can I get the parameter by it’s ID on state loading.


You should really have a look at the juce::AudioProcessorValueTreeState class which has a lot to offer. It’s also covered in a dedicated tutorial which answers your questions:

Thanks. But I mean using it from the JUCE host. Is that APVTS about?

Hosted plugins have getHostedParameter, which returns a pointer to a HostedAudioProcessorParameter.

HostedAudioProcessorParameter is a normal parameter with a getParameterID function that returns a stable parameter identifier.

One possibility is to iterate through the plugin’s parameters once after load, and to build a std::map from ID to parameter index. Then, use the map when fetching parameters, rather than doing a linear search.

1 Like

Sorry, I didn’t understand you were on the hosting side. Don’t have much knowledge on this area but I still looked for answers and found just what reuk answered (he was too fast, hehe), so good to know :wink:

Thanks. It’s getting clear.
I’m trying to avoid iterating of all parameters on load. With Tracktion F.'em or Biotek2 it takes ~10 minutes :grimacing:

The idea is to catch parameter by audioProcessorParameterChangeGestureBegin() then map it.

Perhaps it’s obvious. But how can I assign the parameter in host with knowing it’s ID?

Something like:
juce::AudioProcessorParameter* myParameter = myPlugin.getParameter(ID);

For now it’s done by passing parameter index then getting with myParameter = myPlugin->getParameters()[index];

Are you trying to retrieve the parameter for a particular ID?

If so, I’d recommend something like this, if you need to do lots of parameter lookups:

// Ideally you only want to build this map once, so this code should probably
// run shortly after loading the plugin, and the map should be saved for re-use.
std::map<String, AudioProcessorParameter*> parameterForId;

for (auto parameterIndex = 0; parameterIndex < processor.getParameters().size(); ++parameterIndex)
    auto* parameter = processor.getHostedParameter (parameterIndex);
    parameterForId.emplace (parameter->getParameterId(), parameter);

// Now we can quickly find a particular parameter
const auto iter = parameterForId.find ("myparameter");

if (iter != parameterForId.cend())
    auto* myParameter = iter->second;
    // Do something with myParameter


Yes. I’m trying to store controlled parameters in the session. Am I getting right, that if I have (stored in the save file) the ID, then I must iterate through params to find it?

Sorry for dumb questions.

Yes, you’ll need to iterate through all parameters at least once to add them to the map. Doing this once should not have any appreciable performance impact, even with thousands of parameters (JUCE uses such maps in several locations internally - we’d definitely have heard about it if building these maps was causing performance issues). Once the parameters are in a map, lookup is much faster than checking each parameter individually.