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("vocoder.ny"),
55};
56
57// ============================================================================
58// Module registration entry point
59//
60// This is the symbol that Audacity looks for when the module is built as a
61// dynamic library.
62//
63// When the module is builtin to Audacity, we use the same function, but it is
64// declared static so as not to clash with other builtin modules.
65// ============================================================================
67{
68 // Create and register the importer
69 // Trust the module manager not to leak this
70 return std::make_unique<NyquistEffectsModule>();
71}
72
73// ============================================================================
74// Register this as a builtin module
75// ============================================================================
76DECLARE_BUILTIN_PROVIDER(NyquistsEffectBuiltin);
77
79//
80// NyquistEffectsModule
81//
83
85{
86}
87
89{
90}
91
92// ============================================================================
93// ComponentInterface implementation
94// ============================================================================
95
97{
98 return {};
99}
100
102{
103 return XO("Nyquist Effects");
104}
105
107{
108 return XO("The Audacity Team");
109}
110
112{
113 // This "may" be different if this were to be maintained as a separate DLL
115}
116
118{
119 return XO("Provides Nyquist Effects support to Audacity");
120}
121
122// ============================================================================
123// PluginProvider implementation
124// ============================================================================
125
127{
128 const auto &audacityPathList = FileNames::AudacityPathList();
129
130 for (size_t i = 0, cnt = audacityPathList.size(); i < cnt; i++)
131 {
132 wxFileName name(audacityPathList[i], wxT(""));
133 name.AppendDir(wxT("nyquist"));
134 name.SetFullName(wxT("nyquist.lsp"));
135 if (name.FileExists())
136 {
137 // set_xlisp_path doesn't handle fn_Str() in Unicode build. May or may not actually work.
138 nyx_set_xlisp_path(name.GetPath().ToUTF8());
139 return true;
140 }
141 }
142
143 wxLogWarning(wxT("Critical Nyquist files could not be found. Nyquist effects will not work."));
144
145 return false;
146}
147
149{
150 nyx_set_xlisp_path(NULL);
151
152 return;
153}
154
156{
157#if USE_NYQUIST
159#else
160 return {};
161#endif
162}
163
165{
166 static FileExtensions result{{ _T("ny") }};
167 return result;
168}
169
171{
172 return FileNames::PlugInDir();
173}
174
176{
177 // Autoregister effects that we "think" are ones that have been shipped with
178 // Audacity. A little simplistic, but it should suffice for now.
179 auto pathList = NyquistEffect::GetNyquistSearchPath();
180 FilePaths files;
181 TranslatableString ignoredErrMsg;
182
185 {
186 // No checking of error ?
189 }
190
191 for (size_t i = 0; i < WXSIZEOF(kShippedEffects); i++)
192 {
193 files.clear();
194 pm.FindFilesInPathList(kShippedEffects[i], pathList, files);
195 for (size_t j = 0, cnt = files.size(); j < cnt; j++)
196 {
197 /*
198 TODO: Currently the names of Nyquist plug-ins cannot have
199 context specific translations or internal names different from
200 the visible English names.
201
202 This makes it unnecessary to pass a second argument to
203 IsPluginRegistered for correction of the registry (as is needed
204 in the case of built-in effects).
205
206 If it does become necessary in the future, we will need to open the
207 .ny files to access their $name lines so that this argument could
208 be supplied.
209 */
210 if (!pm.IsPluginRegistered(files[j]))
211 {
212 // No checking of error ?
213 DiscoverPluginsAtPath(files[j], ignoredErrMsg,
215 }
216 }
217 }
218}
219
221{
222 auto pathList = NyquistEffect::GetNyquistSearchPath();
223 FilePaths files;
224
225 // Add the Nyquist prompt
226 files.push_back(NYQUIST_PROMPT_ID);
227
228 // Load .ny plug-ins
229 pm.FindFilesInPathList(wxT("*.ny"), pathList, files);
230 // LLL: Works for all platform with NEW plugin support (dups are removed)
231 pm.FindFilesInPathList(wxT("*.NY"), pathList, files); // Ed's fix for bug 179
232
233 return { files.begin(), files.end() };
234}
235
237 const PluginPath & path, TranslatableString &errMsg,
238 const RegistrationCallback &callback)
239{
240 errMsg = {};
241 NyquistEffect effect(path);
242 if (effect.IsOk())
243 {
244 if (callback)
245 callback(this, &effect);
246 return 1;
247 }
248
249 errMsg = effect.InitializationError();
250 return 0;
251}
252
253std::unique_ptr<ComponentInterface>
255{
256 // Acquires a resource for the application.
257 auto effect = std::make_unique<NyquistEffect>(path);
258 if (effect->IsOk())
259 return effect;
260 return nullptr;
261}
262
264{
265 if(path == NYQUIST_PROMPT_ID)
266 return true;
267
268 return wxFileName::FileExists(path);
269}
270
271// ============================================================================
272// NyquistEffectsModule implementation
273// ============================================================================
wxT("CloseDown"))
const TranslatableString name
Definition: Distortion.cpp:76
#define NYQUISTEFFECTS_FAMILY
Definition: EffectBase.h:132
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:66
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:2694
void Terminate() override
Called just prior to deletion to allow releasing any resources.
VendorSymbol GetVendor() const override
virtual ~NyquistEffectsModule()
Definition: LoadNyquist.cpp:88
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:96
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,...