audacia/src/effects/LoadEffects.cpp

215 lines
5.7 KiB
C++
Raw Normal View History

/**********************************************************************
Audacity: A Digital Audio Editor
LoadEffects.cpp
Dominic Mazzoni
2018-03-06 21:42:58 +00:00
**************************************************************************//**
Automation: AudacityCommand This is a squash of 50 commits. This merges the capabilities of BatchCommands and Effects using a new AudacityCommand class. AudacityCommand provides one function to specify the parameters, and then we leverage that one function in automation, whether by chains, mod-script-pipe or (future) Nyquist. - Now have AudacityCommand which is using the same mechanism as Effect - Has configurable parameters - Has data-entry GUI (built using shuttle GUI) - Registers with PluginManager. - Menu commands now provided in chains, and to python batch. - Tested with Zoom Toggle. - ShuttleParams now can set, get, set defaults, validate and specify the parameters. - Bugfix: Don't overwrite values with defaults first time out. - Add DefineParams function for all built-in effects. - Extend CommandContext to carry output channels for results. We abuse EffectsManager. It handles both Effects and AudacityCommands now. In time an Effect should become a special case of AudacityCommand and we'll split and rename the EffectManager class. - Don't use 'default' as a parameter name. - Massive renaming for CommandDefinitionInterface - EffectIdentInterface becomes EffectDefinitionInterface - EffectAutomationParameters becomes CommandAutomationParameters - PluginType is now a bit field. This way we can search for related types at the same time. - Most old batch commands made into AudacityCommands. The ones that weren't are for a reason. They are used by mod-script-pipe to carry commands and responses across from a non-GUI thread to the GUI thread. - Major tidy up of ScreenshotCommand - Reworking of SelectCommand - GetPreferenceCommand and SetPreferenceCommand - GetTrackInfo and SetTrackInfo - GetInfoCommand - Help, Open, Save, Import and Export commands. - Removed obsolete commands ExecMenu, GetProjectInfo and SetProjectInfo which are now better handled by other commands. - JSONify "GetInfo: Commands" output, i.e. commas in the right places. - General work on better Doxygen. - Lyrics -> LyricsPanel - Meter -> MeterPanel - Updated Linux makefile. - Scripting commands added into Extra menu. - Distinct names for previously duplicated find-clipping parameters. - Fixed longstanding error with erroneous status field number which previously caused an ASSERT in debug. - Sensible formatting of numbers in Chains, 0.1 not 0.1000000000137
2018-01-14 18:51:41 +00:00
\class BuiltinEffectsModule
\brief Internal module to auto register all built in effects.
2018-03-06 21:42:58 +00:00
*****************************************************************************/
#include "LoadEffects.h"
#include "../Prefs.h"
#include "Effect.h"
#include "ModuleManager.h"
static bool sInitialized = false;
struct BuiltinEffectsModule::Entry {
ComponentInterfaceSymbol name;
BuiltinEffectsModule::Factory factory;
bool excluded;
using Entries = std::vector< Entry >;
static Entries &Registry()
{
static Entries result;
return result;
}
};
void BuiltinEffectsModule::DoRegistration(
const ComponentInterfaceSymbol &name, const Factory &factory, bool excluded )
{
wxASSERT( !sInitialized );
Entry::Registry().emplace_back( Entry{ name, factory, excluded } );
}
// ============================================================================
// Module registration entry point
//
// This is the symbol that Audacity looks for when the module is built as a
// dynamic library.
//
// When the module is builtin to Audacity, we use the same function, but it is
// declared static so as not to clash with other builtin modules.
// ============================================================================
DECLARE_MODULE_ENTRY(AudacityModule)
{
// Create and register the importer
// Trust the module manager not to leak this
return safenew BuiltinEffectsModule();
}
// ============================================================================
// Register this as a builtin module
// ============================================================================
DECLARE_BUILTIN_MODULE(BuiltinsEffectBuiltin);
///////////////////////////////////////////////////////////////////////////////
//
// BuiltinEffectsModule
//
///////////////////////////////////////////////////////////////////////////////
BuiltinEffectsModule::BuiltinEffectsModule()
{
}
BuiltinEffectsModule::~BuiltinEffectsModule()
{
}
// ============================================================================
// ComponentInterface implementation
// ============================================================================
PluginPath BuiltinEffectsModule::GetPath()
{
return {};
}
ComponentInterfaceSymbol BuiltinEffectsModule::GetSymbol()
{
return XO("Builtin Effects");
}
VendorSymbol BuiltinEffectsModule::GetVendor()
{
return XO("The Audacity Team");
}
wxString BuiltinEffectsModule::GetVersion()
{
// This "may" be different if this were to be maintained as a separate DLL
return AUDACITY_VERSION_STRING;
}
TranslatableString BuiltinEffectsModule::GetDescription()
{
return XO("Provides builtin effects to Audacity");
}
// ============================================================================
// ModuleInterface implementation
// ============================================================================
bool BuiltinEffectsModule::Initialize()
{
for ( const auto &entry : Entry::Registry() ) {
auto path = wxString(BUILTIN_EFFECT_PREFIX) + entry.name.Internal();
mEffects[ path ] = &entry;
}
sInitialized = true;
return true;
}
void BuiltinEffectsModule::Terminate()
{
// Nothing to do here
return;
}
EffectFamilySymbol BuiltinEffectsModule::GetOptionalFamilySymbol()
{
// Returns empty, because there should not be an option in Preferences to
// disable the built-in effects.
return {};
}
const FileExtensions &BuiltinEffectsModule::GetFileExtensions()
{
static FileExtensions empty;
return empty;
}
bool BuiltinEffectsModule::AutoRegisterPlugins(PluginManagerInterface & pm)
{
TranslatableString ignoredErrMsg;
for (const auto &pair : mEffects)
{
const auto &path = pair.first;
if (!pm.IsPluginRegistered(path, &pair.second->name.Msgid()))
{
if ( pair.second->excluded )
continue;
// No checking of error ?
DiscoverPluginsAtPath(path, ignoredErrMsg,
PluginManagerInterface::DefaultRegistrationCallback);
}
}
// We still want to be called during the normal registration process
return false;
}
PluginPaths BuiltinEffectsModule::FindPluginPaths(PluginManagerInterface & WXUNUSED(pm))
{
PluginPaths names;
for ( const auto &pair : mEffects )
names.push_back( pair.first );
return names;
}
unsigned BuiltinEffectsModule::DiscoverPluginsAtPath(
const PluginPath & path, TranslatableString &errMsg,
const RegistrationCallback &callback)
{
errMsg = {};
2016-03-31 13:24:26 +00:00
auto effect = Instantiate(path);
if (effect)
{
2018-01-01 01:03:52 +00:00
if (callback)
callback(this, effect.get());
return 1;
}
errMsg = XO("Unknown built-in effect name");
return 0;
}
bool BuiltinEffectsModule::IsPluginValid(const PluginPath & path, bool bFast)
{
// bFast is unused as checking in the list is fast.
static_cast<void>(bFast);
return mEffects.find( path ) != mEffects.end();
}
std::unique_ptr<ComponentInterface>
BuiltinEffectsModule::CreateInstance(const PluginPath & path)
{
// Acquires a resource for the application.
return Instantiate(path);
}
// ============================================================================
// BuiltinEffectsModule implementation
// ============================================================================
std::unique_ptr<Effect> BuiltinEffectsModule::Instantiate(const PluginPath & path)
{
wxASSERT(path.StartsWith(BUILTIN_EFFECT_PREFIX));
auto iter = mEffects.find( path );
if ( iter != mEffects.end() )
return iter->second->factory();
wxASSERT( false );
return nullptr;
}