# Value tree state parameters (float vs bool problem)

**URL:** <https://forum.juce.com/t/value-tree-state-parameters-float-vs-bool-problem/37553>\
**Category:** General JUCE discussion\
**Created:** [February 10, 2020, 9:09pm UTC](https://forum.juce.com/t/value-tree-state-parameters-float-vs-bool-problem/37553 "2020-02-10T21:09:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mrugalla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mrugalla/32/13092_2.png) [@Mrugalla](https://forum.juce.com/u/Mrugalla)\
**Post date:** [February 10, 2020, 9:09pm UTC](https://forum.juce.com/t/value-tree-state-parameters-float-vs-bool-problem/37553/1 "2020-02-10T21:09:08Z")

</div>

solved: the line “std::atomic\* phaseParameter = nullptr;” needed to be float. i had it as bool. that’s weird btw. i thought we store a bool value? whatever^^

i get an error on the line:

polarityParam = parameters.getRawParameterValue(“polarity”);

in my AudioProcessor constructor. it says it can’t convert from float to bool. as you can see this is supposed to be a polarity switch and the information comes from a togglebutton, so my question is: why does it think it’s a float? how can i change that?

btw, i followed this tutorial but i can’t see what’s different in its code:  
[https://docs.juce.com/master/tutorial\_audio\_processor\_value\_tree\_state.html](https://docs.juce.com/master/tutorial_audio_processor_value_tree_state.html)

---

<div class="post-metadata">

**Author:** ![asimilon](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/asimilon/32/4235_2.png) [@asimilon](https://forum.juce.com/u/asimilon)\
**Post date:** [February 10, 2020, 9:57pm UTC](https://forum.juce.com/t/value-tree-state-parameters-float-vs-bool-problem/37553/2 "2020-02-10T21:57:17Z")

</div>

`getRawParameterValue` is always returning a `std::atomic<float>*`, and the thing it points to is always going from 0.0f to 1.0f, regardless of how the parameter is set up. So for an `AudioParameterBool` it will be off = 0.0f and on = 1.0f

What you could do additionally in your `processBlock` is something like:

```auto
    bool polarity = *polarityParam > 0.5f;

```

then you have an actual `bool` to test.  
Another thing you can do with other ranged parameters (eg. you have set up an `AudioParameterInt` which is supposed to go from 3 to 9):

```auto
// in the constructor
    threeToNineValue = parameters.getRawParameterValue("threeToNine");
    threeToNineParam = parameters.getParameter("threeToNine");

// in the processBlock
    int threeToNine = threeToNineParam->convertFrom0to1(*threeToNineValue);

// in the .h
    std::atomic<float>* threeToNineValue;
    RangedAudioParameter* threeToNineParameter;

```

Personally what I prefer to do is along the lines of the “Adding Parameters Programatically” in that tutorial.

```auto
AudioProcessorValueTreeState::ParameterLayout createParameterLayout()
{
    std::vector<std::unique_ptr<AudioParameterInt>> params;
 
    auto p = std::make_unique<AudioParameterInt>("some_param", "Some param", 3, 9, 6);
    someParam = p.get();
    params.push_back(std::move(p));
 
    // add more parameters...

    return { params.begin(), params.end() };
}
// in the .h
    AudioParameterInt* someParam;

```

then when it comes to using the parameter value in `processBlock`

```auto
    auto someParamValue = someParam->get();

```

the value of `someParamValue` will be automatically converted to the 3 to 9 range, same for `AudioParameterBool` will automatically give you a `bool` and any `AudioParameterFloat` you have will get its correct range, not just 0.0f to 0.1f that you need to remap.
