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 > | AddGroup (const ChannelGroup *group, 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 ChannelGroup *group, 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 () |
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 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) |
Public Member Functions inherited from ClientData::Site< RealtimeEffectState > | |
~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... | |
Public Member Functions inherited from Observer::Publisher< RealtimeEffectStateChange > | |
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 Public Member Functions inherited from SharedNonInterfering< RealtimeEffectState > | |
static std::shared_ptr< RealtimeEffectState > | make_shared (Args &&...args) |
Static Public Member Functions inherited from ClientData::Site< RealtimeEffectState > | |
static size_t | numFactories () |
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 ChannelGroup *, std::pair< size_t, double > > | mGroups |
AtomicUniquePointer< AccessState > | mpAccessState { nullptr } |
wxString | mParameters |
size_t | mCurrentProcessor { 0 } |
bool | mInitialized { false } |
Additional Inherited Members | |
Public Types inherited from ClientData::Site< RealtimeEffectState > | |
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... | |
Public Types inherited from Observer::Publisher< RealtimeEffectStateChange > | |
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 Public Attributes inherited from Observer::Publisher< RealtimeEffectStateChange > | |
static constexpr bool | notifies_all |
Protected Member Functions inherited from ClientData::Site< RealtimeEffectState > | |
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... | |
void | ForCorresponding (Site &other, const Function &function, bool create=true) |
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 | EraseIf (const Function &function) |
Erase attached objects satisfying a predicate. More... | |
void | BuildAll () |
For each RegisteredFactory, if the corresponding attachment is absent in this , build and store it. More... | |
Protected Member Functions inherited from Observer::Publisher< RealtimeEffectStateChange > | |
CallbackReturn | Publish (const RealtimeEffectStateChange &message) |
Send a message to connected callbacks. More... | |
Definition at line 32 of file RealtimeEffectState.h.
|
explicit |
Definition at line 316 of file RealtimeEffectState.cpp.
References ClientData::Site< RealtimeEffectState >::BuildAll(), and SetID().
|
delete |
RealtimeEffectState::~RealtimeEffectState | ( | ) |
Definition at line 322 of file RealtimeEffectState.cpp.
std::shared_ptr< EffectInstance > RealtimeEffectState::AddGroup | ( | const ChannelGroup * | group, |
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 AddGroup and Process must be the same
Definition at line 458 of file RealtimeEffectState.cpp.
References anonymous_namespace{RealtimeEffectState.cpp}::AllocateChannelsToProcessors(), EnsureInstance(), mCurrentProcessor, mGroups, mOutputs, mPlugin, mWorkerSettings, and anonymous_namespace{ClipSegmentTest.cpp}::sampleRate.
Referenced by RealtimeEffectManager::AddGroup(), and RealtimeEffectManager::Initialize().
|
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 379 of file RealtimeEffectState.cpp.
References IsActive(), MakeInstance(), mInitialized, mLastActive, mMainSettings, mPlugin, mwInstance, mWorkerSettings, and anonymous_namespace{ClipSegmentTest.cpp}::sampleRate.
Referenced by AddGroup(), and Initialize().
|
noexcept |
Main thread cleans up playback.
Definition at line 692 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 822 of file RealtimeEffectState.cpp.
References GetAccessState(), GetEffect(), MakeInstance(), mpAccessState, and mPlugin.
Referenced by SetActive(), and RealtimeEffectStateUI::Show().
|
inlineprivate |
Definition at line 127 of file RealtimeEffectState.h.
Referenced by GetAccess(), and MakeInstance().
const EffectInstanceFactory * RealtimeEffectState::GetEffect | ( | ) |
Initializes the effect on demand.
Definition at line 344 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 339 of file RealtimeEffectState.cpp.
References mID.
Referenced by anonymous_namespace{RealtimeEffectPanel.cpp}::GetEffectName(), 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 408 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 91 of file RealtimeEffectState.h.
|
overridevirtual |
Implements XMLTagHandler.
Definition at line 778 of file RealtimeEffectState.cpp.
|
override |
Definition at line 767 of file RealtimeEffectState.cpp.
References EffectSettingsManager::LoadSettings(), mMainSettings, mParameters, mPlugin, and XMLTag().
|
overridevirtual |
Implements XMLTagHandler.
Definition at line 726 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 418 of file RealtimeEffectState.cpp.
References EnsureInstance(), mCurrentProcessor, mGroups, mLatency, mPlugin, and anonymous_namespace{ClipSegmentTest.cpp}::sampleRate.
Referenced by RealtimeEffectManager::Initialize().
|
noexcept |
Test only in the worker thread, or else when there is no processing.
Definition at line 673 of file RealtimeEffectState.cpp.
References mWorkerSettings.
Referenced by EnsureInstance(), ProcessEnd(), and ProcessStart().
|
noexcept |
Test only in the main thread.
Definition at line 668 of file RealtimeEffectState.cpp.
References mMainSettings.
|
private |
Definition at line 361 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 ChannelGroup * | group, |
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 AddGroup.
The iteration over channels in AddGroup and Process must be the same
inbuf | chans input buffers |
outbuf | chans output buffers |
dummybuf | one dummy output buffer |
Definition at line 535 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 649 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 490 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 678 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 327 of file RealtimeEffectState.cpp.
References GetEffect(), id, and mID.
Referenced by HandleXMLTag(), and RealtimeEffectState().
|
inlineprivate |
Definition at line 131 of file RealtimeEffectState.h.
Referenced by ProcessEnd(), and ProcessStart().
void RealtimeEffectState::WriteXML | ( | XMLWriter & | xmlFile | ) |
Definition at line 785 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 712 of file RealtimeEffectState.cpp.
Referenced by RealtimeEffectList::HandleXMLChild(), HandleXMLEndTag(), HandleXMLTag(), and WriteXML().
|
private |
Definition at line 197 of file RealtimeEffectState.h.
Referenced by AddGroup(), Finalize(), and Initialize().
|
private |
Definition at line 189 of file RealtimeEffectState.h.
Referenced by AddGroup(), Finalize(), Initialize(), and Process().
|
private |
Definition at line 136 of file RealtimeEffectState.h.
Referenced by GetEffect(), GetID(), HandleXMLTag(), and SetID().
|
private |
Definition at line 198 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 180 of file RealtimeEffectState.h.
Referenced by EnsureInstance(), Process(), ProcessEnd(), and ProcessStart().
|
private |
How many samples must be discarded.
Definition at line 178 of file RealtimeEffectState.h.
Referenced by Finalize(), Initialize(), and Process().
|
private |
Updated immediately by Access::Set in the main thread.
Definition at line 163 of file RealtimeEffectState.h.
Referenced by RealtimeEffectState::AccessState::AccessState(), EnsureInstance(), Finalize(), GetEffect(), HandleXMLEndTag(), HandleXMLTag(), IsEnabled(), MakeInstance(), and WriteXML().
|
private |
Definition at line 164 of file RealtimeEffectState.h.
Referenced by RealtimeEffectState::AccessState::AccessState(), and MakeInstance().
|
private |
Definition at line 174 of file RealtimeEffectState.h.
Referenced by MakeInstance(), ProcessStart(), and RealtimeEffectState::AccessState::FromMainSlot::Reader::Reader().
|
private |
Definition at line 165 of file RealtimeEffectState.h.
Referenced by RealtimeEffectState::AccessState::AccessState(), GetEffect(), RealtimeEffectState::AccessState::MainRead(), and MakeInstance().
|
private |
Definition at line 175 of file RealtimeEffectState.h.
Referenced by AddGroup(), GetEffect(), and RealtimeEffectState::AccessState::WorkerWrite().
|
private |
Definition at line 194 of file RealtimeEffectState.h.
Referenced by GetAccess().
|
private |
Definition at line 196 of file RealtimeEffectState.h.
Referenced by HandleXMLEndTag(), and HandleXMLTag().
|
private |
Stateless effect object.
Definition at line 141 of file RealtimeEffectState.h.
Referenced by AddGroup(), EnsureInstance(), GetAccess(), GetEffect(), GetInstance(), HandleXMLEndTag(), HandleXMLTag(), Initialize(), MakeInstance(), Process(), and WriteXML().
|
private |
Stateful instance made by the plug-in.
Definition at line 139 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 173 of file RealtimeEffectState.h.
Referenced by AddGroup(), EnsureInstance(), Finalize(), IsActive(), Process(), ProcessEnd(), ProcessStart(), RealtimeEffectState::AccessState::FromMainSlot::Reader::Reader(), and RealtimeEffectState::AccessState::WorkerWrite().