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
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
95
98 bool AddState(std::shared_ptr<RealtimeEffectState> pState);
99
103
106 bool ReplaceState(size_t index, std::shared_ptr<RealtimeEffectState> pState);
107
110 void RemoveState(std::shared_ptr<RealtimeEffectState> pState);
111
113 void Clear();
114
116 std::optional<size_t> FindState(
117 const std::shared_ptr<RealtimeEffectState> &pState) const;
118
121 size_t GetStatesCount() const noexcept;
124 std::shared_ptr<RealtimeEffectState> GetStateAt(size_t index) noexcept;
127 std::shared_ptr<const RealtimeEffectState> GetStateAt(size_t index) const
128 noexcept;
129
138 void MoveEffect(size_t fromIndex, size_t toIndex);
139
140 static const std::string &XMLTag();
141 bool HandleXMLTag(
142 const std::string_view &tag, const AttributesList &attrs) override;
143
145 XMLTagHandler *HandleXMLChild(const std::string_view &tag) override;
146
148 void WriteXML(XMLWriter &xmlFile) const;
149
150 void RestoreUndoRedoState(AudacityProject &project) noexcept override;
151
153 bool IsActive() const;
154
156 void SetActive(bool value);
157
158private:
160
161 using LockGuard = std::lock_guard<Lock>;
162 mutable Lock mLock;
163
164 std::atomic<bool> mActive{ true };
165};
166
167#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:89
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
static RealtimeEffectList & Get(AudacityProject &project)
std::optional< size_t > FindState(const std::shared_ptr< RealtimeEffectState > &pState) const
Report the position of a state in the list.
Lock & GetLock() const
std::lock_guard< Lock > LockGuard
bool AddState(std::shared_ptr< RealtimeEffectState > pState)
void RestoreUndoRedoState(AudacityProject &project) noexcept override
Modify the project when undoing or redoing to some state in history.
std::vector< std::shared_ptr< RealtimeEffectState > > States
std::unique_ptr< ClientData::Cloneable<> > Clone() const override
size_t GetStatesCount() const noexcept
bool IsActive() const
Non-blocking atomic boolean load.
void RemoveState(std::shared_ptr< RealtimeEffectState > pState)
void Clear()
Use only in the main thread. Sends Remove messages.
std::atomic< bool > mActive
bool HandleXMLTag(const std::string_view &tag, const AttributesList &attrs) override
void SetActive(bool value)
Done by main thread only, under a lock guard.
RealtimeEffectList & operator=(const RealtimeEffectList &)=delete
static RealtimeEffectList & Set(AudacityProject &project, const std::shared_ptr< RealtimeEffectList > &list)
static const std::string & XMLTag()
XMLTagHandler * HandleXMLChild(const std::string_view &tag) override
Use only in the main thread. May add a state while deserializing.
void WriteXML(XMLWriter &xmlFile) const
Use only in the main thread, to avoid races.
void MoveEffect(size_t fromIndex, size_t toIndex)
Use only in the main thread. Changes effect order in the stack. Does nothing if fromIndex equals toIn...
bool ReplaceState(size_t index, std::shared_ptr< RealtimeEffectState > pState)
std::shared_ptr< RealtimeEffectState > GetStateAt(size_t index) noexcept
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:225
Base class for extra information attached to undo/redo states.
Definition: UndoManager.h:91
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:26
Intended for locking of resources that are only lightly contended and locked for very short times,...
Definition: spinlock.h:22
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
std::shared_ptr< RealtimeEffectState > affectedState