OpenShot Audio Library | OpenShotAudio: juce_ChangeBroadcaster.cpp Source File

OpenShot Audio Library | OpenShotAudio 1.0.0

Loading...
Searching...
No Matches
juce_ChangeBroadcaster.cpp
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
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
23namespace juce
24{
25
26ChangeBroadcaster::ChangeBroadcaster() noexcept
27{
28 broadcastCallback.owner = this;
29}
30
31ChangeBroadcaster::~ChangeBroadcaster()
32{
33}
34
35 void ChangeBroadcaster::addChangeListener (ChangeListener* const listener)
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 anyListeners = true;
43}
44
45 void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener)
46{
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
50
51 changeListeners.remove (listener);
52 anyListeners = changeListeners.size() > 0;
53}
54
55 void ChangeBroadcaster::removeAllChangeListeners()
56{
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
60
61 changeListeners.clear();
62 anyListeners = false;
63}
64
65 void ChangeBroadcaster::sendChangeMessage()
66{
67 if (anyListeners)
68 broadcastCallback.triggerAsyncUpdate();
69}
70
71 void ChangeBroadcaster::sendSynchronousChangeMessage()
72{
73 // This can only be called by the event thread.
74 JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
75
76 broadcastCallback.cancelPendingUpdate();
77 callListeners();
78}
79
80 void ChangeBroadcaster::dispatchPendingMessages()
81{
82 broadcastCallback.handleUpdateNowIfNeeded();
83}
84
85void ChangeBroadcaster::callListeners()
86{
87 changeListeners.call ([this] (ChangeListener& l) { l.changeListenerCallback (this); });
88}
89
90//==============================================================================
91ChangeBroadcaster::ChangeBroadcasterCallback::ChangeBroadcasterCallback()
92 : owner (nullptr)
93{
94}
95
96void ChangeBroadcaster::ChangeBroadcasterCallback::handleAsyncUpdate()
97{
98 jassert (owner != nullptr);
99 owner->callListeners();
100}
101
102} // namespace juce
juce::AsyncUpdater::handleAsyncUpdate
virtual void handleAsyncUpdate()=0
juce::ChangeBroadcaster::sendChangeMessage
void sendChangeMessage()
Definition juce_ChangeBroadcaster.cpp:65
juce::ChangeBroadcaster::~ChangeBroadcaster
virtual ~ChangeBroadcaster()
Definition juce_ChangeBroadcaster.cpp:31
juce::ChangeBroadcaster::ChangeBroadcaster
ChangeBroadcaster() noexcept
Definition juce_ChangeBroadcaster.cpp:26
juce::ChangeBroadcaster::addChangeListener
void addChangeListener(ChangeListener *listener)
Definition juce_ChangeBroadcaster.cpp:35
juce::ChangeBroadcaster::removeChangeListener
void removeChangeListener(ChangeListener *listener)
Definition juce_ChangeBroadcaster.cpp:45
juce::ChangeBroadcaster::removeAllChangeListeners
void removeAllChangeListeners()
Definition juce_ChangeBroadcaster.cpp:55
juce::ChangeBroadcaster::sendSynchronousChangeMessage
void sendSynchronousChangeMessage()
Definition juce_ChangeBroadcaster.cpp:71
juce::ChangeBroadcaster::dispatchPendingMessages
void dispatchPendingMessages()
Definition juce_ChangeBroadcaster.cpp:80
juce::ChangeListener
Definition juce_ChangeListener.h:45
juce::ChangeListener::changeListenerCallback
virtual void changeListenerCallback(ChangeBroadcaster *source)=0