mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-16 15:41:11 +02:00
LoadEffects.cpp doesn't depend on individual effect classes...
This commit is contained in:
@@ -14,51 +14,11 @@
|
|||||||
#include "../Audacity.h" // for USE_* macros
|
#include "../Audacity.h" // for USE_* macros
|
||||||
#include "LoadEffects.h"
|
#include "LoadEffects.h"
|
||||||
|
|
||||||
#include "../Experimental.h"
|
|
||||||
|
|
||||||
#include "../Prefs.h"
|
#include "../Prefs.h"
|
||||||
|
|
||||||
#include "Amplify.h"
|
#include "Effect.h"
|
||||||
#include "AutoDuck.h"
|
|
||||||
#include "BassTreble.h"
|
|
||||||
#include "ChangeSpeed.h"
|
|
||||||
#include "ClickRemoval.h"
|
|
||||||
#include "Compressor.h"
|
|
||||||
#include "Distortion.h"
|
|
||||||
#include "DtmfGen.h"
|
|
||||||
#include "Echo.h"
|
|
||||||
#include "Paulstretch.h"
|
|
||||||
#include "Equalization.h"
|
|
||||||
#include "Fade.h"
|
|
||||||
#include "Invert.h"
|
|
||||||
#include "Loudness.h"
|
|
||||||
#include "Noise.h"
|
|
||||||
#ifdef EXPERIMENTAL_NOISE_REDUCTION
|
|
||||||
#include "NoiseReduction.h"
|
|
||||||
#endif
|
|
||||||
#include "NoiseRemoval.h"
|
|
||||||
#include "Normalize.h"
|
|
||||||
#include "Phaser.h"
|
|
||||||
#include "Repair.h"
|
|
||||||
#include "Repeat.h"
|
|
||||||
#include "Reverb.h"
|
|
||||||
#include "Reverse.h"
|
|
||||||
#include "Silence.h"
|
|
||||||
#include "ScienFilter.h"
|
|
||||||
#include "StereoToMono.h"
|
|
||||||
#ifdef USE_SBSMS
|
|
||||||
#include "TimeScale.h"
|
|
||||||
#endif
|
|
||||||
#include "ToneGen.h"
|
|
||||||
#include "TruncSilence.h"
|
|
||||||
#include "Wahwah.h"
|
|
||||||
|
|
||||||
#include "FindClipping.h"
|
static bool sInitialized = false;
|
||||||
|
|
||||||
#ifdef USE_SOUNDTOUCH
|
|
||||||
#include "ChangePitch.h"
|
|
||||||
#include "ChangeTempo.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct BuiltinEffectsModule::Entry {
|
struct BuiltinEffectsModule::Entry {
|
||||||
wxString name;
|
wxString name;
|
||||||
@@ -76,142 +36,10 @@ struct BuiltinEffectsModule::Entry {
|
|||||||
void BuiltinEffectsModule::DoRegistration(
|
void BuiltinEffectsModule::DoRegistration(
|
||||||
const ComponentInterfaceSymbol &name, const Factory &factory, bool excluded )
|
const ComponentInterfaceSymbol &name, const Factory &factory, bool excluded )
|
||||||
{
|
{
|
||||||
|
wxASSERT( !sInitialized );
|
||||||
Entry::Registry().emplace_back( Entry{ name.Internal(), factory, excluded } );
|
Entry::Registry().emplace_back( Entry{ name.Internal(), factory, excluded } );
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// Include the SoundTouch effects, if requested
|
|
||||||
//
|
|
||||||
#if defined(USE_SOUNDTOUCH)
|
|
||||||
#define SOUNDTOUCH_EFFECTS \
|
|
||||||
EFFECT( CHANGEPITCH, EffectChangePitch, () ) \
|
|
||||||
EFFECT( CHANGETEMPO, EffectChangeTempo, () )
|
|
||||||
#else
|
|
||||||
#define SOUNDTOUCH_EFFECTS
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//
|
|
||||||
// Select the desired Noise Reduction/Removal effect
|
|
||||||
//
|
|
||||||
#if defined(EXPERIMENTAL_NOISE_REDUCTION)
|
|
||||||
#define NOISEREDUCTION_EFFECT \
|
|
||||||
EFFECT( NOISEREDUCTION, EffectNoiseReduction, () )
|
|
||||||
#else
|
|
||||||
#define NOISEREDUCTION_EFFECT \
|
|
||||||
EFFECT( NOISEREMOVAL, EffectNoiseRemoval, () )
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//
|
|
||||||
// Include the Classic Filters effect, if requested
|
|
||||||
//
|
|
||||||
#if defined(EXPERIMENTAL_SCIENCE_FILTERS)
|
|
||||||
#define CLASSICFILTER_EFFECT \
|
|
||||||
EFFECT( CLASSICFILTERS, EffectScienFilter, () )
|
|
||||||
#else
|
|
||||||
#define CLASSICFILTER_EFFECT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//
|
|
||||||
// Include the SBSMS effect, if requested
|
|
||||||
//
|
|
||||||
#if defined(USE_SBSMS)
|
|
||||||
#define SBSMS_EFFECTS \
|
|
||||||
EFFECT( TIMESCALE, EffectTimeScale, () )
|
|
||||||
#else
|
|
||||||
#define SBSMS_EFFECTS
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define the list of effects that will be autoregistered and how to instantiate each
|
|
||||||
//
|
|
||||||
#define EFFECT_LIST \
|
|
||||||
EFFECT( CHIRP, EffectChirp, () ) \
|
|
||||||
EFFECT( DTMFTONES, EffectDtmf, () ) \
|
|
||||||
EFFECT( NOISE, EffectNoise, () ) \
|
|
||||||
EFFECT( SILENCE, EffectSilence, () ) \
|
|
||||||
EFFECT( TONE, EffectTone, () ) \
|
|
||||||
EFFECT( AMPLIFY, EffectAmplify, () ) \
|
|
||||||
EFFECT( BASSTREBLE, EffectBassTreble, () ) \
|
|
||||||
EFFECT( CHANGESPEED, EffectChangeSpeed, () ) \
|
|
||||||
EFFECT( CLICKREMOVAL, EffectClickRemoval, () ) \
|
|
||||||
EFFECT( COMPRESSOR, EffectCompressor, () ) \
|
|
||||||
EFFECT( DISTORTION, EffectDistortion, () ) \
|
|
||||||
EFFECT( ECHO, EffectEcho, () ) \
|
|
||||||
EFFECT( FADEIN, EffectFadeIn, () ) \
|
|
||||||
EFFECT( FADEOUT, EffectFadeOut, () ) \
|
|
||||||
EFFECT( FILTER_CURVE, EffectEqualizationCurve, () ) \
|
|
||||||
EFFECT( GRAPHIC_EQ, EffectEqualizationGraphic, () ) \
|
|
||||||
EFFECT( INVERT, EffectInvert, () ) \
|
|
||||||
EFFECT( LOUDNESS , EffectLoudness, () ) \
|
|
||||||
EFFECT( NORMALIZE, EffectNormalize, () ) \
|
|
||||||
EFFECT( PHASER, EffectPhaser, () ) \
|
|
||||||
EFFECT( REPAIR, EffectRepair, () ) \
|
|
||||||
EFFECT( REPEAT, EffectRepeat, () ) \
|
|
||||||
EFFECT( REVERB, EffectReverb, () ) \
|
|
||||||
EFFECT( REVERSE, EffectReverse, () ) \
|
|
||||||
EFFECT( STEREOTOMONO, EffectStereoToMono, () ) \
|
|
||||||
EFFECT( TRUNCATESILENCE, EffectTruncSilence, () ) \
|
|
||||||
EFFECT( WAHWAH, EffectWahwah, () ) \
|
|
||||||
EFFECT( FINDCLIPPING, EffectFindClipping, () ) \
|
|
||||||
NOISEREDUCTION_EFFECT \
|
|
||||||
SOUNDTOUCH_EFFECTS \
|
|
||||||
EFFECT( AUTODUCK, EffectAutoDuck, () ) \
|
|
||||||
EFFECT( PAULSTRETCH, EffectPaulstretch, () ) \
|
|
||||||
SBSMS_EFFECTS
|
|
||||||
|
|
||||||
// EFFECT( EQUALIZATION, EffectEqualization, () ) \
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define the list of effects that do not get autoregistered
|
|
||||||
//
|
|
||||||
#define EXCLUDE_LIST \
|
|
||||||
CLASSICFILTER_EFFECT
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define the EFFECT() macro to generate enum names
|
|
||||||
//
|
|
||||||
#define EFFECT(n, i, args) ENUM_ ## n,
|
|
||||||
|
|
||||||
//
|
|
||||||
// Create the enum for the list of effects (will be used in a switch statement)
|
|
||||||
//
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
EFFECT_LIST
|
|
||||||
EXCLUDE_LIST
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
// Redefine EFFECT() to add the effect's name to an array
|
|
||||||
//
|
|
||||||
#undef EFFECT
|
|
||||||
#define EFFECT(n, i, args) results.push_back((i :: Symbol).Internal());
|
|
||||||
|
|
||||||
//
|
|
||||||
// Create the effect name array
|
|
||||||
//
|
|
||||||
static const std::vector<wxString> kEffectNames() {
|
|
||||||
std::vector<wxString> results;
|
|
||||||
EFFECT_LIST;
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Create the effect name array of excluded effects
|
|
||||||
//
|
|
||||||
static const std::vector<wxString> kExcludedNames() {
|
|
||||||
std::vector<wxString> results;
|
|
||||||
EXCLUDE_LIST;
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Redefine EFFECT() to generate a case statement for the lookup switch
|
|
||||||
//
|
|
||||||
#undef EFFECT
|
|
||||||
#define EFFECT(n, i, args) case ENUM_ ## n: return std::make_unique<i> args;
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Module registration entry point
|
// Module registration entry point
|
||||||
//
|
//
|
||||||
@@ -290,18 +118,11 @@ TranslatableString BuiltinEffectsModule::GetDescription()
|
|||||||
|
|
||||||
bool BuiltinEffectsModule::Initialize()
|
bool BuiltinEffectsModule::Initialize()
|
||||||
{
|
{
|
||||||
const auto &names = kEffectNames();
|
for ( const auto &entry : Entry::Registry() ) {
|
||||||
for (const auto &name : names)
|
auto path = wxString(BUILTIN_EFFECT_PREFIX) + entry.name;
|
||||||
{
|
mEffects[ path ] = &entry;
|
||||||
mNames.push_back(wxString(BUILTIN_EFFECT_PREFIX) + name);
|
|
||||||
}
|
}
|
||||||
|
sInitialized = true;
|
||||||
const auto &excluded = kExcludedNames();
|
|
||||||
for (const auto &name : excluded)
|
|
||||||
{
|
|
||||||
mNames.push_back(wxString(BUILTIN_EFFECT_PREFIX) + name);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,11 +148,11 @@ const FileExtensions &BuiltinEffectsModule::GetFileExtensions()
|
|||||||
bool BuiltinEffectsModule::AutoRegisterPlugins(PluginManagerInterface & pm)
|
bool BuiltinEffectsModule::AutoRegisterPlugins(PluginManagerInterface & pm)
|
||||||
{
|
{
|
||||||
TranslatableString ignoredErrMsg;
|
TranslatableString ignoredErrMsg;
|
||||||
const auto &names = kEffectNames();
|
for (const auto &pair : mEffects)
|
||||||
for (const auto &name : names)
|
|
||||||
{
|
{
|
||||||
PluginPath path(wxString(BUILTIN_EFFECT_PREFIX) + name);
|
if ( pair.second->excluded )
|
||||||
|
continue;
|
||||||
|
const auto &path = pair.first;
|
||||||
if (!pm.IsPluginRegistered(path))
|
if (!pm.IsPluginRegistered(path))
|
||||||
{
|
{
|
||||||
// No checking of error ?
|
// No checking of error ?
|
||||||
@@ -346,7 +167,10 @@ bool BuiltinEffectsModule::AutoRegisterPlugins(PluginManagerInterface & pm)
|
|||||||
|
|
||||||
PluginPaths BuiltinEffectsModule::FindPluginPaths(PluginManagerInterface & WXUNUSED(pm))
|
PluginPaths BuiltinEffectsModule::FindPluginPaths(PluginManagerInterface & WXUNUSED(pm))
|
||||||
{
|
{
|
||||||
return mNames;
|
PluginPaths names;
|
||||||
|
for ( const auto &pair : mEffects )
|
||||||
|
names.push_back( pair.first );
|
||||||
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned BuiltinEffectsModule::DiscoverPluginsAtPath(
|
unsigned BuiltinEffectsModule::DiscoverPluginsAtPath(
|
||||||
@@ -370,7 +194,7 @@ bool BuiltinEffectsModule::IsPluginValid(const PluginPath & path, bool bFast)
|
|||||||
{
|
{
|
||||||
// bFast is unused as checking in the list is fast.
|
// bFast is unused as checking in the list is fast.
|
||||||
static_cast<void>(bFast);
|
static_cast<void>(bFast);
|
||||||
return make_iterator_range( mNames ).contains( path );
|
return mEffects.find( path ) != mEffects.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
ComponentInterface *BuiltinEffectsModule::CreateInstance(const PluginPath & path)
|
ComponentInterface *BuiltinEffectsModule::CreateInstance(const PluginPath & path)
|
||||||
@@ -395,14 +219,10 @@ void BuiltinEffectsModule::DeleteInstance(ComponentInterface *instance)
|
|||||||
std::unique_ptr<Effect> BuiltinEffectsModule::Instantiate(const PluginPath & path)
|
std::unique_ptr<Effect> BuiltinEffectsModule::Instantiate(const PluginPath & path)
|
||||||
{
|
{
|
||||||
wxASSERT(path.StartsWith(BUILTIN_EFFECT_PREFIX));
|
wxASSERT(path.StartsWith(BUILTIN_EFFECT_PREFIX));
|
||||||
auto index = make_iterator_range( mNames ).index( path );
|
auto iter = mEffects.find( path );
|
||||||
wxASSERT( index != wxNOT_FOUND );
|
if ( iter != mEffects.end() )
|
||||||
|
return iter->second->factory();
|
||||||
switch ( index )
|
|
||||||
{
|
|
||||||
EFFECT_LIST;
|
|
||||||
EXCLUDE_LIST;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
wxASSERT( false );
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <unordered_map>
|
||||||
#include "../MemoryX.h"
|
#include "../MemoryX.h"
|
||||||
|
|
||||||
class Effect;
|
class Effect;
|
||||||
@@ -81,7 +82,7 @@ private:
|
|||||||
ModuleManagerInterface *mModMan;
|
ModuleManagerInterface *mModMan;
|
||||||
PluginPath mPath;
|
PluginPath mPath;
|
||||||
|
|
||||||
PluginPaths mNames;
|
|
||||||
|
|
||||||
struct Entry;
|
struct Entry;
|
||||||
|
using EffectHash = std::unordered_map< wxString, const Entry* > ;
|
||||||
|
EffectHash mEffects;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user