OpenShot Library | OpenShotAudio  0.2.2
juce_ChangeBroadcaster.h
1 
2 /** @weakgroup juce_events-broadcasters
3  * @{
4  */
5 /*
6  ==============================================================================
7 
8  This file is part of the JUCE library.
9  Copyright (c) 2017 - ROLI Ltd.
10 
11  JUCE is an open source library subject to commercial or open-source
12  licensing.
13 
14  The code included in this file is provided under the terms of the ISC license
15  http://www.isc.org/downloads/software-support-policy/isc-license. Permission
16  To use, copy, modify, and/or distribute this software for any purpose with or
17  without fee is hereby granted provided that the above copyright notice and
18  this permission notice appear in all copies.
19 
20  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22  DISCLAIMED.
23 
24  ==============================================================================
25 */
26 
27 namespace juce
28 {
29 
30 //==============================================================================
31 /**
32  Holds a list of ChangeListeners, and sends messages to them when instructed.
33 
34  @see ChangeListener
35 
36  @tags{Events}
37 */
39 {
40 public:
41  //==============================================================================
42  /** Creates an ChangeBroadcaster. */
43  ChangeBroadcaster() noexcept;
44 
45  /** Destructor. */
46  virtual ~ChangeBroadcaster();
47 
48  //==============================================================================
49  /** Registers a listener to receive change callbacks from this broadcaster.
50  Trying to add a listener that's already on the list will have no effect.
51  */
52  void addChangeListener (ChangeListener* listener);
53 
54  /** Unregisters a listener from the list.
55  If the listener isn't on the list, this won't have any effect.
56  */
57  void removeChangeListener (ChangeListener* listener);
58 
59  /** Removes all listeners from the list. */
60  void removeAllChangeListeners();
61 
62  //==============================================================================
63  /** Causes an asynchronous change message to be sent to all the registered listeners.
64 
65  The message will be delivered asynchronously by the main message thread, so this
66  method will return immediately. To call the listeners synchronously use
67  sendSynchronousChangeMessage().
68  */
69  void sendChangeMessage();
70 
71  /** Sends a synchronous change message to all the registered listeners.
72 
73  This will immediately call all the listeners that are registered. For thread-safety
74  reasons, you must only call this method on the main message thread.
75 
76  @see dispatchPendingMessages
77  */
78  void sendSynchronousChangeMessage();
79 
80  /** If a change message has been sent but not yet dispatched, this will call
81  sendSynchronousChangeMessage() to make the callback immediately.
82 
83  For thread-safety reasons, you must only call this method on the main message thread.
84  */
85  void dispatchPendingMessages();
86 
87 private:
88  //==============================================================================
89  class ChangeBroadcasterCallback : public AsyncUpdater
90  {
91  public:
92  ChangeBroadcasterCallback();
93  void handleAsyncUpdate() override;
94 
95  ChangeBroadcaster* owner;
96  };
97 
98  friend class ChangeBroadcasterCallback;
99  ChangeBroadcasterCallback broadcastCallback;
100  ListenerList <ChangeListener> changeListeners;
101 
102  std::atomic<bool> anyListeners { false };
103 
104  void callListeners();
105 
106  JUCE_DECLARE_NON_COPYABLE (ChangeBroadcaster)
107 };
108 
109 } // namespace juce
110 
111 /** @}*/
#define JUCE_API
This macro is added to all JUCE public class declarations.
Has a callback method that is triggered asynchronously.
Holds a set of objects and can invoke a member function callback on each object in the set with a sin...
Holds a list of ChangeListeners, and sends messages to them when instructed.
Receives change event callbacks that are sent out by a ChangeBroadcaster.