The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
3.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef __JUCE_CHANGEBROADCASTER_JUCEHEADER__
  18. #define __JUCE_CHANGEBROADCASTER_JUCEHEADER__
  19. #include "juce_ChangeListener.h"
  20. #include "juce_ListenerList.h"
  21. #include "juce_AsyncUpdater.h"
  22. //==============================================================================
  23. /**
  24. Holds a list of ChangeListeners, and sends messages to them when instructed.
  25. @see ChangeListener
  26. */
  27. class JUCE_API ChangeBroadcaster
  28. {
  29. public:
  30. //==============================================================================
  31. /** Creates an ChangeBroadcaster. */
  32. ChangeBroadcaster() noexcept;
  33. /** Destructor. */
  34. virtual ~ChangeBroadcaster();
  35. //==============================================================================
  36. /** Registers a listener to receive change callbacks from this broadcaster.
  37. Trying to add a listener that's already on the list will have no effect.
  38. */
  39. void addChangeListener (ChangeListener* listener);
  40. /** Unregisters a listener from the list.
  41. If the listener isn't on the list, this won't have any effect.
  42. */
  43. void removeChangeListener (ChangeListener* listener);
  44. /** Removes all listeners from the list. */
  45. void removeAllChangeListeners();
  46. //==============================================================================
  47. /** Causes an asynchronous change message to be sent to all the registered listeners.
  48. The message will be delivered asynchronously by the main message thread, so this
  49. method will return immediately. To call the listeners synchronously use
  50. sendSynchronousChangeMessage().
  51. */
  52. void sendChangeMessage();
  53. /** Sends a synchronous change message to all the registered listeners.
  54. This will immediately call all the listeners that are registered. For thread-safety
  55. reasons, you must only call this method on the main message thread.
  56. @see dispatchPendingMessages
  57. */
  58. void sendSynchronousChangeMessage();
  59. /** If a change message has been sent but not yet dispatched, this will call
  60. sendSynchronousChangeMessage() to make the callback immediately.
  61. For thread-safety reasons, you must only call this method on the main message thread.
  62. */
  63. void dispatchPendingMessages();
  64. private:
  65. //==============================================================================
  66. class ChangeBroadcasterCallback : public AsyncUpdater
  67. {
  68. public:
  69. ChangeBroadcasterCallback();
  70. void handleAsyncUpdate() override;
  71. ChangeBroadcaster* owner;
  72. };
  73. friend class ChangeBroadcasterCallback;
  74. ChangeBroadcasterCallback callback;
  75. ListenerList <ChangeListener> changeListeners;
  76. void callListeners();
  77. JUCE_DECLARE_NON_COPYABLE (ChangeBroadcaster)
  78. };
  79. #endif // __JUCE_CHANGEBROADCASTER_JUCEHEADER__