![]() |
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 () |
![]() | |
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 | 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 | |
![]() | |
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 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.
group.IsLeader()
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(), ChannelGroup::IsLeader(), mCurrentProcessor, mGroups, mOutputs, mPlugin, mWorkerSettings, and anonymous_namespace{ClipSegmentTest.cpp}::sampleRate.
Referenced by RealtimeEffectManager::AddGroup().
|
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 655 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 785 of file RealtimeEffectState.cpp.
References GetAccessState(), GetEffect(), MakeInstance(), mpAccessState, and mPlugin.
Referenced by SetActive(), and RealtimeEffectStateUI::Show().
|
inlineprivate |
Definition at line 130 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 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 94 of file RealtimeEffectState.h.
|
overridevirtual |
Implements XMLTagHandler.
Definition at line 741 of file RealtimeEffectState.cpp.
|
override |
Definition at line 730 of file RealtimeEffectState.cpp.
References EffectSettingsManager::LoadSettings(), mMainSettings, mParameters, mPlugin, and XMLTag().
|
overridevirtual |
Implements XMLTagHandler.
Definition at line 689 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 636 of file RealtimeEffectState.cpp.
References mWorkerSettings.
Referenced by EnsureInstance(), ProcessEnd(), and ProcessStart().
|
noexcept |
Test only in the main thread.
Definition at line 631 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 536 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 612 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 491 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 641 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 134 of file RealtimeEffectState.h.
Referenced by ProcessEnd(), and ProcessStart().
void RealtimeEffectState::WriteXML | ( | XMLWriter & | xmlFile | ) |
Definition at line 748 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 675 of file RealtimeEffectState.cpp.
Referenced by RealtimeEffectList::HandleXMLChild(), HandleXMLEndTag(), HandleXMLTag(), and WriteXML().
|
private |
Definition at line 200 of file RealtimeEffectState.h.
Referenced by AddGroup(), Finalize(), and Initialize().
|
private |
Definition at line 192 of file RealtimeEffectState.h.
Referenced by AddGroup(), Finalize(), Initialize(), and Process().
|
private |
Definition at line 139 of file RealtimeEffectState.h.
Referenced by GetEffect(), GetID(), HandleXMLTag(), and SetID().
|
private |
Definition at line 201 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 183 of file RealtimeEffectState.h.
Referenced by EnsureInstance(), Process(), ProcessEnd(), and ProcessStart().
|
private |
How many samples must be discarded.
Definition at line 181 of file RealtimeEffectState.h.
Referenced by Finalize(), Initialize(), and Process().
|
private |
Updated immediately by Access::Set in the main thread.
Definition at line 166 of file RealtimeEffectState.h.
Referenced by RealtimeEffectState::AccessState::AccessState(), EnsureInstance(), Finalize(), GetEffect(), HandleXMLEndTag(), HandleXMLTag(), IsEnabled(), MakeInstance(), and WriteXML().
|
private |
Definition at line 167 of file RealtimeEffectState.h.
Referenced by RealtimeEffectState::AccessState::AccessState(), and MakeInstance().
|
private |
Definition at line 177 of file RealtimeEffectState.h.
Referenced by MakeInstance(), ProcessStart(), and RealtimeEffectState::AccessState::FromMainSlot::Reader::Reader().
|
private |
Definition at line 168 of file RealtimeEffectState.h.
Referenced by RealtimeEffectState::AccessState::AccessState(), GetEffect(), RealtimeEffectState::AccessState::MainRead(), and MakeInstance().
|
private |
Definition at line 178 of file RealtimeEffectState.h.
Referenced by AddGroup(), GetEffect(), and RealtimeEffectState::AccessState::WorkerWrite().
|
private |
Definition at line 197 of file RealtimeEffectState.h.
Referenced by GetAccess().
|
private |
Definition at line 199 of file RealtimeEffectState.h.
Referenced by HandleXMLEndTag(), and HandleXMLTag().
|
private |
Stateless effect object.
Definition at line 144 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 142 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 176 of file RealtimeEffectState.h.
Referenced by AddGroup(), EnsureInstance(), Finalize(), IsActive(), Process(), ProcessEnd(), ProcessStart(), RealtimeEffectState::AccessState::FromMainSlot::Reader::Reader(), and RealtimeEffectState::AccessState::WorkerWrite().