Best practice to communicate plugin parameters with GUI objects

Hello,

I’ve started learning juce again and it is still not clear to me after making some tutorials and demos what is the best way or best practice of communicating plugin parameters with GUI objects.

For instance, If I follow the most basic tutorials and the gain plugin demo I conclude that if I have an “juce::AudioParameterFloat* gain” parameter in my AudioProcessor and a “juce::Slider gain_slider” in my editor then the way of changing the gain parameter value when the slider changes is on my editor with:
void xxAudioProcessorEditor::sliderValueChanged (juce::Slider* slider)
{
*audioProcessor.gain = static_cast<float>(gain_slider.getValue());
}.

However, is this really scalable with more parameters and GUI objects ? In other more complex demos I see they are doing it a bit different but still not exactly clear how.

Anyone that can provide some guidance ?

The official JUCE tutorials on that are very misleading and regularly cause this exact confusion. one of the core tutorials teaches you to use a Slider::Listener to update a parameter value of the processor, but you never do that in a real project, because automation will not affect the GUI state if the GUI only cares for the slider itself.

One day the JUCE team came up with a great set of classes, SliderParameterAttachment, ButtonParameterAttachment and ParameterAttachment in general. They provide a minimal interface of input arguments in the constructor and then forever connect the parameter with the GUI object perfectly without having to manually tell the slider any properties, like the range or value or something.