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...
 
template<typename StateVisitor >
void Visit (const StateVisitor &func) const
 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 &project)=0
 Modify the project when undoing or redoing to some state in history. More...
 
virtual bool CanUndoOrRedo (const AudacityProject &project)
 Whether undo or redo is now permitted; default returns true. 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 (ChannelGroup &group)
 
static const RealtimeEffectListGet (const ChannelGroup &group)
 
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 42 of file RealtimeEffectList.h.

Member Typedef Documentation

◆ Lock

Definition at line 56 of file RealtimeEffectList.h.

◆ LockGuard

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

Definition at line 167 of file RealtimeEffectList.h.

◆ States

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

Definition at line 57 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 84 of file RealtimeEffectList.cpp.

85{
86 const auto &id = pState->GetID();
87 if (pState->GetEffect() != nullptr) {
88 auto shallowCopy = mStates;
89 shallowCopy.emplace_back(pState);
90 // Lock for only a short time
91 (LockGuard{ mLock }, swap(shallowCopy, mStates));
92
95 mStates.size() - 1,
96 { },
97 pState
98 });
99
100 return true;
101 }
102 else
103 // Effect initialization failed for the id
104 return false;
105}
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:770
@ 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 165 of file RealtimeEffectList.cpp.

166{
167 decltype(mStates) temp;
168
169 // Swap an empty list in as a whole, not removing one at a time
170 // Lock for only a short time
171 (LockGuard{ mLock }, swap(temp, mStates));
172
173 for (auto index = temp.size(); index--;)
175 { RealtimeEffectListMessage::Type::Remove, index, {}, temp[index] });
176}
@ 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(), EffectStereoToMono::ProcessOne(), and ProjectFileManager::ReadProjectFile().

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 178 of file RealtimeEffectList.cpp.

180{
181 const auto begin = mStates.begin()
182 , end = mStates.end()
183 , iter = std::find(begin, end, pState);
184 if (iter == end)
185 return {};
186 return std::distance(begin, iter);
187}
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]

RealtimeEffectList & RealtimeEffectList::Get ( ChannelGroup group)
static

Definition at line 71 of file RealtimeEffectList.cpp.

72{
73 return group.GetGroupData()
74 .Attachments::Get<RealtimeEffectList>(channelGroupEffects);
75}
static const ChannelGroup::Attachments::RegisteredFactory channelGroupEffects
ChannelGroupData & GetGroupData()
Make attachment site on demand as needed.
Definition: Channel.cpp:111

References channelGroupEffects, and ChannelGroup::GetGroupData().

Here is the call graph for this function:

◆ Get() [3/4]

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

Definition at line 56 of file RealtimeEffectList.cpp.

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

References Get(), and project.

Here is the call graph for this function:

◆ Get() [4/4]

const RealtimeEffectList & RealtimeEffectList::Get ( const ChannelGroup group)
static

Definition at line 77 of file RealtimeEffectList.cpp.

79{
80 return Get(const_cast<ChannelGroup &>(group));
81}

References Get().

Here is the call graph for this function:

◆ GetLock()

Lock & RealtimeEffectList::GetLock ( ) const
inline

Definition at line 62 of file RealtimeEffectList.h.

62{ return 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 203 of file RealtimeEffectList.cpp.

204{
205 return const_cast<RealtimeEffectList*>(this)->GetStateAt(index);
206}
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 195 of file RealtimeEffectList.cpp.

196{
197 if (index < mStates.size())
198 return mStates[index];
199 return nullptr;
200}

◆ 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 189 of file RealtimeEffectList.cpp.

190{
191 return mStates.size();
192}

References mStates.

Referenced by WaveTrackMenuTable::OnMergeStereo(), and 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 261 of file RealtimeEffectList.cpp.

262{
263 if (tag == RealtimeEffectState::XMLTag()) {
265 return mStates.back().get();
266 }
267 return nullptr;
268}
wxString PluginID
Definition: EffectManager.h:30
static const std::string & XMLTag()
static std::shared_ptr< RealtimeEffectState > make_shared(Args &&...args)
Definition: MemoryX.h:523

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 248 of file RealtimeEffectList.cpp.

250{
251 if (tag == XMLTag()) {
252 for (auto &[attr, value] : attrs) {
253 if (attr == activeAttribute)
254 SetActive(value.Get<bool>());
255 }
256 return true;
257 }
258 return false;
259}
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 285 of file RealtimeEffectList.cpp.

286{
287 return mActive.load(std::memory_order_relaxed);
288}
std::atomic< bool > mActive

References mActive.

Referenced by Clone(), RealtimeEffectPanel::SetTrack(), 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 208 of file RealtimeEffectList.cpp.

209{
210 assert(fromIndex < mStates.size());
211 assert(toIndex < mStates.size());
212
213 auto shallowCopy = mStates;
214 if(fromIndex == toIndex)
215 return;
216 if(fromIndex < toIndex)
217 {
218 const auto first = shallowCopy.begin() + fromIndex;
219 const auto last = shallowCopy.begin() + toIndex + 1;
220 std::rotate(first, first + 1, last);
221 }
222 else
223 {
224 const auto first =
225 shallowCopy.rbegin() + (shallowCopy.size() - (fromIndex + 1));
226 const auto last = shallowCopy.rbegin() + (shallowCopy.size() - toIndex);
227 std::rotate(first, first + 1, last);
228 }
229 // Lock for only a short time
230 (LockGuard{ mLock }, swap(shallowCopy, mStates));
231
234 fromIndex,
235 toIndex,
236 mStates[toIndex]
237 });
238}
@ 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 142 of file RealtimeEffectList.cpp.

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

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 108 of file RealtimeEffectList.cpp.

110{
111 if (index >= mStates.size())
112 return false;
113 const auto &id = pState->GetID();
114 if (pState->GetEffect() != nullptr) {
115 auto shallowCopy = mStates;
116
119 index,
120 { },
121 shallowCopy[index]
122 });
123
124 swap(pState, shallowCopy[index]);
125 // Lock for only a short time
126 (LockGuard{ mLock }, swap(shallowCopy, mStates));
127
130 index,
131 { },
132 pState
133 });
134
135 return true;
136 }
137 else
138 // Effect initialization failed for the id
139 return false;
140}
@ 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 project)
overridevirtualnoexcept

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

Implements UndoStateExtension.

Definition at line 279 of file RealtimeEffectList.cpp.

280{
281 // Restore per-project states
282 Set(project, shared_from_this());
283}
static RealtimeEffectList & Set(AudacityProject &project, const std::shared_ptr< RealtimeEffectList > &list)

References project.

◆ 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, and project.

◆ SetActive()

void RealtimeEffectList::SetActive ( bool  value)

Done by main thread only, under a lock guard.

Definition at line 290 of file RealtimeEffectList.cpp.

291{
292 (LockGuard{ mLock }, mActive.store(value, std::memory_order_relaxed));
293}

References mActive, and mLock.

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

Here is the caller graph for this function:

◆ Visit() [1/2]

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

Apply the function to all states sequentially.

Definition at line 84 of file RealtimeEffectList.h.

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

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

Here is the caller graph for this function:

◆ Visit() [2/2]

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

Apply the function to all states sequentially.

Definition at line 92 of file RealtimeEffectList.h.

93 {
94 for (const auto &state : mStates)
95 func(*state, IsActive());
96 }

◆ WriteXML()

void RealtimeEffectList::WriteXML ( XMLWriter xmlFile) const

Use only in the main thread, to avoid races.

Definition at line 270 of file RealtimeEffectList.cpp.

271{
272 xmlFile.StartTag(XMLTag());
274 for (const auto & state : mStates)
275 state->WriteXML(xmlFile);
276 xmlFile.EndTag(XMLTag());
277}
virtual void StartTag(const wxString &name)
Definition: XMLWriter.cpp:79
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:36
virtual void EndTag(const wxString &name)
Definition: XMLWriter.cpp:102

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 240 of file RealtimeEffectList.cpp.

241{
242 static const std::string result{"effects"};
243 return result;
244}

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 170 of file RealtimeEffectList.h.

Referenced by IsActive(), and SetActive().

◆ mLock

Lock RealtimeEffectList::mLock
mutableprivate

Definition at line 168 of file RealtimeEffectList.h.

Referenced by AddState(), Clear(), MoveEffect(), RemoveState(), ReplaceState(), and SetActive().

◆ mStates

States RealtimeEffectList::mStates
private

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