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.

103 lines
3.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - 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. ChangeBroadcaster::ChangeBroadcaster() noexcept
  20. {
  21. broadcastCallback.owner = this;
  22. }
  23. ChangeBroadcaster::~ChangeBroadcaster()
  24. {
  25. }
  26. void ChangeBroadcaster::addChangeListener (ChangeListener* const listener)
  27. {
  28. // Listeners can only be safely added when the event thread is locked
  29. // You can use a MessageManagerLock if you need to call this from another thread.
  30. JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
  31. changeListeners.add (listener);
  32. anyListeners = true;
  33. }
  34. void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener)
  35. {
  36. // Listeners can only be safely removed when the event thread is locked
  37. // You can use a MessageManagerLock if you need to call this from another thread.
  38. JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
  39. changeListeners.remove (listener);
  40. anyListeners = changeListeners.size() > 0;
  41. }
  42. void ChangeBroadcaster::removeAllChangeListeners()
  43. {
  44. // Listeners can only be safely removed when the event thread is locked
  45. // You can use a MessageManagerLock if you need to call this from another thread.
  46. JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
  47. changeListeners.clear();
  48. anyListeners = false;
  49. }
  50. void ChangeBroadcaster::sendChangeMessage()
  51. {
  52. if (anyListeners)
  53. broadcastCallback.triggerAsyncUpdate();
  54. }
  55. void ChangeBroadcaster::sendSynchronousChangeMessage()
  56. {
  57. // This can only be called by the event thread.
  58. JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
  59. broadcastCallback.cancelPendingUpdate();
  60. callListeners();
  61. }
  62. void ChangeBroadcaster::dispatchPendingMessages()
  63. {
  64. broadcastCallback.handleUpdateNowIfNeeded();
  65. }
  66. void ChangeBroadcaster::callListeners()
  67. {
  68. changeListeners.call ([this] (ChangeListener& l) { l.changeListenerCallback (this); });
  69. }
  70. //==============================================================================
  71. ChangeBroadcaster::ChangeBroadcasterCallback::ChangeBroadcasterCallback()
  72. : owner (nullptr)
  73. {
  74. }
  75. void ChangeBroadcaster::ChangeBroadcasterCallback::handleAsyncUpdate()
  76. {
  77. jassert (owner != nullptr);
  78. owner->callListeners();
  79. }
  80. } // namespace juce