Audacity 3.2.0
LoadNyquist.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 LoadNyquist.cpp
6
7 Dominic Mazzoni
8
9**********************************************************************/
10
11
12
13#include "LoadNyquist.h"
14
15#include <wx/log.h>
16
17#include "NyquistBase.h"
18
19#include "FileNames.h"
20#include "PluginManager.h"
21#include "ModuleManager.h"
22
23#include <nyx.h>
24
25// ============================================================================
26// List of effects that ship with Audacity. These will be autoregistered.
27// ============================================================================
28const static wxChar *kShippedEffects[] =
29{
30 wxT("adjustable-fade.ny"),
31 wxT("beat.ny"),
32 wxT("clipfix.ny"),
33 wxT("crossfadeclips.ny"),
34 wxT("crossfadetracks.ny"),
35 wxT("delay.ny"),
36 wxT("equalabel.ny"),
37 wxT("highpass.ny"),
38 wxT("label-sounds.ny"),
39 wxT("legacy-limiter.ny"),
40 wxT("lowpass.ny"),
41 wxT("noisegate.ny"),
42 wxT("notch.ny"),
43 wxT("nyquist-plug-in-installer.ny"),
44 wxT("pluck.ny"),
45 wxT("rhythmtrack.ny"),
46 wxT("rissetdrum.ny"),
47 wxT("sample-data-export.ny"),
48 wxT("sample-data-import.ny"),
49 wxT("ShelfFilter.ny"),
50 wxT("spectral-delete.ny"),
51 wxT("SpectralEditMulti.ny"),
52 wxT("SpectralEditParametricEQ.ny"),
53 wxT("SpectralEditShelves.ny"),
54 wxT("StudioFadeOut.ny"),
55 wxT("tremolo.ny"),
56 wxT("vocoder.ny"),
57};
58
59// ============================================================================
60// Module registration entry point
61//
62// This is the symbol that Audacity looks for when the module is built as a
63// dynamic library.
64//
65// When the module is builtin to Audacity, we use the same function, but it is
66// declared static so as not to clash with other builtin modules.
67// ============================================================================
69{
70 // Create and register the importer
71 // Trust the module manager not to leak this
72 return std::make_unique<NyquistEffectsModule>();
73}
74
75// ============================================================================
76// Register this as a builtin module
77// ============================================================================
78DECLARE_BUILTIN_PROVIDER(NyquistsEffectBuiltin);
79
81//
82// NyquistEffectsModule
83//
85
87{
88}
89
91{
92}
93
94// ============================================================================
95// ComponentInterface implementation
96// ============================================================================
97
99{
100 return {};
101}
102
104{
105 return XO("Nyquist Effects");
106}
107
109{
110 return XO("The Audacity Team");
111}
112
114{
115 // This "may" be different if this were to be maintained as a separate DLL
117}
118
120{
121 return XO("Provides Nyquist Effects support to Audacity");
122}
123
124// ============================================================================
125// PluginProvider implementation
126// ============================================================================
127
129{
130 const auto &audacityPathList = FileNames::AudacityPathList();
131
132 for (size_t i = 0, cnt = audacityPathList.size(); i < cnt; i++)
133 {
134 wxFileName name(audacityPathList[i], wxT(""));
135 name.AppendDir(wxT("nyquist"));
136 name.SetFullName(wxT("nyquist.lsp"));
137 if (name.FileExists())
138 {
139 // set_xlisp_path doesn't handle fn_Str() in Unicode build. May or may not actually work.
140 nyx_set_xlisp_path(name.GetPath().ToUTF8());
141 return true;
142 }
143 }
144
145 wxLogWarning(wxT("Critical Nyquist files could not be found. Nyquist effects will not work."));
146
147 return false;
148}
149
151{
152 nyx_set_xlisp_path(NULL);
153
154 return;
155}
156
158{
159#if USE_NYQUIST
161#else
162 return {};
163#endif
164}
165
167{
168 static FileExtensions result{{ _T("ny") }};
169 return result;
170}
171
173{
174 return FileNames::PlugInDir();
175}
176
178{
179 // Autoregister effects that we "think" are ones that have been shipped with
180 // Audacity. A little simplistic, but it should suffice for now.
181 auto pathList = NyquistBase::GetNyquistSearchPath();
182 FilePaths files;
183 TranslatableString ignoredErrMsg;
184
187 {
188 // No checking of error ?
191 }
192
193 for (size_t i = 0; i < WXSIZEOF(kShippedEffects); i++)
194 {
195 files.clear();
196 pm.FindFilesInPathList(kShippedEffects[i], pathList, files);
197 for (size_t j = 0, cnt = files.size(); j < cnt; j++)
198 {
199 /*
200 TODO: Currently the names of Nyquist plug-ins cannot have
201 context specific translations or internal names different from
202 the visible English names.
203
204 This makes it unnecessary to pass a second argument to
205 IsPluginRegistered for correction of the registry (as is needed
206 in the case of built-in effects).
207
208 If it does become necessary in the future, we will need to open the
209 .ny files to access their $name lines so that this argument could
210 be supplied.
211 */
212 if (!pm.IsPluginRegistered(files[j]))
213 {
214 // No checking of error ?
215 DiscoverPluginsAtPath(files[j], ignoredErrMsg,
217 }
218 }
219 }
220}
221
223{
224 auto pathList = NyquistBase::GetNyquistSearchPath();
225 FilePaths files;
226
227 // Add the Nyquist prompt
228 files.push_back(NYQUIST_PROMPT_ID);
229
230 // Load .ny plug-ins
231 pm.FindFilesInPathList(wxT("*.ny"), pathList, files);
232 // LLL: Works for all platform with NEW plugin support (dups are removed)
233 pm.FindFilesInPathList(wxT("*.NY"), pathList, files); // Ed's fix for bug 179
234
235 return { files.begin(), files.end() };
236}
237
239 const PluginPath & path, TranslatableString &errMsg,
240 const RegistrationCallback &callback)
241{
242 errMsg = {};
243 NyquistBase effect(path);
244 if (effect.IsOk())
245 {
246 if (callback)
247 callback(this, &effect);
248 return 1;
249 }
250
251 errMsg = effect.InitializationError();
252 return 0;
253}
254
255std::unique_ptr<ComponentInterface>
257{
258 // Acquires a resource for the application.
259 auto effect = NyquistBase::GetEffectHook::Call(path);
260 if (effect && effect->IsOk())
261 return effect;
262 return nullptr;
263}
264
266{
267 if(path == NYQUIST_PROMPT_ID)
268 return true;
269
270 return wxFileName::FileExists(path);
271}
272
273// ============================================================================
274// NyquistEffectsModule implementation
275// ============================================================================
wxT("CloseDown"))
#define NYQUISTEFFECTS_FAMILY
Definition: EffectBase.h:141
XO("Cut/Copy/Paste")
std::vector< PluginPath > PluginPaths
Definition: Identifier.h:215
wxString PluginPath
type alias for identifying a Plugin supplied by a module, each module defining its own interpretation...
Definition: Identifier.h:214
DECLARE_PROVIDER_ENTRY(AudacityModule)
Definition: LoadNyquist.cpp:68
DECLARE_BUILTIN_PROVIDER(NyquistsEffectBuiltin)
static const wxChar * kShippedEffects[]
Definition: LoadNyquist.cpp:28
#define NYQUISTEFFECTS_VERSION
Definition: NyquistBase.h:24
#define NYQUIST_PROMPT_ID
#define NYQUIST_PROMPT_NAME
wxString FilePath
Definition: Project.h:21
wxString name
Definition: TagsEditor.cpp:166
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
static result_type Call(Arguments &&...arguments)
Null check of the installed function is done for you.
An Effect that calls up a Nyquist (XLISP) plug-in, i.e. many possible effects from this one class.
Definition: NyquistBase.h:77
const TranslatableString & InitializationError() const
Definition: NyquistBase.h:172
static FilePaths GetNyquistSearchPath()
void Terminate() override
Called just prior to deletion to allow releasing any resources.
VendorSymbol GetVendor() const override
virtual ~NyquistEffectsModule()
Definition: LoadNyquist.cpp:90
bool CheckPluginExist(const PluginPath &path) const override
Performs plugin/module existence check, still plugin may fail to load. Implementation should avoid lo...
unsigned DiscoverPluginsAtPath(const PluginPath &path, TranslatableString &errMsg, const RegistrationCallback &callback) override
std::unique_ptr< ComponentInterface > LoadPlugin(const PluginPath &path) override
Load the plug-in at a path reported by DiscoverPluginsAtPath.
FilePath InstallPath() override
Where plug-in files should be copied to install them.
const FileExtensions & GetFileExtensions() override
File types associated with this protocol.
PluginPath GetPath() const override
Definition: LoadNyquist.cpp:98
void AutoRegisterPlugins(PluginManagerInterface &pm) override
Called so that a provider of a static set of plug-ins can register them.
ComponentInterfaceSymbol GetSymbol() const override
TranslatableString GetDescription() const override
EffectFamilySymbol GetOptionalFamilySymbol() override
A symbol identifying the family of plug-ins provided by this.
PluginPaths FindModulePaths(PluginManagerInterface &pm) override
wxString GetVersion() const override
bool Initialize() override
Called immediately after creation. Let provider initialize.
virtual void FindFilesInPathList(const wxString &pattern, const FilePaths &pathList, FilePaths &files, bool directories=false)=0
virtual bool IsPluginRegistered(const PluginPath &path, const TranslatableString *pName=nullptr)=0
Was the plugin registry already populated for a path (maybe from loading the config file)?
static const PluginID & DefaultRegistrationCallback(PluginProvider *provider, ComponentInterface *ident)
std::function< const PluginID &(PluginProvider *, ComponentInterface *) > RegistrationCallback
Further expand a path reported by FindModulePaths.
Holds a msgid for the translation catalog; may also bind format arguments.
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
FILES_API FilePath PlugInDir()
The user plug-in directory (not a system one)
FILES_API const FilePaths & AudacityPathList()
A list of directories that should be searched for Audacity files (plug-ins, help files,...