Audacity  2.2.2
LoadEffects.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  LoadEffects.cpp
6 
7  Dominic Mazzoni
8 
9 **************************************************************************/
14 #include "../Audacity.h"
15 #include "../Prefs.h"
16 
17 #include "LoadEffects.h"
18 #include "../MemoryX.h"
19 
20 #include "EffectManager.h"
21 
22 #include "Amplify.h"
23 #include "AutoDuck.h"
24 #include "BassTreble.h"
25 #include "ChangeSpeed.h"
26 #include "ClickRemoval.h"
27 #include "Compressor.h"
28 #include "Distortion.h"
29 #include "DtmfGen.h"
30 #include "Echo.h"
31 #include "Paulstretch.h"
32 #include "Equalization.h"
33 #include "Fade.h"
34 #include "Invert.h"
35 #include "Noise.h"
36 #ifdef EXPERIMENTAL_NOISE_REDUCTION
37 #include "NoiseReduction.h"
38 #endif
39 #include "NoiseRemoval.h"
40 #include "Normalize.h"
41 #include "Phaser.h"
42 #include "Repair.h"
43 #include "Repeat.h"
44 #include "Reverb.h"
45 #include "Reverse.h"
46 #include "Silence.h"
47 #include "ScienFilter.h"
48 #include "StereoToMono.h"
49 #ifdef USE_SBSMS
50 #include "TimeScale.h"
51 #endif
52 #include "ToneGen.h"
53 #include "TruncSilence.h"
54 #include "Wahwah.h"
55 
56 #include "FindClipping.h"
57 
58 #ifdef USE_SOUNDTOUCH
59 #include "ChangePitch.h"
60 #include "ChangeTempo.h"
61 #endif
62 
63 #include "../Experimental.h"
64 
65 //
66 // Include the SoundTouch effects, if requested
67 //
68 #if defined(USE_SOUNDTOUCH)
69 #define SOUNDTOUCH_EFFECTS \
70  EFFECT( CHANGEPITCH, EffectChangePitch, () ) \
71  EFFECT( CHANGETEMPO, EffectChangeTempo, () )
72 #else
73 #define SOUNDTOUCH_EFFECTS
74 #endif
75 
76 //
77 // Select the desired Noise Reduction/Removal effect
78 //
79 #if defined(EXPERIMENTAL_NOISE_REDUCTION)
80 #define NOISEREDUCTION_EFFECT \
81  EFFECT( NOISEREDUCTION, EffectNoiseReduction, () )
82 #else
83 #define NOISEREDUCTION_EFFECT \
84  EFFECT( NOISEREMOVAL, EffectNoiseRemoval, () )
85 #endif
86 
87 //
88 // Include the Classic Filters effect, if requested
89 //
90 #if defined(EXPERIMENTAL_SCIENCE_FILTERS)
91 #define CLASSICFILTER_EFFECT \
92  EFFECT( CLASSICFILTERS, EffectScienFilter, () )
93 #else
94 #define CLASSICFILTER_EFFECT
95 #endif
96 
97 //
98 // Include the SBSMS effect, if requested
99 //
100 #if defined(USE_SBSMS)
101 #define SBSMS_EFFECTS \
102  EFFECT( TIMESCALE, EffectTimeScale, () )
103 #else
104 #define SBSMS_EFFECTS
105 #endif
106 
107 //
108 // Define the list of effects that will be autoregistered and how to instantiate each
109 //
110 #define EFFECT_LIST \
111  EFFECT( CHIRP, EffectToneGen, (true) ) \
112  EFFECT( DTMFTONES, EffectDtmf, () ) \
113  EFFECT( NOISE, EffectNoise, () ) \
114  EFFECT( SILENCE, EffectSilence, () ) \
115  EFFECT( TONE, EffectToneGen, (false) ) \
116  EFFECT( AMPLIFY, EffectAmplify, () ) \
117  EFFECT( BASSTREBLE, EffectBassTreble, () ) \
118  EFFECT( CHANGESPEED, EffectChangeSpeed, () ) \
119  EFFECT( CLICKREMOVAL, EffectClickRemoval, () ) \
120  EFFECT( COMPRESSOR, EffectCompressor, () ) \
121  EFFECT( DISTORTION, EffectDistortion, () ) \
122  EFFECT( ECHO, EffectEcho, () ) \
123  EFFECT( EQUALIZATION, EffectEqualization, () ) \
124  EFFECT( FADEIN, EffectFade, (true) ) \
125  EFFECT( FADEOUT, EffectFade, (false) ) \
126  EFFECT( INVERT, EffectInvert, () ) \
127  EFFECT( NORMALIZE, EffectNormalize, () ) \
128  EFFECT( PHASER, EffectPhaser, () ) \
129  EFFECT( REPAIR, EffectRepair, () ) \
130  EFFECT( REPEAT, EffectRepeat, () ) \
131  EFFECT( REVERB, EffectReverb, () ) \
132  EFFECT( REVERSE, EffectReverse, () ) \
133  EFFECT( STEREOTOMONO, EffectStereoToMono, () ) \
134  EFFECT( TRUNCATESILENCE, EffectTruncSilence, () ) \
135  EFFECT( WAHWAH, EffectWahwah, () ) \
136  EFFECT( FINDCLIPPING, EffectFindClipping, () ) \
137  NOISEREDUCTION_EFFECT \
138  SOUNDTOUCH_EFFECTS \
139  EFFECT( AUTODUCK, EffectAutoDuck, () ) \
140  EFFECT( PAULSTRETCH, EffectPaulstretch, () ) \
141  SBSMS_EFFECTS
142 
143 //
144 // Define the list of effects that do not get autoregistered
145 //
146 #define EXCLUDE_LIST \
147  CLASSICFILTER_EFFECT
148 
149 //
150 // Define the EFFECT() macro to generate enum names
151 //
152 #define EFFECT(n, i, args) ENUM_ ## n,
153 
154 //
155 // Create the enum for the list of effects (will be used in a switch statement)
156 //
157 enum
158 {
161 };
162 
163 //
164 // Redefine EFFECT() to add the effect's name to an array
165 //
166 #undef EFFECT
167 #define EFFECT(n, i, args) results.push_back((n ## _PLUGIN_SYMBOL).Internal());
168 
169 //
170 // Create the effect name array
171 //
172 static const std::vector<wxString> kEffectNames() {
173  std::vector<wxString> results;
174  EFFECT_LIST;
175  return results;
176 }
177 
178 //
179 // Create the effect name array of excluded effects
180 //
181 static const std::vector<wxString> kExcludedNames() {
182  std::vector<wxString> results;
183  EXCLUDE_LIST;
184  return results;
185 }
186 
187 //
188 // Redefine EFFECT() to generate a case statement for the lookup switch
189 //
190 #undef EFFECT
191 #define EFFECT(n, i, args) case ENUM_ ## n: return std::make_unique<i> args;
192 
193 // ============================================================================
194 // Module registration entry point
195 //
196 // This is the symbol that Audacity looks for when the module is built as a
197 // dynamic library.
198 //
199 // When the module is builtin to Audacity, we use the same function, but it is
200 // declared static so as not to clash with other builtin modules.
201 // ============================================================================
202 DECLARE_MODULE_ENTRY(AudacityModule)
203 {
204  // Create and register the importer
205  // Trust the module manager not to leak this
206  return safenew BuiltinEffectsModule(moduleManager, path);
207 }
208 
209 // ============================================================================
210 // Register this as a builtin module
211 // ============================================================================
212 DECLARE_BUILTIN_MODULE(BuiltinsEffectBuiltin);
213 
215 //
216 // BuiltinEffectsModule
217 //
219 
221  const wxString *path)
222 {
223  mModMan = moduleManager;
224  if (path)
225  {
226  mPath = *path;
227  }
228 }
229 
231 {
232  mPath.Clear();
233 }
234 
235 // ============================================================================
236 // IdentInterface implementation
237 // ============================================================================
238 
240 {
241  return mPath;
242 }
243 
245 {
246  return XO("Builtin Effects");
247 }
248 
250 {
251  return XO("The Audacity Team");
252 }
253 
255 {
256  // This "may" be different if this were to be maintained as a separate DLL
258 }
259 
261 {
262  return _("Provides builtin effects to Audacity");
263 }
264 
265 // ============================================================================
266 // ModuleInterface implementation
267 // ============================================================================
268 
270 {
271  const auto &names = kEffectNames();
272  for (const auto &name : names)
273  {
274  mNames.Add(wxString(BUILTIN_EFFECT_PREFIX) + name);
275  }
276 
277  const auto &excluded = kExcludedNames();
278  for (const auto &name : excluded)
279  {
280  mNames.Add(wxString(BUILTIN_EFFECT_PREFIX) + name);
281  }
282 
283  return true;
284 }
285 
287 {
288  // Nothing to do here
289  return;
290 }
291 
293 {
294  wxString ignoredErrMsg;
295  const auto &names = kEffectNames();
296  for (const auto &name : names)
297  {
298  wxString path(wxString(BUILTIN_EFFECT_PREFIX) + name);
299 
300  if (!pm.IsPluginRegistered(path))
301  {
302  // No checking of error ?
303  DiscoverPluginsAtPath(path, ignoredErrMsg,
305  }
306  }
307 
308  // We still want to be called during the normal registration process
309  return false;
310 }
311 
313 {
314  return mNames;
315 }
316 
318  const wxString & path, wxString &errMsg,
319  const RegistrationCallback &callback)
320 {
321  errMsg.clear();
322  auto effect = Instantiate(path);
323  if (effect)
324  {
325  if (callback)
326  callback(this, effect.get());
327  return 1;
328  }
329 
330  errMsg = _("Unknown built-in effect name");
331  return 0;
332 }
333 
334 bool BuiltinEffectsModule::IsPluginValid(const wxString & path, bool bFast)
335 {
336  // bFast is unused as checking in the list is fast.
337  static_cast<void>(bFast);
338  return mNames.Index(path) != wxNOT_FOUND;
339 }
340 
342 {
343  // Acquires a resource for the application.
344  // Safety of this depends on complementary calls to DeleteInstance on the module manager side.
345  return Instantiate(path).release();
346 }
347 
349 {
350  // Releases the resource.
351  std::unique_ptr < Effect > {
352  dynamic_cast<Effect *>(instance)
353  };
354 }
355 
356 // ============================================================================
357 // BuiltinEffectsModule implementation
358 // ============================================================================
359 
360 std::unique_ptr<Effect> BuiltinEffectsModule::Instantiate(const wxString & path)
361 {
362  wxASSERT(path.StartsWith(BUILTIN_EFFECT_PREFIX));
363  wxASSERT(mNames.Index(path) != wxNOT_FOUND);
364 
365  switch (mNames.Index(path))
366  {
367  EFFECT_LIST;
368  EXCLUDE_LIST;
369  }
370 
371  return nullptr;
372 }
static wxArrayString names()
Definition: Tags.cpp:697
#define AUDACITY_VERSION_STRING
Definition: Audacity.h:81
#define BUILTIN_EFFECT_PREFIX
Definition: Effect.h:47
DECLARE_BUILTIN_MODULE(BuiltinsEffectBuiltin)
static const PluginID & DefaultRegistrationCallback(ModuleInterface *provider, IdentInterface *ident)
IdentInterface * CreateInstance(const wxString &path) override
Base class for many of the effects in Audacity.
Definition: Effect.h:62
#define XO(s)
Definition: Internat.h:33
bool Initialize() override
#define safenew
Definition: Audacity.h:230
static const std::vector< wxString > kExcludedNames()
virtual bool IsPluginRegistered(const wxString &path)=0
std::unique_ptr< Effect > Instantiate(const wxString &path)
ModuleManagerInterface * mModMan
Definition: LoadEffects.h:64
#define EFFECT_LIST
virtual ~BuiltinEffectsModule()
bool AutoRegisterPlugins(PluginManagerInterface &pm) override
wxString GetPath() override
wxArrayString mNames
Definition: LoadEffects.h:67
IdentInterfaceSymbol pairs a persistent string identifier used internally with an optional...
IdentInterfaceSymbol GetSymbol() override
BuiltinEffectsModule(ModuleManagerInterface *moduleManager, const wxString *path)
static const std::vector< wxString > kEffectNames()
Internal module to auto register all built in effects.
Definition: LoadEffects.h:24
IdentInterfaceSymbol GetVendor() override
bool IsPluginValid(const wxString &path, bool bFast) override
_("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
DECLARE_MODULE_ENTRY(AudacityModule)
wxString GetVersion() override
const wxChar * name
Definition: Distortion.cpp:94
std::function< const PluginID &(ModuleInterface *, IdentInterface *) > RegistrationCallback
#define EXCLUDE_LIST
wxArrayString FindPluginPaths(PluginManagerInterface &pm) override
Change Pitch effect provides raising or lowering the pitch without changing the tempo.
IdentInterface provides name / vendor / version functions to identify plugins. It is what makes a cla...
unsigned DiscoverPluginsAtPath(const wxString &path, wxString &errMsg, const RegistrationCallback &callback) override
void Terminate() override
void DeleteInstance(IdentInterface *instance) override
wxString GetDescription() override