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 
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 XO("The Audacity Team");
112 }
113 
115 {
116  // This "may" be different if this were to be maintained as a separate DLL
117  return NYQUISTEFFECTS_VERSION;
118 }
119 
121 {
122  return _("Provides Nyquist Effects support to Audacity");
123 }
124 
125 // ============================================================================
126 // ModuleInterface implementation
127 // ============================================================================
128 
130 {
131  wxArrayString audacityPathList = wxGetApp().audacityPathList;
132 
133  for (size_t i = 0, cnt = audacityPathList.GetCount(); i < cnt; i++)
134  {
135  wxFileName name(audacityPathList[i], wxT(""));
136  name.AppendDir(wxT("nyquist"));
137  name.SetFullName(wxT("nyquist.lsp"));
138  if (name.FileExists())
139  {
140  // set_xlisp_path doesn't handle fn_Str() in Unicode build. May or may not actually work.
141  nyx_set_xlisp_path(name.GetPath().ToUTF8());
142  return true;
143  }
144  }
145 
146  wxLogWarning(wxT("Critical Nyquist files could not be found. Nyquist effects will not work."));
147 
148  return false;
149 }
150 
152 {
153  nyx_set_xlisp_path(NULL);
154 
155  return;
156 }
157 
159 {
160  static const wxString ext[] = { _T("ny") };
161  static const wxArrayString result{ sizeof(ext)/sizeof(*ext), ext };
162  return result;
163 }
164 
166 {
167  return FileNames::PlugInDir();
168 }
169 
171 {
172  // Autoregister effects that we "think" are ones that have been shipped with
173  // Audacity. A little simplistic, but it should suffice for now.
174  wxArrayString pathList = NyquistEffect::GetNyquistSearchPath();
175  wxArrayString files;
176  wxString ignoredErrMsg;
177 
179  {
180  // No checking of error ?
183  }
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.GetCount(); j < cnt; j++)
196  {
197  if (!pm.IsPluginRegistered(files[j]))
198  {
199  // No checking of error ?
200  DiscoverPluginsAtPath(files[j], ignoredErrMsg,
202  }
203  }
204  }
205 
206  // We still want to be called during the normal registration process
207  return false;
208 }
209 
211 {
212  wxArrayString pathList = NyquistEffect::GetNyquistSearchPath();
213  wxArrayString files;
214 
215  // Add the Nyquist prompt effect
216  files.Add(NYQUIST_PROMPT_ID);
217  files.Add(NYQUIST_TOOLS_PROMPT_ID);
218 
219  // Load .ny plug-ins
220  pm.FindFilesInPathList(wxT("*.ny"), pathList, files);
221  // LLL: Works for all platform with NEW plugin support (dups are removed)
222  pm.FindFilesInPathList(wxT("*.NY"), pathList, files); // Ed's fix for bug 179
223 
224  return files;
225 }
226 
228  const wxString & path, wxString &errMsg,
229  const RegistrationCallback &callback)
230 {
231  errMsg.clear();
232  NyquistEffect effect(path);
233  if (effect.IsOk())
234  {
235  if (callback)
236  callback(this, &effect);
237  return 1;
238  }
239 
240  errMsg = effect.InitializationError();
241  return 0;
242 }
243 
244 bool NyquistEffectsModule::IsPluginValid(const wxString & path, bool bFast)
245 {
246  // Ignores bFast parameter, since checking file exists is fast enough for
247  // the small number of Nyquist plug-ins that we have.
248  static_cast<void>(bFast);
249  if((path == NYQUIST_PROMPT_ID) || (path == NYQUIST_TOOLS_PROMPT_ID))
250  return true;
251 
252  return wxFileName::FileExists(path);
253 }
254 
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 
269 {
270  std::unique_ptr < NyquistEffect > {
271  dynamic_cast<NyquistEffect *>(instance)
272  };
273 }
274 
275 // ============================================================================
276 // NyquistEffectsModule implementation
277 // ============================================================================
#define NYQUIST_TOOLS_PROMPT_ID
Definition: Nyquist.h:38
virtual void FindFilesInPathList(const wxString &pattern, const wxArrayString &pathList, wxArrayString &files, bool directories=false)=0
static const PluginID & DefaultRegistrationCallback(ModuleInterface *provider, IdentInterface *ident)
static wxArrayString GetNyquistSearchPath()
Definition: Nyquist.cpp:2267
#define NYQUIST_PROMPT_ID
Definition: Nyquist.h:37
#define XO(s)
Definition: Internat.h:33
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:76
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:230
virtual bool IsPluginRegistered(const wxString &path)=0
IdentInterfaceSymbol GetVendor() override
#define NYQUISTEFFECTS_VERSION
Definition: Nyquist.h:30
wxString GetPath() override
Definition: LoadNyquist.cpp:99
IdentInterface * CreateInstance(const wxString &path) override
IdentInterfaceSymbol GetSymbol() override
virtual ~NyquistEffectsModule()
Definition: LoadNyquist.cpp:90
IdentInterfaceSymbol pairs a persistent string identifier used internally with an optional...
static const wxChar * kShippedEffects[]
Definition: LoadNyquist.cpp:23
ModuleManagerInterface * mModMan
Definition: LoadNyquist.h:58
DECLARE_MODULE_ENTRY(AudacityModule)
Definition: LoadNyquist.cpp:62
DECLARE_BUILTIN_MODULE(NyquistsEffectBuiltin)
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
const wxString & InitializationError() const
Definition: Nyquist.h:144
const wxChar * name
Definition: Distortion.cpp:94
std::function< const PluginID &(ModuleInterface *, IdentInterface *) > RegistrationCallback
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
IdentInterface provides name / vendor / version functions to identify plugins. It is what makes a cla...
static wxString PlugInDir()
The user plug-in directory (not a system one)
Definition: FileNames.cpp:214
void Terminate() override
bool Initialize() override
wxString GetVersion() override