JUCE way of communicating data between components?

Hi again.

Quick question regarding the "JUCE" way of communicating data between components. Say I have an OptionsComponent that has a Low / High settings value I want to use in my TargetComponent which can change at any moment. Whats the best way of getting that settings value in TargetComponent?

1 Like

The JUCE way is using the Observer pattern, or "Listener" in juce parlance. For example, if you want a component to react to a Slider move, you derive it from Slider::Listener and override the sliderValueChanged() method. You get a pointer to the Slider and can ask it for its new value and react accordingly.

Have a look at this tutorial:  https://www.juce.com/doc/tutorial_listeners_and_broadcasters

So to clarify. If the value in OptionsComponent changes, the best thing is to send a custom Message with the updated value, have TargetComponent as a listener and handle the message and store the value locally?

Or just call a method.

You only need all this listener/broadcaster stuff if you have dynamic relationships with multiple listeners that come and go, or if you need asynchronous messaging. Otherwise, just use plain old functions.

1 Like

So send in a reference to the OptionsComponent to the TargetComponent to call? 

Sure, if that makes sense in your app. Keep things simple!