Audacity 3.2.0
Classes | Public Member Functions | Static Private Member Functions | List of all members
LV2EffectsModule Class Referencefinal

#include <LoadLV2.h>

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

Classes

struct  Factory
 

Public Member Functions

 LV2EffectsModule ()
 
virtual ~LV2EffectsModule ()
 
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 &pm) override
 Called so that a provider of a static set of plug-ins can register them. More...
 
PluginPaths FindModulePaths (PluginManagerInterface &pm) 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
 

Static Private Member Functions

static const LilvPlugin * GetPlugin (const PluginPath &path)
 

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

Definition at line 30 of file LoadLV2.h.

Constructor & Destructor Documentation

◆ LV2EffectsModule()

LV2EffectsModule::LV2EffectsModule ( )

Definition at line 68 of file LoadLV2.cpp.

69{
70}

◆ ~LV2EffectsModule()

LV2EffectsModule::~LV2EffectsModule ( )
virtual

Definition at line 72 of file LoadLV2.cpp.

73{
74}

Member Function Documentation

◆ AutoRegisterPlugins()

void LV2EffectsModule::AutoRegisterPlugins ( PluginManagerInterface pluginManager)
overridevirtual

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

Implements PluginProvider.

Definition at line 198 of file LoadLV2.cpp.

199{
200}

◆ CheckPluginExist()

bool LV2EffectsModule::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 269 of file LoadLV2.cpp.

270{
271 return GetPlugin(path) != nullptr;
272}
static const LilvPlugin * GetPlugin(const PluginPath &path)
Definition: LoadLV2.cpp:317

References GetPlugin().

Here is the call graph for this function:

◆ DiscoverPluginsAtPath()

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

Implements PluginProvider.

Definition at line 239 of file LoadLV2.cpp.

242{
243 errMsg = {};
244 if (const auto plug = GetPlugin(path)) {
245 LV2EffectBase effect(*plug);
246 if (effect.InitializePlugin()) {
247 if (callback)
248 callback( this, &effect );
249 return 1;
250 }
251 }
252
253 errMsg = XO("Could not load the library");
254 return 0;
255}
XO("Cut/Copy/Paste")

References GetPlugin(), LV2EffectBase::InitializePlugin(), and XO().

Here is the call graph for this function:

◆ FindModulePaths()

PluginPaths LV2EffectsModule::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 202 of file LoadLV2.cpp.

203{
204 // Retrieve data about all LV2 plugins
205 const LilvPlugins *plugs = lilv_world_get_all_plugins(LV2Symbols::gWorld);
206
207 // Iterate over all plugins retrieve their URI
208 PluginPaths plugins;
209 LILV_FOREACH(plugins, i, plugs)
210 {
211 const LilvPlugin *plug = lilv_plugins_get(plugs, i);
212 const LilvNode *cls = lilv_plugin_class_get_uri(lilv_plugin_get_class(plug));
213 LilvNodePtr name{ lilv_plugin_get_name(plug) };
214
215 // Bypass unsupported plugin types
216 using namespace LV2Symbols;
217 if (lilv_node_equals(cls, node_InstrumentPlugin) ||
218 lilv_node_equals(cls, node_MIDIPlugin) ||
219 lilv_node_equals(cls, node_MathConstants) ||
220 lilv_node_equals(cls, node_MathFunctions))
221 {
222 wxLogInfo(wxT("LV2 plugin '%s' has unsupported type '%s'"), lilv_node_as_string(lilv_plugin_get_uri(plug)), lilv_node_as_string(cls));
223 continue;
224 }
225
226 // If it doesn't have a name or has no ports, then it's not valid
227 if (!name || !lilv_plugin_get_port_by_index(plug, 0))
228 {
229 wxLogInfo(wxT("LV2 plugin '%s' is invalid"), lilv_node_as_string(lilv_plugin_get_uri(plug)));
230 continue;
231 }
232
233 plugins.push_back(LilvString(lilv_plugin_get_uri(plug)));
234 }
235
236 return plugins;
237}
wxT("CloseDown"))
const TranslatableString name
Definition: Distortion.cpp:76
std::vector< PluginPath > PluginPaths
Definition: Identifier.h:215
wxString LilvString(const LilvNode *node)
Definition: LV2Utils.h:37
Lilv_ptr< LilvNode, lilv_node_free > LilvNodePtr
Definition: LV2Utils.h:33
LilvWorld * gWorld
Definition: LV2Symbols.cpp:31

References LV2Symbols::gWorld, LilvString(), name, and wxT().

Here is the call graph for this function:

◆ GetDescription()

TranslatableString LV2EffectsModule::GetDescription ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 101 of file LoadLV2.cpp.

102{
103 return XO("Provides LV2 Effects support to Audacity");
104}

References XO().

Here is the call graph for this function:

◆ GetFileExtensions()

const FileExtensions & LV2EffectsModule::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 192 of file LoadLV2.cpp.

193{
194 static FileExtensions empty;
195 return empty;
196}
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.

◆ GetOptionalFamilySymbol()

EffectFamilySymbol LV2EffectsModule::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 183 of file LoadLV2.cpp.

184{
185#if USE_LV2
186 return LV2EFFECTS_FAMILY;
187#else
188 return {};
189#endif
190}
#define LV2EFFECTS_FAMILY
Definition: LV2Effect.h:31

References LV2EFFECTS_FAMILY.

◆ GetPath()

PluginPath LV2EffectsModule::GetPath ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 80 of file LoadLV2.cpp.

81{
82 return {};
83}

◆ GetPlugin()

const LilvPlugin * LV2EffectsModule::GetPlugin ( const PluginPath path)
staticprivate

Definition at line 317 of file LoadLV2.cpp.

318{
319 using namespace LV2Symbols;
320 if (LilvNodePtr uri{ lilv_new_uri(gWorld, path.ToUTF8()) })
321 // lilv.h says returns from the following two functions don't need freeing
322 return lilv_plugins_get_by_uri(
323 lilv_world_get_all_plugins(gWorld), uri.get());
324 return nullptr;
325}

References LV2Symbols::gWorld.

Referenced by CheckPluginExist(), DiscoverPluginsAtPath(), and LoadPlugin().

Here is the caller graph for this function:

◆ GetSymbol()

ComponentInterfaceSymbol LV2EffectsModule::GetSymbol ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 85 of file LoadLV2.cpp.

86{
87 return XO("LV2 Effects");
88}

References XO().

Here is the call graph for this function:

◆ GetVendor()

VendorSymbol LV2EffectsModule::GetVendor ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 90 of file LoadLV2.cpp.

91{
92 return XO("The Audacity Team");
93}

References XO().

Here is the call graph for this function:

◆ GetVersion()

wxString LV2EffectsModule::GetVersion ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 95 of file LoadLV2.cpp.

96{
97 // This "may" be different if this were to be maintained as a separate DLL
98 return LV2EFFECTS_VERSION;
99}
#define LV2EFFECTS_VERSION
Definition: LV2Effect.h:28

References LV2EFFECTS_VERSION.

◆ Initialize()

bool LV2EffectsModule::Initialize ( )
overridevirtual

Called immediately after creation. Let provider initialize.

Returns
"true" if initialization was successful

Implements PluginProvider.

Definition at line 110 of file LoadLV2.cpp.

111{
113 return false;
114
115 wxString newVar;
116
117#if defined(__WXMAC__)
118#define LV2PATH wxT("/Library/Audio/Plug-Ins/LV2")
119
120 wxFileName libdir;
121// libdir.AssignDir(wxT(LIBDIR));
122 libdir.AppendDir(wxT("lv2"));
123
124 newVar += wxT(":$HOME/.lv2");
125
126 // Look in ~/Library/Audio/Plug-Ins/lv2 and /Library/Audio/Plug-Ins/lv2
127 newVar += wxT(":$HOME") LV2PATH;
128 newVar += wxT(":") LV2PATH;
129
130 newVar += wxT(":/usr/local/lib/lv2");
131 newVar += wxT(":/usr/lib/lv2");
132 newVar += wxT(":") + libdir.GetPath();
133
134#elif defined(__WXMSW__)
135
136 newVar += wxT(";%APPDATA%\\LV2");
137 newVar += wxT(";%COMMONPROGRAMFILES%\\LV2");
138 newVar += wxT(";%COMMONPROGRAMFILES(x86)%\\LV2");
139
140#else
141
142 wxFileName libdir;
143 libdir.AssignDir(wxT(LIBDIR));
144 libdir.AppendDir(wxT("lv2"));
145
146 newVar += wxT(":$HOME/.lv2");
147#if defined(__LP64__)
148 newVar += wxT(":/usr/local/lib64/lv2");
149 newVar += wxT(":/usr/lib64/lv2");
150#endif
151 newVar += wxT(":/usr/local/lib/lv2");
152 newVar += wxT(":/usr/lib/lv2");
153 newVar += wxT(":") + libdir.GetPath();
154
155 // Tell SUIL where to find his GUI support modules
156 wxSetEnv(wxT("SUIL_MODULE_DIR"), wxT(PKGLIBDIR));
157#endif
158
159 // Start with the LV2_PATH environment variable (if any)
160 wxString pathVar;
161 wxGetEnv(wxT("LV2_PATH"), &pathVar);
162
163 if (pathVar.empty())
164 {
165 pathVar = newVar.Mid(1);
166 }
167 else
168 {
169 pathVar += newVar;
170 }
171
172 wxSetEnv(wxT("LV2_PATH"), pathVar);
173 lilv_world_load_all(LV2Symbols::gWorld);
174
175 return true;
176}
#define LV2PATH
PluginPath GetPath() const override
Definition: LoadLV2.cpp:80
URIDLIST bool InitializeGWorld()
Call before any use of the constants defined in this file.
Definition: LV2Symbols.cpp:48

References LV2Symbols::gWorld, LV2Symbols::InitializeGWorld(), LV2PATH, and wxT().

Here is the call graph for this function:

◆ InstallPath()

FilePath LV2EffectsModule::InstallPath ( )
inlineoverridevirtual

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 55 of file LoadLV2.h.

55{ return {}; }

◆ LoadPlugin()

std::unique_ptr< ComponentInterface > LV2EffectsModule::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 258 of file LoadLV2.cpp.

259{
260 // Acquires a resource for the application.
261 if (const auto plug = GetPlugin(path)) {
262 auto result = Factory::Call(*plug);
263 result->InitializePlugin();
264 return result;
265 }
266 return nullptr;
267}
static result_type Call(Arguments &&...arguments)
Null check of the installed function is done for you.

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

Here is the call graph for this function:

◆ MakeValidator()

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

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

Reimplemented from PluginProvider.

Definition at line 307 of file LoadLV2.cpp.

308{
309 return std::make_unique<LV2PluginValidator>();
310}

◆ Terminate()

void LV2EffectsModule::Terminate ( )
overridevirtual

Called just prior to deletion to allow releasing any resources.

Implements PluginProvider.

Definition at line 178 of file LoadLV2.cpp.

179{
181}
void FinalizeGWorld()
Call at end of session.
Definition: LV2Symbols.cpp:71

References LV2Symbols::FinalizeGWorld().

Here is the call graph for this function:

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