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