Audio plugin host https://kx.studio/carla
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.

juce_ChangeBroadcaster.h 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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_H_INCLUDED
  18. #define JUCE_CHANGEBROADCASTER_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. Holds a list of ChangeListeners, and sends messages to them when instructed.
  22. @see ChangeListener
  23. */
  24. class JUCE_API ChangeBroadcaster
  25. {
  26. public:
  27. //==============================================================================
  28. /** Creates an ChangeBroadcaster. */
  29. ChangeBroadcaster() noexcept;
  30. /** Destructor. */
  31. virtual ~ChangeBroadcaster();
  32. //==============================================================================
  33. /** Registers a listener to receive change callbacks from this broadcaster.
  34. Trying to add a listener that's already on the list will have no effect.
  35. */
  36. void addChangeListener (ChangeListener* listener);
  37. /** Unregisters a listener from the list.
  38. If the listener isn't on the list, this won't have any effect.
  39. */
  40. void removeChangeListener (ChangeListener* listener);
  41. /** Removes all listeners from the list. */
  42. void removeAllChangeListeners();
  43. //==============================================================================
  44. /** Causes an asynchronous change message to be sent to all the registered listeners.
  45. The message will be delivered asynchronously by the main message thread, so this
  46. method will return immediately. To call the listeners synchronously use
  47. sendSynchronousChangeMessage().
  48. */
  49. void sendChangeMessage();
  50. /** Sends a synchronous change message to all the registered listeners.
  51. This will immediately call all the listeners that are registered. For thread-safety
  52. reasons, you must only call this method on the main message thread.
  53. @see dispatchPendingMessages
  54. */
  55. void sendSynchronousChangeMessage();
  56. /** If a change message has been sent but not yet dispatched, this will call
  57. sendSynchronousChangeMessage() to make the callback immediately.
  58. For thread-safety reasons, you must only call this method on the main message thread.
  59. */
  60. void dispatchPendingMessages();
  61. private:
  62. //==============================================================================
  63. class ChangeBroadcasterCallback : public AsyncUpdater
  64. {
  65. public:
  66. ChangeBroadcasterCallback();
  67. void handleAsyncUpdate() override;
  68. ChangeBroadcaster* owner;
  69. };
  70. friend class ChangeBroadcasterCallback;
  71. ChangeBroadcasterCallback callback;
  72. ListenerList <ChangeListener> changeListeners;
  73. void callListeners();
  74. JUCE_DECLARE_NON_COPYABLE (ChangeBroadcaster)
  75. };
  76. #endif // JUCE_CHANGEBROADCASTER_H_INCLUDED