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.

93 lines
2.8KB

  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. class ActionBroadcaster::ActionMessage : public MessageManager::MessageBase
  20. {
  21. public:
  22. ActionMessage (const ActionBroadcaster* ab,
  23. const String& messageText, ActionListener* l) noexcept
  24. : broadcaster (const_cast<ActionBroadcaster*> (ab)),
  25. message (messageText),
  26. listener (l)
  27. {}
  28. void messageCallback() override
  29. {
  30. if (auto b = broadcaster.get())
  31. if (b->actionListeners.contains (listener))
  32. listener->actionListenerCallback (message);
  33. }
  34. private:
  35. WeakReference<ActionBroadcaster> broadcaster;
  36. const String message;
  37. ActionListener* const listener;
  38. JUCE_DECLARE_NON_COPYABLE (ActionMessage)
  39. };
  40. //==============================================================================
  41. ActionBroadcaster::ActionBroadcaster()
  42. {
  43. // are you trying to create this object before or after juce has been initialised??
  44. JUCE_ASSERT_MESSAGE_MANAGER_EXISTS
  45. }
  46. ActionBroadcaster::~ActionBroadcaster()
  47. {
  48. // all event-based objects must be deleted BEFORE juce is shut down!
  49. JUCE_ASSERT_MESSAGE_MANAGER_EXISTS
  50. }
  51. void ActionBroadcaster::addActionListener (ActionListener* const listener)
  52. {
  53. const ScopedLock sl (actionListenerLock);
  54. if (listener != nullptr)
  55. actionListeners.add (listener);
  56. }
  57. void ActionBroadcaster::removeActionListener (ActionListener* const listener)
  58. {
  59. const ScopedLock sl (actionListenerLock);
  60. actionListeners.removeValue (listener);
  61. }
  62. void ActionBroadcaster::removeAllActionListeners()
  63. {
  64. const ScopedLock sl (actionListenerLock);
  65. actionListeners.clear();
  66. }
  67. void ActionBroadcaster::sendActionMessage (const String& message) const
  68. {
  69. const ScopedLock sl (actionListenerLock);
  70. for (int i = actionListeners.size(); --i >= 0;)
  71. (new ActionMessage (this, message, actionListeners.getUnchecked(i)))->post();
  72. }
  73. } // namespace juce