Audacity 3.2.0
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]

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

151{
152}

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

309{
310 wxString modulePath;
311 if(VST3Utils::ParsePluginPath(path, &modulePath, nullptr))
312 return wxFileName::FileExists(modulePath) || wxFileName::DirExists(modulePath);
313
314 return wxFileName::FileExists(path) || wxFileName::DirExists(path);
315}
static bool ParsePluginPath(const wxString &pluginPath, wxString *modulePath, std::string *effectUIDString)
Definition: VST3Utils.cpp:29

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

205{
206 try
207 {
208 auto module = GetModule(path);
209
210 const auto moduleFactory = module->getFactory();
211 auto nEffects { 0u };
212 for(auto& classInfo : moduleFactory.classInfos())
213 {
214 if(classInfo.category() == kVstAudioEffectClass)
215 {
216 std::unique_ptr<VST3Effect> effect;
217 try
218 {
219 effect = std::make_unique<VST3Effect>(module, classInfo);
220 ++nEffects;
221 }
222 catch(std::exception& e)
223 {
224 wxLogError(
225 "Effect %[email protected]%s cannot be loaded: %s",
226 classInfo.name().c_str(),
227 path.c_str(),
228 e.what()
229 );
230 }
231 catch(...)
232 {
233 wxLogError(
234 "Effect %[email protected]%s cannot be loaded: unknown error",
235 classInfo.name().c_str(),
236 path.c_str()
237 );
238 }
239 if(effect && callback)
240 callback(this, effect.get());
241 }
242 }
243 if(nEffects == 0u)
244 throw std::runtime_error("no effects found");
245
246 return nEffects;
247 }
248 catch(std::exception& e)
249 {
250 errMsg = XO("VST3 module error: %s").Format(e.what());
251 }
252
253 return 0u;
254}
XO("Cut/Copy/Paste")
std::shared_ptr< VST3::Hosting::Module > GetModule(const wxString &path)

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

156{
157 //Note: The host recursively scans these folders at startup in this order (User/Global/Application).
158 //https://developer.steinberg.help/display/VST/Plug-in+Locations
159
160 FilePaths pathList;
161#ifdef __WXMSW__
162 // Windows specific VST3 search paths
163 {
164 wxString programFilesPath;
165 if(wxGetEnv("programfiles", &programFilesPath))
166 pathList.push_back(programFilesPath + "\\Common Files\\VST3");
167 }
168#elif __WXMAC__
169 pathList.push_back("~/Library/Audio/Plug-ins/VST3/");
170 pathList.push_back("/Library/Audio/Plug-ins/VST3/");
171 pathList.push_back("/Network/Library/Audio/Plug-ins/VST3/");
172#elif __WXGTK__
173 pathList.push_back(wxGetHomeDir() + "/.vst3/");
174 pathList.push_back("/usr/lib/vst3/");
175 pathList.push_back("/usr/local/lib/vst3/");
176#endif
177
178 // bundled/app specific
179 {
180 auto path = wxFileName(wxStandardPaths::Get().GetExecutablePath());
181#ifdef __WXGTK__
182 path.AppendDir("vst3");
183#else
184 path.AppendDir("VST3");
185#endif
186 pathList.push_back(path.GetPath());
187 }
188
189 PluginPaths result;
190 VST3PluginTraverser vst3PluginTraverser([&](const wxString& pluginPath){
191 result.push_back(pluginPath);
192 });
193
194 for(const auto& path : pathList)
195 {
196 wxDir dir(path);
197 if(dir.IsOpened())
198 dir.Traverse(vst3PluginTraverser, wxEmptyString, wxDIR_DEFAULT);
199 }
200 return result;
201}
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:194

References BasicUI::Get().

Here is the call graph for this function:

◆ GetDescription()

TranslatableString VST3EffectsModule::GetDescription ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 114 of file VST3EffectsModule.cpp.

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

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

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

◆ GetModule()

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

Definition at line 72 of file VST3EffectsModule.cpp.

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

129{
131}
static EffectFamilySymbol GetFamilySymbol()
Definition: VST3Effect.cpp:95

References VST3Effect::GetFamilySymbol().

Here is the call graph for this function:

◆ GetPath()

PluginPath VST3EffectsModule::GetPath ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 94 of file VST3EffectsModule.cpp.

95{
96 return {};
97}

◆ GetSymbol()

ComponentInterfaceSymbol VST3EffectsModule::GetSymbol ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 99 of file VST3EffectsModule.cpp.

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

References XO().

Here is the call graph for this function:

◆ GetVendor()

VendorSymbol VST3EffectsModule::GetVendor ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 104 of file VST3EffectsModule.cpp.

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

References XO().

Here is the call graph for this function:

◆ GetVersion()

wxString VST3EffectsModule::GetVersion ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 109 of file VST3EffectsModule.cpp.

110{
111 return AUDACITY_VERSION_STRING;
112}

◆ Initialize()

bool VST3EffectsModule::Initialize ( )
overridevirtual

Called immediately after creation. Let provider initialize.

Returns
"true" if initialization was successful

Implements PluginProvider.

Definition at line 119 of file VST3EffectsModule.cpp.

120{
121 return true;
122}

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

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

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

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

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

◆ Terminate()

void VST3EffectsModule::Terminate ( )
overridevirtual

Called just prior to deletion to allow releasing any resources.

Implements PluginProvider.

Definition at line 124 of file VST3EffectsModule.cpp.

125{
126}

Member Data Documentation

◆ mModules

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

Definition at line 35 of file VST3EffectsModule.h.

Referenced by GetModule().


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