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?
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:
strings don’t make much sense in dsp code
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.
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;
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”));
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.