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< Covariant, Owner >
using Base = std::conditional_t< std::is_void_v< Covariant >, Cloneable, Covariant >
 
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< Covariant, Owner >
 Cloneable ()=default
 
 Cloneable (const Cloneable &)=default
 
Cloneableoperator= (const Cloneable &)=default
 
virtual ~Cloneable ()=default
 
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 83 of file RealtimeEffectList.cpp.

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

165{
166 decltype(mStates) temp;
167
168 // Swap an empty list in as a whole, not removing one at a time
169 // Lock for only a short time
170 (LockGuard{ mLock }, swap(temp, mStates));
171
172 for (auto index = temp.size(); index--;)
174 { RealtimeEffectListMessage::Type::Remove, index, {}, temp[index] });
175}
@ 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 ProjectFileManager::FixTracks(), 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< Covariant, 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 177 of file RealtimeEffectList.cpp.

179{
180 const auto begin = mStates.begin()
181 , end = mStates.end()
182 , iter = std::find(begin, end, pState);
183 if (iter == end)
184 return {};
185 return std::distance(begin, iter);
186}
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
const char * begin(const char *str) noexcept
Definition: StringUtils.h:101

References details::begin(), details::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.Attachments::Get<RealtimeEffectList>(channelGroupEffects);
74}
static const ChannelGroup::Attachments::RegisteredFactory channelGroupEffects

References channelGroupEffects.

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

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

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

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

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

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

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

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

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

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

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

285{
286 return mActive.load(std::memory_order_relaxed);
287}
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 207 of file RealtimeEffectList.cpp.

208{
209 assert(fromIndex < mStates.size());
210 assert(toIndex < mStates.size());
211
212 auto shallowCopy = mStates;
213 if(fromIndex == toIndex)
214 return;
215 if(fromIndex < toIndex)
216 {
217 const auto first = shallowCopy.begin() + fromIndex;
218 const auto last = shallowCopy.begin() + toIndex + 1;
219 std::rotate(first, first + 1, last);
220 }
221 else
222 {
223 const auto first =
224 shallowCopy.rbegin() + (shallowCopy.size() - (fromIndex + 1));
225 const auto last = shallowCopy.rbegin() + (shallowCopy.size() - toIndex);
226 std::rotate(first, first + 1, last);
227 }
228 // Lock for only a short time
229 (LockGuard{ mLock }, swap(shallowCopy, mStates));
230
233 fromIndex,
234 toIndex,
235 mStates[toIndex]
236 });
237}
void rotate(const float *oldPhase, const float *newPhase, std::complex< float > *dst, int32_t n)
Definition: VectorOps.h:140
@ Move
Item position has changed, from srcIndex to dstIndex. affectedState is the moved state.

References mLock, RealtimeEffectListMessage::Move, mStates, Observer::Publisher< RealtimeEffectListMessage >::Publish(), staffpad::vo::rotate(), 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 141 of file RealtimeEffectList.cpp.

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

References details::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 107 of file RealtimeEffectList.cpp.

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

279{
280 // Restore per-project states
281 Set(project, shared_from_this());
282}
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 289 of file RealtimeEffectList.cpp.

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

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

270{
271 xmlFile.StartTag(XMLTag());
273 for (const auto & state : mStates)
274 state->WriteXML(xmlFile);
275 xmlFile.EndTag(XMLTag());
276}
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 239 of file RealtimeEffectList.cpp.

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

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: