FR : GenericBroadcaster<T> and/or VarBroadcaster


I’ve been baffled for a long time why JUCE only has the ChangeBroadcaster and ActionBroadcaster classes for implementing classes that need to broadcast things to listeners. This leaves a hole for easily broadcasting things like ints, doubles and maybe pairs or tuples etc of such things. I know that possible solutions are using Value or std::function<void(T)> but both have their own issues. (For example Value makes it necessary for the broadcasting class to deal with Values instead of simple data types. std::function only supports one “listener” and doesn’t provide async/cross thread capabilities directly.)

Wouldn’t it make sense to have something like GenericBroadcaster<T> and/or VarBroadcaster together with the necessary Listener base classes?


Remember that ChangeBroadcaster and ActionBroadcaster have a very specific difference in that ChangeBroadcaster will coalesce calls to sendChangeMessage into a single callback.
ActionBroadcaster will deliver a message for every “action message” sent.

I can’t say I’ve ever used ActionBroadcaster personally, it feels a bit like a legacy thing to me. These days it seems a lot easier to simply use MessageManager::callAsync or post a message directly (with a WeakRef for safety) as that’s essentially what ActionBroadcaster does under the hood.


I am not mainly interested about the async capabilities (which would of course be a nice plus), but of how to send simple data values into listeners without involving Values or ValueTrees or writing custom broadcaster/listener classes.

I am now attempting to implement the generic broadcaster/listener thing myself and it sure is hairy… :sweat_smile: