VST3: fetch midi mappings all at once, use it for note/sound-off
[carla.git] / source / modules / juce_events / broadcasters / juce_ChangeBroadcaster.cpp
bloba92e88cee6a92f99a682ebcccff3b3cc4bc7bf50
1 /*
2 ==============================================================================
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
20 ==============================================================================
23 namespace juce
26 ChangeBroadcaster::ChangeBroadcaster() noexcept
28 broadcastCallback.owner = this;
31 ChangeBroadcaster::~ChangeBroadcaster()
35 void ChangeBroadcaster::addChangeListener (ChangeListener* const listener)
37 // Listeners can only be safely added when the event thread is locked
38 // You can use a MessageManagerLock if you need to call this from another thread.
39 JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
41 changeListeners.add (listener);
42 anyListeners = true;
45 void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener)
47 // Listeners can only be safely removed when the event thread is locked
48 // You can use a MessageManagerLock if you need to call this from another thread.
49 JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
51 changeListeners.remove (listener);
52 anyListeners = changeListeners.size() > 0;
55 void ChangeBroadcaster::removeAllChangeListeners()
57 // Listeners can only be safely removed when the event thread is locked
58 // You can use a MessageManagerLock if you need to call this from another thread.
59 JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
61 changeListeners.clear();
62 anyListeners = false;
65 void ChangeBroadcaster::sendChangeMessage()
67 if (anyListeners)
68 broadcastCallback.triggerAsyncUpdate();
71 void ChangeBroadcaster::sendSynchronousChangeMessage()
73 // This can only be called by the event thread.
74 JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
76 broadcastCallback.cancelPendingUpdate();
77 callListeners();
80 void ChangeBroadcaster::dispatchPendingMessages()
82 broadcastCallback.handleUpdateNowIfNeeded();
85 void ChangeBroadcaster::callListeners()
87 changeListeners.call ([this] (ChangeListener& l) { l.changeListenerCallback (this); });
90 //==============================================================================
91 ChangeBroadcaster::ChangeBroadcasterCallback::ChangeBroadcasterCallback()
92 : owner (nullptr)
96 void ChangeBroadcaster::ChangeBroadcasterCallback::handleAsyncUpdate()
98 jassert (owner != nullptr);
99 owner->callListeners();
102 } // namespace juce