mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-16 07:31:16 +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 "LoadEffects.h"
|
||||
|
||||
#include "../Experimental.h"
|
||||
|
||||
#include "../Prefs.h"
|
||||
|
||||
#include "Amplify.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 "Effect.h"
|
||||
|
||||
#include "FindClipping.h"
|
||||
|
||||
#ifdef USE_SOUNDTOUCH
|
||||
#include "ChangePitch.h"
|
||||
#include "ChangeTempo.h"
|
||||
#endif
|
||||
static bool sInitialized = false;
|
||||
|
||||
struct BuiltinEffectsModule::Entry {
|
||||
wxString name;
|
||||
@@ -76,142 +36,10 @@ struct BuiltinEffectsModule::Entry {
|
||||
void BuiltinEffectsModule::DoRegistration(
|
||||
const ComponentInterfaceSymbol &name, const Factory &factory, bool excluded )
|
||||
{
|
||||
wxASSERT( !sInitialized );
|
||||
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
|
||||
//
|
||||
@@ -290,18 +118,11 @@ TranslatableString BuiltinEffectsModule::GetDescription()
|
||||
|
||||
bool BuiltinEffectsModule::Initialize()
|
||||
{
|
||||
const auto &names = kEffectNames();
|
||||
for (const auto &name : names)
|
||||
{
|
||||
mNames.push_back(wxString(BUILTIN_EFFECT_PREFIX) + name);
|
||||
for ( const auto &entry : Entry::Registry() ) {
|
||||
auto path = wxString(BUILTIN_EFFECT_PREFIX) + entry.name;
|
||||
mEffects[ path ] = &entry;
|
||||
}
|
||||
|
||||
const auto &excluded = kExcludedNames();
|
||||
for (const auto &name : excluded)
|
||||
{
|
||||
mNames.push_back(wxString(BUILTIN_EFFECT_PREFIX) + name);
|
||||
}
|
||||
|
||||
sInitialized = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -327,11 +148,11 @@ const FileExtensions &BuiltinEffectsModule::GetFileExtensions()
|
||||
bool BuiltinEffectsModule::AutoRegisterPlugins(PluginManagerInterface & pm)
|
||||
{
|
||||
TranslatableString ignoredErrMsg;
|
||||
const auto &names = kEffectNames();
|
||||
for (const auto &name : names)
|
||||
for (const auto &pair : mEffects)
|
||||
{
|
||||
PluginPath path(wxString(BUILTIN_EFFECT_PREFIX) + name);
|
||||
|
||||
if ( pair.second->excluded )
|
||||
continue;
|
||||
const auto &path = pair.first;
|
||||
if (!pm.IsPluginRegistered(path))
|
||||
{
|
||||
// No checking of error ?
|
||||
@@ -346,7 +167,10 @@ bool BuiltinEffectsModule::AutoRegisterPlugins(PluginManagerInterface & 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(
|
||||
@@ -370,7 +194,7 @@ bool BuiltinEffectsModule::IsPluginValid(const PluginPath & path, bool bFast)
|
||||
{
|
||||
// bFast is unused as checking in the list is fast.
|
||||
static_cast<void>(bFast);
|
||||
return make_iterator_range( mNames ).contains( path );
|
||||
return mEffects.find( path ) != mEffects.end();
|
||||
}
|
||||
|
||||
ComponentInterface *BuiltinEffectsModule::CreateInstance(const PluginPath & path)
|
||||
@@ -395,14 +219,10 @@ void BuiltinEffectsModule::DeleteInstance(ComponentInterface *instance)
|
||||
std::unique_ptr<Effect> BuiltinEffectsModule::Instantiate(const PluginPath & path)
|
||||
{
|
||||
wxASSERT(path.StartsWith(BUILTIN_EFFECT_PREFIX));
|
||||
auto index = make_iterator_range( mNames ).index( path );
|
||||
wxASSERT( index != wxNOT_FOUND );
|
||||
|
||||
switch ( index )
|
||||
{
|
||||
EFFECT_LIST;
|
||||
EXCLUDE_LIST;
|
||||
}
|
||||
auto iter = mEffects.find( path );
|
||||
if ( iter != mEffects.end() )
|
||||
return iter->second->factory();
|
||||
|
||||
wxASSERT( false );
|
||||
return nullptr;
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include "../MemoryX.h"
|
||||
|
||||
class Effect;
|
||||
@@ -81,7 +82,7 @@ private:
|
||||
ModuleManagerInterface *mModMan;
|
||||
PluginPath mPath;
|
||||
|
||||
PluginPaths mNames;
|
||||
|
||||
struct Entry;
|
||||
using EffectHash = std::unordered_map< wxString, const Entry* > ;
|
||||
EffectHash mEffects;
|
||||
};
|
||||
|
Reference in New Issue
Block a user