# Parameter Group Loop Help

**URL:** <https://forum.juce.com/t/parameter-group-loop-help/46232>\
**Category:** General JUCE discussion\
**Created:** [May 27, 2021, 6:28pm UTC](https://forum.juce.com/t/parameter-group-loop-help/46232 "2021-05-27T18:28:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DavidCNAntonia](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/davidcnantonia/32/3293_2.png) [@DavidCNAntonia](https://forum.juce.com/u/DavidCNAntonia)\
**Post date:** [May 27, 2021, 6:28pm UTC](https://forum.juce.com/t/parameter-group-loop-help/46232/1 "2021-05-27T18:28:27Z")

</div>

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”.

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [May 27, 2021, 6:32pm UTC](https://forum.juce.com/t/parameter-group-loop-help/46232/2 "2021-05-27T18:32:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DavidCNAntonia](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/davidcnantonia/32/3293_2.png) [@DavidCNAntonia](https://forum.juce.com/u/DavidCNAntonia)\
**Post date:** [May 27, 2021, 7:22pm UTC](https://forum.juce.com/t/parameter-group-loop-help/46232/3 "2021-05-27T19:22:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DavidCNAntonia](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/davidcnantonia/32/3293_2.png) [@DavidCNAntonia](https://forum.juce.com/u/DavidCNAntonia)\
**Post date:** [May 28, 2021, 12:31pm UTC](https://forum.juce.com/t/parameter-group-loop-help/46232/4 "2021-05-28T12:31:21Z")

</div>

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.
