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

#include <VSTEffect.h>

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

Public Member Functions

 VSTEffectInstance (PerTrackEffect &effect, const PluginPath &path, size_t blockSize, size_t userBlockSize, bool useLatency)
 
 ~VSTEffectInstance () 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 (VSTEffectUIWrapper *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 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 VSTEffectWrapper
 VSTEffectWrapper (const PluginPath &path)
 
 ~VSTEffectWrapper ()
 
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 (VSTEffectSettings &vst3Settings, bool doFetch=true) const
 
bool StoreSettings (const VSTEffectSettings &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 UpdateDisplay ()
 
virtual void SetBufferDelay (int samples)
 
std::unique_ptr< EffectInstance::MessageMakeMessageFS (const VSTEffectSettings &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 VSTEffectUIWrapper
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 VSTEffectWrapper
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 }
 
VSTEffectUIWrappermpOwningValidator {}
 
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 VSTEffectWrapper
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 VSTEffectWrapper
static VSTEffectSettingsGetSettings (EffectSettings &settings)
 
static const VSTEffectSettingsGetSettings (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 488 of file VSTEffect.h.

Constructor & Destructor Documentation

◆ VSTEffectInstance()

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

Definition at line 4006 of file VSTEffect.cpp.

4015 : PerTrackEffect::Instance(effect)
4016 , VSTEffectWrapper(path)
4017 , mUseLatency{ useLatency }
4018{
4019 // what also happens in the effect ctor
4020 //
4021 memset(&mTimeInfo, 0, sizeof(mTimeInfo));
4022 mTimeInfo.samplePos = 0.0;
4023 mTimeInfo.sampleRate = 44100.0; // this is a bogus value, but it's only for the display
4024 mTimeInfo.nanoSeconds = wxGetUTCTimeMillis().ToDouble();
4025 mTimeInfo.tempo = 120.0;
4029
4030 mBlockSize = blockSize;
4031 mUserBlockSize = userBlockSize;
4032
4033 Load();
4034
4035 if (!IsReady() )
4036 {
4037 // Set some defaults since some VSTs need them...these will be reset when
4038 // normal or realtime processing begins
4039 mBlockSize = 8192;
4040 DoProcessInitialize(44100.0);
4041 }
4042
4043 mIsMeldaPlugin = (mVendor == "MeldaProduction");
4044}
const int kVstNanosValid
Definition: aeffectx.h:148
const int kVstTempoValid
Definition: aeffectx.h:150
size_t mUserBlockSize
Definition: VSTEffect.h:579
bool DoProcessInitialize(double sampleRate)
Definition: VSTEffect.cpp:1120
const bool mUseLatency
Definition: VSTEffect.h:545
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
wxString mVendor
Definition: VSTEffect.h:228
VstTimeInfo mTimeInfo
Definition: VSTEffect.h:276
VSTEffectWrapper(const PluginPath &path)
Definition: VSTEffect.h:128

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

Here is the call graph for this function:

◆ ~VSTEffectInstance()

VSTEffectInstance::~VSTEffectInstance ( )
override

Definition at line 4047 of file VSTEffect.cpp.

4048{
4049 PowerOff();
4050}

References PowerOff().

Here is the call graph for this function:

Member Function Documentation

◆ ApplyChunk()

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

Definition at line 1265 of file VSTEffect.cpp.

1266{
1267 VstPatchChunkInfo info = {
1269
1270 const auto len = chunk.size();
1271 const auto data = chunk.data();
1272
1273 callSetChunk(true, len, data, &info);
1274 for (auto& slave : mSlaves)
1275 slave->callSetChunk(true, len, data, &info);
1276}
int numParams
Definition: aeffectx.h:274
int32_t version
Definition: aeffectx.h:296
int32_t uniqueID
Definition: aeffectx.h:295
VSTInstanceArray mSlaves
Definition: VSTEffect.h:575
void callSetChunk(bool isPgm, int len, void *buf)
Definition: VSTEffect.cpp:2507
AEffect * mAEffect
Definition: VSTEffect.h:135

References VSTEffectWrapper::callSetChunk(), VSTEffectWrapper::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 VSTEffectInstance::Automate ( int  index,
float  value 
)
overridevirtual

Reimplemented from VSTEffectUIWrapper.

Definition at line 3984 of file VSTEffect.cpp.

3985{
3986 if (mMainThreadId != std::this_thread::get_id())
3987 return;
3988
3990 {
3991 mpOwningValidator->Automate(index, value);
3992 }
3993}
VSTEffectUIWrapper * mpOwningValidator
Definition: VSTEffect.h:585
virtual void Automate(int index, float value)
Definition: VSTEffect.cpp:3980
std::thread::id mMainThreadId
Definition: VSTEffect.h:136

References VSTEffectUIWrapper::Automate(), VSTEffectWrapper::mMainThreadId, and mpOwningValidator.

Here is the call graph for this function:

◆ callProcessReplacing()

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

Definition at line 2473 of file VSTEffect.cpp.

2475{
2477 const_cast<float**>(inputs),
2478 const_cast<float**>(outputs), sampleframes);
2479}
void(* processReplacing)(AEffect *, float **, float **, int)
Definition: aeffectx.h:298

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

Referenced by ProcessBlock().

Here is the caller graph for this function:

◆ ChunkMustBeAppliedInMainThread()

bool VSTEffectInstance::ChunkMustBeAppliedInMainThread ( ) const
private

Definition at line 1279 of file VSTEffect.cpp.

1280{
1281 // Some plugins (e.g. Melda) can not have their chunk set in the
1282 // audio thread, resulting in making the whole app hang.
1283 // This is why we defer the setting of the chunk in the main thread.
1284
1285 const bool IsAudioThread = (mMainThreadId != std::this_thread::get_id());
1286
1287 return IsAudioThread && mIsMeldaPlugin;
1288}

References mIsMeldaPlugin, and VSTEffectWrapper::mMainThreadId.

Referenced by RealtimeProcessStart().

Here is the caller graph for this function:

◆ DeferChunkApplication()

void VSTEffectInstance::DeferChunkApplication ( )

Definition at line 1253 of file VSTEffect.cpp.

1254{
1255 std::lock_guard<std::mutex> guard(mDeferredChunkMutex);
1256
1257 if (! mChunkToSetAtIdleTime.empty() )
1258 {
1260 mChunkToSetAtIdleTime.resize(0);
1261 }
1262}
std::mutex mDeferredChunkMutex
Definition: VSTEffect.h:589
std::vector< char > mChunkToSetAtIdleTime
Definition: VSTEffect.h:590
void ApplyChunk(std::vector< char > &chunk)
Definition: VSTEffect.cpp:1265

References ApplyChunk(), mChunkToSetAtIdleTime, and mDeferredChunkMutex.

Referenced by VSTEffectEditor::OnIdle().

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

◆ DoProcessInitialize()

bool VSTEffectInstance::DoProcessInitialize ( double  sampleRate)

Definition at line 1120 of file VSTEffect.cpp.

1121{
1122 // Initialize time info
1123 memset(&mTimeInfo, 0, sizeof(mTimeInfo));
1124 mTimeInfo.sampleRate = sampleRate;
1125 mTimeInfo.nanoSeconds = wxGetUTCTimeMillis().ToDouble();
1126 mTimeInfo.tempo = 120.0;
1130
1131 // Set processing parameters...power must be off for this
1132 callDispatcher(effSetSampleRate, 0, 0, NULL, sampleRate);
1134
1135 // Turn on the power
1136 PowerOn();
1137
1138 // Set the initial buffer delay
1140
1141 mReady = true;
1142 return true;
1143}
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 SetBufferDelay(int samples) override
Definition: VSTEffect.cpp:2414
intptr_t callDispatcher(int opcode, int index, intptr_t value, void *ptr, float opt) override
Definition: VSTEffect.cpp:2456

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

Referenced by ProcessInitialize(), and VSTEffectInstance().

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

◆ GetAudioInCount()

unsigned VSTEffectInstance::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 1061 of file VSTEffect.cpp.

1062{
1063 return mAudioIns;
1064}
unsigned mAudioIns
Definition: VSTEffect.h:232

References VSTEffectWrapper::mAudioIns.

Referenced by SetBlockSize().

Here is the caller graph for this function:

◆ GetAudioOutCount()

unsigned VSTEffectInstance::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 1066 of file VSTEffect.cpp.

1067{
1068 return mAudioOuts;
1069}
unsigned mAudioOuts
Definition: VSTEffect.h:233

References VSTEffectWrapper::mAudioOuts.

Referenced by SetBlockSize().

Here is the caller graph for this function:

◆ GetBlockSize()

size_t VSTEffectInstance::GetBlockSize ( ) const
overridevirtual

Implements EffectInstance.

Definition at line 1088 of file VSTEffect.cpp.

1089{
1090 return mBlockSize;
1091}

References mBlockSize.

◆ GetLatency()

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

Default implementation returns 0

Reimplemented from EffectInstance.

Definition at line 1093 of file VSTEffect.cpp.

1095{
1096 if (mUseLatency)
1097 return mBufferDelay;
1098 return 0;
1099}

◆ HasGUI()

bool VSTEffectInstance::HasGUI ( ) const
inline

Definition at line 568 of file VSTEffect.h.

568{ return mGui; }

References VSTEffectWrapper::mGui.

◆ IsReady()

bool VSTEffectInstance::IsReady ( )

Definition at line 1101 of file VSTEffect.cpp.

1102{
1103 return mReady;
1104}

References mReady.

Referenced by VSTEffectInstance().

Here is the caller graph for this function:

◆ MakeMessage() [1/2]

std::unique_ptr< EffectInstance::Message > VSTEffectInstance::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 1021 of file VSTEffect.cpp.

1022{
1023 // The purpose here is just to allocate vectors (chunk and paramVector)
1024 // with sufficient size, not to get the values too
1026 FetchSettings(settings, /* doFetch = */ false);
1027
1028 VSTEffectMessage::ParamVector paramVector;
1029 paramVector.resize(mAEffect->numParams, std::nullopt);
1030
1031 return std::make_unique<VSTEffectMessage>( std::move(settings.mChunk), std::move(paramVector) );
1032}
static Settings & settings()
Definition: TrackInfo.cpp:87
bool FetchSettings(VSTEffectSettings &vst3Settings, bool doFetch=true) const
Definition: VSTEffect.cpp:3783

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

Referenced by VSTEffectEditor::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 > VSTEffectInstance::MakeMessage ( int  id,
double  value 
) const

Definition at line 1035 of file VSTEffect.cpp.

1036{
1037 return std::make_unique<VSTEffectMessage>(id, value, mAEffect->numParams);
1038}

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

◆ NeedIdle()

void VSTEffectInstance::NeedIdle ( )
overridevirtual

Reimplemented from VSTEffectUIWrapper.

Definition at line 2238 of file VSTEffect.cpp.

2239{
2241 {
2243 }
2244}
virtual void NeedIdle()
Definition: VSTEffect.cpp:2234

References mpOwningValidator, and VSTEffectUIWrapper::NeedIdle().

Here is the call graph for this function:

◆ OnePresetWasLoadedWhilePlaying()

bool VSTEffectInstance::OnePresetWasLoadedWhilePlaying ( )

Definition at line 1248 of file VSTEffect.cpp.

1249{
1250 return mPresetLoadedWhilePlaying.exchange(false);
1251}
std::atomic_bool mPresetLoadedWhilePlaying
Definition: VSTEffect.h:587

References mPresetLoadedWhilePlaying.

◆ PowerOff()

void VSTEffectInstance::PowerOff ( )

Definition at line 2294 of file VSTEffect.cpp.

2295{
2296 if (mHasPower)
2297 {
2298 // Tell the effect we're going to stop processing
2299 if (mVstVersion >= 2)
2300 {
2301 callDispatcher(effStopProcess, 0, 0, NULL, 0.0);
2302 }
2303
2304 // Turn the power off
2305 callDispatcher(effMainsChanged, 0, 0, NULL, 0.0);
2306
2307 // Set state
2308 mHasPower = false;
2309 }
2310}
const int effMainsChanged
Definition: aeffectx.h:104
const int effStopProcess
Definition: aeffectx.h:142

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

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

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

◆ PowerOn()

void VSTEffectInstance::PowerOn ( )

Definition at line 2276 of file VSTEffect.cpp.

2277{
2278 if (!mHasPower)
2279 {
2280 // Turn the power on
2281 callDispatcher(effMainsChanged, 0, 1, NULL, 0.0);
2282
2283 // Tell the effect we're going to start processing
2284 if (mVstVersion >= 2)
2285 {
2286 callDispatcher(effStartProcess, 0, 0, NULL, 0.0);
2287 }
2288
2289 // Set state
2290 mHasPower = true;
2291 }
2292}
const int effStartProcess
Definition: aeffectx.h:141

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

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

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

◆ ProcessBlock()

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

Called for destructive effect computation.

Implements EffectInstance.

Definition at line 1159 of file VSTEffect.cpp.

1161{
1162 // Only call the effect if there's something to do...some do not like zero-length block
1163 if (blockLen)
1164 {
1165 // Go let the plugin moleste the samples
1166 callProcessReplacing(inBlock, outBlock, blockLen);
1167
1168 // And track the position
1169 mTimeInfo.samplePos += (double) blockLen;
1170 }
1171
1172 return blockLen;
1173}
void callProcessReplacing(const float *const *inputs, float *const *outputs, int sampleframes)
Definition: VSTEffect.cpp:2473

References callProcessReplacing(), VSTEffectWrapper::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 VSTEffectInstance::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:

Implements EffectInstance.

Definition at line 1146 of file VSTEffect.cpp.

1147{
1148 return GuardedCall<bool>([&] {
1149 mReady = false;
1150
1151 PowerOff();
1152
1153 return true;
1154 });
1155
1156}

References mReady, and PowerOff().

Here is the call graph for this function:

◆ ProcessInitialize()

bool VSTEffectInstance::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

Implements EffectInstance.

Definition at line 1106 of file VSTEffect.cpp.

1108{
1109 // Issue 3942: Copy the contents of settings first.
1110 // settings may refer to what is in the RealtimeEffectState, but that might
1111 // get reassigned by EffectSettingsAccess::Set, when the validator's
1112 // Automate() is called-back by the plug-in during callSetParameter.
1113 // So this avoids a dangling reference.
1114 auto copiedSettings = GetSettings(settings);
1115 StoreSettings(copiedSettings);
1116
1117 return DoProcessInitialize(sampleRate);
1118}
bool StoreSettings(const VSTEffectSettings &vst3settings) const
Definition: VSTEffect.cpp:3833
static VSTEffectSettings & GetSettings(EffectSettings &settings)
Definition: VSTEffect.h:114

References DoProcessInitialize(), VSTEffectWrapper::GetSettings(), settings(), and VSTEffectWrapper::StoreSettings().

Referenced by RealtimeInitialize().

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

◆ RealtimeAddProcessor()

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

Reimplemented from EffectInstance.

Definition at line 1186 of file VSTEffect.cpp.

1188{
1189 if (!mRecruited)
1190 {
1191 // Assign self to the first processor
1192 mRecruited = true;
1193 return true;
1194 }
1195
1196 auto &effect = static_cast<const PerTrackEffect &>(mProcessor);
1197 auto slave = std::make_unique<VSTEffectInstance>(
1198 const_cast<PerTrackEffect &>(effect),
1200
1201 slave->SetBlockSize(mBlockSize);
1202
1203 if (!slave->ProcessInitialize(settings, sampleRate, ChannelNames()))
1204 return false;
1205
1206 mSlaves.emplace_back(move(slave));
1207 return true;
1208}
ChannelName
const PerTrackEffect & mProcessor
Base class for many of the effects in Audacity.
PluginPath mPath
Definition: VSTEffect.h:214

References mBlockSize, VSTEffectWrapper::mPath, PerTrackEffect::Instance::mProcessor, mRecruited, mSlaves, mUseLatency, mUserBlockSize, and settings().

Here is the call graph for this function:

◆ RealtimeFinalize()

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

Reimplemented from EffectInstance.

Definition at line 1210 of file VSTEffect.cpp.

1211{
1212return GuardedCall<bool>([&]{
1213
1216
1217 mRecruited = false;
1218
1219 for (const auto &slave : mSlaves)
1220 slave->ProcessFinalize();
1221 mSlaves.clear();
1222
1223 return ProcessFinalize();
1224});
1225}
for(int ii=0, nn=names.size();ii< nn;++ii)
bool ProcessFinalize() noexcept override
Definition: VSTEffect.cpp:1146
virtual void Flush()
Definition: VSTEffect.cpp:2201

References for().

Here is the call graph for this function:

◆ RealtimeInitialize()

bool VSTEffectInstance::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 1176 of file VSTEffect.cpp.

1177{
1178 // Temporarily disconnect from any validator, so that setting the chunk
1179 // does not cause Automate() callbacks (as some effects will do) that then
1180 // would send slider movement messages that might destroy information in
1181 // the settings.
1183 return ProcessInitialize(settings, sampleRate, {});
1184}
ValueRestorer< T > valueRestorer(T &var)
inline functions provide convenient parameter type deduction
Definition: MemoryX.h:251
bool ProcessInitialize(EffectSettings &settings, double sampleRate, ChannelNames chanMap) override
Definition: VSTEffect.cpp:1106

References mpOwningValidator, ProcessInitialize(), settings(), and valueRestorer().

Here is the call graph for this function:

◆ RealtimeProcess()

size_t VSTEffectInstance::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 1367 of file VSTEffect.cpp.

1369{
1370 if (!mRecruited)
1371 {
1372 // unexpected!
1373 return 0;
1374 }
1375
1376 wxASSERT(numSamples <= mBlockSize);
1377
1378 if (group == 0)
1379 {
1380 // use the recruited "this" instance
1381 return ProcessBlock(settings, inbuf, outbuf, numSamples);
1382 }
1383 else if (group <= mSlaves.size())
1384 {
1385 // use the slave which maps to the group
1386 return mSlaves[group - 1]->ProcessBlock(settings, inbuf, outbuf, numSamples);
1387 }
1388 else
1389 return 0;
1390}
size_t ProcessBlock(EffectSettings &settings, const float *const *inBlock, float *const *outBlock, size_t blockLen) override
Called for destructive effect computation.
Definition: VSTEffect.cpp:1159

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

Here is the call graph for this function:

◆ RealtimeProcessEnd()

bool VSTEffectInstance::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 1392 of file VSTEffect.cpp.

1393{
1395 mDeferredChunkMutex.unlock();
1396
1397 return true;
1398}
bool ChunkMustBeAppliedInMainThread() const
Definition: VSTEffect.cpp:1279

◆ RealtimeProcessStart()

bool VSTEffectInstance::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 1296 of file VSTEffect.cpp.

1297{
1298 const bool applyChunkInMainThread = ChunkMustBeAppliedInMainThread();
1299
1300 if (applyChunkInMainThread)
1301 mDeferredChunkMutex.lock();
1302
1303 if (!package.pMessage)
1304 return true;
1305
1306 auto& message = static_cast<VSTEffectMessage&>(*package.pMessage);
1307
1308 auto &chunk = message.mChunk;
1309
1310 if (!chunk.empty())
1311 {
1312 if (applyChunkInMainThread)
1313 {
1314 // Apply the chunk later
1315 //
1316 mChunkToSetAtIdleTime = chunk;
1317 }
1318 else
1319 {
1320 // Apply the chunk now
1321 ApplyChunk(chunk);
1322 }
1323
1324 // Don't apply the chunk again until another message supplies a chunk
1325 chunk.resize(0);
1326
1327 // Don't return yet. Maybe some slider movements also accumulated after
1328 // the change of the chunk.
1329
1330 const bool IsAudioThread = (mMainThreadId != std::this_thread::get_id());
1331 if (IsAudioThread)
1332 {
1333 // At the moment, the only reason why this method would be called in the audio thread,
1334 // is because a preset was loaded while playing
1335
1336 mPresetLoadedWhilePlaying.store(true);
1337 }
1338
1339 }
1340
1341
1342 assert(message.mParamsVec.size() == mAEffect->numParams);
1343
1344 for (size_t paramID=0; paramID < mAEffect->numParams; paramID++)
1345 {
1346 if (message.mParamsVec[paramID])
1347 {
1348 float val = (float)(*message.mParamsVec[paramID]);
1349
1350 // set the change on the recruited "this" instance
1351 callSetParameter(paramID, val);
1352
1353 // set the change on any existing slaves
1354 for (auto& slave : mSlaves)
1355 {
1356 slave->callSetParameter(paramID, val);
1357 }
1358
1359 // clear the used info
1360 message.mParamsVec[paramID] = std::nullopt;
1361 }
1362 }
1363
1364 return true;
1365}
void callSetParameter(int index, float value) const
Definition: VSTEffect.cpp:2488

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

Here is the call graph for this function:

◆ RealtimeResume()

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

Reimplemented from EffectInstance.

Definition at line 1237 of file VSTEffect.cpp.

1238{
1239 PowerOn();
1240
1241 for (const auto &slave : mSlaves)
1242 slave->PowerOn();
1243
1244 return true;
1245}

References mSlaves, and PowerOn().

Here is the call graph for this function:

◆ RealtimeSuspend()

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

Reimplemented from EffectInstance.

Definition at line 1227 of file VSTEffect.cpp.

1228{
1229 PowerOff();
1230
1231 for (const auto &slave : mSlaves)
1232 slave->PowerOff();
1233
1234 return true;
1235}

References mSlaves, and PowerOff().

Here is the call graph for this function:

◆ SetBlockSize()

size_t VSTEffectInstance::SetBlockSize ( size_t  maxBlockSize)
overridevirtual

Implements EffectInstance.

Definition at line 1071 of file VSTEffect.cpp.

1072{
1073 // Issue 3935 for IEM plug-ins, VST 2 versions:
1074 // It is mysterious why this further limitation of size works to
1075 // prevent the crashes in destructive processing, or why this is not
1076 // needed for non-destructive, but here it is
1077 // Those plugins report many channels (like 64) but most others will not
1078 // be affected by these lines with the default size of 8192
1079 // Note it may make the Block Size option of the settings dialog misleading
1080 auto numChannels = std::max({ 1u, GetAudioInCount(), GetAudioOutCount() });
1081 maxBlockSize = std::max(size_t(1),
1082 std::min(maxBlockSize, size_t(0x8000u / numChannels)));
1083
1084 mBlockSize = std::min( maxBlockSize, mUserBlockSize );
1085 return mBlockSize;
1086}
int min(int a, int b)
unsigned GetAudioInCount() const override
How many input buffers to allocate at once.
Definition: VSTEffect.cpp:1061
unsigned GetAudioOutCount() const override
How many output buffers to allocate at once.
Definition: VSTEffect.cpp:1066

References GetAudioInCount(), GetAudioOutCount(), mBlockSize, min(), and mUserBlockSize.

Here is the call graph for this function:

◆ SetBufferDelay()

void VSTEffectInstance::SetBufferDelay ( int  samples)
overridevirtual

Reimplemented from VSTEffectWrapper.

Definition at line 2414 of file VSTEffect.cpp.

2415{
2416 // We do not support negative delay
2417 if (samples >= 0 && mUseLatency)
2418 {
2419 mBufferDelay = samples;
2420 }
2421
2422 return;
2423}

References VSTEffectWrapper::mBufferDelay, and mUseLatency.

Referenced by DoProcessInitialize().

Here is the caller graph for this function:

◆ SetOwningValidator()

void VSTEffectInstance::SetOwningValidator ( VSTEffectUIWrapper vi)

Definition at line 4053 of file VSTEffect.cpp.

4054{
4055 mpOwningValidator = vi;
4056}

References mpOwningValidator.

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

Here is the caller graph for this function:

◆ SizeWindow()

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

Reimplemented from VSTEffectUIWrapper.

Definition at line 2316 of file VSTEffect.cpp.

2317{
2319 {
2321 }
2322}
virtual void SizeWindow(int w, int h)
Definition: VSTEffect.cpp:2312

References mpOwningValidator, and VSTEffectUIWrapper::SizeWindow().

Here is the call graph for this function:

◆ UsesMessages()

bool VSTEffectInstance::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 1291 of file VSTEffect.cpp.

1292{
1293 return true;
1294}

Member Data Documentation

◆ mBlockSize

size_t VSTEffectInstance::mBlockSize { 8192 }

◆ mChunkToSetAtIdleTime

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

Definition at line 590 of file VSTEffect.h.

Referenced by DeferChunkApplication(), and RealtimeProcessStart().

◆ mDeferredChunkMutex

std::mutex VSTEffectInstance::mDeferredChunkMutex
private

Definition at line 589 of file VSTEffect.h.

Referenced by DeferChunkApplication(), and RealtimeProcessStart().

◆ mHasPower

bool VSTEffectInstance::mHasPower { false }
private

Definition at line 577 of file VSTEffect.h.

Referenced by PowerOff(), and PowerOn().

◆ mIsMeldaPlugin

bool VSTEffectInstance::mIsMeldaPlugin { false }
private

Definition at line 596 of file VSTEffect.h.

Referenced by ChunkMustBeAppliedInMainThread(), and VSTEffectInstance().

◆ mpOwningValidator

VSTEffectUIWrapper* VSTEffectInstance::mpOwningValidator {}
private

Definition at line 585 of file VSTEffect.h.

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

◆ mPresetLoadedWhilePlaying

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

Definition at line 587 of file VSTEffect.h.

Referenced by OnePresetWasLoadedWhilePlaying(), and RealtimeProcessStart().

◆ mReady

bool VSTEffectInstance::mReady { false }
private

Definition at line 581 of file VSTEffect.h.

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

◆ mRecruited

bool VSTEffectInstance::mRecruited { false }
private

Definition at line 583 of file VSTEffect.h.

Referenced by RealtimeAddProcessor(), and RealtimeProcess().

◆ mSlaves

VSTInstanceArray VSTEffectInstance::mSlaves
private

◆ mUseLatency

const bool VSTEffectInstance::mUseLatency

Definition at line 545 of file VSTEffect.h.

Referenced by RealtimeAddProcessor(), and SetBufferDelay().

◆ mUserBlockSize

size_t VSTEffectInstance::mUserBlockSize { mBlockSize }
private

Definition at line 579 of file VSTEffect.h.

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


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