1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-16 08:09:32 +02:00

Cleaner class hierarchy

This commit is contained in:
James Crook 2018-02-08 21:12:49 +00:00 committed by Paul Licameli
parent b1b1a362ed
commit 8ebf502cd6
11 changed files with 56 additions and 76 deletions

View File

@ -62,17 +62,30 @@ class ShuttleParams;
/*************************************************************************************//** /*************************************************************************************//**
\class ParamsInterface
\brief ParamsInterface provides a DefineParameters virtual function,
that defines the parameters of the command.
*******************************************************************************************/
class AUDACITY_DLL_API ParamsInterface /* not final */
{
public:
virtual ~ParamsInterface() {};
// returns true if implemented.
virtual bool DefineParams( ShuttleParams & WXUNUSED(S) ){ return false;};
};
/*************************************************************************************//**
\class CommandDefinitionInterface \class CommandDefinitionInterface
\brief CommandDefinitionInterface is an IdentInterface (to name the command) along with a \brief CommandDefinitionInterface is an IdentInterface (to name the command) along with a
DefineParameters virtual function, that defines the parameters of the command. DefineParameters virtual function, that defines the parameters of the command.
*******************************************************************************************/ *******************************************************************************************/
class AUDACITY_DLL_API CommandDefinitionInterface /* not final */ : public IdentInterface class AUDACITY_DLL_API CommandDefinitionInterface /* not final */ : public IdentInterface, public ParamsInterface
{ {
public: public:
virtual ~CommandDefinitionInterface() {}; virtual ~CommandDefinitionInterface() {};
// returns true if implemented.
virtual bool DefineParams( ShuttleParams & WXUNUSED(S) ){ return false;};
}; };
/*************************************************************************************//** /*************************************************************************************//**
@ -83,7 +96,7 @@ public:
flag-functions for interactivity, play-preview and whether the effect can run without a GUI. flag-functions for interactivity, play-preview and whether the effect can run without a GUI.
*******************************************************************************************/ *******************************************************************************************/
class AUDACITY_DLL_API EffectDefinitionInterface /* not final */ : public CommandDefinitionInterface class AUDACITY_DLL_API EffectDefinitionInterface /* not final */ : public IdentInterface, public ParamsInterface
{ {
public: public:
virtual ~EffectDefinitionInterface() {}; virtual ~EffectDefinitionInterface() {};

View File

@ -120,7 +120,7 @@ public:
// Return value is the number of plugins found. // Return value is the number of plugins found.
using RegistrationCallback = using RegistrationCallback =
std::function< std::function<
const PluginID &(ModuleInterface *, CommandDefinitionInterface *) >; const PluginID &(ModuleInterface *, IdentInterface *) >;
virtual unsigned DiscoverPluginsAtPath( virtual unsigned DiscoverPluginsAtPath(
const wxString & path, wxString &errMsg, const wxString & path, wxString &errMsg,
const RegistrationCallback &callback ) const RegistrationCallback &callback )

View File

@ -57,9 +57,9 @@ class PluginManagerInterface /* not final */
public: public:
static const PluginID &DefaultRegistrationCallback( static const PluginID &DefaultRegistrationCallback(
ModuleInterface *provider, CommandDefinitionInterface *ident ); ModuleInterface *provider, IdentInterface *ident );
static const PluginID &GenericRegistrationCallback( static const PluginID &AudacityCommandRegistrationCallback(
ModuleInterface *provider, CommandDefinitionInterface *ident ); ModuleInterface *provider, IdentInterface *ident );
virtual bool IsPluginRegistered(const wxString & path) = 0; virtual bool IsPluginRegistered(const wxString & path) = 0;

View File

@ -269,7 +269,7 @@ auto BatchCommands::GetAllCommands() -> CommandNameVector
PluginManager & pm = PluginManager::Get(); PluginManager & pm = PluginManager::Get();
EffectManager & em = EffectManager::Get(); EffectManager & em = EffectManager::Get();
{ {
const PluginDescriptor *plug = pm.GetFirstPlugin(PluginTypeEffect|PluginTypeGeneric); const PluginDescriptor *plug = pm.GetFirstPlugin(PluginTypeEffect|PluginTypeAudacityCommand);
while (plug) while (plug)
{ {
auto command = em.GetCommandIdentifier(plug->GetID()); auto command = em.GetCommandIdentifier(plug->GetID());
@ -278,7 +278,7 @@ auto BatchCommands::GetAllCommands() -> CommandNameVector
plug->GetUntranslatedName(), // plug->GetTranslatedName(), plug->GetUntranslatedName(), // plug->GetTranslatedName(),
command command
} ); } );
plug = pm.GetNextPlugin(PluginTypeEffect|PluginTypeGeneric); plug = pm.GetNextPlugin(PluginTypeEffect|PluginTypeAudacityCommand);
} }
} }
@ -615,7 +615,7 @@ bool BatchCommands::ApplyEffectCommand(const PluginID & ID, const wxString & com
// FIXME: for later versions may want to not select-all in batch mode. // FIXME: for later versions may want to not select-all in batch mode.
// IF nothing selected, THEN select everything // IF nothing selected, THEN select everything
// (most effects require that you have something selected). // (most effects require that you have something selected).
if( plug->GetPluginType() != PluginTypeGeneric ) if( plug->GetPluginType() != PluginTypeAudacityCommand )
project->SelectAllIfNone(); project->SelectAllIfNone();
bool res = false; bool res = false;
@ -625,7 +625,7 @@ bool BatchCommands::ApplyEffectCommand(const PluginID & ID, const wxString & com
// transfer the parameters to the effect... // transfer the parameters to the effect...
if (EffectManager::Get().SetEffectParameters(ID, params)) if (EffectManager::Get().SetEffectParameters(ID, params))
{ {
if( plug->GetPluginType() == PluginTypeGeneric ) if( plug->GetPluginType() == PluginTypeAudacityCommand )
// and apply the effect... // and apply the effect...
res = project->DoAudacityCommand(ID, res = project->DoAudacityCommand(ID,
Context, Context,

View File

@ -1376,18 +1376,24 @@ void PluginDescriptor::SetImporterExtensions(const wxArrayString & extensions)
// ============================================================================ // ============================================================================
const PluginID &PluginManagerInterface::DefaultRegistrationCallback( const PluginID &PluginManagerInterface::DefaultRegistrationCallback(
ModuleInterface *provider, CommandDefinitionInterface *pInterface ) ModuleInterface *provider, IdentInterface *pInterface )
{ {
EffectDefinitionInterface * pEInterface = dynamic_cast<EffectDefinitionInterface*>(pInterface); EffectDefinitionInterface * pEInterface = dynamic_cast<EffectDefinitionInterface*>(pInterface);
if( pEInterface ) if( pEInterface )
return PluginManager::Get().RegisterPlugin(provider, pEInterface, PluginTypeEffect); return PluginManager::Get().RegisterPlugin(provider, pEInterface, PluginTypeEffect);
return PluginManager::Get().RegisterPlugin(provider, pInterface); CommandDefinitionInterface * pCInterface = dynamic_cast<CommandDefinitionInterface*>(pInterface);
if( pCInterface )
return PluginManager::Get().RegisterPlugin(provider, pCInterface);
return "";
} }
const PluginID &PluginManagerInterface::GenericRegistrationCallback( const PluginID &PluginManagerInterface::AudacityCommandRegistrationCallback(
ModuleInterface *provider, CommandDefinitionInterface *pInterface ) ModuleInterface *provider, IdentInterface *pInterface )
{ {
return PluginManager::Get().RegisterPlugin(provider, pInterface); CommandDefinitionInterface * pCInterface = dynamic_cast<CommandDefinitionInterface*>(pInterface);
if( pCInterface )
return PluginManager::Get().RegisterPlugin(provider, pCInterface);
return "";
} }
@ -1416,17 +1422,10 @@ const PluginID & PluginManager::RegisterPlugin(ModuleInterface *module)
const PluginID & PluginManager::RegisterPlugin(ModuleInterface *provider, CommandDefinitionInterface *command) const PluginID & PluginManager::RegisterPlugin(ModuleInterface *provider, CommandDefinitionInterface *command)
{ {
PluginDescriptor & plug = CreatePlugin(GetID(command), command, (PluginType)PluginTypeGeneric); PluginDescriptor & plug = CreatePlugin(GetID(command), command, (PluginType)PluginTypeAudacityCommand);
plug.SetProviderID(PluginManager::GetID(provider)); plug.SetProviderID(PluginManager::GetID(provider));
//plug.SetEffectType(effect->GetType());
//plug.SetEffectFamily(effect->GetFamily());
//plug.SetEffectInteractive(effect->IsInteractive());
//plug.SetEffectDefault(effect->IsDefault());
//plug.SetEffectRealtime(effect->SupportsRealtime());
//plug.SetEffectAutomatable(effect->SupportsAutomation());
plug.SetEnabled(true); plug.SetEnabled(true);
plug.SetValid(true); plug.SetValid(true);
@ -1840,7 +1839,7 @@ bool PluginManager::DropFile(const wxString &fileName)
std::vector<PluginID> ids; std::vector<PluginID> ids;
std::vector<wxString> names; std::vector<wxString> names;
nPlugIns = module->DiscoverPluginsAtPath(dstPath, errMsg, nPlugIns = module->DiscoverPluginsAtPath(dstPath, errMsg,
[&](ModuleInterface *provider, CommandDefinitionInterface *ident){ [&](ModuleInterface *provider, IdentInterface *ident){
// Register as by default, but also collecting the PluginIDs // Register as by default, but also collecting the PluginIDs
// and names // and names
const PluginID * id = &PluginManagerInterface::DefaultRegistrationCallback( const PluginID * id = &PluginManagerInterface::DefaultRegistrationCallback(
@ -1911,7 +1910,7 @@ void PluginManager::Load()
// Now the rest // Now the rest
LoadGroup(&registry, PluginTypeEffect); LoadGroup(&registry, PluginTypeEffect);
LoadGroup(&registry, PluginTypeGeneric ); LoadGroup(&registry, PluginTypeAudacityCommand );
LoadGroup(&registry, PluginTypeExporter); LoadGroup(&registry, PluginTypeExporter);
LoadGroup(&registry, PluginTypeImporter); LoadGroup(&registry, PluginTypeImporter);
@ -2209,7 +2208,7 @@ void PluginManager::Save()
// Save the individual groups // Save the individual groups
SaveGroup(&registry, PluginTypeEffect); SaveGroup(&registry, PluginTypeEffect);
SaveGroup(&registry, PluginTypeExporter); SaveGroup(&registry, PluginTypeExporter);
SaveGroup(&registry, PluginTypeGeneric); SaveGroup(&registry, PluginTypeAudacityCommand);
SaveGroup(&registry, PluginTypeImporter); SaveGroup(&registry, PluginTypeImporter);
SaveGroup(&registry, PluginTypeStub); SaveGroup(&registry, PluginTypeStub);
@ -2635,7 +2634,7 @@ PluginID PluginManager::GetID(ModuleInterface *module)
PluginID PluginManager::GetID(CommandDefinitionInterface *command) PluginID PluginManager::GetID(CommandDefinitionInterface *command)
{ {
return wxString::Format(wxT("%s_%s_%s_%s_%s"), return wxString::Format(wxT("%s_%s_%s_%s_%s"),
GetPluginTypeString(PluginTypeGeneric), GetPluginTypeString(PluginTypeAudacityCommand),
wxEmptyString, wxEmptyString,
command->GetVendor(), command->GetVendor(),
command->GetName(), command->GetName(),
@ -2680,7 +2679,7 @@ wxString PluginManager::GetPluginTypeString(PluginType type)
case PluginTypeEffect: case PluginTypeEffect:
str = wxT("Effect"); str = wxT("Effect");
break; break;
case PluginTypeGeneric: case PluginTypeAudacityCommand:
str = wxT("Generic"); str = wxT("Generic");
break; break;
case PluginTypeExporter: case PluginTypeExporter:

View File

@ -34,7 +34,7 @@ typedef enum
PluginTypeNone = 0, // 2.1.0 placeholder entries...not used by 2.1.1 or greater PluginTypeNone = 0, // 2.1.0 placeholder entries...not used by 2.1.1 or greater
PluginTypeStub =1, // Used for plugins that have not yet been registered PluginTypeStub =1, // Used for plugins that have not yet been registered
PluginTypeEffect =1<<1, PluginTypeEffect =1<<1,
PluginTypeGeneric=1<<2, PluginTypeAudacityCommand=1<<2,
PluginTypeExporter=1<<3, PluginTypeExporter=1<<3,
PluginTypeImporter=1<<4, PluginTypeImporter=1<<4,
PluginTypeModule=1<<5, PluginTypeModule=1<<5,

View File

@ -326,9 +326,12 @@ void LongMessageDialog::AcceptText( const wxString & Text )
void LongMessageDialog::Flush() void LongMessageDialog::Flush()
{ {
if( pDlg ){ if( pDlg ){
pDlg->mText += "\n\n"; if( !pDlg->mText.EndsWith( "\n\n" ))
pDlg->mTextCtrl->SetValue( pDlg->mText ); {
pDlg->mTextCtrl->ShowPosition( pDlg->mTextCtrl->GetLastPosition() ); pDlg->mText += "\n\n";
pDlg->mTextCtrl->SetValue( pDlg->mText );
pDlg->mTextCtrl->ShowPosition( pDlg->mTextCtrl->GetLastPosition() );
}
} }
} }

View File

@ -16,7 +16,6 @@ This class now lists
- Tracks - Tracks
- Clips - Clips
- Labels - Labels
- Keycodes
- Boxes - Boxes
*//*******************************************************************/ *//*******************************************************************/
@ -40,7 +39,7 @@ This class now lists
#include "../ShuttleGui.h" #include "../ShuttleGui.h"
#include "CommandContext.h" #include "CommandContext.h"
const int nTypes =7; const int nTypes =6;
static const wxString kTypes[nTypes] = static const wxString kTypes[nTypes] =
{ {
XO("Commands"), XO("Commands"),
@ -48,7 +47,6 @@ static const wxString kTypes[nTypes] =
XO("Tracks"), XO("Tracks"),
XO("Clips"), XO("Clips"),
XO("Labels"), XO("Labels"),
XO("Keycodes"),
XO("Boxes") XO("Boxes")
}; };
@ -58,7 +56,6 @@ enum {
kTracks, kTracks,
kClips, kClips,
kLabels, kLabels,
kKeycodes,
kBoxes kBoxes
}; };
@ -134,7 +131,6 @@ bool GetInfoCommand::ApplyInner(const CommandContext &context)
case kTracks : return SendTracks( context ); case kTracks : return SendTracks( context );
case kClips : return SendClips( context ); case kClips : return SendClips( context );
case kLabels : return SendLabels( context ); case kLabels : return SendLabels( context );
case kKeycodes : return SendKeycodes( context );
case kBoxes : return SendBoxes( context ); case kBoxes : return SendBoxes( context );
default: default:
context.Status( "Command options not recognised" ); context.Status( "Command options not recognised" );
@ -178,44 +174,20 @@ bool GetInfoCommand::SendCommands(const CommandContext &context )
PluginManager & pm = PluginManager::Get(); PluginManager & pm = PluginManager::Get();
EffectManager & em = EffectManager::Get(); EffectManager & em = EffectManager::Get();
{ {
const PluginDescriptor *plug = pm.GetFirstPlugin(PluginTypeEffect | PluginTypeGeneric); const PluginDescriptor *plug = pm.GetFirstPlugin(PluginTypeEffect | PluginTypeAudacityCommand);
while (plug) while (plug)
{ {
auto command = em.GetCommandIdentifier(plug->GetID()); auto command = em.GetCommandIdentifier(plug->GetID());
if (!command.IsEmpty()){ if (!command.IsEmpty()){
em.GetCommandDefinition( plug->GetID(), context ); em.GetCommandDefinition( plug->GetID(), context );
} }
plug = pm.GetNextPlugin(PluginTypeEffect | PluginTypeGeneric ); plug = pm.GetNextPlugin(PluginTypeEffect | PluginTypeAudacityCommand );
} }
} }
context.EndArray(); context.EndArray();
return true; return true;
} }
#if 0
// Old version which gives enabled/disabled status too.
bool GetInfoCommand::SendMenus(const CommandContext &context)
{
bool bShowStatus = true;
wxArrayString names;
CommandManager *cmdManager = context.GetProject()->GetCommandManager();
cmdManager->GetAllCommandNames(names, false);
wxArrayString::iterator iter;
for (iter = names.begin(); iter != names.end(); ++iter)
{
wxString name = *iter;
wxString out = name;
if (bShowStatus)
{
out += wxT("\t");
out += cmdManager->GetEnabled(name) ? wxT("Enabled") : wxT("Disabled");
}
context.Status(out);
}
return true;
}
#endif
bool GetInfoCommand::SendBoxes(const CommandContext &context) bool GetInfoCommand::SendBoxes(const CommandContext &context)
{ {
//context.Status("Boxes"); //context.Status("Boxes");
@ -334,12 +306,6 @@ bool GetInfoCommand::SendLabels(const CommandContext &context)
return true; return true;
} }
bool GetInfoCommand::SendKeycodes(const CommandContext &context)
{
context.Status("Keycodes - Not yet");
return true;
}
/******************************************************************* /*******************************************************************
The various Explore functions are called from the Send functions, The various Explore functions are called from the Send functions,
and may be recursive. 'Send' is the top level. and may be recursive. 'Send' is the top level.

View File

@ -52,7 +52,6 @@ private:
bool SendTracks(const CommandContext & context); bool SendTracks(const CommandContext & context);
bool SendLabels(const CommandContext & context); bool SendLabels(const CommandContext & context);
bool SendClips(const CommandContext & context); bool SendClips(const CommandContext & context);
bool SendKeycodes(const CommandContext & context);
bool SendBoxes(const CommandContext & context); bool SendBoxes(const CommandContext & context);
void ExploreMenu( const CommandContext &context, wxMenu * pMenu, int Id, int depth ); void ExploreMenu( const CommandContext &context, wxMenu * pMenu, int Id, int depth );

View File

@ -224,7 +224,7 @@ bool BuiltinCommandsModule::AutoRegisterPlugins(PluginManagerInterface & pm)
// Uses Generic Registration, not Default. // Uses Generic Registration, not Default.
// Registers as TypeGeneric, not TypeEffect. // Registers as TypeGeneric, not TypeEffect.
DiscoverPluginsAtPath(path, ignoredErrMsg, DiscoverPluginsAtPath(path, ignoredErrMsg,
PluginManagerInterface::GenericRegistrationCallback); PluginManagerInterface::AudacityCommandRegistrationCallback);
} }
} }

View File

@ -200,7 +200,7 @@ wxString EffectManager::GetCommandDescription(const PluginID & ID)
void EffectManager::GetCommandDefinition(const PluginID & ID, const CommandContext & context) void EffectManager::GetCommandDefinition(const PluginID & ID, const CommandContext & context)
{ {
CommandDefinitionInterface *command; ParamsInterface *command;
command = GetEffect(ID); command = GetEffect(ID);
if( !command ) if( !command )
command = GetAudacityCommand( ID ); command = GetAudacityCommand( ID );
@ -917,14 +917,14 @@ const PluginID & EffectManager::GetEffectByIdentifier(const wxString & strTarget
PluginManager & pm = PluginManager::Get(); PluginManager & pm = PluginManager::Get();
// Effects OR Generic commands... // Effects OR Generic commands...
const PluginDescriptor *plug = pm.GetFirstPlugin(PluginTypeEffect | PluginTypeGeneric); const PluginDescriptor *plug = pm.GetFirstPlugin(PluginTypeEffect | PluginTypeAudacityCommand);
while (plug) while (plug)
{ {
if (GetCommandIdentifier(plug->GetID()).IsSameAs(strTarget)) if (GetCommandIdentifier(plug->GetID()).IsSameAs(strTarget))
{ {
return plug->GetID(); return plug->GetID();
} }
plug = pm.GetNextPlugin(PluginTypeEffect | PluginTypeGeneric); plug = pm.GetNextPlugin(PluginTypeEffect | PluginTypeAudacityCommand);
} }
return empty;; return empty;;
} }