JUCE equivalent to NSNotificationCenter?


#1

I’m moving my Mac app to JUCE and I’m wondering if there’s an equivalent to NSNotificationCenter?

The Poco C++ libraries have one built in but I’d like to stick with JUCE and avoid other 3rd party libraries if possible.


#2

I’m not familiar with native programming, but looking at the doc for NSNotificationCenter, I guess the closest thing you may find in JUCE is the Listener mechanism, which is often implemented using a ListenerList object.

You may want to have a look at this tutorial, which explains the basics of the mechanism: https://juce.com/doc/tutorial_listeners_and_broadcasters


#3

Thanks for your reply! I’m aware of the listener/broadcaster paradigm. But for this the objects need to “know” each other. The great thing about NSNotificationCenter is that you can register with it directly saying “please notify me when notification xy happens”. And another object you don’t “know” directly (because it’s e.g. implemented in a different framework) pushes a notification to the NotificationCenter which in turn notifies all listeners.

I will see if I can come up with a NotificationCenter built on JUCE’s listener/broadcaster.

A bit of a drawback is that the function being called is always the same which leaves you with an if/else construct for each notification observing class.

With NSNotificationCenter (and also Poco) you can say: if notification A appears, please call this function, for notification B, please call this one. Makes it a bit more straight forward in my opinion.

Anyways, thanks for your answer, thought I missed something obvious.