# getRawParameterValue()

**URL:** <https://forum.juce.com/t/getrawparametervalue/22922>\
**Category:** General JUCE discussion\
**Created:** [June 14, 2017, 2:46pm UTC](https://forum.juce.com/t/getrawparametervalue/22922 "2017-06-14T14:46:40Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [June 14, 2017, 2:46pm UTC](https://forum.juce.com/t/getrawparametervalue/22922/1 "2017-06-14T14:46:40Z")

</div>

[https://www.juce.com/doc/tutorial\_audio\_processor\_value\_tree\_state](https://www.juce.com/doc/tutorial_audio_processor_value_tree_state)

In this example:

- Why is getRawParameterValue() called in processBlock - isn’t it better and ok to get the pointers somewhere that only gets called once (e.g. during construction of the Audio Processor)? I note that it does a linear search through the parameters every time this is called.
- Are the raw values thread-safe? I’m guessing ‘sort of’ ? 🙂

---

<div class="post-metadata">

**Author:** ![matthieu-brucher](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@matthieu-brucher](https://forum.juce.com/u/matthieu-brucher)\
**Post date:** [June 14, 2017, 6:46pm UTC](https://forum.juce.com/t/getrawparametervalue/22922/2 "2017-06-14T18:46:48Z")

</div>

Each time you have a call to PRocessBlock, the parameters may have changed.  
In other frameworks, you would have a setValue() call of some sorts, so you wouldn’t have to check each time in the processBlock function these values.  
I think this is the main drawback of JUCE at the moment (with the fact that you don’t get a parameter hierarchy).

---

<div class="post-metadata">

**Author:** ![holy-city](https://avatars.discourse-cdn.com/v4/letter/h/8491ac/32.png) [@holy-city](https://forum.juce.com/u/holy-city)\
**Post date:** [June 14, 2017, 7:44pm UTC](https://forum.juce.com/t/getrawparametervalue/22922/3 "2017-06-14T19:44:33Z")

</div>

I’m dealing with this right now.

In addition to the setValue() method there’s the (soon to be deprecated) parameterChanged() method in AudioProcesssor, where each plugin parameter is assigned an index and you can use a giant switch statement to set internal variables whenever a parameter is called.

One thing that I’m working on now is to derive a class from AudioProcessorParameter and give it a callback in the constructor. For example something like this

```
CustomParameter : public AudioProcessorParameter
{
public:
    CustomParameter (std::function <void(void)> callback)
    : valueChanged (callback)
    { 
    // rest of constructor
    }
    void setValue (float newValue) override
    {
        value.set (newValue);
        valueChanged();
    }
    float getValue() const override
    {
        return value.get();
    }
    // .... implementation of other virtual methods etc etc

private:
    std::function <void (void)> valueChanged;
    Atomic <float> rawValue;
};

```

Then say we have a gain plugin, we can make the parameter class (which acts as a wrapper for an atomic variable) talk to an underlying variable in the plugin processor class by initializing the callback with a lambda expression when the parameter is constructed.

```
class GainPlugin : public AudioProcessor
{
public:
    GainPlugin ()
    : /* yada yada yada */        
    {
        //initialize the callback with a lambda expression
        addParameter (gainParam = new CustomParameter ([this] () -> void { this->gainVal = this->gainParam->getValue(); }) 
    }
    //..... etc etc
    void processBlock (AudioSampleBuffer& buffer, MidiBuffer&) override
    {
        for (int channel = 0; channel < buffer.getNumChannels())
        {
            float* channelData = buffer.getWritePointer (channel);

             for (int sample = 0; sample < buffer.getNumSamples())
                 channelData[sample] = gain * channelData[sample];
        }
    }
private:
    ScopedPointer<CustomParameter> gainParameter;
    float gain;
};

```

I will say that I haven’t tested this thoroughly, but I needed to roll my own parameter class anyway and this made things easier. Hope this helps or gives you other ideas, I personally think the parameter classes are a little too dense and too OOP-y. I would much rather keep the parameterChanged() method around.

---

<div class="post-metadata">

**Author:** ![pizzafilms](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pizzafilms/32/562_2.png) [@pizzafilms](https://forum.juce.com/u/pizzafilms)\
**Post date:** [June 15, 2017, 12:05am UTC](https://forum.juce.com/t/getrawparametervalue/22922/4 "2017-06-15T00:05:59Z")

</div>

You don’t have to check all the parameters during every processBlock. Just add a parameter listener any/all of your parameters and then deal with whatever changed in the parameterChanged() handler.

You’ll probably end up with something like this:

```
void YourPlugin::parameterChanged(const String& parmID, float newValue)
{
    if(parmID == kGlide)
    {
        // do whatever
    }
    else if(parmID == kOverdrive)
    {
        // whatever
    }
}

```

I don’t know why the team didn’t make the paramID an int to make it an easy switch statement, but there are ways around that.

---

<div class="post-metadata">

**Author:** ![matthieu-brucher](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@matthieu-brucher](https://forum.juce.com/u/matthieu-brucher)\
**Post date:** [June 15, 2017, 8:41am UTC](https://forum.juce.com/t/getrawparametervalue/22922/5 "2017-06-15T08:41:09Z")

</div>

An unordered\_map with callbacks/lambdas 😛  
The listener idea is nice, indeed better than what we have. I assume this is [https://www.juce.com/doc/classAudioProcessorListener](https://www.juce.com/doc/classAudioProcessorListener)?  
Thanks!

---

<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:** [June 15, 2017, 10:07am UTC](https://forum.juce.com/t/getrawparametervalue/22922/6 "2017-06-15T10:07:14Z")

</div>

> [@Matthieu\_Brucher](#):
>
> The listener idea is nice, indeed better than what we have. I assume this is [404 - Missing Page - JUCE](https://www.juce.com/doc/classAudioProcessorListener)?

Unfortunately this has caveats, see this thread:

> [@AudioProcessorListener is not notified when host changes parameter](https://forum.juce.com/t/audioprocessorlistener-is-not-notified-when-host-changes-parameter/16059/2):
>
> That's because each wrapper (which is the gate between the Host and the AudioProcessor) is an AudioProcessorListener, therefore when an object that is an&nbsp;AudioProcessorListener calls setValue() it doesn't exactly want a callback to tell it the value has been set. Think of "setValueNotifyingHost" as actually being "setValueNotifyingListener". I think to be honest you probablt shouldn't be using theAudioProcessorListener unless you are creating a new wrapper.

The best way I found was using the SliderAttachments in AudioProcessorValueTreeState etc.  
And if you like that pattern, I have the same done for the “normal” ValueTree, see here:

> **[GitHub - ffAudio/ffGuiAttachments: Attachments for JUCE ValueTree to gui...](https://github.com/ffAudio/ffGuiAttachments)**
>
> Attachments for JUCE ValueTree to gui components. Contribute to ffAudio/ffGuiAttachments development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![matthieu-brucher](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@matthieu-brucher](https://forum.juce.com/u/matthieu-brucher)\
**Post date:** [June 15, 2017, 10:14am UTC](https://forum.juce.com/t/getrawparametervalue/22922/7 "2017-06-15T10:14:16Z")

</div>

Thanks…  
This is getting hairier and hairier, and no tutorial to explain everything 😕

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [June 15, 2017, 10:18am UTC](https://forum.juce.com/t/getrawparametervalue/22922/8 "2017-06-15T10:18:31Z")

</div>

> [@jimc](#):
>
> [404 - Missing Page - JUCE](https://www.juce.com/doc/tutorial_audio_processor_value_tree_state)

Well, there is a tutorial - I’m just becoming suspicious of it 🙂

[https://www.juce.com/doc/tutorial\_audio\_processor\_value\_tree\_state](https://www.juce.com/doc/tutorial_audio_processor_value_tree_state)

---

<div class="post-metadata">

**Author:** ![matthieu-brucher](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@matthieu-brucher](https://forum.juce.com/u/matthieu-brucher)\
**Post date:** [June 15, 2017, 10:19am UTC](https://forum.juce.com/t/getrawparametervalue/22922/9 "2017-06-15T10:19:47Z")

</div>

me too… It’s only for really simple stuff, and as soon as you start working with state (saving the plugin state, restoring it, changing presets), all hell breaks loose.

---

<div class="post-metadata">

**Author:** ![pizzafilms](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pizzafilms/32/562_2.png) [@pizzafilms](https://forum.juce.com/u/pizzafilms)\
**Post date:** [June 15, 2017, 6:53pm UTC](https://forum.juce.com/t/getrawparametervalue/22922/10 "2017-06-15T18:53:15Z")

</div>

I don’t believe so. I just recently switched to using it in a very-close-to-release beta plugin with 76 parameters and it’s working very well…with some added parameter wrapper classes for utility functions.

My getStateInformation() looks like this:

```
ScopedPointer<XmlElement> allXml = new XmlElement(kEntireStateTag);
XmlElement* parmsXml(parms.state.createXml());
XmlElement* globalsXml(globals.createXml()); //instrument options
allXml->addChildElement(parmsXml);
allXml->addChildElement(globalsXml);
copyXmlToBinary (*allXml, destData);

```

And my setStateInformation() looks like this (minus some error checking):

```
ScopedPointer<XmlElement> xmlState (getXmlFromBinary (data, sizeInBytes));
XmlElement* parmsXml = xmlState->getChildByName(kParmsStateTag);
XmlElement* globalsXml = xmlState->getChildByName(kGlobalsStateTag);
auto state = ValueTree::fromXml(*parmsXml);
parms.state = state;

```

And thanks to the Button & Slider attachments, the UI is always in sync. I did have to roll my own class for a MultiButton Attachment, but I basically modified the SliderAttachment code and made it work for an array of Buttons.

Honestly, having switched to the ValueTree parameters and the attachment class simplified my UI code tremendously.Everything stays in sync easily.

But there could definitely be some more example code for this as well as some more robustness to the AudioProcessorValueTreeState class and it’s parameters.

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [June 15, 2017, 6:54pm UTC](https://forum.juce.com/t/getrawparametervalue/22922/11 "2017-06-15T18:54:18Z")

</div>

The base class for the attachments should be exposed in the header file really - i had to do two custom attachment jobs…

---

<div class="post-metadata">

**Author:** ![matthieu-brucher](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@matthieu-brucher](https://forum.juce.com/u/matthieu-brucher)\
**Post date:** [June 15, 2017, 7:19pm UTC](https://forum.juce.com/t/getrawparametervalue/22922/12 "2017-06-15T19:19:21Z")

</div>

I had a binary state befre that I wanted to keep. But this worked, it’s the preset that didn’t. Now, I will try reading an XML again…  
I still have the huge parameter mess. I’m not sure checking dozens of parametes in a ValueTree is really efficient!

---

<div class="post-metadata">

**Author:** ![pizzafilms](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pizzafilms/32/562_2.png) [@pizzafilms](https://forum.juce.com/u/pizzafilms)\
**Post date:** [June 15, 2017, 7:24pm UTC](https://forum.juce.com/t/getrawparametervalue/22922/13 "2017-06-15T19:24:44Z")

</div>

Well, you’re really only checking the one that changed. Granted, you end up with a ton of if statements on a String. I don’t know why they didn’t make the paramID an int. In my wrapper class, I have an int ID and use that for a switch statement.

---

<div class="post-metadata">

**Author:** ![matthieu-brucher](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@matthieu-brucher](https://forum.juce.com/u/matthieu-brucher)\
**Post date:** [June 15, 2017, 7:54pm UTC](https://forum.juce.com/t/getrawparametervalue/22922/14 "2017-06-15T19:54:47Z")

</div>

Indeed, tbut that’s when I have the ValueTree Listener.  
The “harder” part was that you don’t have all the information in the tutorial, you need to dig here and there and there is no official proper pattern to solve these simple issues.

---

<div class="post-metadata">

**Author:** ![pizzafilms](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pizzafilms/32/562_2.png) [@pizzafilms](https://forum.juce.com/u/pizzafilms)\
**Post date:** [June 15, 2017, 8:07pm UTC](https://forum.juce.com/t/getrawparametervalue/22922/15 "2017-06-15T20:07:28Z")

</div>

Yes, the JUCE tutorial situation could use some attention.

---

<div class="post-metadata">

**Author:** ![JussiNeuralDSP](https://avatars.discourse-cdn.com/v4/letter/j/c68b51/32.png) [@JussiNeuralDSP](https://forum.juce.com/u/JussiNeuralDSP)\
**Post date:** [March 1, 2018, 2:05pm UTC](https://forum.juce.com/t/getrawparametervalue/22922/16 "2018-03-01T14:05:04Z")

</div>

My quick’n’dirty solution was to add getRawValue function to AudioProcessorParameterWithID:

virtual float getRawValue() const { jassert(0); return 0; }

jassert just to prevent usage directly…

and to AudioProcessorValueTreeState::Parameter:

float getRawValue() const override { return value; }

But seriously: No string searches in processBlock!

- Jussi

---

<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:** [March 1, 2018, 2:09pm UTC](https://forum.juce.com/t/getrawparametervalue/22922/17 "2018-03-01T14:09:06Z")

</div>

> [@JussiNeuralDSP](#):
>
> jassert(0);

…there is also `jassertfalse;`

---

<div class="post-metadata">

**Author:** ![Juce-iGi](https://avatars.discourse-cdn.com/v4/letter/j/a4c791/32.png) [@Juce-iGi](https://forum.juce.com/u/Juce-iGi)\
**Post date:** [April 17, 2018, 8:59pm UTC](https://forum.juce.com/t/getrawparametervalue/22922/18 "2018-04-17T20:59:35Z")

</div>

Hi!

I’m new to JUCE and wonder if reading raw parameter values is possible in a fast way without always calling mytree.getRawParameterValue everytime. (costs much in processBlock())

I’d like to get back to this point of jimc’ original question:

> [@](#):
>
> isn’t it better and ok to get the **pointers** somewhere that only gets called once (e.g. during construction of the Audio Processor)?

I didn’t find any answer to this part of the question. (hope, i didn’t oversee it).  
However I’ve tried exactly doing this in the constructor of my processor:

```
mytree.createAndAddParameter("filterCutoff", "Filter Cutoff", "filter Cutoff", filterCutoffRange, 400.0f, nullptr, nullptr);
valueFilterCutoff = tree.getRawParameterValue("filterCutoff");

```

(valueFilterCutoff is a float\* which is then derefenced to read the raw value later)

It seems to work perfectly, but is there something, that I have to keep in mind? Can the pointers change suddenly somehow?

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [April 17, 2018, 9:10pm UTC](https://forum.juce.com/t/getrawparametervalue/22922/19 "2018-04-17T21:10:40Z")

</div>

I don’t think the pointers will change.

---

<div class="post-metadata">

**Author:** ![Juce-iGi](https://avatars.discourse-cdn.com/v4/letter/j/a4c791/32.png) [@Juce-iGi](https://forum.juce.com/u/Juce-iGi)\
**Post date:** [April 18, 2018, 7:27am UTC](https://forum.juce.com/t/getrawparametervalue/22922/20 "2018-04-18T07:27:11Z")

</div>

Aah, actually I did oversee the point in the tutorial. Sorry.  
But I’m happy to know, that it works this way. 🙂  
Thanks!

[Next page](https://forum.juce.com/t/getrawparametervalue/22922.md?page=2)
