Value tree state parameters (float vs bool problem)

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:

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:

    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):

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

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();
    // 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 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.

1 Like