OpenShot Library | libopenshot-audio  0.2.0
juce_ChangeBroadcaster.cpp
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2017 - ROLI Ltd.
6 
7  JUCE is an open source library subject to commercial or open-source
8  licensing.
9 
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.
15 
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.
19 
20  ==============================================================================
21 */
22 
23 namespace juce
24 {
25 
27 {
28  broadcastCallback.owner = this;
29 }
30 
32 {
33 }
34 
36 {
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
40 
41  changeListeners.add (listener);
42 }
43 
45 {
46  // Listeners can only be safely removed when the event thread is locked
47  // You can use a MessageManagerLock if you need to call this from another thread.
48  JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
49 
50  changeListeners.remove (listener);
51 }
52 
54 {
55  // Listeners can only be safely removed when the event thread is locked
56  // You can use a MessageManagerLock if you need to call this from another thread.
57  JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
58 
59  changeListeners.clear();
60 }
61 
63 {
64  if (changeListeners.size() > 0)
65  broadcastCallback.triggerAsyncUpdate();
66 }
67 
69 {
70  // This can only be called by the event thread.
71  JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
72 
73  broadcastCallback.cancelPendingUpdate();
74  callListeners();
75 }
76 
78 {
79  broadcastCallback.handleUpdateNowIfNeeded();
80 }
81 
82 void ChangeBroadcaster::callListeners()
83 {
84  changeListeners.call ([this] (ChangeListener& l) { l.changeListenerCallback (this); });
85 }
86 
87 //==============================================================================
88 ChangeBroadcaster::ChangeBroadcasterCallback::ChangeBroadcasterCallback()
89  : owner (nullptr)
90 {
91 }
92 
93 void ChangeBroadcaster::ChangeBroadcasterCallback::handleAsyncUpdate()
94 {
95  jassert (owner != nullptr);
96  owner->callListeners();
97 }
98 
99 } // namespace juce
juce::ChangeBroadcaster::removeAllChangeListeners
void removeAllChangeListeners()
Removes all listeners from the list.
Definition: juce_ChangeBroadcaster.cpp:53
juce::ChangeListener
Receives change event callbacks that are sent out by a ChangeBroadcaster.
Definition: juce_ChangeListener.h:48
juce::ChangeBroadcaster::sendChangeMessage
void sendChangeMessage()
Causes an asynchronous change message to be sent to all the registered listeners.
Definition: juce_ChangeBroadcaster.cpp:62
juce::ChangeBroadcaster::sendSynchronousChangeMessage
void sendSynchronousChangeMessage()
Sends a synchronous change message to all the registered listeners.
Definition: juce_ChangeBroadcaster.cpp:68
juce::ChangeBroadcaster::~ChangeBroadcaster
virtual ~ChangeBroadcaster()
Destructor.
Definition: juce_ChangeBroadcaster.cpp:31
juce::ChangeBroadcaster::ChangeBroadcaster
ChangeBroadcaster() noexcept
Creates an ChangeBroadcaster.
Definition: juce_ChangeBroadcaster.cpp:26
juce::ChangeBroadcaster::removeChangeListener
void removeChangeListener(ChangeListener *listener)
Unregisters a listener from the list.
Definition: juce_ChangeBroadcaster.cpp:44
juce::ChangeBroadcaster::addChangeListener
void addChangeListener(ChangeListener *listener)
Registers a listener to receive change callbacks from this broadcaster.
Definition: juce_ChangeBroadcaster.cpp:35
juce::ChangeBroadcaster::dispatchPendingMessages
void dispatchPendingMessages()
If a change message has been sent but not yet dispatched, this will call sendSynchronousChangeMessage...
Definition: juce_ChangeBroadcaster.cpp:77
juce::ChangeListener::changeListenerCallback
virtual void changeListenerCallback(ChangeBroadcaster *source)=0
Your subclass should implement this method to receive the callback.