Parameters only controlled by slider

Hey I’m sure this is a common beginners issue, i am setting parameters onto some audioProcessor values that the slider has access to and updates those values. However while adding parameters using the sliderattatchement way, the parameters only update while the GUI is open, I believe the slider is the only thing controlling the parameters so the GUI therefore has to be open.
I know i need to instead make the parameters change the value in the processor first then the slider update according to that new value, however I’m not sure how to make the parameters update the value instead of updating the slider which actually has a function of slider attachment to it.

Thanks any help is appreciated!

You can call getParameter on your AudioProcessorValueTreeState to retrieve the parameter you want to update. Then call setValueNotifyingHost on that parameter to update it.

here is how i implement my params

// PluginProcessor.h

public:
    juce::AudioProcessorValueTreeState::ParameterLayout exampleParameterLayout();
    juce::AudioProcessorValueTreeState apvts{ *this, nullptr, "Parameters", exampleParameterLayout() };

for the layout itself

// PluginProcessor.cpp

juce::AudioProcessorValueTreeState::ParameterLayout *your processor classname* exampleParameterLayout()
{
    juce::AudioProcessorValueTreeState::ParameterLayout layout;

    juce::StringArray stringArray;
    stringArray.add("choice a");
    stringArray.add("choice b");
    stringArray.add("choice c");

    // for float values
    layout.add
    (std::make_unique<juce::AudioParameterFloat>("ID_Float", "Float", juce::NormalisableRange<float>(-60.f, 60.f, 0.01f), 0.f));

    // for choice values
    layout.add
    (std::make_unique<juce::AudioParameterChoice>("ID_Choice", "Choices", stringArray, 0));

    return layout;
}

now, how do you update the GUI according to the parameter changes?

// PluginEditor.h

private:
    juce::Slider sliderX;
    std::unique_ptr<juce::AudioProcessorValueTreeState::SliderAttachment> attachmentX;

in your editor

// PluginEditor.cpp -- Constructor

addAndMakeVisible(sliderX);
attachmentX.reset(new juce::AudioProcessorValueTreeState::SliderAttachment{ audioProcessor.apvts, "ID_Float", sliderX });

// PluginEditor.cpp -- Destructor
attachmentX.reset(nullptr);

then obviously you

sliderX.setBounds(x, y, width, height);

in your resized() function.

for updating the parameters, go to your processor.cpp processBlock

// AudioProcessor.cpp

void *classname*::processBlock
    // place this under the code that clears your buffer
   auto myFloat = apvts.getRawParameterValue("ID_Float")->load();

    // do your processing here