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 "Nyquist.h"
18
19#include "FileNames.h"
20#include "PluginManager.h"
21#include "ModuleManager.h"
22
23// ============================================================================
24// List of effects that ship with Audacity. These will be autoregistered.
25// ============================================================================
26const static wxChar *kShippedEffects[] =
27{
28 wxT("adjustable-fade.ny"),
29 wxT("beat.ny"),
30 wxT("clipfix.ny"),
31 wxT("crossfadeclips.ny"),
32 wxT("crossfadetracks.ny"),
33 wxT("delay.ny"),
34 wxT("equalabel.ny"),
35 wxT("highpass.ny"),
36 wxT("label-sounds.ny"),
37 wxT("limiter.ny"),
38 wxT("lowpass.ny"),
39 wxT("noisegate.ny"),
40 wxT("notch.ny"),
41 wxT("nyquist-plug-in-installer.ny"),
42 wxT("pluck.ny"),
43 wxT("rhythmtrack.ny"),
44 wxT("rissetdrum.ny"),
45 wxT("sample-data-export.ny"),
46 wxT("sample-data-import.ny"),
47 wxT("ShelfFilter.ny"),
48 wxT("spectral-delete.ny"),
49 wxT("SpectralEditMulti.ny"),
50 wxT("SpectralEditParametricEQ.ny"),
51 wxT("SpectralEditShelves.ny"),
52 wxT("StudioFadeOut.ny"),
53 wxT("tremolo.ny"),
54 wxT("vocalrediso.ny"),
55 wxT("vocoder.ny"),
56};
57
58// ============================================================================
59// Module registration entry point
60//
61// This is the symbol that Audacity looks for when the module is built as a
62// dynamic library.
63//
64// When the module is builtin to Audacity, we use the same function, but it is
65// declared static so as not to clash with other builtin modules.
66// ============================================================================
68{
69 // Create and register the importer
70 // Trust the module manager not to leak this
71 return std::make_unique<NyquistEffectsModule>();
72}
73
74// ============================================================================
75// Register this as a builtin module
76// ============================================================================
77DECLARE_BUILTIN_PROVIDER(NyquistsEffectBuiltin);
78
80//
81// NyquistEffectsModule
82//
84
86{
87}
88
90{
91}
92
93// ============================================================================
94// ComponentInterface implementation
95// ============================================================================
96
98{
99 return {};
100}
101
103{
104 return XO("Nyquist Effects");
105}
106
108{
109 return XO("The Audacity Team");
110}
111
113{
114 // This "may" be different if this were to be maintained as a separate DLL
116}
117
119{
120 return XO("Provides Nyquist Effects support to Audacity");
121}
122
123// ============================================================================
124// PluginProvider implementation
125// ============================================================================
126
128{
129 const auto &audacityPathList = FileNames::AudacityPathList();
130
131 for (size_t i = 0, cnt = audacityPathList.size(); i < cnt; i++)
132 {
133 wxFileName name(audacityPathList[i], wxT(""));
134 name.AppendDir(wxT("nyquist"));
135 name.SetFullName(wxT("nyquist.lsp"));
136 if (name.FileExists())
137 {
138 // set_xlisp_path doesn't handle fn_Str() in Unicode build. May or may not actually work.
139 nyx_set_xlisp_path(name.GetPath().ToUTF8());
140 return true;
141 }
142 }
143
144 wxLogWarning(wxT("Critical Nyquist files could not be found. Nyquist effects will not work."));
145
146 return false;
147}
148
150{
151 nyx_set_xlisp_path(NULL);
152
153 return;
154}
155
157{
158#if USE_NYQUIST
160#else
161 return {};
162#endif
163}
164
166{
167 static FileExtensions result{{ _T("ny") }};
168 return result;
169}
170
172{
173 return FileNames::PlugInDir();
174}
175
177{
178 // Autoregister effects that we "think" are ones that have been shipped with
179 // Audacity. A little simplistic, but it should suffice for now.
180 auto pathList = NyquistEffect::GetNyquistSearchPath();
181 FilePaths files;
182 TranslatableString ignoredErrMsg;
183
186 {
187 // No checking of error ?
190 }
191
192 for (size_t i = 0; i < WXSIZEOF(kShippedEffects); i++)
193 {
194 files.clear();
195 pm.FindFilesInPathList(kShippedEffects[i], pathList, files);
196 for (size_t j = 0, cnt = files.size(); j < cnt; j++)
197 {
198 /*
199 TODO: Currently the names of Nyquist plug-ins cannot have
200 context specific translations or internal names different from
201 the visible English names.
202
203 This makes it unnecessary to pass a second argument to
204 IsPluginRegistered for correction of the registry (as is needed
205 in the case of built-in effects).
206
207 If it does become necessary in the future, we will need to open the
208 .ny files to access their $name lines so that this argument could
209 be supplied.
210 */
211 if (!pm.IsPluginRegistered(files[j]))
212 {
213 // No checking of error ?
214 DiscoverPluginsAtPath(files[j], ignoredErrMsg,
216 }
217 }
218 }
219}
220
222{
223 auto pathList = NyquistEffect::GetNyquistSearchPath();
224 FilePaths files;
225
226 // Add the Nyquist prompt
227 files.push_back(NYQUIST_PROMPT_ID);
228
229 // Load .ny plug-ins
230 pm.FindFilesInPathList(wxT("*.ny"), pathList, files);
231 // LLL: Works for all platform with NEW plugin support (dups are removed)
232 pm.FindFilesInPathList(wxT("*.NY"), pathList, files); // Ed's fix for bug 179
233
234 return { files.begin(), files.end() };
235}
236
238 const PluginPath & path, TranslatableString &errMsg,
239 const RegistrationCallback &callback)
240{
241 errMsg = {};
242 NyquistEffect effect(path);
243 if (effect.IsOk())
244 {
245 if (callback)
246 callback(this, &effect);
247 return 1;
248 }
249
250 errMsg = effect.InitializationError();
251 return 0;
252}
253
254std::unique_ptr<ComponentInterface>
256{
257 // Acquires a resource for the application.
258 auto effect = std::make_unique<NyquistEffect>(path);
259 if (effect->IsOk())
260 return effect;
261 return nullptr;
262}
263
265{
266 if(path == NYQUIST_PROMPT_ID)
267 return true;
268
269 return wxFileName::FileExists(path);
270}
271
272// ============================================================================
273// NyquistEffectsModule implementation
274// ============================================================================
wxT("CloseDown"))
const TranslatableString name
Definition: Distortion.cpp:76
#define NYQUISTEFFECTS_FAMILY
Definition: EffectBase.h:134
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:67
DECLARE_BUILTIN_PROVIDER(NyquistsEffectBuiltin)
static const wxChar * kShippedEffects[]
Definition: LoadNyquist.cpp:26
#define NYQUISTEFFECTS_VERSION
Definition: Nyquist.h:28
#define NYQUIST_PROMPT_ID
#define NYQUIST_PROMPT_NAME
wxString FilePath
Definition: Project.h:21
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
An Effect that calls up a Nyquist (XLISP) plug-in, i.e. many possible effects from this one class.
Definition: Nyquist.h:78
const TranslatableString & InitializationError() const
Definition: Nyquist.h:162
static FilePaths GetNyquistSearchPath()
Definition: Nyquist.cpp:2698
void Terminate() override
Called just prior to deletion to allow releasing any resources.
VendorSymbol GetVendor() const override
virtual ~NyquistEffectsModule()
Definition: LoadNyquist.cpp:89
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:97
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,...