Audacity 3.2.0
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
VSTInstance Class Referencefinal

#include <VSTInstance.h>

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

Public Member Functions

 VSTInstance (const PerTrackEffect &effect, const PluginPath &path, size_t blockSize, size_t userBlockSize, bool useLatency)
 
 ~VSTInstance () override
 
bool ProcessInitialize (EffectSettings &settings, double sampleRate, ChannelNames chanMap) override
 
bool ProcessFinalize () noexcept override
 
size_t SetBlockSize (size_t maxBlockSize) override
 
size_t GetBlockSize () const override
 
bool RealtimeInitialize (EffectSettings &settings, double sampleRate) override
 
bool RealtimeAddProcessor (EffectSettings &settings, EffectOutputs *pOutputs, unsigned numChannels, float sampleRate) override
 
bool RealtimeFinalize (EffectSettings &settings) noexcept override
 
bool RealtimeSuspend () override
 
bool RealtimeResume () override
 
bool UsesMessages () const noexcept 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...
 
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 IsReady ()
 
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...
 
bool DoProcessInitialize (double sampleRate)
 
void PowerOn ()
 
void PowerOff ()
 
std::unique_ptr< MessageMakeMessage () const override
 Called on the main thread, in which the result may be cloned. More...
 
std::unique_ptr< MessageMakeMessage (int id, double value) const
 
void Automate (int index, float value) override
 
void NeedIdle () override
 
void SizeWindow (int w, int h) override
 
void SetBufferDelay (int samples) override
 
void SetOwningValidator (VSTUIWrapper *vi)
 
bool OnePresetWasLoadedWhilePlaying ()
 
void DeferChunkApplication ()
 
bool HasGUI () 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 VSTWrapper
 VSTWrapper (const PluginPath &path)
 
 ~VSTWrapper ()
 
intptr_t callDispatcher (int opcode, int index, intptr_t value, void *ptr, float opt) override
 
intptr_t constCallDispatcher (int opcode, int index, intptr_t value, void *ptr, float opt) const
 
float callGetParameter (int index) const
 
void callSetChunk (bool isPgm, int len, void *buf)
 
void callSetChunk (bool isPgm, int len, void *buf, VstPatchChunkInfo *info) const
 
int GetString (wxString &outstr, int opcode, int index=0) const
 
wxString GetString (int opcode, int index=0) const
 
void ForEachParameter (ParameterVisitor visitor) const
 
bool FetchSettings (VSTSettings &vst3Settings, bool doFetch=true) const
 
bool StoreSettings (const VSTSettings &vst3settings) const
 
VstPatchChunkInfo GetChunkInfo () const
 
bool IsCompatible (const VstPatchChunkInfo &) const
 
bool LoadXML (const wxFileName &fn)
 
bool HandleXMLTag (const std::string_view &tag, const AttributesList &attrs) override
 
void HandleXMLEndTag (const std::string_view &tag) override
 
void HandleXMLContent (const std::string_view &content) override
 
XMLTagHandlerHandleXMLChild (const std::string_view &tag) override
 
void SetString (int opcode, const wxString &str, int index=0)
 
ComponentInterfaceSymbol GetSymbol () const
 
void callSetParameter (int index, float value) const
 
void SaveXML (const wxFileName &fn) const
 
bool LoadFXB (const wxFileName &fn)
 
bool LoadFXP (const wxFileName &fn)
 
bool LoadFXProgram (unsigned char **bptr, ssize_t &len, int index, bool dryrun)
 
void callSetProgram (int index)
 
void SaveFXB (const wxFileName &fn) const
 
void SaveFXP (const wxFileName &fn) const
 
void SaveFXProgram (wxMemoryBuffer &buf, int index) const
 
bool Load ()
 
void Unload ()
 
void ResetModuleAndHandle ()
 
VstTimeInfoGetTimeInfo ()
 
float GetSampleRate ()
 
int GetProcessLevel ()
 
virtual void SetBufferDelay (int samples)
 
std::unique_ptr< EffectInstance::MessageMakeMessageFS (const VSTSettings &settings) const
 
- 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 VSTUIWrapper
virtual void Idle ()
 
virtual void NeedIdle ()
 
virtual void SizeWindow (int w, int h)
 
virtual void Automate (int index, float value)
 
virtual void Flush ()
 

Public Attributes

const bool mUseLatency
 
size_t mBlockSize { 8192 }
 
- Public Attributes inherited from VSTWrapper
AEffectmAEffect = nullptr
 
std::thread::id mMainThreadId
 
std::recursive_mutex mDispatcherLock
 
int mVstVersion
 
wxString mName
 
bool mInSet
 
bool mInChunk
 
wxString mChunk
 
long mXMLVersion
 
VstPatchChunkInfo mXMLInfo
 
intptr_t mCurrentEffectID {}
 
PluginPath mPath
 
ModuleHandle mModule {}
 
wxString mVendor
 
wxString mDescription
 
int mVersion
 
bool mInteractive { false }
 
unsigned mAudioIns { 0 }
 
unsigned mAudioOuts { 0 }
 
int mMidiIns { 0 }
 
int mMidiOuts { 0 }
 
bool mAutomatable
 
BundleHandle mBundleRef
 
ResourceHandle mResource
 
VstTimeInfo mTimeInfo
 
int mBufferDelay { 0 }
 
int mProcessLevel { 1 }
 
bool mGui { false }
 

Private Member Functions

void callProcessReplacing (const float *const *inputs, float *const *outputs, int sampleframes)
 
void ApplyChunk (std::vector< char > &chunk)
 
bool ChunkMustBeAppliedInMainThread () const
 

Private Attributes

VSTInstanceArray mSlaves
 
bool mHasPower { false }
 
size_t mUserBlockSize { mBlockSize }
 
bool mReady { false }
 
bool mRecruited { false }
 
VSTUIWrappermpOwningValidator {}
 
std::atomic_bool mPresetLoadedWhilePlaying { false }
 
std::mutex mDeferredChunkMutex
 
std::vector< char > mChunkToSetAtIdleTime {}
 
bool mIsMeldaPlugin { false }
 

Additional Inherited Members

- Public Types inherited from EffectInstance
using Message = EffectSettingsAccess::Message
 
using SampleCount = uint64_t
 
- Public Types inherited from VSTWrapper
using ParameterVisitor = std::function< bool(const ParameterInfo &pi) >
 
using ModuleHandle = std::unique_ptr< wxDynamicLibrary >
 
using BundleHandle = CF_ptr< CFBundleRef >
 
- Static Public Member Functions inherited from VSTWrapper
static VSTSettingsGetSettings (EffectSettings &settings)
 
static const VSTSettingsGetSettings (const EffectSettings &settings)
 
static intptr_t AudioMaster (AEffect *effect, int32_t opcode, int32_t index, intptr_t value, void *ptr, float opt)
 
- Protected Attributes inherited from PerTrackEffect::Instance
const PerTrackEffectmProcessor
 

Detailed Description

Definition at line 25 of file VSTInstance.h.

Constructor & Destructor Documentation

◆ VSTInstance()

VSTInstance::VSTInstance ( const PerTrackEffect effect,
const PluginPath path,
size_t  blockSize,
size_t  userBlockSize,
bool  useLatency 
)

Definition at line 451 of file VSTInstance.cpp.

461 , VSTWrapper(path)
462 , mUseLatency{ useLatency }
463{
464 // what also happens in the effect ctor
465 //
466 memset(&mTimeInfo, 0, sizeof(mTimeInfo));
467 mTimeInfo.samplePos = 0.0;
468 mTimeInfo.sampleRate = 44100.0; // this is a bogus value, but it's only for the display
469 mTimeInfo.nanoSeconds = wxGetUTCTimeMillis().ToDouble();
470 mTimeInfo.tempo = 120.0;
474
475 mBlockSize = blockSize;
476 mUserBlockSize = userBlockSize;
477
478 Load();
479
480 if (!IsReady() )
481 {
482 // Set some defaults since some VSTs need them...these will be reset when
483 // normal or realtime processing begins
484 mBlockSize = 8192;
485 DoProcessInitialize(44100.0);
486 }
487
488 mIsMeldaPlugin = (mVendor == "MeldaProduction");
489}
const int kVstNanosValid
Definition: aeffectx.h:148
const int kVstTempoValid
Definition: aeffectx.h:150
size_t mUserBlockSize
Definition: VSTInstance.h:116
bool IsReady()
Definition: VSTInstance.cpp:77
bool DoProcessInitialize(double sampleRate)
Definition: VSTInstance.cpp:96
const bool mUseLatency
Definition: VSTInstance.h:82
size_t mBlockSize
Definition: VSTInstance.h:84
bool mIsMeldaPlugin
Definition: VSTInstance.h:133
double tempo
Definition: aeffectx.h:317
double sampleRate
Definition: aeffectx.h:311
double nanoSeconds
Definition: aeffectx.h:313
int timeSigDenominator
Definition: aeffectx.h:327
double samplePos
Definition: aeffectx.h:309
int timeSigNumerator
Definition: aeffectx.h:325
VstTimeInfo mTimeInfo
Definition: VSTWrapper.h:264
bool Load()
Definition: VSTWrapper.cpp:307
VSTWrapper(const PluginPath &path)
Definition: VSTWrapper.h:117
wxString mVendor
Definition: VSTWrapper.h:216

References DoProcessInitialize(), VstTimeInfo::flags, IsReady(), kVstNanosValid, kVstTempoValid, VSTWrapper::Load(), mBlockSize, mIsMeldaPlugin, VSTWrapper::mTimeInfo, mUserBlockSize, VSTWrapper::mVendor, VstTimeInfo::nanoSeconds, VstTimeInfo::samplePos, VstTimeInfo::sampleRate, VstTimeInfo::tempo, VstTimeInfo::timeSigDenominator, and VstTimeInfo::timeSigNumerator.

Here is the call graph for this function:

◆ ~VSTInstance()

VSTInstance::~VSTInstance ( )
override

Definition at line 491 of file VSTInstance.cpp.

492{
493 PowerOff();
494}
void PowerOff()

References PowerOff().

Here is the call graph for this function:

Member Function Documentation

◆ ApplyChunk()

void VSTInstance::ApplyChunk ( std::vector< char > &  chunk)
private

Definition at line 236 of file VSTInstance.cpp.

237{
238 VstPatchChunkInfo info = {
240
241 const auto len = chunk.size();
242 const auto data = chunk.data();
243
244 callSetChunk(true, len, data, &info);
245 for (auto& slave : mSlaves)
246 slave->callSetChunk(true, len, data, &info);
247}
int numParams
Definition: aeffectx.h:274
int32_t version
Definition: aeffectx.h:296
int32_t uniqueID
Definition: aeffectx.h:295
VSTInstanceArray mSlaves
Definition: VSTInstance.h:112
AEffect * mAEffect
Definition: VSTWrapper.h:124
void callSetChunk(bool isPgm, int len, void *buf)
Definition: VSTWrapper.cpp:721

References VSTWrapper::callSetChunk(), VSTWrapper::mAEffect, mSlaves, AEffect::numParams, AEffect::uniqueID, and AEffect::version.

Referenced by DeferChunkApplication(), and RealtimeProcessStart().

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

◆ Automate()

void VSTInstance::Automate ( int  index,
float  value 
)
overridevirtual

Reimplemented from VSTUIWrapper.

Definition at line 440 of file VSTInstance.cpp.

441{
442 if (mMainThreadId != std::this_thread::get_id())
443 return;
444
446 {
447 mpOwningValidator->Automate(index, value);
448 }
449}
VSTUIWrapper * mpOwningValidator
Definition: VSTInstance.h:122
virtual void Automate(int index, float value)
std::thread::id mMainThreadId
Definition: VSTWrapper.h:125

References VSTUIWrapper::Automate(), VSTWrapper::mMainThreadId, and mpOwningValidator.

Here is the call graph for this function:

◆ callProcessReplacing()

void VSTInstance::callProcessReplacing ( const float *const *  inputs,
float *const *  outputs,
int  sampleframes 
)
private

Definition at line 432 of file VSTInstance.cpp.

434{
436 const_cast<float**>(inputs),
437 const_cast<float**>(outputs), sampleframes);
438}
void(* processReplacing)(AEffect *, float **, float **, int)
Definition: aeffectx.h:298

References VSTWrapper::mAEffect, and AEffect::processReplacing.

Referenced by ProcessBlock().

Here is the caller graph for this function:

◆ ChunkMustBeAppliedInMainThread()

bool VSTInstance::ChunkMustBeAppliedInMainThread ( ) const
private

Definition at line 249 of file VSTInstance.cpp.

250{
251 // Some plugins (e.g. Melda) can not have their chunk set in the
252 // audio thread, resulting in making the whole app hang.
253 // This is why we defer the setting of the chunk in the main thread.
254
255 const bool IsAudioThread = (mMainThreadId != std::this_thread::get_id());
256
257 return IsAudioThread && mIsMeldaPlugin;
258}

References mIsMeldaPlugin, and VSTWrapper::mMainThreadId.

Referenced by RealtimeProcessStart().

Here is the caller graph for this function:

◆ DeferChunkApplication()

void VSTInstance::DeferChunkApplication ( )

Definition at line 225 of file VSTInstance.cpp.

226{
227 std::lock_guard<std::mutex> guard(mDeferredChunkMutex);
228
229 if (! mChunkToSetAtIdleTime.empty() )
230 {
232 mChunkToSetAtIdleTime.resize(0);
233 }
234}
void ApplyChunk(std::vector< char > &chunk)
std::mutex mDeferredChunkMutex
Definition: VSTInstance.h:126
std::vector< char > mChunkToSetAtIdleTime
Definition: VSTInstance.h:127

References ApplyChunk(), mChunkToSetAtIdleTime, and mDeferredChunkMutex.

Referenced by VSTEditor::OnIdle().

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

◆ DoProcessInitialize()

bool VSTInstance::DoProcessInitialize ( double  sampleRate)

Definition at line 96 of file VSTInstance.cpp.

97{
98 // Initialize time info
99 memset(&mTimeInfo, 0, sizeof(mTimeInfo));
101 mTimeInfo.nanoSeconds = wxGetUTCTimeMillis().ToDouble();
102 mTimeInfo.tempo = 120.0;
106
107 // Set processing parameters...power must be off for this
110
111 // Turn on the power
112 PowerOn();
113
114 // Set the initial buffer delay
116
117 mReady = true;
118 return true;
119}
const int effSetBlockSize
Definition: aeffectx.h:103
const int kVstTransportPlaying
Definition: aeffectx.h:157
const int effSetSampleRate
Definition: aeffectx.h:102
int initialDelay
Definition: aeffectx.h:284
void PowerOn()
void SetBufferDelay(int samples) override
intptr_t callDispatcher(int opcode, int index, intptr_t value, void *ptr, float opt) override
Definition: VSTWrapper.cpp:682

References VSTWrapper::callDispatcher(), effSetBlockSize, effSetSampleRate, VstTimeInfo::flags, AEffect::initialDelay, kVstNanosValid, kVstTempoValid, kVstTransportPlaying, VSTWrapper::mAEffect, mBlockSize, mReady, VSTWrapper::mTimeInfo, VstTimeInfo::nanoSeconds, PowerOn(), anonymous_namespace{ClipSegmentTest.cpp}::sampleRate, VstTimeInfo::sampleRate, SetBufferDelay(), VstTimeInfo::tempo, VstTimeInfo::timeSigDenominator, and VstTimeInfo::timeSigNumerator.

Referenced by ProcessInitialize(), and VSTInstance().

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

◆ GetAudioInCount()

unsigned VSTInstance::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 37 of file VSTInstance.cpp.

38{
39 return mAudioIns;
40}
unsigned mAudioIns
Definition: VSTWrapper.h:220

References VSTWrapper::mAudioIns.

Referenced by SetBlockSize().

Here is the caller graph for this function:

◆ GetAudioOutCount()

unsigned VSTInstance::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 42 of file VSTInstance.cpp.

43{
44 return mAudioOuts;
45}
unsigned mAudioOuts
Definition: VSTWrapper.h:221

References VSTWrapper::mAudioOuts.

Referenced by SetBlockSize().

Here is the caller graph for this function:

◆ GetBlockSize()

size_t VSTInstance::GetBlockSize ( ) const
overridevirtual

Implements EffectInstance.

Definition at line 64 of file VSTInstance.cpp.

65{
66 return mBlockSize;
67}

References mBlockSize.

◆ GetLatency()

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

Default implementation returns 0

Reimplemented from EffectInstance.

Definition at line 69 of file VSTInstance.cpp.

71{
72 if (mUseLatency)
73 return mBufferDelay;
74 return 0;
75}
int mBufferDelay
Definition: VSTWrapper.h:266

◆ HasGUI()

bool VSTInstance::HasGUI ( ) const
inline

Definition at line 105 of file VSTInstance.h.

105{ return mGui; }

References VSTWrapper::mGui.

◆ IsReady()

bool VSTInstance::IsReady ( )

Definition at line 77 of file VSTInstance.cpp.

78{
79 return mReady;
80}

References mReady.

Referenced by VSTInstance().

Here is the caller graph for this function:

◆ MakeMessage() [1/2]

std::unique_ptr< EffectInstance::Message > VSTInstance::MakeMessage ( ) const
overridevirtual

Called on the main thread, in which the result may be cloned.

Default implementation returns a null

Reimplemented from EffectInstance.

Definition at line 17 of file VSTInstance.cpp.

18{
19 // The purpose here is just to allocate vectors (chunk and paramVector)
20 // with sufficient size, not to get the values too
22 FetchSettings(settings, /* doFetch = */ false);
23
24 VSTMessage::ParamVector paramVector;
25 paramVector.resize(mAEffect->numParams, std::nullopt);
26
27 return std::make_unique<VSTMessage>( std::move(settings.mChunk), std::move(paramVector) );
28}
static Settings & settings()
Definition: TrackInfo.cpp:51
std::vector< std::optional< double > > ParamVector
Definition: VSTWrapper.h:300
bool FetchSettings(VSTSettings &vst3Settings, bool doFetch=true) const

References VSTWrapper::FetchSettings(), VSTWrapper::mAEffect, AEffect::numParams, and settings().

Referenced by VSTEditor::ValidateUI().

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

◆ MakeMessage() [2/2]

std::unique_ptr< EffectInstance::Message > VSTInstance::MakeMessage ( int  id,
double  value 
) const

Definition at line 31 of file VSTInstance.cpp.

32{
33 return std::make_unique<VSTMessage>(id, value, mAEffect->numParams);
34}

References VSTWrapper::mAEffect, and AEffect::numParams.

◆ NeedIdle()

void VSTInstance::NeedIdle ( )
overridevirtual

Reimplemented from VSTUIWrapper.

Definition at line 369 of file VSTInstance.cpp.

370{
372 {
374 }
375}
virtual void NeedIdle()
Definition: VSTWrapper.cpp:623

References mpOwningValidator, and VSTUIWrapper::NeedIdle().

Here is the call graph for this function:

◆ OnePresetWasLoadedWhilePlaying()

bool VSTInstance::OnePresetWasLoadedWhilePlaying ( )

Definition at line 220 of file VSTInstance.cpp.

221{
222 return mPresetLoadedWhilePlaying.exchange(false);
223}
std::atomic_bool mPresetLoadedWhilePlaying
Definition: VSTInstance.h:124

References mPresetLoadedWhilePlaying.

◆ PowerOff()

void VSTInstance::PowerOff ( )

Definition at line 395 of file VSTInstance.cpp.

396{
397 if (mHasPower)
398 {
399 // Tell the effect we're going to stop processing
400 if (mVstVersion >= 2)
401 {
402 callDispatcher(effStopProcess, 0, 0, NULL, 0.0);
403 }
404
405 // Turn the power off
406 callDispatcher(effMainsChanged, 0, 0, NULL, 0.0);
407
408 // Set state
409 mHasPower = false;
410 }
411}
const int effMainsChanged
Definition: aeffectx.h:104
const int effStopProcess
Definition: aeffectx.h:142
bool mHasPower
Definition: VSTInstance.h:114
int mVstVersion
Definition: VSTWrapper.h:165

References VSTWrapper::callDispatcher(), effMainsChanged, effStopProcess, mHasPower, and VSTWrapper::mVstVersion.

Referenced by ProcessFinalize(), RealtimeSuspend(), and ~VSTInstance().

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

◆ PowerOn()

void VSTInstance::PowerOn ( )

Definition at line 377 of file VSTInstance.cpp.

378{
379 if (!mHasPower)
380 {
381 // Turn the power on
382 callDispatcher(effMainsChanged, 0, 1, NULL, 0.0);
383
384 // Tell the effect we're going to start processing
385 if (mVstVersion >= 2)
386 {
387 callDispatcher(effStartProcess, 0, 0, NULL, 0.0);
388 }
389
390 // Set state
391 mHasPower = true;
392 }
393}
const int effStartProcess
Definition: aeffectx.h:141

References VSTWrapper::callDispatcher(), effMainsChanged, effStartProcess, mHasPower, and VSTWrapper::mVstVersion.

Referenced by VSTEditor::BuildFancy(), DoProcessInitialize(), and RealtimeResume().

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

◆ ProcessBlock()

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

Called for destructive effect computation.

Implements EffectInstance.

Definition at line 133 of file VSTInstance.cpp.

135{
136 // Only call the effect if there's something to do...some do not like zero-length block
137 if (blockLen)
138 {
139 // Go let the plugin moleste the samples
140 callProcessReplacing(inBlock, outBlock, blockLen);
141
142 // And track the position
143 mTimeInfo.samplePos += (double) blockLen;
144 }
145
146 return blockLen;
147}
void callProcessReplacing(const float *const *inputs, float *const *outputs, int sampleframes)

References callProcessReplacing(), VSTWrapper::mTimeInfo, and VstTimeInfo::samplePos.

Referenced by RealtimeProcess().

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

◆ ProcessFinalize()

bool VSTInstance::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 121 of file VSTInstance.cpp.

122{
123 return GuardedCall<bool>([&] {
124 mReady = false;
125
126 PowerOff();
127
128 return true;
129 });
130
131}

References mReady, and PowerOff().

Here is the call graph for this function:

◆ ProcessInitialize()

bool VSTInstance::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 82 of file VSTInstance.cpp.

84{
85 // Issue 3942: Copy the contents of settings first.
86 // settings may refer to what is in the RealtimeEffectState, but that might
87 // get reassigned by EffectSettingsAccess::Set, when the validator's
88 // Automate() is called-back by the plug-in during callSetParameter.
89 // So this avoids a dangling reference.
90 auto copiedSettings = GetSettings(settings);
91 StoreSettings(copiedSettings);
92
94}
static VSTSettings & GetSettings(EffectSettings &settings)
Definition: VSTWrapper.h:103
bool StoreSettings(const VSTSettings &vst3settings) const

References DoProcessInitialize(), VSTWrapper::GetSettings(), anonymous_namespace{ClipSegmentTest.cpp}::sampleRate, settings(), and VSTWrapper::StoreSettings().

Referenced by RealtimeInitialize().

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

◆ RealtimeAddProcessor()

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

Reimplemented from EffectInstance.

Definition at line 159 of file VSTInstance.cpp.

161{
162 if (!mRecruited)
163 {
164 // Assign self to the first processor
165 mRecruited = true;
166 return true;
167 }
168
169 auto &effect = static_cast<const PerTrackEffect &>(mProcessor);
170 auto slave = std::make_unique<VSTInstance>(
171 const_cast<PerTrackEffect &>(effect),
173
174 slave->SetBlockSize(mBlockSize);
175
176 if (!slave->ProcessInitialize(settings, sampleRate, ChannelNames()))
177 return false;
178
179 mSlaves.emplace_back(move(slave));
180 return true;
181}
ChannelName
const PerTrackEffect & mProcessor
Base class for many of the effects in Audacity.
bool mRecruited
Definition: VSTInstance.h:120
PluginPath mPath
Definition: VSTWrapper.h:203

References mBlockSize, VSTWrapper::mPath, PerTrackEffect::Instance::mProcessor, mRecruited, mSlaves, mUseLatency, mUserBlockSize, anonymous_namespace{ClipSegmentTest.cpp}::sampleRate, and settings().

Here is the call graph for this function:

◆ RealtimeFinalize()

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

Reimplemented from EffectInstance.

Definition at line 183 of file VSTInstance.cpp.

184{
185return GuardedCall<bool>([&]{
186
189
190 mRecruited = false;
191
192 for (const auto &slave : mSlaves)
193 slave->ProcessFinalize();
194 mSlaves.clear();
195
196 return ProcessFinalize();
197});
198}
for(int ii=0, nn=names.size();ii< nn;++ii)
bool ProcessFinalize() noexcept override
virtual void Flush()
Definition: VSTWrapper.cpp:616

References for().

Here is the call graph for this function:

◆ RealtimeInitialize()

bool VSTInstance::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 149 of file VSTInstance.cpp.

150{
151 // Temporarily disconnect from any validator, so that setting the chunk
152 // does not cause Automate() callbacks (as some effects will do) that then
153 // would send slider movement messages that might destroy information in
154 // the settings.
155 auto vr = valueRestorer(mpOwningValidator, (VSTUIWrapper*)nullptr);
157}
ValueRestorer< T > valueRestorer(T &var)
inline functions provide convenient parameter type deduction
Definition: MemoryX.h:253
bool ProcessInitialize(EffectSettings &settings, double sampleRate, ChannelNames chanMap) override
Definition: VSTInstance.cpp:82

References mpOwningValidator, ProcessInitialize(), anonymous_namespace{ClipSegmentTest.cpp}::sampleRate, settings(), and valueRestorer().

Here is the call graph for this function:

◆ RealtimeProcess()

size_t VSTInstance::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 336 of file VSTInstance.cpp.

338{
339 if (!mRecruited)
340 {
341 // unexpected!
342 return 0;
343 }
344
345 wxASSERT(numSamples <= mBlockSize);
346
347 if (group == 0)
348 {
349 // use the recruited "this" instance
350 return ProcessBlock(settings, inbuf, outbuf, numSamples);
351 }
352 else if (group <= mSlaves.size())
353 {
354 // use the slave which maps to the group
355 return mSlaves[group - 1]->ProcessBlock(settings, inbuf, outbuf, numSamples);
356 }
357 else
358 return 0;
359}
size_t ProcessBlock(EffectSettings &settings, const float *const *inBlock, float *const *outBlock, size_t blockLen) override
Called for destructive effect computation.

References mBlockSize, mRecruited, mSlaves, ProcessBlock(), and settings().

Here is the call graph for this function:

◆ RealtimeProcessEnd()

bool VSTInstance::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 361 of file VSTInstance.cpp.

362{
364 mDeferredChunkMutex.unlock();
365
366 return true;
367}
bool ChunkMustBeAppliedInMainThread() const

◆ RealtimeProcessStart()

bool VSTInstance::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 265 of file VSTInstance.cpp.

266{
267 const bool applyChunkInMainThread = ChunkMustBeAppliedInMainThread();
268
269 if (applyChunkInMainThread)
270 mDeferredChunkMutex.lock();
271
272 if (!package.pMessage)
273 return true;
274
275 auto& message = static_cast<VSTMessage&>(*package.pMessage);
276
277 auto &chunk = message.mChunk;
278
279 if (!chunk.empty())
280 {
281 if (applyChunkInMainThread)
282 {
283 // Apply the chunk later
284 //
285 mChunkToSetAtIdleTime = chunk;
286 }
287 else
288 {
289 // Apply the chunk now
290 ApplyChunk(chunk);
291 }
292
293 // Don't apply the chunk again until another message supplies a chunk
294 chunk.resize(0);
295
296 // Don't return yet. Maybe some slider movements also accumulated after
297 // the change of the chunk.
298
299 const bool IsAudioThread = (mMainThreadId != std::this_thread::get_id());
300 if (IsAudioThread)
301 {
302 // At the moment, the only reason why this method would be called in the audio thread,
303 // is because a preset was loaded while playing
304
305 mPresetLoadedWhilePlaying.store(true);
306 }
307
308 }
309
310
311 assert(message.mParamsVec.size() == mAEffect->numParams);
312
313 for (size_t paramID=0; paramID < mAEffect->numParams; paramID++)
314 {
315 if (message.mParamsVec[paramID])
316 {
317 float val = (float)(*message.mParamsVec[paramID]);
318
319 // set the change on the recruited "this" instance
320 callSetParameter(paramID, val);
321
322 // set the change on any existing slaves
323 for (auto& slave : mSlaves)
324 {
325 slave->callSetParameter(paramID, val);
326 }
327
328 // clear the used info
329 message.mParamsVec[paramID] = std::nullopt;
330 }
331 }
332
333 return true;
334}
std::vector< char > mChunk
Definition: VSTWrapper.h:324
void callSetParameter(int index, float value) const
Definition: VSTWrapper.cpp:704

References ApplyChunk(), VSTWrapper::callSetParameter(), ChunkMustBeAppliedInMainThread(), VSTWrapper::mAEffect, VSTMessage::mChunk, mChunkToSetAtIdleTime, mDeferredChunkMutex, VSTWrapper::mMainThreadId, mPresetLoadedWhilePlaying, mSlaves, AEffect::numParams, and EffectInstance::MessagePackage::pMessage.

Here is the call graph for this function:

◆ RealtimeResume()

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

Reimplemented from EffectInstance.

Definition at line 210 of file VSTInstance.cpp.

211{
212 PowerOn();
213
214 for (const auto &slave : mSlaves)
215 slave->PowerOn();
216
217 return true;
218}

References mSlaves, and PowerOn().

Here is the call graph for this function:

◆ RealtimeSuspend()

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

Reimplemented from EffectInstance.

Definition at line 200 of file VSTInstance.cpp.

201{
202 PowerOff();
203
204 for (const auto &slave : mSlaves)
205 slave->PowerOff();
206
207 return true;
208}

References mSlaves, and PowerOff().

Here is the call graph for this function:

◆ SetBlockSize()

size_t VSTInstance::SetBlockSize ( size_t  maxBlockSize)
overridevirtual

Implements EffectInstance.

Definition at line 47 of file VSTInstance.cpp.

48{
49 // Issue 3935 for IEM plug-ins, VST 2 versions:
50 // It is mysterious why this further limitation of size works to
51 // prevent the crashes in destructive processing, or why this is not
52 // needed for non-destructive, but here it is
53 // Those plugins report many channels (like 64) but most others will not
54 // be affected by these lines with the default size of 8192
55 // Note it may make the Block Size option of the settings dialog misleading
56 auto numChannels = std::max({ 1u, GetAudioInCount(), GetAudioOutCount() });
57 maxBlockSize = std::max(size_t(1),
58 std::min(maxBlockSize, size_t(0x8000u / numChannels)));
59
61 return mBlockSize;
62}
int min(int a, int b)
unsigned GetAudioInCount() const override
How many input buffers to allocate at once.
Definition: VSTInstance.cpp:37
unsigned GetAudioOutCount() const override
How many output buffers to allocate at once.
Definition: VSTInstance.cpp:42

References GetAudioInCount(), GetAudioOutCount(), anonymous_namespace{StaffPadTimeAndPitch.cpp}::maxBlockSize, mBlockSize, min(), and mUserBlockSize.

Here is the call graph for this function:

◆ SetBufferDelay()

void VSTInstance::SetBufferDelay ( int  samples)
overridevirtual

Reimplemented from VSTWrapper.

Definition at line 421 of file VSTInstance.cpp.

422{
423 // We do not support negative delay
424 if (samples >= 0 && mUseLatency)
425 {
426 mBufferDelay = samples;
427 }
428
429 return;
430}

References VSTWrapper::mBufferDelay, and mUseLatency.

Referenced by DoProcessInitialize().

Here is the caller graph for this function:

◆ SetOwningValidator()

void VSTInstance::SetOwningValidator ( VSTUIWrapper vi)

Definition at line 496 of file VSTInstance.cpp.

497{
499}

References mpOwningValidator.

Referenced by VSTEditor::OnClose(), and VSTEditor::~VSTEditor().

Here is the caller graph for this function:

◆ SizeWindow()

void VSTInstance::SizeWindow ( int  w,
int  h 
)
overridevirtual

Reimplemented from VSTUIWrapper.

Definition at line 413 of file VSTInstance.cpp.

414{
416 {
418 }
419}
virtual void SizeWindow(int w, int h)
Definition: VSTWrapper.cpp:643

References mpOwningValidator, and VSTUIWrapper::SizeWindow().

Here is the call graph for this function:

◆ UsesMessages()

bool VSTInstance::UsesMessages ( ) const
overridevirtualnoexcept

If true, the effect makes no use EffectSettings for inter-thread comminication

Default implementation returns false. In future, all effects should be rewritten to use messages and this function will be removed.

Reimplemented from EffectInstance.

Definition at line 260 of file VSTInstance.cpp.

261{
262 return true;
263}

Member Data Documentation

◆ mBlockSize

size_t VSTInstance::mBlockSize { 8192 }

◆ mChunkToSetAtIdleTime

std::vector<char> VSTInstance::mChunkToSetAtIdleTime {}
private

Definition at line 127 of file VSTInstance.h.

Referenced by DeferChunkApplication(), and RealtimeProcessStart().

◆ mDeferredChunkMutex

std::mutex VSTInstance::mDeferredChunkMutex
private

Definition at line 126 of file VSTInstance.h.

Referenced by DeferChunkApplication(), and RealtimeProcessStart().

◆ mHasPower

bool VSTInstance::mHasPower { false }
private

Definition at line 114 of file VSTInstance.h.

Referenced by PowerOff(), and PowerOn().

◆ mIsMeldaPlugin

bool VSTInstance::mIsMeldaPlugin { false }
private

Definition at line 133 of file VSTInstance.h.

Referenced by ChunkMustBeAppliedInMainThread(), and VSTInstance().

◆ mpOwningValidator

VSTUIWrapper* VSTInstance::mpOwningValidator {}
private

Definition at line 122 of file VSTInstance.h.

Referenced by Automate(), NeedIdle(), RealtimeInitialize(), SetOwningValidator(), and SizeWindow().

◆ mPresetLoadedWhilePlaying

std::atomic_bool VSTInstance::mPresetLoadedWhilePlaying { false }
private

Definition at line 124 of file VSTInstance.h.

Referenced by OnePresetWasLoadedWhilePlaying(), and RealtimeProcessStart().

◆ mReady

bool VSTInstance::mReady { false }
private

Definition at line 118 of file VSTInstance.h.

Referenced by DoProcessInitialize(), IsReady(), and ProcessFinalize().

◆ mRecruited

bool VSTInstance::mRecruited { false }
private

Definition at line 120 of file VSTInstance.h.

Referenced by RealtimeAddProcessor(), and RealtimeProcess().

◆ mSlaves

VSTInstanceArray VSTInstance::mSlaves
private

◆ mUseLatency

const bool VSTInstance::mUseLatency

Definition at line 82 of file VSTInstance.h.

Referenced by RealtimeAddProcessor(), and SetBufferDelay().

◆ mUserBlockSize

size_t VSTInstance::mUserBlockSize { mBlockSize }
private

Definition at line 116 of file VSTInstance.h.

Referenced by RealtimeAddProcessor(), SetBlockSize(), and VSTInstance().


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