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;
23
25
26class Track;
27
29{
30 enum class Type
31 {
32 Insert,
33 WillReplace,
34 DidReplace,
35 Remove,
36 Move
37 };
39 size_t srcIndex;
40 size_t dstIndex;
41 std::shared_ptr<RealtimeEffectState> affectedState;
42};
43
44class REALTIME_EFFECTS_API RealtimeEffectList final
45 // Inheritance from std::enable_shared_from_this must be public
46 // but the per-track lists are managed by unique not shared pointers
47 : public std::enable_shared_from_this<RealtimeEffectList>
48 , public ClientData::Base
49 , public ClientData::Cloneable<>
50 , public UndoStateExtension
51 , public XMLTagHandler
52 , public Observer::Publisher<RealtimeEffectListMessage>
53{
56
57public:
58 using Lock = spinlock;
59 using States = std::vector<std::shared_ptr<RealtimeEffectState>>;
60
62 virtual ~RealtimeEffectList();
63
64 Lock &GetLock() const { return mLock; }
65
68 std::unique_ptr<ClientData::Cloneable<>> Clone() const override;
69
70 static RealtimeEffectList &Get(AudacityProject &project);
71 static const RealtimeEffectList &Get(const AudacityProject &project);
72 static RealtimeEffectList &Set(
73 AudacityProject &project,
74 const std::shared_ptr<RealtimeEffectList> &list);
75
76 static RealtimeEffectList &Get(Track &track);
77 static const RealtimeEffectList &Get(const Track &track);
78
79 // Type that state visitor functions would have for out-of-line definition
80 // of Visit
81 // using StateVisitor =
82 // std::function<void(RealtimeEffectState &state, bool listIsActive)> ;
83
85 template<typename StateVisitor>
86 void Visit(const StateVisitor &func)
87 {
88 for (auto &state : mStates)
89 func(*state, IsActive());
90 }
91
93 template<typename StateVisitor>
94 void Visit(const StateVisitor &func) const
95 {
96 for (const auto &state : mStates)
97 func(*state, IsActive());
98 }
99
103
106 bool AddState(std::shared_ptr<RealtimeEffectState> pState);
107
111
114 bool ReplaceState(size_t index, std::shared_ptr<RealtimeEffectState> pState);
115
118 void RemoveState(std::shared_ptr<RealtimeEffectState> pState);
119
121 void Clear();
122
124 std::optional<size_t> FindState(
125 const std::shared_ptr<RealtimeEffectState> &pState) const;
126
129 size_t GetStatesCount() const noexcept;
132 std::shared_ptr<RealtimeEffectState> GetStateAt(size_t index) noexcept;
135 std::shared_ptr<const RealtimeEffectState> GetStateAt(size_t index) const
136 noexcept;
137
146 void MoveEffect(size_t fromIndex, size_t toIndex);
147
148 static const std::string &XMLTag();
149 bool HandleXMLTag(
150 const std::string_view &tag, const AttributesList &attrs) override;
151
153 XMLTagHandler *HandleXMLChild(const std::string_view &tag) override;
154
156 void WriteXML(XMLWriter &xmlFile) const;
157
158 void RestoreUndoRedoState(AudacityProject &project) noexcept override;
159
161 bool IsActive() const;
162
164 void SetActive(bool value);
165
166private:
167 States mStates;
168
169 using LockGuard = std::lock_guard<Lock>;
170 mutable Lock mLock;
171
172 std::atomic<bool> mActive{ true };
173};
174
175#endif // __AUDACITY_REALTIMEEFFECTLIST_H__
Generalized interface for discovery of plug-ins for one protocol.
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
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:226
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:196
STL namespace.
A convenient default parameter for class template Site.
Definition: ClientData.h:28
A convenient base class defining abstract virtual Clone() for a given kind of pointer.
Definition: ClientData.h:48
virtual PointerType Clone() const =0
std::shared_ptr< RealtimeEffectState > affectedState