Show valueTree current value in a label


#1

Hi there,
Is there a way of get from a ValueTree the current value and convert it to string for displaying in a label?

I’ve tried this but doesn’t work:

        Value paramVal = valueTreeState.getParameterAsValue(pitchA.paramIDs[index]);
        lcdText.setText(pitchA.params[index] + "    " + std::to_string(paramVal), dontSendNotification);

Thanks


#2

RESOLVED:

I store the paramVal in a float var and call getValue() method:

        Value paramVal = valueTreeState.getParameterAsValue(pitchB.paramIDs[index]);
        float value = paramVal.getValue();
        lcdText.setText(pitchA.params[index] + "    " + std::to_string(value), dontSendNotification);

#3

A much better way of doing this would be to use the Value's toString method:

Value paramVal = valueTreeState.getParameterAsValue(pitchB.paramIDs[index]);
lcdText.setText(pitchA.params[index] + "    " + paramVal.toString(), dontSendNotification);

If you look in the header files of the corresponding classes you can see a list of methods available - toString() is nice and obvious.


#4

You can also get the label to refer to the value within the ValueTree:

class MainContentComponent   : public Component,
                               public Timer
{
public:
    MainContentComponent()
    {
        valueTree = ValueTree ("MY_VALUE_TREE");
        valueTree.setProperty ("somevalue", 0, nullptr);
        
        addAndMakeVisible (label);
        label.getTextValue().referTo (valueTree.getPropertyAsValue ("somevalue", nullptr));
        
        setSize (100,100);
        
        startTimer (1000);
    }
    
    ~MainContentComponent() { }

    void resized() override
    {
        label.setBounds(10, 10, getWidth() - 20, 24);
    }
    
    void timerCallback() override
    {
        valueTree.setProperty ("somevalue", Random::getSystemRandom().nextInt (100), nullptr);
    }

private:
    ValueTree valueTree;
    Label label;
};

This avoids the need to set the label directly, although of course you can do the string concatenation this way.


#5

Mhm, I think that I’ll do all by myself without ValueTree, because I need to store about 80 arrays of values…each array 20 values… and the display problem is resolved. I make a simple tree with bool values the let me browse the effects and their parameters and values in a one display (black label).