![]() |
Audacity 3.2.0
|
#include <RealtimeEffectState.h>
Classes | |
struct | Access |
Main thread's interface to inter-thread communication of changes of settings. More... | |
class | AccessState |
Mediator of two-way inter-thread communication of changes of settings. More... | |
struct | EffectFactory |
struct | Response |
struct | SettingsAndCounter |
Public Member Functions | |
RealtimeEffectState (const PluginID &id) | |
RealtimeEffectState (const RealtimeEffectState &other)=delete | |
RealtimeEffectState & | operator= (const RealtimeEffectState &other)=delete |
~RealtimeEffectState () | |
void | SetID (const PluginID &id) |
May be called with nonempty id at most once in the lifetime of a state. More... | |
const PluginID & | GetID () const noexcept |
const EffectInstanceFactory * | GetEffect () |
Initializes the effect on demand. More... | |
const EffectInstanceFactory * | GetEffect () const |
const accessor will not initialize the effect on demand More... | |
std::shared_ptr< EffectInstance > | GetInstance () |
Expose a pointer to the state's instance (making one as needed). More... | |
const EffectOutputs * | GetOutputs () const |
Get locations that a GUI can connect meters to. More... | |
std::shared_ptr< EffectInstance > | Initialize (double rate) |
Main thread sets up for playback. More... | |
std::shared_ptr< EffectInstance > | AddTrack (const Track &track, unsigned chans, float sampleRate) |
Main thread sets up this state before adding it to lists. More... | |
bool | ProcessStart (bool running) |
Worker thread begins a batch of samples. More... | |
size_t | Process (const Track &track, unsigned chans, const float *const *inbuf, float *const *outbuf, float *dummybuf, size_t numSamples) |
Worker thread processes part of a batch of samples. More... | |
bool | ProcessEnd () |
Worker thread finishes a batch of samples. More... | |
const EffectSettings & | GetSettings () const |
bool | IsEnabled () const noexcept |
Test only in the main thread. More... | |
bool | IsActive () const noexcept |
Test only in the worker thread, or else when there is no processing. More... | |
void | SetActive (bool active) |
Set only in the main thread. More... | |
bool | Finalize () noexcept |
Main thread cleans up playback. More... | |
bool | HandleXMLTag (const std::string_view &tag, const AttributesList &attrs) override |
void | HandleXMLEndTag (const std::string_view &tag) override |
XMLTagHandler * | HandleXMLChild (const std::string_view &tag) override |
void | WriteXML (XMLWriter &xmlFile) |
std::shared_ptr< EffectSettingsAccess > | GetAccess () |
![]() | |
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 XMLTagHandler * | HandleXMLChild (const std::string_view &tag)=0 |
void | ReadXMLEndTag (const char *tag) |
void | ReadXMLContent (const char *s, int len) |
XMLTagHandler * | ReadXMLChild (const char *tag) |
![]() | |
~Site () | |
Site () | |
Site (const Site &other) | |
Site (Site &&other) | |
Site & | operator= (const Site &other) |
Site & | operator= (Site &&other) |
size_t | size () const |
How many attachment pointers are in the Site. More... | |
Subclass & | Get (const RegisteredFactory &key) |
Get reference to an attachment, creating on demand if not present, down-cast it to Subclass. More... | |
auto | Get (const RegisteredFactory &key) const -> std::enable_if_t< std::is_const< Subclass >::value, Subclass & > |
Get reference to an attachment, creating on demand if not present, down-cast it to Subclass. More... | |
Subclass * | Find (const RegisteredFactory &key) |
Get a (bare) pointer to an attachment, or null, down-cast it to Subclass *; will not create on demand. More... | |
auto | Find (const RegisteredFactory &key) const -> std::enable_if_t< std::is_const< Subclass >::value, Subclass * > |
Get a (bare) pointer to an attachment, or null, down-cast it to Subclass *; will not create on demand. More... | |
void | Assign (const RegisteredFactory &key, ReplacementPointer &&replacement) |
Reassign Site's pointer to ClientData. More... | |
![]() | |
Publisher (ExceptionPolicy *pPolicy=nullptr, Alloc a={}) | |
Constructor supporting type-erased custom allocation/deletion. More... | |
Publisher (Publisher &&)=default | |
Publisher & | operator= (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 const std::string & | XMLTag () |
![]() | |
static std::shared_ptr< RealtimeEffectState > | make_shared (Args &&...args) |
![]() | |
static size_t | slots () |
How many static factories have been registered with this specialization of Site. More... | |
Private Member Functions | |
std::shared_ptr< EffectInstance > | MakeInstance () |
std::shared_ptr< EffectInstance > | EnsureInstance (double rate) |
AccessState * | GetAccessState () const |
AccessState * | TestAccessState () const |
Private Attributes | |
PluginID | mID |
std::weak_ptr< EffectInstance > | mwInstance |
Stateful instance made by the plug-in. More... | |
const EffectInstanceFactory * | mPlugin {} |
Stateless effect object. More... | |
NonInterfering< SettingsAndCounter > | mMainSettings |
Updated immediately by Access::Set in the main thread. More... | |
std::unique_ptr< EffectInstance::Message > | mMessage |
std::unique_ptr< EffectOutputs > | mMovedOutputs |
Members that are changed also in the worker thread | |
NonInterfering< SettingsAndCounter > | mWorkerSettings |
std::unique_ptr< EffectInstance::Message > | mMovedMessage |
std::unique_ptr< EffectOutputs > | mOutputs |
std::optional< EffectInstance::SampleCount > | mLatency |
How many samples must be discarded. More... | |
bool | mLastActive {} |
Assigned in the worker thread at the start of each processing scope. More... | |
Members that do not change during processing | |
std::unordered_map< const Track *, std::pair< size_t, double > > | mGroups |
AtomicUniquePointer< AccessState > | mpAccessState { nullptr } |
wxString | mParameters |
size_t | mCurrentProcessor { 0 } |
bool | mInitialized { false } |
Additional Inherited Members | |
![]() | |
using | DataType = Base |
using | DataPointer = UniquePtr< Base > |
using | DataFactory = std::function< DataPointer(RealtimeEffectState &) > |
Type of function from which RegisteredFactory is constructed; it builds attachments. More... | |
![]() | |
using | message_type = RealtimeEffectStateChange |
using | CallbackReturn = std::conditional_t< true, void, bool > |
using | Callback = std::function< CallbackReturn(const RealtimeEffectStateChange &) > |
Type of functions that can be connected to the Publisher. More... | |
![]() | |
static constexpr bool | notifies_all |
![]() | |
void | ForEach (const Function &function) |
Invoke function on each ClientData object that has been created in this . More... | |
void | ForEach (const Function &function) const |
Invoke function on each ClientData object that has been created in this . More... | |
Base * | FindIf (const Function &function) |
Return pointer to first attachment in this that is not null and satisfies a predicate, or nullptr. More... | |
const Base * | FindIf (const Function &function) const |
Return pointer to first attachment in this that is not null and satisfies a predicate, or nullptr. More... | |
void | BuildAll () |
For each RegisteredFactory, if the corresponding attachment is absent in this , build and store it. More... | |
![]() | |
CallbackReturn | Publish (const RealtimeEffectStateChange &message) |
Send a message to connected callbacks. More... | |
Definition at line 32 of file RealtimeEffectState.h.
|
explicit |
Definition at line 315 of file RealtimeEffectState.cpp.
References ClientData::Site< RealtimeEffectState >::BuildAll(), and SetID().
|
delete |
RealtimeEffectState::~RealtimeEffectState | ( | ) |
Definition at line 321 of file RealtimeEffectState.cpp.
std::shared_ptr< EffectInstance > RealtimeEffectState::AddTrack | ( | const Track & | track, |
unsigned | chans, | ||
float | sampleRate | ||
) |
Main thread sets up this state before adding it to lists.
Set up processors to be visited repeatedly in Process.
The iteration over channels in AddTrack and Process must be the same
Definition at line 457 of file RealtimeEffectState.cpp.
References anonymous_namespace{RealtimeEffectState.cpp}::AllocateChannelsToProcessors(), EnsureInstance(), mCurrentProcessor, mGroups, mOutputs, mPlugin, and mWorkerSettings.
Referenced by RealtimeEffectManager::AddTrack().
|
private |
copying settings in the main thread while worker isn't yet running
If there was already an instance, recycle it; else make one here
Definition at line 378 of file RealtimeEffectState.cpp.
References IsActive(), MakeInstance(), mInitialized, mLastActive, mMainSettings, mPlugin, mwInstance, and mWorkerSettings.
Referenced by AddTrack(), and Initialize().
|
noexcept |
Main thread cleans up playback.
Definition at line 651 of file RealtimeEffectState.cpp.
References mCurrentProcessor, mGroups, mInitialized, mLatency, mMainSettings, mwInstance, and mWorkerSettings.
Referenced by RealtimeEffectManager::Finalize().
std::shared_ptr< EffectSettingsAccess > RealtimeEffectState::GetAccess | ( | ) |
Expose access so a dialog can be connected to this state To be called by the main thread only
result != nullptr
Definition at line 781 of file RealtimeEffectState.cpp.
References GetAccessState(), GetEffect(), MakeInstance(), mpAccessState, and mPlugin.
Referenced by SetActive(), and RealtimeEffectStateUI::Show().
|
inlineprivate |
Definition at line 126 of file RealtimeEffectState.h.
Referenced by GetAccess(), and MakeInstance().
const EffectInstanceFactory * RealtimeEffectState::GetEffect | ( | ) |
Initializes the effect on demand.
Definition at line 343 of file RealtimeEffectState.cpp.
References GlobalHook< EffectFactory, const EffectInstanceFactory *(const PluginID &) >::Call(), EffectSettingsManager::MakeOutputs(), EffectSettingsManager::MakeSettings(), mID, mMainSettings, mMovedOutputs, mOutputs, and mPlugin.
Referenced by GetAccess(), and SetID().
|
inline |
const accessor will not initialize the effect on demand
Definition at line 58 of file RealtimeEffectState.h.
|
noexcept |
Definition at line 338 of file RealtimeEffectState.cpp.
References mID.
Referenced by RealtimeEffectStateUI::Show(), and RealtimeEffectStateUI::UpdateTitle().
std::shared_ptr< EffectInstance > RealtimeEffectState::GetInstance | ( | ) |
Expose a pointer to the state's instance (making one as needed).
true
(no promise result is not null) If there was already an instance, recycle it; else make one here
Definition at line 407 of file RealtimeEffectState.cpp.
References MakeInstance(), mPlugin, and mwInstance.
|
inline |
Get locations that a GUI can connect meters to.
Definition at line 67 of file RealtimeEffectState.h.
|
inline |
Definition at line 90 of file RealtimeEffectState.h.
|
overridevirtual |
Implements XMLTagHandler.
Definition at line 737 of file RealtimeEffectState.cpp.
|
override |
Definition at line 726 of file RealtimeEffectState.cpp.
References EffectSettingsManager::LoadSettings(), mMainSettings, mParameters, mPlugin, and XMLTag().
|
overridevirtual |
Implements XMLTagHandler.
Definition at line 685 of file RealtimeEffectState.cpp.
References activeAttribute, idAttribute, mID, mMainSettings, mParameters, mPlugin, nameAttribute, parameterAttribute, parametersAttribute, SetID(), valueAttribute, versionAttribute, wxT(), and XMLTag().
std::shared_ptr< EffectInstance > RealtimeEffectState::Initialize | ( | double | rate | ) |
Main thread sets up for playback.
Definition at line 417 of file RealtimeEffectState.cpp.
References EnsureInstance(), mCurrentProcessor, mGroups, mLatency, and mPlugin.
Referenced by RealtimeEffectManager::Initialize().
|
noexcept |
Test only in the worker thread, or else when there is no processing.
Definition at line 632 of file RealtimeEffectState.cpp.
References mWorkerSettings.
Referenced by EnsureInstance(), ProcessEnd(), and ProcessStart().
|
noexcept |
Test only in the main thread.
Definition at line 627 of file RealtimeEffectState.cpp.
References mMainSettings.
|
private |
Definition at line 360 of file RealtimeEffectState.cpp.
References GetAccessState(), EffectInstanceFactory::MakeInstance(), mMainSettings, mMessage, mMovedMessage, mMovedOutputs, and mPlugin.
Referenced by EnsureInstance(), GetAccess(), and GetInstance().
|
delete |
size_t RealtimeEffectState::Process | ( | const Track & | track, |
unsigned | chans, | ||
const float *const * | inbuf, | ||
float *const * | outbuf, | ||
float * | dummybuf, | ||
size_t | numSamples | ||
) |
Worker thread processes part of a batch of samples.
Visit the effect processors that were added in AddTrack.
The iteration over channels in AddTrack and Process must be the same
inbuf | chans input buffers |
outbuf | chans output buffers |
dummybuf | one dummy output buffer |
Definition at line 533 of file RealtimeEffectState.cpp.
References anonymous_namespace{RealtimeEffectState.cpp}::AllocateChannelsToProcessors(), staffpad::vo::copy(), limitSampleBufferSize(), mGroups, min(), mLastActive, mLatency, mPlugin, mwInstance, mWorkerSettings, and stackAllocate.
Referenced by RealtimeEffectManager::Process().
bool RealtimeEffectState::ProcessEnd | ( | ) |
Worker thread finishes a batch of samples.
Definition at line 608 of file RealtimeEffectState.cpp.
References IsActive(), mLastActive, mwInstance, mWorkerSettings, and TestAccessState().
Referenced by RealtimeEffectManager::ProcessEnd().
bool RealtimeEffectState::ProcessStart | ( | bool | running | ) |
Worker thread begins a batch of samples.
running | means no pause or deactivation of containing list |
Definition at line 488 of file RealtimeEffectState.cpp.
References IsActive(), mLastActive, mMovedMessage, mwInstance, mWorkerSettings, and TestAccessState().
Referenced by RealtimeEffectManager::ProcessStart().
void RealtimeEffectState::SetActive | ( | bool | active | ) |
Set only in the main thread.
Definition at line 637 of file RealtimeEffectState.cpp.
References EffectOff, EffectOn, GetAccess(), Observer::Publisher< RealtimeEffectStateChange >::Publish(), and settings().
void RealtimeEffectState::SetID | ( | const PluginID & | id | ) |
May be called with nonempty id at most once in the lifetime of a state.
Call with empty id is ignored. Called by the constructor that takes an id
Definition at line 326 of file RealtimeEffectState.cpp.
References GetEffect(), id, and mID.
Referenced by HandleXMLTag(), and RealtimeEffectState().
|
inlineprivate |
Definition at line 130 of file RealtimeEffectState.h.
Referenced by ProcessEnd(), and ProcessStart().
void RealtimeEffectState::WriteXML | ( | XMLWriter & | xmlFile | ) |
Definition at line 744 of file RealtimeEffectState.cpp.
References activeAttribute, XMLWriter::EndTag(), PluginManager::GetID(), ComponentInterface::GetVersion(), idAttribute, mMainSettings, mPlugin, nameAttribute, parameterAttribute, parametersAttribute, EffectSettingsManager::SaveSettings(), XMLWriter::StartTag(), valueAttribute, versionAttribute, XMLWriter::WriteAttr(), and XMLTag().
|
static |
Definition at line 671 of file RealtimeEffectState.cpp.
Referenced by RealtimeEffectList::HandleXMLChild(), HandleXMLEndTag(), HandleXMLTag(), and WriteXML().
|
private |
Definition at line 195 of file RealtimeEffectState.h.
Referenced by AddTrack(), Finalize(), and Initialize().
|
private |
Definition at line 187 of file RealtimeEffectState.h.
Referenced by AddTrack(), Finalize(), Initialize(), and Process().
|
private |
Definition at line 135 of file RealtimeEffectState.h.
Referenced by GetEffect(), GetID(), HandleXMLTag(), and SetID().
|
private |
Definition at line 196 of file RealtimeEffectState.h.
Referenced by EnsureInstance(), and Finalize().
|
private |
Assigned in the worker thread at the start of each processing scope.
Definition at line 179 of file RealtimeEffectState.h.
Referenced by EnsureInstance(), Process(), ProcessEnd(), and ProcessStart().
|
private |
How many samples must be discarded.
Definition at line 177 of file RealtimeEffectState.h.
Referenced by Finalize(), Initialize(), and Process().
|
private |
Updated immediately by Access::Set in the main thread.
Definition at line 162 of file RealtimeEffectState.h.
Referenced by RealtimeEffectState::AccessState::AccessState(), EnsureInstance(), Finalize(), GetEffect(), HandleXMLEndTag(), HandleXMLTag(), IsEnabled(), MakeInstance(), and WriteXML().
|
private |
Definition at line 163 of file RealtimeEffectState.h.
Referenced by RealtimeEffectState::AccessState::AccessState(), and MakeInstance().
|
private |
Definition at line 173 of file RealtimeEffectState.h.
Referenced by MakeInstance(), ProcessStart(), and RealtimeEffectState::AccessState::FromMainSlot::Reader::Reader().
|
private |
Definition at line 164 of file RealtimeEffectState.h.
Referenced by RealtimeEffectState::AccessState::AccessState(), GetEffect(), RealtimeEffectState::AccessState::MainRead(), and MakeInstance().
|
private |
Definition at line 174 of file RealtimeEffectState.h.
Referenced by AddTrack(), GetEffect(), and RealtimeEffectState::AccessState::WorkerWrite().
|
private |
Definition at line 192 of file RealtimeEffectState.h.
Referenced by GetAccess().
|
private |
Definition at line 194 of file RealtimeEffectState.h.
Referenced by HandleXMLEndTag(), and HandleXMLTag().
|
private |
Stateless effect object.
Definition at line 140 of file RealtimeEffectState.h.
Referenced by AddTrack(), EnsureInstance(), GetAccess(), GetEffect(), GetInstance(), HandleXMLEndTag(), HandleXMLTag(), Initialize(), MakeInstance(), Process(), and WriteXML().
|
private |
Stateful instance made by the plug-in.
Definition at line 138 of file RealtimeEffectState.h.
Referenced by EnsureInstance(), Finalize(), GetInstance(), Process(), ProcessEnd(), and ProcessStart().
|
private |
Updated with delay, but atomically, in the worker thread; skipped by the copy constructor so that there isn't a race when pushing an Undo state
Definition at line 172 of file RealtimeEffectState.h.
Referenced by AddTrack(), EnsureInstance(), Finalize(), IsActive(), Process(), ProcessEnd(), ProcessStart(), RealtimeEffectState::AccessState::FromMainSlot::Reader::Reader(), and RealtimeEffectState::AccessState::WorkerWrite().