Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
LadspaInstance Struct Reference

#include <LadspaInstance.h>

Inheritance diagram for LadspaInstance:
[legend]
Collaboration diagram for LadspaInstance:
[legend]

Public Member Functions

 LadspaInstance (const PerTrackEffect &processor, const LADSPA_Descriptor *pData, const ArrayOf< unsigned long > &inputPorts, const ArrayOf< unsigned long > &outputPorts, unsigned audioIns, unsigned audioOuts, int latencyPort)
 
bool ProcessInitialize (EffectSettings &settings, double sampleRate, ChannelNames chanMap) override
 
bool ProcessFinalize () noexcept override
 
size_t ProcessBlock (EffectSettings &settings, const float *const *inBlock, float *const *outBlock, size_t blockLen) override
 Called for destructive effect computation. More...
 
SampleCount GetLatency (const EffectSettings &settings, double sampleRate) const override
 
bool RealtimeInitialize (EffectSettings &settings, double sampleRate) override
 
bool RealtimeAddProcessor (EffectSettings &settings, EffectOutputs *pOutputs, unsigned numChannels, float sampleRate) override
 
bool RealtimeSuspend () override
 
bool RealtimeResume () override
 
bool RealtimeProcessStart (MessagePackage &package) override
 settings are possibly changed, since last call, by an asynchronous dialog More...
 
size_t RealtimeProcess (size_t group, EffectSettings &settings, const float *const *inBuf, float *const *outBuf, size_t numSamples) override
 
bool RealtimeProcessEnd (EffectSettings &settings) noexcept override
 settings can be updated to let a dialog change appearance at idle More...
 
bool RealtimeFinalize (EffectSettings &settings) noexcept override
 
unsigned GetAudioInCount () const override
 How many input buffers to allocate at once. More...
 
unsigned GetAudioOutCount () const override
 How many output buffers to allocate at once. More...
 
LADSPA_Handle InitInstance (float sampleRate, LadspaEffectSettings &settings, LadspaEffectOutputs *pOutputs) const
 
void FreeInstance (LADSPA_Handle handle) const
 
- Public Member Functions inherited from PerTrackEffect::Instance
 Instance (const PerTrackEffect &processor)
 
 ~Instance () override
 
bool Process (EffectSettings &settings) final
 Uses the other virtual functions of this class. More...
 
bool ProcessInitialize (EffectSettings &settings, double sampleRate, ChannelNames chanMap) override
 
bool ProcessFinalize () noexcept override
 
- Public Member Functions inherited from EffectInstanceEx
virtual bool Init ()
 Call once to set up state for whole list of tracks to be processed. More...
 
virtual bool Process (EffectSettings &settings)=0
 Actually do the effect here. More...
 
 ~EffectInstanceEx () override
 
- Public Member Functions inherited from EffectInstance
virtual ~EffectInstance ()
 
virtual size_t GetBlockSize () const =0
 
virtual size_t SetBlockSize (size_t maxBlockSize)=0
 
virtual unsigned GetAudioInCount () const =0
 How many input buffers to allocate at once. More...
 
virtual unsigned GetAudioOutCount () const =0
 How many output buffers to allocate at once. More...
 
virtual bool RealtimeInitialize (EffectSettings &settings, double sampleRate)
 
virtual bool RealtimeAddProcessor (EffectSettings &settings, EffectOutputs *pOutputs, unsigned numChannels, float sampleRate)
 
virtual bool RealtimeSuspend ()
 
virtual bool RealtimeResume ()
 
virtual std::unique_ptr< MessageMakeMessage () const
 Called on the main thread, in which the result may be cloned. More...
 
virtual bool UsesMessages () const noexcept
 
virtual bool RealtimeProcessStart (MessagePackage &package)
 settings are possibly changed, since last call, by an asynchronous dialog More...
 
virtual size_t RealtimeProcess (size_t group, EffectSettings &settings, const float *const *inBuf, float *const *outBuf, size_t numSamples)
 
virtual void RealtimePassThrough (size_t group, EffectSettings &settings, const float *const *inBuf, size_t numSamples)
 Called instead of RealtimeProcess when the effect is bypassed. Default implementation does nothing. More...
 
virtual bool RealtimeProcessEnd (EffectSettings &settings) noexcept
 settings can be updated to let a dialog change appearance at idle More...
 
virtual bool RealtimeFinalize (EffectSettings &settings) noexcept
 
virtual size_t GetTailSize () const
 
virtual SampleCount GetLatency (const EffectSettings &settings, double sampleRate) const
 
virtual bool NeedsDither () const
 
virtual bool ProcessInitialize (EffectSettings &settings, double sampleRate, ChannelNames chanMap)=0
 
virtual bool ProcessFinalize () noexcept=0
 
virtual size_t ProcessBlock (EffectSettings &settings, const float *const *inBlock, float *const *outBlock, size_t blockLen)=0
 Called for destructive effect computation. More...
 
- Public Member Functions inherited from EffectInstanceWithBlockSize
 ~EffectInstanceWithBlockSize () override
 
size_t GetBlockSize () const override
 
size_t SetBlockSize (size_t maxBlockSize) override
 

Static Public Member Functions

static bool LoadUseLatency (const EffectDefinitionInterface &effect)
 Get the preference for using latency. More...
 
static bool SaveUseLatency (const EffectDefinitionInterface &effect, bool value)
 Set the preference for using latency. More...
 
static LadspaEffectSettingsGetSettings (EffectSettings &settings)
 Assume settings originated from MakeSettings() and copies thereof. More...
 
static const LadspaEffectSettingsGetSettings (const EffectSettings &settings)
 Assume settings originated from MakeSettings() and copies thereof. More...
 

Public Attributes

const LADSPA_Descriptor *const mData
 
const ArrayOf< unsigned long > & mInputPorts
 
const ArrayOf< unsigned long > & mOutputPorts
 
bool mReady { false }
 
LADSPA_Handle mMaster {}
 
std::vector< LADSPA_HandlemSlaves
 
const unsigned mAudioIns
 
const unsigned mAudioOuts
 
const int mLatencyPort
 
const bool mUseLatency
 

Additional Inherited Members

- Public Types inherited from EffectInstance
using Message = EffectSettingsAccess::Message
 
using SampleCount = uint64_t
 
- Protected Attributes inherited from PerTrackEffect::Instance
const PerTrackEffectmProcessor
 
- Protected Attributes inherited from EffectInstanceWithBlockSize
size_t mBlockSize { 0 }
 

Detailed Description

Definition at line 39 of file LadspaInstance.h.

Constructor & Destructor Documentation

◆ LadspaInstance()

LadspaInstance::LadspaInstance ( const PerTrackEffect processor,
const LADSPA_Descriptor pData,
const ArrayOf< unsigned long > &  inputPorts,
const ArrayOf< unsigned long > &  outputPorts,
unsigned  audioIns,
unsigned  audioOuts,
int  latencyPort 
)

Definition at line 117 of file LadspaInstance.cpp.

122 : PerTrackEffect::Instance{ processor }
123 , mData{ pData }, mInputPorts{ inputPorts }, mOutputPorts{ outputPorts }
124 , mAudioIns{ audioIns }, mAudioOuts{ audioOuts }
125 , mLatencyPort{ latencyPort }
126 , mUseLatency{ LoadUseLatency(processor) }
127{
128
129}
const bool mUseLatency
const unsigned mAudioIns
const ArrayOf< unsigned long > & mInputPorts
const unsigned mAudioOuts
const LADSPA_Descriptor *const mData
const int mLatencyPort
const ArrayOf< unsigned long > & mOutputPorts
static bool LoadUseLatency(const EffectDefinitionInterface &effect)
Get the preference for using latency.

Member Function Documentation

◆ FreeInstance()

void LadspaInstance::FreeInstance ( LADSPA_Handle  handle) const

Definition at line 297 of file LadspaInstance.cpp.

298{
299 if (mData->deactivate)
300 {
301 mData->deactivate(handle);
302 }
303
304 mData->cleanup(handle);
305}
void(* deactivate)(LADSPA_Handle Instance)
Definition: ladspa.h:549
void(* cleanup)(LADSPA_Handle Instance)
Definition: ladspa.h:558

References _LADSPA_Descriptor::cleanup, _LADSPA_Descriptor::deactivate, and mData.

Referenced by ProcessFinalize().

Here is the caller graph for this function:

◆ GetAudioInCount()

unsigned LadspaInstance::GetAudioInCount ( ) const
overridevirtual

How many input buffers to allocate at once.

If the instance processes channels independently, this can return 1 The result is not necessarily well defined before RealtimeInitialize

Implements EffectInstance.

Definition at line 208 of file LadspaInstance.cpp.

209{
210 return mAudioIns;
211}

References mAudioIns.

◆ GetAudioOutCount()

unsigned LadspaInstance::GetAudioOutCount ( ) const
overridevirtual

How many output buffers to allocate at once.

The result is not necessarily well defined before RealtimeInitialize

Implements EffectInstance.

Definition at line 203 of file LadspaInstance.cpp.

204{
205 return mAudioOuts;
206}

References mAudioOuts.

◆ GetLatency()

auto LadspaInstance::GetLatency ( const EffectSettings settings,
double  sampleRate 
) const
overridevirtual

Default implementation returns 0

Reimplemented from EffectInstance.

Definition at line 131 of file LadspaInstance.cpp.

133{
134 auto &controls = GetSettings(settings).controls;
135 if (mUseLatency && mLatencyPort >= 0)
136 return controls[mLatencyPort];
137 return 0;
138}
static Settings & settings()
Definition: TrackInfo.cpp:51
std::vector< float > controls
static LadspaEffectSettings & GetSettings(EffectSettings &settings)
Assume settings originated from MakeSettings() and copies thereof.

References anonymous_namespace{DynamicRangeProcessorEditor.cpp}::GetSettings(), and settings().

Here is the call graph for this function:

◆ GetSettings() [1/2]

static const LadspaEffectSettings & LadspaInstance::GetSettings ( const EffectSettings settings)
inlinestatic

Assume settings originated from MakeSettings() and copies thereof.

Definition at line 59 of file LadspaInstance.h.

60 {
61 return GetSettings(const_cast<EffectSettings &>(settings));
62 }
Externalized state of a plug-in.

References anonymous_namespace{DynamicRangeProcessorEditor.cpp}::GetSettings(), and settings().

Here is the call graph for this function:

◆ GetSettings() [2/2]

static LadspaEffectSettings & LadspaInstance::GetSettings ( EffectSettings settings)
inlinestatic

Assume settings originated from MakeSettings() and copies thereof.

Definition at line 51 of file LadspaInstance.h.

52 {
53 auto pSettings = settings.cast<LadspaEffectSettings>();
54 assert(pSettings);
55 return *pSettings;
56 }

References settings().

Referenced by ProcessInitialize(), and RealtimeAddProcessor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitInstance()

LADSPA_Handle LadspaInstance::InitInstance ( float  sampleRate,
LadspaEffectSettings settings,
LadspaEffectOutputs pOutputs 
) const

Definition at line 269 of file LadspaInstance.cpp.

272{
273 /* Instantiate the plugin */
275 if (!handle)
276 return nullptr;
277
278 auto &controls = settings.controls;
279 for (unsigned long p = 0; p < mData->PortCount; ++p) {
281 if (LADSPA_IS_PORT_CONTROL(d)) {
283 mData->connect_port(handle, p, &controls[p]);
284 else {
285 static LADSPA_Data sink;
286 mData->connect_port(handle, p,
287 pOutputs ? &pOutputs->controls[p] : &sink);
288 }
289 }
290 }
291 if (mData->activate)
292 mData->activate(handle);
293
294 return handle;
295}
int LADSPA_PortDescriptor
Definition: ladspa.h:152
float LADSPA_Data
Definition: ladspa.h:84
#define LADSPA_IS_PORT_INPUT(x)
Definition: ladspa.h:168
void * LADSPA_Handle
Definition: ladspa.h:363
#define LADSPA_IS_PORT_CONTROL(x)
Definition: ladspa.h:170
LADSPA_Handle(* instantiate)(const struct _LADSPA_Descriptor *Descriptor, unsigned long SampleRate)
Definition: ladspa.h:437
void(* activate)(LADSPA_Handle Instance)
Definition: ladspa.h:489
void(* connect_port)(LADSPA_Handle Instance, unsigned long Port, LADSPA_Data *DataLocation)
Definition: ladspa.h:466
const LADSPA_PortDescriptor * PortDescriptors
Definition: ladspa.h:410
unsigned long PortCount
Definition: ladspa.h:406
std::vector< float > controls

References _LADSPA_Descriptor::activate, _LADSPA_Descriptor::connect_port, LadspaEffectOutputs::controls, _LADSPA_Descriptor::instantiate, LADSPA_IS_PORT_CONTROL, LADSPA_IS_PORT_INPUT, mData, _LADSPA_Descriptor::PortCount, _LADSPA_Descriptor::PortDescriptors, anonymous_namespace{ClipSegmentTest.cpp}::sampleRate, and settings().

Referenced by ProcessInitialize(), and RealtimeAddProcessor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadUseLatency()

bool LadspaInstance::LoadUseLatency ( const EffectDefinitionInterface effect)
static

Get the preference for using latency.

Definition at line 20 of file LadspaInstance.cpp.

21{
22 bool result{};
24 OptionsKey, UseLatencyKey, result, true /* default value */);
25 return result;
26}
static const wchar_t * UseLatencyKey
static const wchar_t * OptionsKey
bool GetConfig(const EffectDefinitionInterface &ident, ConfigurationType type, const RegistryPath &group, const RegistryPath &key, Value &var, const Value &defval)

References PluginSettings::GetConfig(), OptionsKey, PluginSettings::Shared, and UseLatencyKey.

Here is the call graph for this function:

◆ ProcessBlock()

size_t LadspaInstance::ProcessBlock ( EffectSettings settings,
const float *const *  inBlock,
float *const *  outBlock,
size_t  blockLen 
)
overridevirtual

Called for destructive effect computation.

Implements EffectInstance.

Definition at line 168 of file LadspaInstance.cpp.

170{
171 for (unsigned i = 0; i < mAudioIns; ++i)
173 const_cast<float*>(inBlock[i]));
174
175 for (unsigned i = 0; i < mAudioOuts; ++i)
176 mData->connect_port(mMaster, mOutputPorts[i], outBlock[i]);
177
178 mData->run(mMaster, blockLen);
179 return blockLen;
180}
void(* run)(LADSPA_Handle Instance, unsigned long SampleCount)
Definition: ladspa.h:505
LADSPA_Handle mMaster

References _LADSPA_Descriptor::connect_port, mAudioIns, mAudioOuts, mData, mInputPorts, mMaster, mOutputPorts, and _LADSPA_Descriptor::run.

◆ ProcessFinalize()

bool LadspaInstance::ProcessFinalize ( )
overridevirtualnoexcept

Called at end of destructive processing, for each (mono/stereo) track Default implementation does nothing, returns true This may be called during stack unwinding:

Reimplemented from PerTrackEffect::Instance.

Definition at line 155 of file LadspaInstance.cpp.

156{
157return GuardedCall<bool>([&]{
158 if (mReady) {
159 mReady = false;
161 mMaster = nullptr;
162 }
163
164 return true;
165});
166}
void FreeInstance(LADSPA_Handle handle) const

References FreeInstance(), mMaster, and mReady.

Here is the call graph for this function:

◆ ProcessInitialize()

bool LadspaInstance::ProcessInitialize ( EffectSettings settings,
double  sampleRate,
ChannelNames  chanMap 
)
overridevirtual

Called at start of destructive processing, for each (mono/stereo) track Default implementation does nothing, returns true

Parameters
chanMapnull or array terminated with ChannelNameEOL. Do not retain the pointer
Postcondition
GetAudioInCount() and GetAudioOutCount() are well defined

Reimplemented from PerTrackEffect::Instance.

Definition at line 140 of file LadspaInstance.cpp.

142{
143 /* Instantiate the plugin */
144 if (!mReady) {
145 auto &ladspaSettings = GetSettings(settings);
146 // Destructive effect processing doesn't need output ports
147 mMaster = InitInstance(sampleRate, ladspaSettings, nullptr);
148 if (!mMaster)
149 return false;
150 mReady = true;
151 }
152 return true;
153}
LADSPA_Handle InitInstance(float sampleRate, LadspaEffectSettings &settings, LadspaEffectOutputs *pOutputs) const

References GetSettings(), InitInstance(), mMaster, mReady, anonymous_namespace{ClipSegmentTest.cpp}::sampleRate, and settings().

Here is the call graph for this function:

◆ RealtimeAddProcessor()

bool LadspaInstance::RealtimeAddProcessor ( EffectSettings settings,
EffectOutputs pOutputs,
unsigned  numChannels,
float  sampleRate 
)
overridevirtual
Returns
success Default implementation does nothing, returns true

Reimplemented from EffectInstance.

Definition at line 187 of file LadspaInstance.cpp.

189{
190 auto &ladspaSettings = GetSettings(settings);
191 // Connect to outputs only if this is the first processor for the track.
192 // (What's right when a mono effect is on a stereo channel? Unclear, but
193 // this definitely causes connection with the first channel.)
194 auto pLadspaOutputs = mSlaves.empty()
195 ? static_cast<LadspaEffectOutputs *>(pOutputs) : nullptr;
196 auto slave = InitInstance(sampleRate, ladspaSettings, pLadspaOutputs);
197 if (!slave)
198 return false;
199 mSlaves.push_back(slave);
200 return true;
201}
Carry output control port information back to main thread.
std::vector< LADSPA_Handle > mSlaves

References GetSettings(), InitInstance(), mSlaves, anonymous_namespace{ClipSegmentTest.cpp}::sampleRate, and settings().

Here is the call graph for this function:

◆ RealtimeFinalize()

bool LadspaInstance::RealtimeFinalize ( EffectSettings settings)
overridevirtualnoexcept
Returns
success Default implementation does nothing, returns true

Reimplemented from EffectInstance.

Definition at line 213 of file LadspaInstance.cpp.

214{
215return GuardedCall<bool>([&]{
216 for (size_t i = 0, cnt = mSlaves.size(); i < cnt; ++i)
218 mSlaves.clear();
219
220 return true;
221});
222}

◆ RealtimeInitialize()

bool LadspaInstance::RealtimeInitialize ( EffectSettings settings,
double  sampleRate 
)
overridevirtual
Returns
success
Postcondition
GetAudioInCount() and GetAudioOutCount() are well defined

Default implementation does nothing, returns false (so assume realtime is not supported). Other member functions related to realtime return true or zero, but will not be called, unless a derived class overrides RealtimeInitialize.

Reimplemented from EffectInstance.

Definition at line 182 of file LadspaInstance.cpp.

183{
184 return true;
185}

◆ RealtimeProcess()

size_t LadspaInstance::RealtimeProcess ( size_t  group,
EffectSettings settings,
const float *const *  inBuf,
float *const *  outBuf,
size_t  numSamples 
)
overridevirtual
Returns
success Default implementation does nothing, returns 0

Reimplemented from EffectInstance.

Definition at line 245 of file LadspaInstance.cpp.

247{
248 if (group >= mSlaves.size())
249 return 0;
250
251 for (unsigned i = 0; i < mAudioIns; ++i)
253 const_cast<float*>(inbuf[i]));
254
255 for (unsigned i = 0; i < mAudioOuts; ++i)
257 mSlaves[group], mOutputPorts[i], outbuf[i]);
258
259 mData->run(mSlaves[group], numSamples);
260
261 return numSamples;
262}

References _LADSPA_Descriptor::connect_port, mAudioIns, mAudioOuts, mData, mInputPorts, mOutputPorts, mSlaves, and _LADSPA_Descriptor::run.

◆ RealtimeProcessEnd()

bool LadspaInstance::RealtimeProcessEnd ( EffectSettings settings)
overridevirtualnoexcept

settings can be updated to let a dialog change appearance at idle

Returns
success Default implementation does nothing, returns true

Reimplemented from EffectInstance.

Definition at line 264 of file LadspaInstance.cpp.

265{
266 return true;
267}

◆ RealtimeProcessStart()

bool LadspaInstance::RealtimeProcessStart ( MessagePackage package)
overridevirtual

settings are possibly changed, since last call, by an asynchronous dialog

Returns
success Default implementation does nothing, returns true

Reimplemented from EffectInstance.

Definition at line 240 of file LadspaInstance.cpp.

241{
242 return true;
243}

◆ RealtimeResume()

bool LadspaInstance::RealtimeResume ( )
overridevirtual
Returns
success Default implementation does nothing, returns true

Reimplemented from EffectInstance.

Definition at line 232 of file LadspaInstance.cpp.

233{
234 if (auto fn = mData->activate)
235 for (auto &slave : mSlaves)
236 fn(slave);
237 return true;
238}
static const auto fn

References _LADSPA_Descriptor::activate, fn, mData, and mSlaves.

◆ RealtimeSuspend()

bool LadspaInstance::RealtimeSuspend ( )
overridevirtual
Returns
success Default implementation does nothing, returns true

Reimplemented from EffectInstance.

Definition at line 224 of file LadspaInstance.cpp.

225{
226 if (auto fn = mData->deactivate)
227 for (auto &slave : mSlaves)
228 fn(slave);
229 return true;
230}

References _LADSPA_Descriptor::deactivate, fn, mData, and mSlaves.

◆ SaveUseLatency()

bool LadspaInstance::SaveUseLatency ( const EffectDefinitionInterface effect,
bool  value 
)
static

Set the preference for using latency.

Definition at line 28 of file LadspaInstance.cpp.

30{
31 return SetConfig(
33}
bool SetConfig(const EffectDefinitionInterface &ident, ConfigurationType type, const RegistryPath &group, const RegistryPath &key, const Value &value)

References OptionsKey, PluginSettings::SetConfig(), PluginSettings::Shared, and UseLatencyKey.

Referenced by LadspaEffectOptionsDialog::OnOk().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mAudioIns

const unsigned LadspaInstance::mAudioIns

Definition at line 111 of file LadspaInstance.h.

Referenced by GetAudioInCount(), ProcessBlock(), and RealtimeProcess().

◆ mAudioOuts

const unsigned LadspaInstance::mAudioOuts

Definition at line 112 of file LadspaInstance.h.

Referenced by GetAudioOutCount(), ProcessBlock(), and RealtimeProcess().

◆ mData

const LADSPA_Descriptor* const LadspaInstance::mData

◆ mInputPorts

const ArrayOf<unsigned long>& LadspaInstance::mInputPorts

Definition at line 102 of file LadspaInstance.h.

Referenced by ProcessBlock(), and RealtimeProcess().

◆ mLatencyPort

const int LadspaInstance::mLatencyPort

Definition at line 113 of file LadspaInstance.h.

◆ mMaster

LADSPA_Handle LadspaInstance::mMaster {}

Definition at line 106 of file LadspaInstance.h.

Referenced by ProcessBlock(), ProcessFinalize(), and ProcessInitialize().

◆ mOutputPorts

const ArrayOf<unsigned long>& LadspaInstance::mOutputPorts

Definition at line 103 of file LadspaInstance.h.

Referenced by ProcessBlock(), and RealtimeProcess().

◆ mReady

bool LadspaInstance::mReady { false }

Definition at line 105 of file LadspaInstance.h.

Referenced by ProcessFinalize(), and ProcessInitialize().

◆ mSlaves

std::vector<LADSPA_Handle> LadspaInstance::mSlaves

◆ mUseLatency

const bool LadspaInstance::mUseLatency

Definition at line 114 of file LadspaInstance.h.


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