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.

112 lines
4.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2016 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license/
  7. Permission to use, copy, modify, and/or distribute this software for any
  8. purpose with or without fee is hereby granted, provided that the above
  9. copyright notice and this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  11. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  12. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  13. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  14. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  16. OF THIS SOFTWARE.
  17. -----------------------------------------------------------------------------
  18. To release a closed-source product which uses other parts of JUCE not
  19. licensed under the ISC terms, commercial licenses are available: visit
  20. www.juce.com for more information.
  21. ==============================================================================
  22. */
  23. #ifndef JUCE_CHANGEBROADCASTER_H_INCLUDED
  24. #define JUCE_CHANGEBROADCASTER_H_INCLUDED
  25. //==============================================================================
  26. /**
  27. Holds a list of ChangeListeners, and sends messages to them when instructed.
  28. @see ChangeListener
  29. */
  30. class JUCE_API ChangeBroadcaster
  31. {
  32. public:
  33. //==============================================================================
  34. /** Creates an ChangeBroadcaster. */
  35. ChangeBroadcaster() noexcept;
  36. /** Destructor. */
  37. virtual ~ChangeBroadcaster();
  38. //==============================================================================
  39. /** Registers a listener to receive change callbacks from this broadcaster.
  40. Trying to add a listener that's already on the list will have no effect.
  41. */
  42. void addChangeListener (ChangeListener* listener);
  43. /** Unregisters a listener from the list.
  44. If the listener isn't on the list, this won't have any effect.
  45. */
  46. void removeChangeListener (ChangeListener* listener);
  47. /** Removes all listeners from the list. */
  48. void removeAllChangeListeners();
  49. //==============================================================================
  50. /** Causes an asynchronous change message to be sent to all the registered listeners.
  51. The message will be delivered asynchronously by the main message thread, so this
  52. method will return immediately. To call the listeners synchronously use
  53. sendSynchronousChangeMessage().
  54. */
  55. void sendChangeMessage();
  56. /** Sends a synchronous change message to all the registered listeners.
  57. This will immediately call all the listeners that are registered. For thread-safety
  58. reasons, you must only call this method on the main message thread.
  59. @see dispatchPendingMessages
  60. */
  61. void sendSynchronousChangeMessage();
  62. /** If a change message has been sent but not yet dispatched, this will call
  63. sendSynchronousChangeMessage() to make the callback immediately.
  64. For thread-safety reasons, you must only call this method on the main message thread.
  65. */
  66. void dispatchPendingMessages();
  67. private:
  68. //==============================================================================
  69. class ChangeBroadcasterCallback : public AsyncUpdater
  70. {
  71. public:
  72. ChangeBroadcasterCallback();
  73. void handleAsyncUpdate() override;
  74. ChangeBroadcaster* owner;
  75. };
  76. friend class ChangeBroadcasterCallback;
  77. ChangeBroadcasterCallback broadcastCallback;
  78. ListenerList <ChangeListener> changeListeners;
  79. void callListeners();
  80. JUCE_DECLARE_NON_COPYABLE (ChangeBroadcaster)
  81. };
  82. #endif // JUCE_CHANGEBROADCASTER_H_INCLUDED