Audacity 3.2.0
RealtimeEffectList.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 RealtimeEffectList.h
6
7 *********************************************************************/
8
9#ifndef __AUDACITY_REALTIMEEFFECTLIST_H__
10#define __AUDACITY_REALTIMEEFFECTLIST_H__
11
12#include <atomic>
13#include <optional>
14#include <vector>
15
16#include "PluginProvider.h" // for PluginID
17#include "spinlock.h"
18#include "UndoManager.h"
19#include "XMLTagHandler.h"
20#include "Observer.h"
21
22class AudacityProject;
23class ChannelGroup;
25
27{
28 enum class Type
29 {
30 Insert,
31 WillReplace,
32 DidReplace,
33 Remove,
34 Move
35 };
37 size_t srcIndex;
38 size_t dstIndex;
39 std::shared_ptr<RealtimeEffectState> affectedState;
40};
41
42class REALTIME_EFFECTS_API RealtimeEffectList final
43 // Inheritance from std::enable_shared_from_this must be public
44 // but the per-group lists are managed by unique not shared pointers
45 : public std::enable_shared_from_this<RealtimeEffectList>
46 , public ClientData::Base
47 , public ClientData::Cloneable<>
48 , public UndoStateExtension
49 , public XMLTagHandler
50 , public Observer::Publisher<RealtimeEffectListMessage>
51{
54
55public:
56 using Lock = spinlock;
57 using States = std::vector<std::shared_ptr<RealtimeEffectState>>;
58
60 virtual ~RealtimeEffectList();
61
62 Lock &GetLock() const { return mLock; }
63
67
69 static const RealtimeEffectList &Get(const AudacityProject &project);
70 static RealtimeEffectList &Set(
72 const std::shared_ptr<RealtimeEffectList> &list);
73
74 static RealtimeEffectList &Get(ChannelGroup &group);
75 static const RealtimeEffectList &Get(const ChannelGroup &group);
76
77 // Type that state visitor functions would have for out-of-line definition
78 // of Visit
79 // using StateVisitor =
80 // std::function<void(RealtimeEffectState &state, bool listIsActive)> ;
81
83 template<typename StateVisitor>
84 void Visit(const StateVisitor &func)
85 {
86 for (auto &state : mStates)
87 func(*state, IsActive());
88 }
89
91 template<typename StateVisitor>
92 void Visit(const StateVisitor &func) const
93 {
94 for (const auto &state : mStates)
95 func(*state, IsActive());
96 }
97
101
104 bool AddState(std::shared_ptr<RealtimeEffectState> pState);
105
109
112 bool ReplaceState(size_t index, std::shared_ptr<RealtimeEffectState> pState);
113
116 void RemoveState(std::shared_ptr<RealtimeEffectState> pState);
117
119 void Clear();
120
122 std::optional<size_t> FindState(
123 const std::shared_ptr<RealtimeEffectState> &pState) const;
124
127 size_t GetStatesCount() const noexcept;
130 std::shared_ptr<RealtimeEffectState> GetStateAt(size_t index) noexcept;
133 std::shared_ptr<const RealtimeEffectState> GetStateAt(size_t index) const
134 noexcept;
135
144 void MoveEffect(size_t fromIndex, size_t toIndex);
145
146 static const std::string &XMLTag();
147 bool HandleXMLTag(
148 const std::string_view &tag, const AttributesList &attrs) override;
149
151 XMLTagHandler *HandleXMLChild(const std::string_view &tag) override;
152
154 void WriteXML(XMLWriter &xmlFile) const;
155
156 void RestoreUndoRedoState(AudacityProject &project) noexcept override;
157
159 bool IsActive() const;
160
162 void SetActive(bool value);
163
164private:
165 States mStates;
166
167 using LockGuard = std::lock_guard<Lock>;
168 mutable Lock mLock;
169
170 std::atomic<bool> mActive{ true };
171};
172
173#endif // __AUDACITY_REALTIMEEFFECTLIST_H__
Generalized interface for discovery of plug-ins for one protocol.
const auto project
std::vector< Attribute > AttributesList
Definition: XMLTagHandler.h:40
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
An object that sends messages to an open-ended list of subscribed callbacks.
Definition: Observer.h:108
void Visit(const StateVisitor &func)
Apply the function to all states sequentially.
RealtimeEffectList(const RealtimeEffectList &)=delete
Lock & GetLock() const
std::lock_guard< Lock > LockGuard
std::vector< std::shared_ptr< RealtimeEffectState > > States
void Visit(const StateVisitor &func) const
Apply the function to all states sequentially.
RealtimeEffectList & operator=(const RealtimeEffectList &)=delete
Base class for extra information attached to undo/redo states.
Definition: UndoManager.h:83
This class is an interface which should be implemented by classes which wish to be able to load and s...
Definition: XMLTagHandler.h:42
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:25
Intended for locking of resources that are only lightly contended and locked for very short times,...
Definition: spinlock.h:22
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:201
template struct REGISTRIES_API Cloneable<>
STL namespace.
A convenient default parameter for class template Site.
Definition: ClientData.h:29
A convenient base class defining abstract virtual Clone() for a given kind of pointer.
Definition: ClientData.h:50
virtual PointerType Clone() const =0
std::shared_ptr< RealtimeEffectState > affectedState