Setting value of parameter in APVTS?

Hi, I want to create an LFO that I will be able to map to the parameters of my plugin. However I notice there is no method that looks like “setParameterValue(String& id)”. Are there best practices for what I am trying to do?
note that the user decides what will be modulated by the lfo, I intend to have a “map” button that will listen for changes in the apvts when clicked, and then assign the right parameter to the LFO.
So would I have to access the ValueTree underneath the apvts and call setProperty? That’s my best guess. Or should I call getParameterAsValue, then use the function referTo() in order to bind them together like this:

class LFO
{
public:
    LFO(juce::AudioProcessorValueTreeState& state)
    {
        valueToControl = juce::Value();
        valueToControl.referTo(state.getParameterAsValue(/*parameter id*/ "ap_00"));
    }

    void process(/*rate, offset etc.*/)
    {
        auto currentSample = /*imagine some dsp is happening here*/

        valueToControl.setValue(currentSample);
    }

private:
    juce::Value& valueToControl;
};

Thanks in advance.

I think you shouldn’t modulate the value tree directly. If you change parameter values you should inform the host about it and that ends up with the parameter moving around in the GUI all the time. Rather you should store your parameter values somewhere and then modulate them before forwarding them to the dsp part. I hope that makes sense?

But my qestion is though how exactly am I supposed to set the parameter value. There isn’t exactly a “AudioProcessorValueTreeState::setParameter(String id)” function.

Hi dariop,

You shouldn’t ever need to, or better said, that is not how APVTS is intended to be used.

“…I intend to have a “map” button that will listen for changes in the apvts when clicked, and then assign the right parameter to the LFO.”

The parameter changes will be constantly listened for. The ‘map’ button won’t listen for changes to more than one parameter (assuming it is attached to one). What you are trying to do may be better done somehow else. It sounds like you mean you want to show the GUI components attached to parameters only when the “map” button is activated.

instead of letting an lfo modulate a param rather add the lfo’s output to a param all in processBlock. get the parameter value before processing the lfo

1 Like

That was my initial idea but I don’t actually know what the parameter would be. I have about 20~ parameters that could be modulated (not at once).
I’d want it to function like the Max for Live tool “LFO”:
press map:


Then I press the parameter I want to modulate (in this case its the frequency of the eq point 4):

the lfo is then binded to that parameter and modulates it.
The only way I can think of doing it right not is to somehow get the component that the mouse clicks on. e.g. the frequency slider. Then modulate it through the UI. However since the Editor gets destroyed when the UI closes I don’t think this is possible.

Does some “Automation” functionality exist within juce to automate parameters or is that just the host?

Another example of what I want to do is shown in the synth phaseplant:
It's actually the best synth plugin (Phase Plant) - YouTube

ok first of all, phase plant is huge when it comes to modularity. they did a bunch of incredible things that are really hard to copy. modularity is always very complicated. but your modulator-linking-thing is still on the easier side of things. think of it. the lfo is being synthesized in the audioProcessor already. it would only be a step back to send it into the parameter, instead of instantly using its output, you know? it would be a much better idea to just link its output to the output of some parameter in processBlock and add them together there. what is linking? many possible solutions, but i’d probably make a struct where all of my parameters are processed. that struct has a vector with pointers and it’s empty at init. when you add the pointer to the lfo’s output to that vector you could feed its output into that parameter easy peasy, and since it’s a vector you could link infinitely many modulators

1 Like