Updating a Label text from internal values

Hello,

I’m trying to update an int value for within my code upto a displayed label but struggle a bit. This is what I have done:

  • Added a Label on the UI, with id “SEED”
  • added a trigger on a button in my UI that in turns will update the value
  • inside the trigger function I’m trying to update the “text” property of the “SEED” identified object, but that doesn’t seem to do anything.
    Here is some view on what I’m doing (I’ve tried to follow the previous topic here Basic question on changing properties at run-time)
    image
    magicState.addTrigger("NEWSEED",
    [this]()
    {
        int seed = rand();
        for (auto i = 0; i < NBSEQUENCERS; i++)
            sequencers[i].newseed(rand());
        auto label = magicState.getValueTree().getOrCreateChildWithName("SEED", nullptr);
        label.setProperty ("text",   seed,  nullptr);
        DBG("Clicked " + std::to_string(seed));
    });

Any help appreciated ^^

Oh, that is actually much easier:

The magicState has (just like the AudioProcessorValueTreeState) a public ValueTree, where you can add information that is not an AudioProcessorParameter (e.g. because it is not supposed to be exposed to host automation).

PGM has an interface to that ValueTree getPropertyAsValue().

So you can access that value from the code with

magicState.getPropertyAsValue ("node:property") = "Hello, World";

And the label has a property “Value”, where you should see the a dropdown menu to select the property, whose value is then displayed and automatically updated in the Label.

Oh OK, working fine like so. I see that the label field can be set as editable, is there a way to update the poperty fro there downto the plugin then ? Not for automation but as a stored data?

Absolutely, it works both ways.
If it is editable, the user can edit it and you can get notification in the processor via Value::Listener.

And if you assign a different value in the code, the Label should automatically reflect that.

Just one caveat: when setStateInformation sets the ValueTree, the Value referTo might break. So it is best to make that connection in the virtual postSetStateInformation();

// have this as mmber in the processor, so you can listen to it
juce::Value myValue;

void postSetStateInformation() override
{
    myValue.referTo (magicState.getPropertyAsValue ("node:property"));
}

You might also be able to listen directly to the magicState.getPropertyAsValue(), not sure. If it is just an ephemeral ValueTree, this might not work as expected. I try to have the enclosing object as member somewhere, because that’s where the ListenerList is kept.