Audacity  2.2.2
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 #include "../../AudacityApp.h"
12 
13 #include <wx/log.h>
14 
15 #include "Nyquist.h"
16 
17 #include "LoadNyquist.h"
18 #include "../../FileNames.h"
19 
20 // ============================================================================
21 // List of effects that ship with Audacity. These will be autoregistered.
22 // ============================================================================
23 const static wxChar *kShippedEffects[] =
24 {
25  wxT("adjustable-fade.ny"),
26  wxT("beat.ny"),
27  wxT("clipfix.ny"),
28  wxT("crossfadeclips.ny"),
29  wxT("crossfadetracks.ny"),
30  wxT("delay.ny"),
31  wxT("equalabel.ny"),
32  wxT("highpass.ny"),
33  wxT("limiter.ny"),
34  wxT("lowpass.ny"),
35  wxT("notch.ny"),
36  wxT("pluck.ny"),
37  wxT("rhythmtrack.ny"),
38  wxT("rissetdrum.ny"),
39  wxT("sample-data-export.ny"),
40  wxT("sample-data-import.ny"),
41  wxT("SilenceMarker.ny"),
42  wxT("SoundFinder.ny"),
43  wxT("SpectralEditMulti.ny"),
44  wxT("SpectralEditParametricEQ.ny"),
45  wxT("SpectralEditShelves.ny"),
46  wxT("StudioFadeOut.ny"),
47  wxT("tremolo.ny"),
48  wxT("vocalrediso.ny"),
49  wxT("vocalremover.ny"),
50  wxT("vocoder.ny"),
51 };
52 
53 // ============================================================================
54 // Module registration entry point
55 //
56 // This is the symbol that Audacity looks for when the module is built as a
57 // dynamic library.
58 //
59 // When the module is builtin to Audacity, we use the same function, but it is
60 // declared static so as not to clash with other builtin modules.
61 // ============================================================================
62 DECLARE_MODULE_ENTRY(AudacityModule)
63 {
64  // Create and register the importer
65  // Trust the module manager not to leak this
66  return safenew NyquistEffectsModule(moduleManager, path);
67 }
68 
69 // ============================================================================
70 // Register this as a builtin module
71 // ============================================================================
72 DECLARE_BUILTIN_MODULE(NyquistsEffectBuiltin);
73 
75 //
76 // NyquistEffectsModule
77 //
79 
80 NyquistEffectsModule::NyquistEffectsModule(ModuleManagerInterface *moduleManager,
81  const wxString *path)
82 {
83  mModMan = moduleManager;
84  if (path)
85  {
86  mPath = *path;
87  }
88 }
89 
91 {
92  mPath.Clear();
93 }
94 
95 // ============================================================================
96 // IdentInterface implementation
97 // ============================================================================
98 
100 {
101  return mPath;
102 }
103 
105 {
106  return XO("Nyquist Effects");
107 }
108 
110 {
111  return GetSymbol();
112 }
113 
115 {
116  return XO("The Audacity Team");
117 }
118 
120 {
121  // This "may" be different if this were to be maintained as a separate DLL
122  return NYQUISTEFFECTS_VERSION;
123 }
124 
126 {
127  return _("Provides Nyquist Effects support to Audacity");
128 }
129 
130 // ============================================================================
131 // ModuleInterface implementation
132 // ============================================================================
133 
135 {
136  wxArrayString audacityPathList = wxGetApp().audacityPathList;
137 
138  for (size_t i = 0, cnt = audacityPathList.GetCount(); i < cnt; i++)
139  {
140  wxFileName name(audacityPathList[i], wxT(""));
141  name.AppendDir(wxT("nyquist"));
142  name.SetFullName(wxT("nyquist.lsp"));
143  if (name.FileExists())
144  {
145  // set_xlisp_path doesn't handle fn_Str() in Unicode build. May or may not actually work.
146  nyx_set_xlisp_path(name.GetPath().ToUTF8());
147  return true;
148  }
149  }
150 
151  wxLogWarning(wxT("Critical Nyquist files could not be found. Nyquist effects will not work."));
152 
153  return false;
154 }
155 
157 {
158  nyx_set_xlisp_path(NULL);
159 
160  return;
161 }
162 
164 {
165  static const wxString ext[] = { _T("ny") };
166  static const wxArrayString result{ sizeof(ext)/sizeof(*ext), ext };
167  return result;
168 }
169 
171 {
172  return FileNames::PlugInDir();
173 }
174 
175 bool NyquistEffectsModule::AutoRegisterPlugins(PluginManagerInterface & pm)
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  wxArrayString pathList = NyquistEffect::GetNyquistSearchPath();
180  wxArrayString files;
181  wxString ignoredErrMsg;
182 
183  if (!pm.IsPluginRegistered(NYQUIST_PROMPT_ID))
184  {
185  // No checking of error ?
187  PluginManagerInterface::DefaultRegistrationCallback);
188  }
189 
190  for (size_t i = 0; i < WXSIZEOF(kShippedEffects); i++)
191  {
192  files.Clear();
193  pm.FindFilesInPathList(kShippedEffects[i], pathList, files);
194  for (size_t j = 0, cnt = files.GetCount(); j < cnt; j++)
195  {
196  if (!pm.IsPluginRegistered(files[j]))
197  {
198  // No checking of error ?
199  DiscoverPluginsAtPath(files[j], ignoredErrMsg,
200  PluginManagerInterface::DefaultRegistrationCallback);
201  }
202  }
203  }
204 
205  // We still want to be called during the normal registration process
206  return false;
207 }
208 
209 wxArrayString NyquistEffectsModule::FindPluginPaths(PluginManagerInterface & pm)
210 {
211  wxArrayString pathList = NyquistEffect::GetNyquistSearchPath();
212  wxArrayString files;
213 
214  // Add the Nyquist prompt effect
215  files.Add(NYQUIST_PROMPT_ID);
216 
217  // Load .ny plug-ins
218  pm.FindFilesInPathList(wxT("*.ny"), pathList, files);
219  // LLL: Works for all platform with NEW plugin support (dups are removed)
220  pm.FindFilesInPathList(wxT("*.NY"), pathList, files); // Ed's fix for bug 179
221 
222  return files;
223 }
224 
226  const wxString & path, wxString &errMsg,
227  const RegistrationCallback &callback)
228 {
229  errMsg.clear();
230  NyquistEffect effect(path);
231  if (effect.IsOk())
232  {
233  if (callback)
234  callback(this, &effect);
235  return 1;
236  }
237 
238  errMsg = effect.InitializationError();
239  return 0;
240 }
241 
242 bool NyquistEffectsModule::IsPluginValid(const wxString & path, bool bFast)
243 {
244  // Ignores bFast parameter, since checking file exists is fast enough for
245  // the small number of Nyquist plug-ins that we have.
246  bFast;
247  if (path == NYQUIST_PROMPT_ID)
248  {
249  return true;
250  }
251 
252  return wxFileName::FileExists(path);
253 }
254 
255 IdentInterface *NyquistEffectsModule::CreateInstance(const wxString & path)
256 {
257  // Acquires a resource for the application.
258  auto effect = std::make_unique<NyquistEffect>(path);
259  if (effect->IsOk())
260  {
261  // Safety of this depends on complementary calls to DeleteInstance on the module manager side.
262  return effect.release();
263  }
264 
265  return NULL;
266 }
267 
268 void NyquistEffectsModule::DeleteInstance(IdentInterface *instance)
269 {
270  std::unique_ptr < NyquistEffect > {
271  dynamic_cast<NyquistEffect *>(instance)
272  };
273 }
274 
275 // ============================================================================
276 // NyquistEffectsModule implementation
277 // ============================================================================
wxString GetName() override
static wxArrayString GetNyquistSearchPath()
Definition: Nyquist.cpp:2025
#define NYQUIST_PROMPT_ID
Definition: Nyquist.h:33
#define XO(s)
Definition: Internat.h:30
void DeleteInstance(IdentInterface *instance) override
An Effect that calls up a Nyquist (XLISP) plug-in, i.e. many possible effects from this one class...
Definition: Nyquist.h:68
wxString InstallPath() override
NyquistEffectsModule(ModuleManagerInterface *moduleManager, const wxString *path)
Definition: LoadNyquist.cpp:80
wxArrayString FindPluginPaths(PluginManagerInterface &pm) override
unsigned DiscoverPluginsAtPath(const wxString &path, wxString &errMsg, const RegistrationCallback &callback) override
wxArrayString FileExtensions() override
#define safenew
Definition: Audacity.h:223
#define NYQUISTEFFECTS_VERSION
Definition: Nyquist.h:30
wxString GetVendor() override
wxString GetPath() override
Definition: LoadNyquist.cpp:99
IdentInterface * CreateInstance(const wxString &path) override
virtual ~NyquistEffectsModule()
Definition: LoadNyquist.cpp:90
static const wxChar * kShippedEffects[]
Definition: LoadNyquist.cpp:23
wxString GetSymbol() override
ModuleManagerInterface * mModMan
Definition: LoadNyquist.h:59
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
DECLARE_MODULE_ENTRY(AudacityModule)
Definition: LoadNyquist.cpp:62
DECLARE_BUILTIN_MODULE(NyquistsEffectBuiltin)
const wxString & InitializationError() const
Definition: Nyquist.h:137
const wxChar * name
Definition: Distortion.cpp:94
wxString GetDescription() override
wxArrayString audacityPathList
A list of directories that should be searched for Audacity files (plug-ins, help files, etc.).
Definition: AudacityApp.h:138
bool AutoRegisterPlugins(PluginManagerInterface &pm) override
AudacityApp & wxGetApp()
bool IsPluginValid(const wxString &path, bool bFast) override
static wxString PlugInDir()
The user plug-in directory (not a system one)
Definition: FileNames.cpp:208
void Terminate() override
bool Initialize() override
wxString GetVersion() override