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.

106 lines
3.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. namespace juce
  18. {
  19. //==============================================================================
  20. /**
  21. Holds a list of ChangeListeners, and sends messages to them when instructed.
  22. @see ChangeListener
  23. @tags{Events}
  24. */
  25. class JUCE_API ChangeBroadcaster
  26. {
  27. public:
  28. //==============================================================================
  29. /** Creates an ChangeBroadcaster. */
  30. ChangeBroadcaster() noexcept;
  31. /** Destructor. */
  32. virtual ~ChangeBroadcaster();
  33. //==============================================================================
  34. /** Registers a listener to receive change callbacks from this broadcaster.
  35. Trying to add a listener that's already on the list will have no effect.
  36. */
  37. void addChangeListener (ChangeListener* listener);
  38. /** Unregisters a listener from the list.
  39. If the listener isn't on the list, this won't have any effect.
  40. */
  41. void removeChangeListener (ChangeListener* listener);
  42. /** Removes all listeners from the list. */
  43. void removeAllChangeListeners();
  44. //==============================================================================
  45. /** Causes an asynchronous change message to be sent to all the registered listeners.
  46. The message will be delivered asynchronously by the main message thread, so this
  47. method will return immediately. To call the listeners synchronously use
  48. sendSynchronousChangeMessage().
  49. */
  50. void sendChangeMessage();
  51. /** Sends a synchronous change message to all the registered listeners.
  52. This will immediately call all the listeners that are registered. For thread-safety
  53. reasons, you must only call this method on the main message thread.
  54. @see dispatchPendingMessages
  55. */
  56. void sendSynchronousChangeMessage();
  57. /** If a change message has been sent but not yet dispatched, this will call
  58. sendSynchronousChangeMessage() to make the callback immediately.
  59. For thread-safety reasons, you must only call this method on the main message thread.
  60. */
  61. void dispatchPendingMessages();
  62. private:
  63. //==============================================================================
  64. class ChangeBroadcasterCallback : public AsyncUpdater
  65. {
  66. public:
  67. ChangeBroadcasterCallback();
  68. void handleAsyncUpdate() override;
  69. ChangeBroadcaster* owner;
  70. };
  71. friend class ChangeBroadcasterCallback;
  72. ChangeBroadcasterCallback broadcastCallback;
  73. ListenerList <ChangeListener> changeListeners;
  74. std::atomic<bool> anyListeners { false };
  75. void callListeners();
  76. JUCE_DECLARE_NON_COPYABLE (ChangeBroadcaster)
  77. };
  78. } // namespace juce