# Fast access to parameters?

**URL:** <https://forum.juce.com/t/fast-access-to-parameters/38535>\
**Category:** Audio Plugins\
**Created:** [April 7, 2020, 5:09pm UTC](https://forum.juce.com/t/fast-access-to-parameters/38535 "2020-04-07T17:09:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![HowardAntares](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/howardantares/32/4629_2.png) [@HowardAntares](https://forum.juce.com/u/HowardAntares)\
**Post date:** [April 7, 2020, 5:09pm UTC](https://forum.juce.com/t/fast-access-to-parameters/38535/1 "2020-04-07T17:09:15Z")

</div>

I am updating from JUCE 5.3.2 to 5.4.7, and am looking at restructuring a fair amount of code, specifically the AudioProcessorValueTreeState.

One practice that I’ve used previously was to always create the parameters as member variables in my PluginProcessor class using CreateAndAddParameter. Then, whenever I needed to access the parameter, I directly used that member variable (a raw pointer). The idea is that this would greatly speed up access to the parameters without having to look them up. (A couple of my plugins have over 100 parameters, so it seemed like a good optimization to use.)

Is this still a viable/reasonable idea, using the ParameterLayout scheme instead of the deprecated CreateAndAddParameter? If so, I’ve been having trouble figuring out how to keep a pointer in my processor class. Here is the only thing I’ve come up with that doesn’t generate a compile error:

```
AudioProcessorValueTreeState::ParameterLayout TestPlugin1AudioProcessor::createParameterLayout()
{
  std::vector<std::unique_ptr<RangedAudioParameter>> params;
  params.push_back( std::make_unique<AudioParameterFloat>( "gain", "Gain", -36.0f, 0.0f, 0.0f ) );
  pGainParam = dynamic_cast <AudioParameterFloat*>(&(*params.back()));
  return { params.begin(), params.end() };
}

```

I’ve tried using a std::unique\_ptr as the member variable, but I cannot find a way to first create it using std::make\_unique, and then call push\_back on it. (I intend to have a variety of parameter types, so I wanted (I assume) a vector of RangedAudioParameter objects, correct?)

---

<div class="post-metadata">

**Author:** ![ttg](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ttg/32/14456_2.png) [@ttg](https://forum.juce.com/u/ttg)\
**Post date:** [April 7, 2020, 5:40pm UTC](https://forum.juce.com/t/fast-access-to-parameters/38535/2 "2020-04-07T17:40:28Z")

</div>

Is there any reason for additional data for your realtime callbacks more than `getRawParameterValue()` ? (it’s a ~~float~~ atomic float \* with the value described by your range, in your example it’ll be (-36.0f, 0.0f)

---

<div class="post-metadata">

**Author:** ![HowardAntares](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/howardantares/32/4629_2.png) [@HowardAntares](https://forum.juce.com/u/HowardAntares)\
**Post date:** [April 7, 2020, 6:17pm UTC](https://forum.juce.com/t/fast-access-to-parameters/38535/3 "2020-04-07T18:17:51Z")

</div>

Well, some of my parameters interact with each other, and I need access to them from my parameterChanged() callback, not just the parameter being changed at the moment. So I need the actual current value at that moment, which getRawParameterValue does not guarantee in the listener callbacks.

Also, I need access to the range itself sometimes, which is not provided via that call.

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [April 7, 2020, 8:00pm UTC](https://forum.juce.com/t/fast-access-to-parameters/38535/4 "2020-04-07T20:00:07Z")

</div>

You could consider an approach something like this:

```cpp
class MyProcessor : public juce::AudioProcessor
{
    ...

private:
    template <typename Param, typename... Args>
    static Param& addToLayout (juce::AudioProcessorValueTreeState::ParameterLayout& layout,
                               Args&&... args)
    {
        auto param = std::make_unique<Param> (std::forward<Args> (args)...);
        auto& result = *param;
        layout.add (std::move (param));
        return result;
    }

    juce::AudioProcessorValueTreeState::ParameterLayout createParameters()
    {
        juce::AudioProcessorValueTreeState::ParameterLayout layout;

        floatParam = &addToLayout<juce::AudioParameterFloat> (layout, "float", "float", juce::NormalisableRange<float>(), 0.5);
        intParam = &addToLayout<juce::AudioParameterInt> (layout, "int", "int", 0, 10, 5);
        boolParam = &addToLayout<juce::AudioParameterBool> (layout, "bool", "bool", false);

        return layout;
    }

    juce::AudioParameterFloat* floatParam;
    juce::AudioParameterInt* intParam;
    juce::AudioParameterBool* boolParam;

    juce::AudioProcessorValueTreeState apvts { *this, nullptr, "tree", createParameters() };
};

```
