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.1KB

7 years ago
9 years ago
9 years ago
9 years ago
9 years ago
7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  31. changeListeners.add (listener);
  32. }
  33. void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener)
  34. {
  35. // Listeners can only be safely removed when the event thread is locked
  36. // You can use a MessageManagerLock if you need to call this from another thread.
  37. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  38. changeListeners.remove (listener);
  39. }
  40. void ChangeBroadcaster::removeAllChangeListeners()
  41. {
  42. // Listeners can only be safely removed when the event thread is locked
  43. // You can use a MessageManagerLock if you need to call this from another thread.
  44. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  45. changeListeners.clear();
  46. }
  47. void ChangeBroadcaster::sendChangeMessage()
  48. {
  49. if (changeListeners.size() > 0)
  50. broadcastCallback.triggerAsyncUpdate();
  51. }
  52. void ChangeBroadcaster::sendSynchronousChangeMessage()
  53. {
  54. // This can only be called by the event thread.
  55. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  56. broadcastCallback.cancelPendingUpdate();
  57. callListeners();
  58. }
  59. void ChangeBroadcaster::dispatchPendingMessages()
  60. {
  61. broadcastCallback.handleUpdateNowIfNeeded();
  62. }
  63. void ChangeBroadcaster::callListeners()
  64. {
  65. changeListeners.call (&ChangeListener::changeListenerCallback, this);
  66. }
  67. //==============================================================================
  68. ChangeBroadcaster::ChangeBroadcasterCallback::ChangeBroadcasterCallback()
  69. : owner (nullptr)
  70. {
  71. }
  72. void ChangeBroadcaster::ChangeBroadcasterCallback::handleAsyncUpdate()
  73. {
  74. jassert (owner != nullptr);
  75. owner->callListeners();
  76. }
  77. } // namespace juce