AudioProcessorValueTree value to text issue


#1

Hi,

Trying out AudioProcessorValueTree for the first time using the tutorial and I am having an issue with the value to text function. For some reason when my interface first loads, sliders that are attached to parameters are showing the value of the parameter until they are changed and then it displays the text. This only happens when the value is the lowest value of the parameter (irrespective of what the lowest value is).

e.g. Plugin loads with parameter at lowest value (0.0) but shows the value, slider moves to 1.0 and shows the text. The slider is then moved back to 0.0 and shows the text correctly. When the plugin is loaded with the parameter at a higher value than the minimum the text displays correctly from the start.

static String AudioProcessor::valueToText (float value)
{
if (value < 1.0)
{
return “text”;
} else if (value == 1.0)
{
return “text 2”;
} else if (value == 2.0)
{
return “text 3”;
} else if (value == 3.0)
{
return “text 4”;
} else
{
return “text 5”;
}
}

Is there something irritatingly simple I have missed?

Thanks for any help.


#2

Could you provide a few more details?

What OS are you using?
What plug-in format?
Which host?
Does this happen using the tip of the develop branch? (We’ve made some APVTS changes recently).


#3

I’m using OSX Mojave. Tested in both standalone and Au within studio one 3 + 4. I have been using release but will try develop later.


#4

I can’t reproduce your problem. Could you provide a working example, perhaps as a PIP?

The code you posted looks a little suspicious in isolation - you mention that you’re using a slider, which implies a continuous range of values, but you have equality checks on floating point numbers…


#5

Will make a simplified example of what I am doing. I have tried with and without the equality checks. It seems odd to me as I have the else return function if none of the values match but yet it still displays a value. It seems as if the function is not being called.


#6

I have a hunch, maybe the textToValue and valueToText methods are contradicting?
I.e. the default value is converted into a text, that when converted back, is a different value?
Also I would avoid == for float values. Especially since you are actually comparing to double values.
It is better to write:

static String AudioProcessor::valueToText (float value)
{
    if (value < 0.5f)
        return “text”;
    else if (value < 1.5f)
        return “text 2”;
    else if (value < 2.5f)
        return “text 3”;
    else if (value < 3.5f)
        return “text 4”;
    else
        return “text 5”;
}

EDIT: actually I shouldn’t have followed the example like that, it’s better to check for a value in the middle of the interval…


#7

Sorry, tried looking at making a PIP but I couldn’t work out how to do it. Here is a very basic plugin using the standard JUCE template with one parameter that displays the problem I am having. I have replaced the == with Daniel’s suggestion in this example. I’d be really grateful for any further help on this.

PluginProcessor.cpp (7.5 KB)
PluginProcessor.h (2.2 KB)
PluginEditor.cpp (1.5 KB)
PluginEditor.h (1.2 KB)

EDIT: Have seen Daniel’s edit and will look at doing that instead but this shouldn’t make too much difference to the example files.


#8

Got it. Thanks for your perseverance!

It’s fixed on the develop branch but can’t be easily hotfixed onto the master branch as there have been significant APVTS changes.


#9

Great, thanks for your help!