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

319{
320 wxString modulePath;
321 if(VST3Utils::ParsePluginPath(path, &modulePath, nullptr))
322 return wxFileName::FileExists(modulePath) || wxFileName::DirExists(modulePath);
323
324 return wxFileName::FileExists(path) || wxFileName::DirExists(path);
325}
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 210 of file VST3EffectsModule.cpp.

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

159{
160 //Note: The host recursively scans these folders at startup in this order (User/Global/Application).
161 //https://developer.steinberg.help/display/VST/Plug-in+Locations
162
163 FilePaths pathList;
164#ifdef __WXMSW__
165 // Windows specific VST3 search paths
166 {
167 wxString programFilesPath;
168 if(wxGetEnv("programfiles", &programFilesPath))
169 pathList.push_back(programFilesPath + "\\Common Files\\VST3");
170 }
171#elif __WXMAC__
172 pathList.push_back("~/Library/Audio/Plug-ins/VST3/");
173 pathList.push_back("/Library/Audio/Plug-ins/VST3/");
174 pathList.push_back("/Network/Library/Audio/Plug-ins/VST3/");
175#elif __WXGTK__
176 pathList.push_back(wxGetHomeDir() + "/.vst3/");
177 pathList.push_back("/usr/lib/vst3/");
178 pathList.push_back("/usr/local/lib/vst3/");
179#endif
180
181 // bundled/app specific
182 {
183 auto path = wxFileName(wxStandardPaths::Get().GetExecutablePath());
184#ifdef __WXGTK__
185 path.AppendDir("vst3");
186#else
187 path.AppendDir("VST3");
188#endif
189 pathList.push_back(path.GetPath());
190 }
191 {
192 auto customPaths = pluginManager.ReadCustomPaths(*this);
193 std::copy(customPaths.begin(), customPaths.end(), std::back_inserter(pathList));
194 }
195
196 PluginPaths result;
197 VST3PluginTraverser vst3PluginTraverser([&](const wxString& pluginPath){
198 result.push_back(pluginPath);
199 });
200
201 for(const auto& path : pathList)
202 {
203 wxDir dir(path);
204 if(dir.IsOpened())
205 dir.Traverse(vst3PluginTraverser, wxEmptyString, wxDIR_DEFAULT);
206 }
207 return result;
208}
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.
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:202
void copy(const T *src, T *dst, int32_t n)
Definition: VectorOps.h:40

References staffpad::vo::copy(), BasicUI::Get(), and PluginManagerInterface::ReadCustomPaths().

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

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

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

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

◆ SupportsCustomModulePaths()

bool VST3EffectsModule::SupportsCustomModulePaths ( ) const
overridevirtual

Reimplemented from PluginProvider.

Definition at line 152 of file VST3EffectsModule.cpp.

153{
154 return true;
155}

◆ 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: