Label state callback from processor via dynamic cast

Hello. I couldn’t find any info on how to save a Label state to a ValueTreeState.
This is a quick fix on how to call editor functions from processor. In this case, I’m setting a label text from previous state.

I have a Label that you can set the BPM of the delay, and obviously one would like to save this state for a project. The custom label only accepts numbers and a maximum of three.

Now, you can simply make an extra audioparameter on your tree constructor:

auto bpmLabel_param = std::make_unique(DELAYBPMVALUE_ID, DELAYBPMVALUE_NAME, 0, 999, 120);

Now you have a ready parameter to set and callback.

Go to setStateInformation() of your processor.cpp, create a pointer of your expected main editor type:

MyPluginProcessorEditor editorPtr;
editorPtr = dynamic_cast<MyPluginProcessorEditor>(this->getActiveEditor());

And check if not nullptr and simply call your setter function:

if (edPtr) edPtr->parameterChanged(“DELAYBPMVALUE_ID”,*tree.getRawParameterValue(DELAYBPMVALUE_ID));

Now the Label in your editor is set to your previous state/preset/whatever. You can also call any editor function from editor with this way.

Setter function to change this parameter:

auto BPMparam = tree.getParameter(DELAYBPMVALUE_ID);
auto BPMP2 = tree.getParameterAsValue(DELAYBPMVALUE_ID);

I don’t think this is safe if setStateInformation is not guaranteed to be called on the message thread. The editor could be deleted between setting and using editorPtr.

Probably safer to have the editor pull information from a queue or variables in your processor.