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...
 
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 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 148 of file VST3EffectsModule.cpp.

149{
150}

◆ 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 309 of file VST3EffectsModule.cpp.

310{
311 wxString modulePath;
312 if(VST3Utils::ParsePluginPath(path, &modulePath, nullptr))
313 return wxFileName::FileExists(modulePath) || wxFileName::DirExists(modulePath);
314
315 return wxFileName::FileExists(path) || wxFileName::DirExists(path);
316}
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 201 of file VST3EffectsModule.cpp.

203{
204 try
205 {
206 auto module = GetModule(path);
207
208 const auto moduleFactory = module->getFactory();
209 auto nEffects { 0u };
210 for(auto& classInfo : moduleFactory.classInfos())
211 {
212 if(classInfo.category() == kVstAudioEffectClass)
213 {
214 std::unique_ptr<VST3EffectBase> effect;
215 try
216 {
217 effect = Factory::Call(module, classInfo);
218 ++nEffects;
219 }
220 catch(std::exception& e)
221 {
222 wxLogError(
223 "Effect %s@%s cannot be loaded: %s",
224 classInfo.name().c_str(),
225 path.c_str(),
226 e.what()
227 );
228 }
229 catch(...)
230 {
231 wxLogError(
232 "Effect %s@%s cannot be loaded: unknown error",
233 classInfo.name().c_str(),
234 path.c_str()
235 );
236 }
237 if(effect && callback)
238 callback(this, effect.get());
239 }
240 }
241 if(nEffects == 0u)
242 throw std::runtime_error("no effects found");
243
244 return nEffects;
245 }
246 catch(std::exception& e)
247 {
248 errMsg = XO("VST3 module error: %s").Format(e.what());
249 }
250
251 return 0u;
252}
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 153 of file VST3EffectsModule.cpp.

154{
155 //Note: The host recursively scans these folders at startup in this order (User/Global/Application).
156 //https://developer.steinberg.help/display/VST/Plug-in+Locations
157
158 FilePaths pathList;
159#ifdef __WXMSW__
160 // Windows specific VST3 search paths
161 {
162 wxString programFilesPath;
163 if(wxGetEnv("programfiles", &programFilesPath))
164 pathList.push_back(programFilesPath + "\\Common Files\\VST3");
165 }
166#elif __WXMAC__
167 pathList.push_back("~/Library/Audio/Plug-ins/VST3/");
168 pathList.push_back("/Library/Audio/Plug-ins/VST3/");
169 pathList.push_back("/Network/Library/Audio/Plug-ins/VST3/");
170#elif __WXGTK__
171 pathList.push_back(wxGetHomeDir() + "/.vst3/");
172 pathList.push_back("/usr/lib/vst3/");
173 pathList.push_back("/usr/local/lib/vst3/");
174#endif
175
176 // bundled/app specific
177 {
178 auto path = wxFileName(wxStandardPaths::Get().GetExecutablePath());
179#ifdef __WXGTK__
180 path.AppendDir("vst3");
181#else
182 path.AppendDir("VST3");
183#endif
184 pathList.push_back(path.GetPath());
185 }
186
187 PluginPaths result;
188 VST3PluginTraverser vst3PluginTraverser([&](const wxString& pluginPath){
189 result.push_back(pluginPath);
190 });
191
192 for(const auto& path : pathList)
193 {
194 wxDir dir(path);
195 if(dir.IsOpened())
196 dir.Traverse(vst3PluginTraverser, wxEmptyString, wxDIR_DEFAULT);
197 }
198 return result;
199}
std::vector< PluginPath > PluginPaths
Definition: Identifier.h:215
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:196

References BasicUI::Get().

Here is the call graph for this function:

◆ GetDescription()

TranslatableString VST3EffectsModule::GetDescription ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 112 of file VST3EffectsModule.cpp.

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

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 131 of file VST3EffectsModule.cpp.

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

◆ GetModule()

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

Definition at line 70 of file VST3EffectsModule.cpp.

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

127{
129}
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 92 of file VST3EffectsModule.cpp.

93{
94 return {};
95}

◆ GetSymbol()

ComponentInterfaceSymbol VST3EffectsModule::GetSymbol ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 97 of file VST3EffectsModule.cpp.

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

References XO().

Here is the call graph for this function:

◆ GetVendor()

VendorSymbol VST3EffectsModule::GetVendor ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 102 of file VST3EffectsModule.cpp.

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

References XO().

Here is the call graph for this function:

◆ GetVersion()

wxString VST3EffectsModule::GetVersion ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 107 of file VST3EffectsModule.cpp.

108{
109 return AUDACITY_VERSION_STRING;
110}

◆ Initialize()

bool VST3EffectsModule::Initialize ( )
overridevirtual

Called immediately after creation. Let provider initialize.

Returns
"true" if initialization was successful

Implements PluginProvider.

Definition at line 117 of file VST3EffectsModule.cpp.

118{
119 return true;
120}

◆ 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 139 of file VST3EffectsModule.cpp.

140{
141#ifdef VST3_DEFAULT_INSTALL_PATH
142 return FilePath { VST3_DEFAULT_INSTALL_PATH };
143#else
144 return {};
145#endif
146}
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 255 of file VST3EffectsModule.cpp.

256{
257 try
258 {
259 wxString modulePath;
260 std::string effectUIDString;
261
262 if(!VST3Utils::ParsePluginPath(pluginPath, &modulePath, &effectUIDString))
263 throw std::runtime_error("failed to parse plugin string");
264
265 auto module = GetModule(modulePath);
266 const auto pluginFactory = module->getFactory();
267 for(const auto& classInfo : pluginFactory.classInfos())
268 {
269 if(effectUIDString == classInfo.ID().toString()) {
270 auto result = Factory::Call(module, classInfo);
271 return result;
272 }
273 }
274 throw std::runtime_error("effect UID not found");
275 }
276 catch(std::exception& e)
277 {
278 wxLogError("VST3 Module was not loaded: %s", e.what());
279 }
280 return nullptr;
281}

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 303 of file VST3EffectsModule.cpp.

304{
305 return std::make_unique<VST3PluginValidator>();
306}

◆ Terminate()

void VST3EffectsModule::Terminate ( )
overridevirtual

Called just prior to deletion to allow releasing any resources.

Implements PluginProvider.

Definition at line 122 of file VST3EffectsModule.cpp.

123{
124}

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: