Working with Label components

Hi Foley’s people,

I want to do some basic tasks with Labels in PGM, as demonstrated here without PGM, JUCE: Tutorial: The Label class .

These are basic things like reading user inputted text in a label, editing text in a label at runtime, etc. Doing this without PGM is easy.

However, in Foleys PGM, I’ve only ever accessed values of Sliders, ComboBoxes, and ToggleButtons, for which I can use AudioParameterFloat, AudioParameterChoice and AudioParameterBool to get and set their values. And I’ve looked over the examples, but didn’t find anything that showed how to work with editable Labels in PGM. I don’t think it should require GuiItem, since the Label component is already built into PGM.

So… what am I missing? Are there any examples of doing basic things with Labels in PGM, like reading user inputted text from an Editable label?

Thanks!

Hi and sorry for the late reply,

The parameters from juce are only available for numeric values. THey represent values exposed to the host, and the hosts don’t support text. The two reasons I can see is:

  1. strings don’t make much sense in dsp code
  2. strings pose a risk, as they can allocate, if you don’t use preallocated char*

However for data that is not used from the audio thread, there are the properties, which is a ValueTree, an XML like structure, where you can place variants into.
From code you access them via:

auto value = magicState.getPropertyAsValue ("someNode:someProperty");

In the label you set this path “someNode:someProperty” in the “value” field.

Further info can be found for juce::Value

Thanks! That helped a lot. So now I can

  1. Change a label’s properties by giving the Label a class and making that class’s Active Property (here the property is *Labels:Editable) true or false, with the line in the code like;

magicState.getPropertyAsValue(“Labels:Editable”).setValue(true);

and

  1. Get a label’s text value by giving the Label some value, like Labels:Value, with the line in the code like;

DBG(magicState.getPropertyAsValue(“Labels:Value”).toString());

But I also need to;

  1. Set a label’s text value. Without PGM, I would just do this with

myLabel.setText(“Test”, juce::dontSendNotification); };

So I’m looking to do something like;

magicState.getPropertyAsValue(“Labels:Value”).setValue(“Test”);

but among other things, that would require a way to convert a string to a JUCE value.

And

  1. Listen to when the text has been changed. Without PGM, I would just add a callback,

inputText.onTextChange = [this] { [DO SOMETHING] };

But I don’t see a way to do this for labels in Foleys PGM.
For TextButtons, they have an onClick property, for which one can have a trigger callback. But Foleys PGM doesn’t expose an onTextChange for Labels.

So, how can one do (3) and (4) with Foleys PGM? I expect this is fairly simple, but I’m not seeing it.

That should actually work. If you look at Value.setValue() it takes a juce::var (aka variant), which can be implicitly created from a String and many more types.

That’s the beauty of juce::Value. You can add a ValueListener to the Value.
Unfortunately the juce::Value doesn’t take a lambda. But it is trivial to create a little adapter:

struct ValueAction : private juce::Value::Listener
{
    juce::Value value;
    std::function<void()> onValueChanged;

    ValueAction() { value.addListener (this); }
    void valueChanged(const juce::Value&) override
    {
        if (onValueChanged)
            onValueChanged();
    }
};

// as a member:
ValueAction textChanged;

// set it up:
textChanged.onValueChanged = [this]{ doSomething(); }
textChanged.value.referTo (magicState.getPropertyAsValue(“Labels:Value”));

Untested, but you get the gist…

Let me know if you got more trouble with it

Thanks,
Yeah. (3) works now, not sure what was my issue before.

My value listener isn’t quite working. I can reimplement the value listener that you had for the gain slider in “PlayerExample” just fine. But when I try it in my plugin (not app) with a slightly different way to set up the Magic GUI Value Tree, its not hearing changes in the gain slider on the interface. That is,

gainValue.setValue (1.0);

will trigger the callback, but the user moving the slider won’t trigger it.

No matter, its probably some silly bug that I’m just not seeing yet.
I’ll try your suggestion above.