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

VST3Effect factory. More...

#include <VST3EffectsModule.h>

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

Classes

struct  Factory
 

Public Member Functions

PluginPath GetPath () const override
 
ComponentInterfaceSymbol GetSymbol () const override
 
VendorSymbol GetVendor () const override
 
wxString GetVersion () const override
 
TranslatableString GetDescription () const override
 
bool Initialize () override
 Called immediately after creation. Let provider initialize. More...
 
void Terminate () override
 Called just prior to deletion to allow releasing any resources. More...
 
EffectFamilySymbol GetOptionalFamilySymbol () override
 A symbol identifying the family of plug-ins provided by this. More...
 
const FileExtensionsGetFileExtensions () override
 File types associated with this protocol. More...
 
FilePath InstallPath () override
 Where plug-in files should be copied to install them. More...
 
void AutoRegisterPlugins (PluginManagerInterface &pluginManager) override
 Called so that a provider of a static set of plug-ins can register them. More...
 
bool SupportsCustomModulePaths () const override
 
PluginPaths FindModulePaths (PluginManagerInterface &pluginManager) override
 
unsigned DiscoverPluginsAtPath (const PluginPath &path, TranslatableString &errMsg, const RegistrationCallback &callback) override
 
bool CheckPluginExist (const PluginPath &path) const override
 Performs plugin/module existence check, still plugin may fail to load. Implementation should avoid loading plugins during this check. More...
 
std::unique_ptr< ComponentInterfaceLoadPlugin (const PluginPath &path) override
 Load the plug-in at a path reported by DiscoverPluginsAtPath. More...
 
std::unique_ptr< ValidatorMakeValidator () const override
 
- Public Member Functions inherited from PluginProvider
virtual ~PluginProvider ()
 
virtual bool Initialize ()=0
 Called immediately after creation. Let provider initialize. More...
 
virtual void Terminate ()=0
 Called just prior to deletion to allow releasing any resources. More...
 
virtual EffectFamilySymbol GetOptionalFamilySymbol ()=0
 A symbol identifying the family of plug-ins provided by this. More...
 
virtual const FileExtensionsGetFileExtensions ()=0
 File types associated with this protocol. More...
 
virtual FilePath InstallPath ()=0
 Where plug-in files should be copied to install them. More...
 
virtual void AutoRegisterPlugins (PluginManagerInterface &pluginManager)=0
 Called so that a provider of a static set of plug-ins can register them. More...
 
virtual bool SupportsCustomModulePaths () const
 
virtual PluginPaths FindModulePaths (PluginManagerInterface &pluginManager)=0
 
virtual unsigned DiscoverPluginsAtPath (const PluginPath &path, TranslatableString &errMsg, const RegistrationCallback &callback)=0
 
virtual bool CheckPluginExist (const PluginPath &path) const =0
 Performs plugin/module existence check, still plugin may fail to load. Implementation should avoid loading plugins during this check. More...
 
virtual std::unique_ptr< ValidatorMakeValidator () const
 
virtual std::unique_ptr< ComponentInterfaceLoadPlugin (const PluginPath &path)=0
 Load the plug-in at a path reported by DiscoverPluginsAtPath. More...
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
virtual PluginPath GetPath () const =0
 
virtual ComponentInterfaceSymbol GetSymbol () const =0
 
virtual VendorSymbol GetVendor () const =0
 
virtual wxString GetVersion () const =0
 
virtual TranslatableString GetDescription () const =0
 
TranslatableString GetName () const
 

Private Member Functions

std::shared_ptr< VST3::Hosting::Module > GetModule (const wxString &path)
 

Private Attributes

std::unordered_map< wxString, std::weak_ptr< VST3::Hosting::Module > > mModules
 

Additional Inherited Members

- Public Types inherited from PluginProvider
using RegistrationCallback = std::function< const PluginID &(PluginProvider *, ComponentInterface *) >
 Further expand a path reported by FindModulePaths. More...
 

Detailed Description

VST3Effect factory.

Definition at line 34 of file VST3EffectsModule.h.

Member Function Documentation

◆ AutoRegisterPlugins()

void VST3EffectsModule::AutoRegisterPlugins ( PluginManagerInterface pluginManager)
overridevirtual

Called so that a provider of a static set of plug-ins can register them.

Implements PluginProvider.

Definition at line 149 of file VST3EffectsModule.cpp.

150{
151}

◆ CheckPluginExist()

bool VST3EffectsModule::CheckPluginExist ( const PluginPath path) const
overridevirtual

Performs plugin/module existence check, still plugin may fail to load. Implementation should avoid loading plugins during this check.

Parameters
pathInternal plugin path/ID discovered via DiscoverPluginsAtPath or module path returned by FindModulePaths

Implements PluginProvider.

Definition at line 319 of file VST3EffectsModule.cpp.

320{
321 wxString modulePath;
322 if(VST3Utils::ParsePluginPath(path, &modulePath, nullptr))
323 return wxFileName::FileExists(modulePath) || wxFileName::DirExists(modulePath);
324
325 return wxFileName::FileExists(path) || wxFileName::DirExists(path);
326}
static bool ParsePluginPath(const wxString &pluginPath, wxString *modulePath, std::string *effectUIDString)
Definition: VST3Utils.cpp:74

References VST3Utils::ParsePluginPath().

Here is the call graph for this function:

◆ DiscoverPluginsAtPath()

unsigned VST3EffectsModule::DiscoverPluginsAtPath ( const PluginPath path,
TranslatableString errMsg,
const RegistrationCallback callback 
)
overridevirtual

Implements PluginProvider.

Definition at line 211 of file VST3EffectsModule.cpp.

213{
214 try
215 {
216 auto module = GetModule(path);
217
218 const auto moduleFactory = module->getFactory();
219 auto nEffects { 0u };
220 for(auto& classInfo : moduleFactory.classInfos())
221 {
222 if(classInfo.category() == kVstAudioEffectClass)
223 {
224 std::unique_ptr<VST3EffectBase> effect;
225 try
226 {
227 effect = Factory::Call(module, classInfo);
228 ++nEffects;
229 }
230 catch(std::exception& e)
231 {
232 wxLogError(
233 "Effect %s@%s cannot be loaded: %s",
234 classInfo.name().c_str(),
235 path.c_str(),
236 e.what()
237 );
238 }
239 catch(...)
240 {
241 wxLogError(
242 "Effect %s@%s cannot be loaded: unknown error",
243 classInfo.name().c_str(),
244 path.c_str()
245 );
246 }
247 if(effect && callback)
248 callback(this, effect.get());
249 }
250 }
251 if(nEffects == 0u)
252 throw std::runtime_error("no effects found");
253
254 return nEffects;
255 }
256 catch(std::exception& e)
257 {
258 errMsg = XO("VST3 module error: %s").Format(e.what());
259 }
260
261 return 0u;
262}
XO("Cut/Copy/Paste")
static result_type Call(Arguments &&...arguments)
Null check of the installed function is done for you.
std::shared_ptr< VST3::Hosting::Module > GetModule(const wxString &path)

References GlobalHook< Factory, std::remove_pointer_t< decltype(DefaultFunction)>, DefaultFunction, Options... >::Call(), GetModule(), and XO().

Here is the call graph for this function:

◆ FindModulePaths()

PluginPaths VST3EffectsModule::FindModulePaths ( PluginManagerInterface pluginManager)
overridevirtual

Find available "paths", which may each be presented to the user, and then reexamined (possibly loading libraries) to find one or more plug-ins

Paths are not necessarily file system paths. Only the provider reinterprets the paths.

Modules may be associated with plug-ins, one-to-many.

See also
GetFileExtensions DiscoverPluginsAtPath

Implements PluginProvider.

Definition at line 159 of file VST3EffectsModule.cpp.

160{
161 //Note: The host recursively scans these folders at startup in this order (User/Global/Application).
162 //https://developer.steinberg.help/display/VST/Plug-in+Locations
163
164 FilePaths pathList;
165#ifdef __WXMSW__
166 // Windows specific VST3 search paths
167 {
168 wxString programFilesPath;
169 if(wxGetEnv("programfiles", &programFilesPath))
170 pathList.push_back(programFilesPath + "\\Common Files\\VST3");
171 }
172#elif __WXMAC__
173 pathList.push_back("~/Library/Audio/Plug-ins/VST3/");
174 pathList.push_back("/Library/Audio/Plug-ins/VST3/");
175 pathList.push_back("/Network/Library/Audio/Plug-ins/VST3/");
176#elif __WXGTK__
177 pathList.push_back(wxGetHomeDir() + "/.vst3/");
178 pathList.push_back("/usr/lib/vst3/");
179 pathList.push_back("/usr/local/lib/vst3/");
180#endif
181
182 // bundled/app specific
183 {
184 auto path = wxFileName(PlatformCompatibility::GetExecutablePath());
185#ifdef __WXGTK__
186 path.AppendDir("vst3");
187#else
188 path.AppendDir("VST3");
189#endif
190 pathList.push_back(path.GetPath());
191 }
192 {
193 auto customPaths = pluginManager.ReadCustomPaths(*this);
194 std::copy(customPaths.begin(), customPaths.end(), std::back_inserter(pathList));
195 }
196
197 PluginPaths result;
198 VST3PluginTraverser vst3PluginTraverser([&](const wxString& pluginPath){
199 result.push_back(pluginPath);
200 });
201
202 for(const auto& path : pathList)
203 {
204 wxDir dir(path);
205 if(dir.IsOpened())
206 dir.Traverse(vst3PluginTraverser, wxEmptyString, wxDIR_DEFAULT);
207 }
208 return result;
209}
std::vector< PluginPath > PluginPaths
Definition: Identifier.h:215
virtual PluginPaths ReadCustomPaths(const PluginProvider &provider)=0
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
std::string FILES_API GetExecutablePath()
void copy(const T *src, T *dst, int32_t n)
Definition: VectorOps.h:40

References staffpad::vo::copy(), PlatformCompatibility::GetExecutablePath(), and PluginManagerInterface::ReadCustomPaths().

Here is the call graph for this function:

◆ GetDescription()

TranslatableString VST3EffectsModule::GetDescription ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 113 of file VST3EffectsModule.cpp.

114{
115 return XO("Adds the ability to use VST3 effects in Audacity.");
116}

References XO().

Here is the call graph for this function:

◆ GetFileExtensions()

const FileExtensions & VST3EffectsModule::GetFileExtensions ( )
overridevirtual

File types associated with this protocol.

"Paths" returned by FindModulePaths() and passed back to DiscoverPluginsAtPath() have provider-specific meaning. They are not necessarily file system paths to existent files that could be placed in any folder and queried for plug-in information.

This function returns nonempty only when that is the case, and lists the possible extensions of such files (an empty string in a nonempty array means any file is a candidate).

Implements PluginProvider.

Definition at line 132 of file VST3EffectsModule.cpp.

133{
134 static const FileExtensions ext {
135 { _T("vst3") }
136 };
137 return ext;
138}

◆ GetModule()

std::shared_ptr< VST3::Hosting::Module > VST3EffectsModule::GetModule ( const wxString &  path)
private

Definition at line 71 of file VST3EffectsModule.cpp.

72{
73 const auto it = mModules.find(path);
74 if(it != mModules.end())
75 {
76 if(auto lock = it->second.lock())
77 return lock;
78 }
79
80 std::string moduleCreateError;
81 //VST sdk provides platform-specific module loading routines as well,
82 //implementation is conditionally included (see CMakeLists.txt)
83 auto module = VST3::Hosting::Module::create(path.ToStdString(), moduleCreateError);
84 if(!module)
85 throw std::runtime_error(moduleCreateError.c_str());
86
87 module->getFactory().setHostContext(&AudacityVst3HostApplication::Get());
88
89 mModules[path] = module;
90 return module;
91}
std::unordered_map< wxString, std::weak_ptr< VST3::Hosting::Module > > mModules

References AudacityVst3HostApplication::Get(), and mModules.

Referenced by DiscoverPluginsAtPath(), and LoadPlugin().

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

◆ GetOptionalFamilySymbol()

EffectFamilySymbol VST3EffectsModule::GetOptionalFamilySymbol ( )
overridevirtual

A symbol identifying the family of plug-ins provided by this.

If it is not empty, then the family as a whole can be enabled or disabled by the user in Preferences

Implements PluginProvider.

Definition at line 127 of file VST3EffectsModule.cpp.

128{
130}
static EffectFamilySymbol GetFamilySymbol()

References VST3EffectBase::GetFamilySymbol().

Here is the call graph for this function:

◆ GetPath()

PluginPath VST3EffectsModule::GetPath ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 93 of file VST3EffectsModule.cpp.

94{
95 return {};
96}

◆ GetSymbol()

ComponentInterfaceSymbol VST3EffectsModule::GetSymbol ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 98 of file VST3EffectsModule.cpp.

99{
100 return XO("VST3 Effects");
101}

References XO().

Here is the call graph for this function:

◆ GetVendor()

VendorSymbol VST3EffectsModule::GetVendor ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 103 of file VST3EffectsModule.cpp.

104{
105 return XO("The Audacity Team");
106}

References XO().

Here is the call graph for this function:

◆ GetVersion()

wxString VST3EffectsModule::GetVersion ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 108 of file VST3EffectsModule.cpp.

109{
110 return AUDACITY_VERSION_STRING;
111}

◆ Initialize()

bool VST3EffectsModule::Initialize ( )
overridevirtual

Called immediately after creation. Let provider initialize.

Returns
"true" if initialization was successful

Implements PluginProvider.

Definition at line 118 of file VST3EffectsModule.cpp.

119{
120 return true;
121}

◆ InstallPath()

FilePath VST3EffectsModule::InstallPath ( )
overridevirtual

Where plug-in files should be copied to install them.

Returns
may be empty. Drag-and-drop is supported only if GetFileExtensions() returns nonempty and this function returns nonempty.

Implements PluginProvider.

Definition at line 140 of file VST3EffectsModule.cpp.

141{
142#ifdef VST3_DEFAULT_INSTALL_PATH
143 return FilePath { VST3_DEFAULT_INSTALL_PATH };
144#else
145 return {};
146#endif
147}
wxString FilePath
Definition: Project.h:21

◆ LoadPlugin()

std::unique_ptr< ComponentInterface > VST3EffectsModule::LoadPlugin ( const PluginPath path)
overridevirtual

Load the plug-in at a path reported by DiscoverPluginsAtPath.

Returns
smart pointer managing the later unloading

Implements PluginProvider.

Definition at line 265 of file VST3EffectsModule.cpp.

266{
267 try
268 {
269 wxString modulePath;
270 std::string effectUIDString;
271
272 if(!VST3Utils::ParsePluginPath(pluginPath, &modulePath, &effectUIDString))
273 throw std::runtime_error("failed to parse plugin string");
274
275 auto module = GetModule(modulePath);
276 const auto pluginFactory = module->getFactory();
277 for(const auto& classInfo : pluginFactory.classInfos())
278 {
279 if(effectUIDString == classInfo.ID().toString()) {
280 auto result = Factory::Call(module, classInfo);
281 return result;
282 }
283 }
284 throw std::runtime_error("effect UID not found");
285 }
286 catch(std::exception& e)
287 {
288 wxLogError("VST3 Module was not loaded: %s", e.what());
289 }
290 return nullptr;
291}

References GlobalHook< Factory, std::remove_pointer_t< decltype(DefaultFunction)>, DefaultFunction, Options... >::Call(), GetModule(), and VST3Utils::ParsePluginPath().

Here is the call graph for this function:

◆ MakeValidator()

std::unique_ptr< PluginProvider::Validator > VST3EffectsModule::MakeValidator ( ) const
overridevirtual

Implementation can provide plugin specific checks to the plugin instances. By default returns null.

Reimplemented from PluginProvider.

Definition at line 313 of file VST3EffectsModule.cpp.

314{
315 return std::make_unique<VST3PluginValidator>();
316}

◆ SupportsCustomModulePaths()

bool VST3EffectsModule::SupportsCustomModulePaths ( ) const
overridevirtual

Reimplemented from PluginProvider.

Definition at line 153 of file VST3EffectsModule.cpp.

154{
155 return true;
156}

◆ Terminate()

void VST3EffectsModule::Terminate ( )
overridevirtual

Called just prior to deletion to allow releasing any resources.

Implements PluginProvider.

Definition at line 123 of file VST3EffectsModule.cpp.

124{
125}

Member Data Documentation

◆ mModules

std::unordered_map<wxString, std::weak_ptr<VST3::Hosting::Module> > VST3EffectsModule::mModules
private

Definition at line 38 of file VST3EffectsModule.h.

Referenced by GetModule().


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