Audacity  3.0.3
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 // ============================================================================
26 const 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("spectral-delete.ny"),
48  wxT("SpectralEditMulti.ny"),
49  wxT("SpectralEditParametricEQ.ny"),
50  wxT("SpectralEditShelves.ny"),
51  wxT("StudioFadeOut.ny"),
52  wxT("tremolo.ny"),
53  wxT("vocalrediso.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 // ============================================================================
66 DECLARE_MODULE_ENTRY(AudacityModule)
67 {
68  // Create and register the importer
69  // Trust the module manager not to leak this
71 }
72 
73 // ============================================================================
74 // Register this as a builtin module
75 // ============================================================================
76 DECLARE_BUILTIN_MODULE(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
114  return NYQUISTEFFECTS_VERSION;
115 }
116 
118 {
119  return XO("Provides Nyquist Effects support to Audacity");
120 }
121 
122 // ============================================================================
123 // ModuleInterface 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
158  return NYQUISTEFFECTS_FAMILY;
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 
183  auto name = NYQUIST_PROMPT_NAME;
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  // We still want to be called during the normal registration process
220  return false;
221 }
222 
224 {
225  auto pathList = NyquistEffect::GetNyquistSearchPath();
226  FilePaths files;
227 
228  // Add the Nyquist prompt
229  files.push_back(NYQUIST_PROMPT_ID);
230 
231  // Load .ny plug-ins
232  pm.FindFilesInPathList(wxT("*.ny"), pathList, files);
233  // LLL: Works for all platform with NEW plugin support (dups are removed)
234  pm.FindFilesInPathList(wxT("*.NY"), pathList, files); // Ed's fix for bug 179
235 
236  return { files.begin(), files.end() };
237 }
238 
240  const PluginPath & path, TranslatableString &errMsg,
241  const RegistrationCallback &callback)
242 {
243  errMsg = {};
244  NyquistEffect effect(path);
245  if (effect.IsOk())
246  {
247  if (callback)
248  callback(this, &effect);
249  return 1;
250  }
251 
252  errMsg = effect.InitializationError();
253  return 0;
254 }
255 
256 bool NyquistEffectsModule::IsPluginValid(const PluginPath & path, bool bFast)
257 {
258  // Ignores bFast parameter, since checking file exists is fast enough for
259  // the small number of Nyquist plug-ins that we have.
260  static_cast<void>(bFast);
261  if(path == NYQUIST_PROMPT_ID)
262  return true;
263 
264  return wxFileName::FileExists(path);
265 }
266 
267 std::unique_ptr<ComponentInterface>
269 {
270  // Acquires a resource for the application.
271  auto effect = std::make_unique<NyquistEffect>(path);
272  if (effect->IsOk())
273  return effect;
274  return nullptr;
275 }
276 
277 // ============================================================================
278 // NyquistEffectsModule implementation
279 // ============================================================================
NyquistEffectsModule::Initialize
bool Initialize() override
Definition: LoadNyquist.cpp:126
DECLARE_BUILTIN_MODULE
DECLARE_BUILTIN_MODULE(NyquistsEffectBuiltin)
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
NYQUIST_PROMPT_ID
#define NYQUIST_PROMPT_ID
Definition: PluginManager.h:360
NyquistEffect
An Effect that calls up a Nyquist (XLISP) plug-in, i.e. many possible effects from this one class.
Definition: Nyquist.h:65
NyquistEffect::InitializationError
const TranslatableString & InitializationError() const
Definition: Nyquist.h:135
NyquistEffectsModule::GetOptionalFamilySymbol
EffectFamilySymbol GetOptionalFamilySymbol() override
Definition: LoadNyquist.cpp:155
NyquistEffectsModule::NyquistEffectsModule
NyquistEffectsModule()
Definition: LoadNyquist.cpp:84
PluginPath
wxString PluginPath
type alias for identifying a Plugin supplied by a module, each module defining its own interpretation...
Definition: Identifier.h:214
NyquistEffectsModule
Definition: LoadNyquist.h:22
NyquistEffectsModule::GetDescription
TranslatableString GetDescription() override
Definition: LoadNyquist.cpp:117
NyquistEffectsModule::GetPath
PluginPath GetPath() override
Definition: LoadNyquist.cpp:96
XO
#define XO(s)
Definition: Internat.h:31
FileNames::PlugInDir
FILES_API FilePath PlugInDir()
The user plug-in directory (not a system one)
NYQUISTEFFECTS_FAMILY
#define NYQUISTEFFECTS_FAMILY
Definition: Effect.h:60
NyquistEffectsModule::InstallPath
FilePath InstallPath() override
Definition: LoadNyquist.cpp:170
NyquistEffectsModule::GetSymbol
ComponentInterfaceSymbol GetSymbol() override
Definition: LoadNyquist.cpp:101
wxArrayStringEx
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Definition: wxArrayStringEx.h:18
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
NyquistEffectsModule::FindPluginPaths
PluginPaths FindPluginPaths(PluginManagerInterface &pm) override
Definition: LoadNyquist.cpp:223
NyquistEffectsModule::CreateInstance
std::unique_ptr< ComponentInterface > CreateInstance(const PluginPath &path) override
Definition: LoadNyquist.cpp:268
NyquistEffectsModule::~NyquistEffectsModule
virtual ~NyquistEffectsModule()
Definition: LoadNyquist.cpp:88
PluginManagerInterface::IsPluginRegistered
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)?
FilePath
wxString FilePath
Definition: Project.h:20
PluginManagerInterface
Definition: PluginInterface.h:55
NyquistEffect::GetNyquistSearchPath
static FilePaths GetNyquistSearchPath()
Definition: Nyquist.cpp:2568
NYQUIST_PROMPT_NAME
#define NYQUIST_PROMPT_NAME
Definition: PluginManager.h:362
name
const TranslatableString name
Definition: Distortion.cpp:98
NyquistEffectsModule::GetFileExtensions
const FileExtensions & GetFileExtensions() override
Definition: LoadNyquist.cpp:164
PluginManagerInterface::FindFilesInPathList
virtual void FindFilesInPathList(const wxString &pattern, const FilePaths &pathList, FilePaths &files, bool directories=false)=0
NyquistEffectsModule::DiscoverPluginsAtPath
unsigned DiscoverPluginsAtPath(const PluginPath &path, TranslatableString &errMsg, const RegistrationCallback &callback) override
Definition: LoadNyquist.cpp:239
Nyquist.h
NyquistEffect::IsOk
bool IsOk()
Definition: Nyquist.cpp:2979
NyquistEffectsModule::AutoRegisterPlugins
bool AutoRegisterPlugins(PluginManagerInterface &pm) override
Definition: LoadNyquist.cpp:175
PluginManagerInterface::DefaultRegistrationCallback
static const PluginID & DefaultRegistrationCallback(ModuleInterface *provider, ComponentInterface *ident)
Definition: PluginManager.cpp:329
NyquistEffectsModule::IsPluginValid
bool IsPluginValid(const PluginPath &path, bool bFast) override
Definition: LoadNyquist.cpp:256
PluginPaths
std::vector< PluginPath > PluginPaths
Definition: Identifier.h:215
FileNames::AudacityPathList
FILES_API const FilePaths & AudacityPathList()
A list of directories that should be searched for Audacity files (plug-ins, help files,...
kShippedEffects
static const wxChar * kShippedEffects[]
Definition: LoadNyquist.cpp:26
FileNames.h
NyquistEffectsModule::Terminate
void Terminate() override
Definition: LoadNyquist.cpp:148
LoadNyquist.h
DECLARE_MODULE_ENTRY
DECLARE_MODULE_ENTRY(AudacityModule)
Definition: LoadNyquist.cpp:66
ModuleInterface::RegistrationCallback
std::function< const PluginID &(ModuleInterface *, ComponentInterface *) > RegistrationCallback
Definition: ModuleInterface.h:123
safenew
#define safenew
Definition: MemoryX.h:10
NyquistEffectsModule::GetVersion
wxString GetVersion() override
Definition: LoadNyquist.cpp:111
NyquistEffectsModule::GetVendor
VendorSymbol GetVendor() override
Definition: LoadNyquist.cpp:106
NYQUISTEFFECTS_VERSION
#define NYQUISTEFFECTS_VERSION
Definition: Nyquist.h:24