Parameter Group Loop Help

Hi All,

I’m creating shared pointer vectors of AudioParameterFloat* so that they can be passed around to custom components. I’m trying to work out how to add these to AudioProcessorParameterGroups but can’t seem to find a solution that works. Any advice on how to get this to work would be much appreciated. Here is how I am creating these particular parameters (some unnecessary code cut out):

aVector = std::make_shared<std::vector<juce::AudioParameterFloat*>>();
aVector->resize(20);

for (int i = 0; i < aVector->size(); i++)
{
    juce::String value(i);
    addParameter(aVector->data()[i] = new juce::AudioProcessorValueTreeState::Parameter ("a"+value, "A "+value, "A "+value, juce::NormalisableRange< float > (0.0, 1.0), 1.0, nullptr, nullptr, false, false, false, juce::AudioProcessorParameter::genericParameter, false));
}

For example, I’d like to add these all to the the group “A”.

I would strongly recommend not to use shared_ptrs for that use case. It is perfectly safe to pass around a simple reference, since the parameters in juce cannot be dynamically added and removed.

2 Likes

Very good point, I hadn’t even thought of that! Any idea how to group the parameters if the shared pointers are ignored?

Sorted the issue (I think). Took a look inside juce_AudioProcessor.cpp to see if I could work out how the parameters are actually added. Posting here for the unlikely event that someone else wants to do the same thing.

std::unique_ptr<juce::AudioProcessorParameterGroup> groupA;

std::vector<juce::AudioParameterFloat*> aVector;
aVector.resize(20);

groupA = std::make_unique<juce::AudioProcessorParameterGroup> ("A", "A", " | ");

for (int i = 0; i < aVector->size(); i++)
{
    juce::String value(i);
    aVector[i] = new juce::AudioProcessorValueTreeState::Parameter ("a"+value, "A "+value, "A "+value, juce::NormalisableRange< float > (0.0, 1.0), 1.0, nullptr, nullptr, false, true, false, juce::AudioProcessorParameter::genericParameter, false));
    groupA->addChild(std::unique_ptr<juce::AudioProcessorParameter>(aVector[i]));
}

addParameterGroup(std::move(groupA));

The parameters are grouped (in hosts and formats that allow) and are also accessible as AudioParameterFloat* from the vector so I can do what I need from the custom components.