The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

109 lines
3.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. BEGIN_JUCE_NAMESPACE
  19. //==============================================================================
  20. ChangeBroadcaster::ChangeBroadcaster() noexcept
  21. {
  22. // are you trying to create this object before or after juce has been intialised??
  23. jassert (MessageManager::instance != nullptr);
  24. callback.owner = this;
  25. }
  26. ChangeBroadcaster::~ChangeBroadcaster()
  27. {
  28. // all event-based objects must be deleted BEFORE juce is shut down!
  29. jassert (MessageManager::instance != nullptr);
  30. }
  31. void ChangeBroadcaster::addChangeListener (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.add (listener);
  37. }
  38. void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener)
  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.remove (listener);
  44. }
  45. void ChangeBroadcaster::removeAllChangeListeners()
  46. {
  47. // Listeners can only be safely added when the event thread is locked
  48. // You can use a MessageManagerLock if you need to call this from another thread.
  49. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  50. changeListeners.clear();
  51. }
  52. void ChangeBroadcaster::sendChangeMessage()
  53. {
  54. if (changeListeners.size() > 0)
  55. callback.triggerAsyncUpdate();
  56. }
  57. void ChangeBroadcaster::sendSynchronousChangeMessage()
  58. {
  59. // This can only be called by the event thread.
  60. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  61. callback.cancelPendingUpdate();
  62. callListeners();
  63. }
  64. void ChangeBroadcaster::dispatchPendingMessages()
  65. {
  66. callback.handleUpdateNowIfNeeded();
  67. }
  68. void ChangeBroadcaster::callListeners()
  69. {
  70. changeListeners.call (&ChangeListener::changeListenerCallback, this);
  71. }
  72. //==============================================================================
  73. ChangeBroadcaster::ChangeBroadcasterCallback::ChangeBroadcasterCallback()
  74. : owner (nullptr)
  75. {
  76. }
  77. void ChangeBroadcaster::ChangeBroadcasterCallback::handleAsyncUpdate()
  78. {
  79. jassert (owner != nullptr);
  80. owner->callListeners();
  81. }
  82. END_JUCE_NAMESPACE