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.cpp 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. ChangeBroadcaster::ChangeBroadcaster() noexcept
  18. {
  19. callback.owner = this;
  20. }
  21. ChangeBroadcaster::~ChangeBroadcaster()
  22. {
  23. }
  24. void ChangeBroadcaster::addChangeListener (ChangeListener* const listener)
  25. {
  26. // Listeners can only be safely added when the event thread is locked
  27. // You can use a MessageManagerLock if you need to call this from another thread.
  28. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  29. changeListeners.add (listener);
  30. }
  31. void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener)
  32. {
  33. // Listeners can only be safely added when the event thread is locked
  34. // You can use a MessageManagerLock if you need to call this from another thread.
  35. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  36. changeListeners.remove (listener);
  37. }
  38. void ChangeBroadcaster::removeAllChangeListeners()
  39. {
  40. // Listeners can only be safely added when the event thread is locked
  41. // You can use a MessageManagerLock if you need to call this from another thread.
  42. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  43. changeListeners.clear();
  44. }
  45. void ChangeBroadcaster::sendChangeMessage()
  46. {
  47. if (changeListeners.size() > 0)
  48. callback.triggerAsyncUpdate();
  49. }
  50. void ChangeBroadcaster::sendSynchronousChangeMessage()
  51. {
  52. // This can only be called by the event thread.
  53. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  54. callback.cancelPendingUpdate();
  55. callListeners();
  56. }
  57. void ChangeBroadcaster::dispatchPendingMessages()
  58. {
  59. callback.handleUpdateNowIfNeeded();
  60. }
  61. void ChangeBroadcaster::callListeners()
  62. {
  63. changeListeners.call (&ChangeListener::changeListenerCallback, this);
  64. }
  65. //==============================================================================
  66. ChangeBroadcaster::ChangeBroadcasterCallback::ChangeBroadcasterCallback()
  67. : owner (nullptr)
  68. {
  69. }
  70. void ChangeBroadcaster::ChangeBroadcasterCallback::handleAsyncUpdate()
  71. {
  72. jassert (owner != nullptr);
  73. owner->callListeners();
  74. }