Show valueTree current value in a label

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



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

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.

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

class MainContentComponent   : public Component,
                               public Timer
        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);

    ValueTree valueTree;
    Label label;

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


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