Audacity 3.2.0
Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
RealtimeEffectList Class Referencefinal

#include <RealtimeEffectList.h>

Inheritance diagram for RealtimeEffectList:
[legend]
Collaboration diagram for RealtimeEffectList:
[legend]

Public Types

using Lock = spinlock
 
using States = std::vector< std::shared_ptr< RealtimeEffectState > >
 
- Public Types inherited from ClientData::Cloneable< Owner >
using Base = Cloneable
 
using PointerType = Owner< Base >
 
- Public Types inherited from Observer::Publisher< RealtimeEffectListMessage >
using message_type = RealtimeEffectListMessage
 
using CallbackReturn = std::conditional_t< true, void, bool >
 
using Callback = std::function< CallbackReturn(const RealtimeEffectListMessage &) >
 Type of functions that can be connected to the Publisher. More...
 

Public Member Functions

 RealtimeEffectList ()
 
virtual ~RealtimeEffectList ()
 
LockGetLock () const
 
std::unique_ptr< ClientData::Cloneable<> > Clone () const override
 
template<typename StateVisitor >
void Visit (const StateVisitor &func)
 Apply the function to all states sequentially. More...
 
bool AddState (std::shared_ptr< RealtimeEffectState > pState)
 
bool ReplaceState (size_t index, std::shared_ptr< RealtimeEffectState > pState)
 
void RemoveState (std::shared_ptr< RealtimeEffectState > pState)
 
void Clear ()
 Use only in the main thread. Sends Remove messages. More...
 
std::optional< size_t > FindState (const std::shared_ptr< RealtimeEffectState > &pState) const
 Report the position of a state in the list. More...
 
size_t GetStatesCount () const noexcept
 
std::shared_ptr< RealtimeEffectStateGetStateAt (size_t index) noexcept
 
std::shared_ptr< const RealtimeEffectStateGetStateAt (size_t index) const noexcept
 
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 toIndex. Otherwise effects between fromIndex (exclusive) and toIndex are shifted towards fromIndex. Sends Move event. More...
 
bool HandleXMLTag (const std::string_view &tag, const AttributesList &attrs) override
 
XMLTagHandlerHandleXMLChild (const std::string_view &tag) override
 Use only in the main thread. May add a state while deserializing. More...
 
void WriteXML (XMLWriter &xmlFile) const
 Use only in the main thread, to avoid races. More...
 
void RestoreUndoRedoState (AudacityProject &project) noexcept override
 Modify the project when undoing or redoing to some state in history. More...
 
bool IsActive () const
 Non-blocking atomic boolean load. More...
 
void SetActive (bool value)
 Done by main thread only, under a lock guard. More...
 
- Public Member Functions inherited from ClientData::Base
virtual ~Base ()
 
- Public Member Functions inherited from ClientData::Cloneable< Owner >
virtual ~Cloneable ()
 
virtual PointerType Clone () const =0
 
- Public Member Functions inherited from UndoStateExtension
virtual ~UndoStateExtension ()
 
virtual void RestoreUndoRedoState (AudacityProject &)=0
 Modify the project when undoing or redoing to some state in history. More...
 
- Public Member Functions inherited from XMLTagHandler
 XMLTagHandler ()
 
virtual ~XMLTagHandler ()
 
virtual bool HandleXMLTag (const std::string_view &tag, const AttributesList &attrs)=0
 
virtual void HandleXMLEndTag (const std::string_view &WXUNUSED(tag))
 
virtual void HandleXMLContent (const std::string_view &WXUNUSED(content))
 
virtual XMLTagHandlerHandleXMLChild (const std::string_view &tag)=0
 
void ReadXMLEndTag (const char *tag)
 
void ReadXMLContent (const char *s, int len)
 
XMLTagHandlerReadXMLChild (const char *tag)
 
- Public Member Functions inherited from Observer::Publisher< RealtimeEffectListMessage >
 Publisher (ExceptionPolicy *pPolicy=nullptr, Alloc a={})
 Constructor supporting type-erased custom allocation/deletion. More...
 
 Publisher (Publisher &&)=default
 
Publisheroperator= (Publisher &&)=default
 
Subscription Subscribe (Callback callback)
 Connect a callback to the Publisher; later-connected are called earlier. More...
 
Subscription Subscribe (Object &obj, Return(Object::*callback)(Args...))
 Overload of Subscribe takes an object and pointer-to-member-function. More...
 

Static Public Member Functions

static RealtimeEffectListGet (AudacityProject &project)
 
static const RealtimeEffectListGet (const AudacityProject &project)
 
static RealtimeEffectListSet (AudacityProject &project, const std::shared_ptr< RealtimeEffectList > &list)
 
static RealtimeEffectListGet (Track &track)
 
static const RealtimeEffectListGet (const Track &track)
 
static const std::string & XMLTag ()
 

Private Types

using LockGuard = std::lock_guard< Lock >
 

Private Member Functions

 RealtimeEffectList (const RealtimeEffectList &)=delete
 
RealtimeEffectListoperator= (const RealtimeEffectList &)=delete
 

Private Attributes

States mStates
 
Lock mLock
 
std::atomic< bool > mActive { true }
 

Additional Inherited Members

- Static Public Attributes inherited from Observer::Publisher< RealtimeEffectListMessage >
static constexpr bool notifies_all
 
- Protected Member Functions inherited from Observer::Publisher< RealtimeEffectListMessage >
CallbackReturn Publish (const RealtimeEffectListMessage &message)
 Send a message to connected callbacks. More...
 

Detailed Description

Definition at line 44 of file RealtimeEffectList.h.

Member Typedef Documentation

◆ Lock

Definition at line 58 of file RealtimeEffectList.h.

◆ LockGuard

using RealtimeEffectList::LockGuard = std::lock_guard<Lock>
private

Definition at line 161 of file RealtimeEffectList.h.

◆ States

using RealtimeEffectList::States = std::vector<std::shared_ptr<RealtimeEffectState> >

Definition at line 59 of file RealtimeEffectList.h.

Constructor & Destructor Documentation

◆ RealtimeEffectList() [1/2]

RealtimeEffectList::RealtimeEffectList ( const RealtimeEffectList )
privatedelete

◆ RealtimeEffectList() [2/2]

RealtimeEffectList::RealtimeEffectList ( )

Definition at line 15 of file RealtimeEffectList.cpp.

16{
17}

◆ ~RealtimeEffectList()

RealtimeEffectList::~RealtimeEffectList ( )
virtual

Definition at line 19 of file RealtimeEffectList.cpp.

20{
21}

Member Function Documentation

◆ AddState()

bool RealtimeEffectList::AddState ( std::shared_ptr< RealtimeEffectState pState)

Use only in the main thread Returns true for success. Sends Insert message on success.

Postcondition
result: !result || pState->GetEffect() != nullptr

Definition at line 81 of file RealtimeEffectList.cpp.

82{
83 const auto &id = pState->GetID();
84 if (pState->GetEffect() != nullptr) {
85 auto shallowCopy = mStates;
86 shallowCopy.emplace_back(pState);
87 // Lock for only a short time
88 (LockGuard{ mLock }, swap(shallowCopy, mStates));
89
92 mStates.size() - 1,
93 { },
94 pState
95 });
96
97 return true;
98 }
99 else
100 // Effect initialization failed for the id
101 return false;
102}
CallbackReturn Publish(const RealtimeEffectListMessage &message)
Send a message to connected callbacks.
Definition: Observer.h:207
std::lock_guard< Lock > LockGuard
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:753
@ Insert
New effect item was added to the list at srcIndex position. affectedState is a new state.

References RealtimeEffectListMessage::Insert, mLock, mStates, Observer::Publisher< RealtimeEffectListMessage >::Publish(), and anonymous_namespace{NoteTrack.cpp}::swap().

Here is the call graph for this function:

◆ Clear()

void RealtimeEffectList::Clear ( )

Use only in the main thread. Sends Remove messages.

Definition at line 162 of file RealtimeEffectList.cpp.

163{
164 decltype(mStates) temp;
165
166 // Swap an empty list in as a whole, not removing one at a time
167 // Lock for only a short time
168 (LockGuard{ mLock }, swap(temp, mStates));
169
170 for (auto index = temp.size(); index--;)
172 { RealtimeEffectListMessage::Type::Remove, index, {}, temp[index] });
173}
@ Remove
Effect item was removed from the list at srcIndex position. affectedState is removed state.

References mLock, mStates, Observer::Publisher< RealtimeEffectListMessage >::Publish(), RealtimeEffectListMessage::Remove, and anonymous_namespace{NoteTrack.cpp}::swap().

Referenced by MixAndRender(), and EffectStereoToMono::ProcessOne().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Clone()

std::unique_ptr< ClientData::Cloneable<> > RealtimeEffectList::Clone ( ) const
overridevirtual

Should be called (for pushing undo states) only from main thread, to avoid races

Implements ClientData::Cloneable< Owner >.

Definition at line 24 of file RealtimeEffectList.cpp.

25{
26 auto result = std::make_unique<RealtimeEffectList>();
27 for (auto &pState : mStates)
28 result->mStates.push_back(pState);
29 result->SetActive(this->IsActive());
30 return result;
31}
bool IsActive() const
Non-blocking atomic boolean load.

References IsActive(), and mStates.

Here is the call graph for this function:

◆ FindState()

std::optional< size_t > RealtimeEffectList::FindState ( const std::shared_ptr< RealtimeEffectState > &  pState) const

Report the position of a state in the list.

Definition at line 175 of file RealtimeEffectList.cpp.

177{
178 const auto begin = mStates.begin()
179 , end = mStates.end()
180 , iter = std::find(begin, end, pState);
181 if (iter == end)
182 return {};
183 return std::distance(begin, iter);
184}
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:150

References PackedArray::begin(), PackedArray::end(), and mStates.

Here is the call graph for this function:

◆ Get() [1/4]

RealtimeEffectList & RealtimeEffectList::Get ( AudacityProject project)
static

◆ Get() [2/4]

const RealtimeEffectList & RealtimeEffectList::Get ( const AudacityProject project)
static

Definition at line 55 of file RealtimeEffectList.cpp.

56{
57 return Get(const_cast<AudacityProject &>(project));
58}
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
static RealtimeEffectList & Get(AudacityProject &project)

References Get().

Here is the call graph for this function:

◆ Get() [3/4]

const RealtimeEffectList & RealtimeEffectList::Get ( const Track track)
static

Definition at line 75 of file RealtimeEffectList.cpp.

76{
77 return Get(const_cast<Track &>(track));
78}
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:225

References Get().

Referenced by Get().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Get() [4/4]

RealtimeEffectList & RealtimeEffectList::Get ( Track track)
static

Definition at line 69 of file RealtimeEffectList.cpp.

70{
71 return track.GetGroupData()
72 .Track::ChannelGroupAttachments::Get<RealtimeEffectList>(trackEffects);
73}
static const Track::ChannelGroupAttachments::RegisteredFactory trackEffects
ChannelGroupData & GetGroupData()
Definition: Track.cpp:179

References Track::GetGroupData(), and trackEffects.

Here is the call graph for this function:

◆ GetLock()

Lock & RealtimeEffectList::GetLock ( ) const
inline

Definition at line 64 of file RealtimeEffectList.h.

64{ return mLock; }

References mLock.

Referenced by RealtimeEffectManager::AllListsLock::AllListsLock(), and RealtimeEffectManager::AllListsLock::Reset().

Here is the caller graph for this function:

◆ GetStateAt() [1/2]

std::shared_ptr< const RealtimeEffectState > RealtimeEffectList::GetStateAt ( size_t  index) const
noexcept

Returns effect state at given position Use only in the main thread, to avoid races

Definition at line 200 of file RealtimeEffectList.cpp.

201{
202 return const_cast<RealtimeEffectList*>(this)->GetStateAt(index);
203}
std::shared_ptr< RealtimeEffectState > GetStateAt(size_t index) noexcept

◆ GetStateAt() [2/2]

std::shared_ptr< RealtimeEffectState > RealtimeEffectList::GetStateAt ( size_t  index)
noexcept

Returns effect state at given position Use only in the main thread, to avoid races

Definition at line 192 of file RealtimeEffectList.cpp.

193{
194 if (index < mStates.size())
195 return mStates[index];
196 return nullptr;
197}

◆ GetStatesCount()

size_t RealtimeEffectList::GetStatesCount ( ) const
noexcept

Use only in the main thread, to avoid races Returns total number of effects in this list

Definition at line 186 of file RealtimeEffectList.cpp.

187{
188 return mStates.size();
189}

References mStates.

Referenced by RealtimeEffectListWindow::ReloadEffectsList().

Here is the caller graph for this function:

◆ HandleXMLChild()

XMLTagHandler * RealtimeEffectList::HandleXMLChild ( const std::string_view &  tag)
overridevirtual

Use only in the main thread. May add a state while deserializing.

Implements XMLTagHandler.

Definition at line 257 of file RealtimeEffectList.cpp.

258{
259 if (tag == RealtimeEffectState::XMLTag()) {
261 return mStates.back().get();
262 }
263 return nullptr;
264}
wxString PluginID
Definition: EffectManager.h:30
static const std::string & XMLTag()
static std::shared_ptr< RealtimeEffectState > make_shared(Args &&...args)
Definition: MemoryX.h:505

References SharedNonInterfering< RealtimeEffectState >::make_shared(), mStates, and RealtimeEffectState::XMLTag().

Here is the call graph for this function:

◆ HandleXMLTag()

bool RealtimeEffectList::HandleXMLTag ( const std::string_view &  tag,
const AttributesList attrs 
)
overridevirtual

Implements XMLTagHandler.

Definition at line 244 of file RealtimeEffectList.cpp.

246{
247 if (tag == XMLTag()) {
248 for (auto &[attr, value] : attrs) {
249 if (attr == activeAttribute)
250 SetActive(value.Get<bool>());
251 }
252 return true;
253 }
254 return false;
255}
static constexpr auto activeAttribute
void SetActive(bool value)
Done by main thread only, under a lock guard.
static const std::string & XMLTag()

References activeAttribute, SetActive(), and XMLTag().

Here is the call graph for this function:

◆ IsActive()

bool RealtimeEffectList::IsActive ( ) const

Non-blocking atomic boolean load.

Definition at line 281 of file RealtimeEffectList.cpp.

282{
283 return mActive.load(std::memory_order_relaxed);
284}
std::atomic< bool > mActive

References mActive.

Referenced by Clone(), RealtimeEffectPanel::SetTrack(), Visit(), and WriteXML().

Here is the caller graph for this function:

◆ MoveEffect()

void RealtimeEffectList::MoveEffect ( size_t  fromIndex,
size_t  toIndex 
)

Use only in the main thread. Changes effect order in the stack. Does nothing if fromIndex equals toIndex. Otherwise effects between fromIndex (exclusive) and toIndex are shifted towards fromIndex. Sends Move event.

Parameters
fromIndexIndex of the moved effect
toIndexFinal position of the moved effect

Definition at line 205 of file RealtimeEffectList.cpp.

206{
207 assert(fromIndex < mStates.size());
208 assert(toIndex < mStates.size());
209
210 auto shallowCopy = mStates;
211 if(fromIndex == toIndex)
212 return;
213 if(fromIndex < toIndex)
214 {
215 const auto first = shallowCopy.begin() + fromIndex;
216 const auto last = shallowCopy.begin() + toIndex + 1;
217 std::rotate(first, first + 1, last);
218 }
219 else
220 {
221 const auto first = shallowCopy.rbegin() + (shallowCopy.size() - (fromIndex + 1));
222 const auto last = shallowCopy.rbegin() + (shallowCopy.size() - toIndex);
223 std::rotate(first, first + 1, last);
224 }
225 // Lock for only a short time
226 (LockGuard{ mLock }, swap(shallowCopy, mStates));
227
230 fromIndex,
231 toIndex,
232 mStates[toIndex]
233 });
234}
@ Move
Item position has changed, from srcIndex to dstIndex. affectedState is the moved state.

References mLock, RealtimeEffectListMessage::Move, mStates, Observer::Publisher< RealtimeEffectListMessage >::Publish(), and anonymous_namespace{NoteTrack.cpp}::swap().

Here is the call graph for this function:

◆ operator=()

RealtimeEffectList & RealtimeEffectList::operator= ( const RealtimeEffectList )
privatedelete

◆ RemoveState()

void RealtimeEffectList::RemoveState ( std::shared_ptr< RealtimeEffectState pState)

Use only in the main thread On success sends Remove message.

Definition at line 139 of file RealtimeEffectList.cpp.

141{
142 auto shallowCopy = mStates;
143 auto end = shallowCopy.end(),
144 found = std::find(shallowCopy.begin(), end, pState);
145 if (found != end)
146 {
147 const auto index = std::distance(shallowCopy.begin(), found);
148 shallowCopy.erase(found);
149
150 // Lock for only a short time
151 (LockGuard{ mLock }, swap(shallowCopy, mStates));
152
155 static_cast<size_t>(index),
156 { },
157 pState
158 });
159 }
160}

References PackedArray::end(), mLock, mStates, Observer::Publisher< RealtimeEffectListMessage >::Publish(), RealtimeEffectListMessage::Remove, and anonymous_namespace{NoteTrack.cpp}::swap().

Here is the call graph for this function:

◆ ReplaceState()

bool RealtimeEffectList::ReplaceState ( size_t  index,
std::shared_ptr< RealtimeEffectState pState 
)

Use only in the main thread Returns true for success. Sends Insert message on success.

Postcondition
result: !result || pState->GetEffect() != nullptr

Definition at line 105 of file RealtimeEffectList.cpp.

107{
108 if (index >= mStates.size())
109 return false;
110 const auto &id = pState->GetID();
111 if (pState->GetEffect() != nullptr) {
112 auto shallowCopy = mStates;
113
116 index,
117 { },
118 shallowCopy[index]
119 });
120
121 swap(pState, shallowCopy[index]);
122 // Lock for only a short time
123 (LockGuard{ mLock }, swap(shallowCopy, mStates));
124
127 index,
128 { },
129 pState
130 });
131
132 return true;
133 }
134 else
135 // Effect initialization failed for the id
136 return false;
137}
@ DidReplace
Effect item was replaced with a new item at srcIndex position. affectedState is an old state.
@ WillReplace
Effect item will be replaced with a new item at srcIndex position. affectedState is the state to be r...

References RealtimeEffectListMessage::DidReplace, mLock, mStates, Observer::Publisher< RealtimeEffectListMessage >::Publish(), anonymous_namespace{NoteTrack.cpp}::swap(), and RealtimeEffectListMessage::WillReplace.

Here is the call graph for this function:

◆ RestoreUndoRedoState()

void RealtimeEffectList::RestoreUndoRedoState ( AudacityProject )
overridevirtualnoexcept

Modify the project when undoing or redoing to some state in history.

Implements UndoStateExtension.

Definition at line 275 of file RealtimeEffectList.cpp.

276{
277 // Restore per-project states
278 Set(project, shared_from_this());
279}
static RealtimeEffectList & Set(AudacityProject &project, const std::shared_ptr< RealtimeEffectList > &list)

◆ Set()

RealtimeEffectList & RealtimeEffectList::Set ( AudacityProject project,
const std::shared_ptr< RealtimeEffectList > &  list 
)
static

Definition at line 47 of file RealtimeEffectList.cpp.

49{
50 auto &result = *list;
51 project.AttachedObjects::Assign(masterEffects, list);
52 return result;
53}

References masterEffects.

◆ SetActive()

void RealtimeEffectList::SetActive ( bool  value)

Done by main thread only, under a lock guard.

Definition at line 286 of file RealtimeEffectList.cpp.

287{
288 (LockGuard{ mLock }, mActive.store(value, std::memory_order_relaxed));
289}

References mActive, and mLock.

Referenced by RealtimeEffectListWindow::EnableEffects(), and HandleXMLTag().

Here is the caller graph for this function:

◆ Visit()

template<typename StateVisitor >
void RealtimeEffectList::Visit ( const StateVisitor &  func)
inline

Apply the function to all states sequentially.

Definition at line 86 of file RealtimeEffectList.h.

87 {
88 for (auto &state : mStates)
89 func(*state, IsActive());
90 }

References IsActive(), and mStates.

Referenced by RealtimeEffectManager::VisitAll(), and RealtimeEffectManager::VisitGroup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteXML()

void RealtimeEffectList::WriteXML ( XMLWriter xmlFile) const

Use only in the main thread, to avoid races.

Definition at line 266 of file RealtimeEffectList.cpp.

267{
268 xmlFile.StartTag(XMLTag());
270 for (const auto & state : mStates)
271 state->WriteXML(xmlFile);
272 xmlFile.EndTag(XMLTag());
273}
virtual void StartTag(const wxString &name)
Definition: XMLWriter.cpp:80
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:37
virtual void EndTag(const wxString &name)
Definition: XMLWriter.cpp:103

References activeAttribute, XMLWriter::EndTag(), IsActive(), mStates, XMLWriter::StartTag(), XMLWriter::WriteAttr(), and XMLTag().

Here is the call graph for this function:

◆ XMLTag()

const std::string & RealtimeEffectList::XMLTag ( )
static

Definition at line 236 of file RealtimeEffectList.cpp.

237{
238 static const std::string result{"effects"};
239 return result;
240}

Referenced by HandleXMLTag(), and WriteXML().

Here is the caller graph for this function:

Member Data Documentation

◆ mActive

std::atomic<bool> RealtimeEffectList::mActive { true }
private

Definition at line 164 of file RealtimeEffectList.h.

Referenced by IsActive(), and SetActive().

◆ mLock

Lock RealtimeEffectList::mLock
mutableprivate

◆ mStates

States RealtimeEffectList::mStates
private

The documentation for this class was generated from the following files: