1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-15 15:49:36 +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
\brief CommandDefinitionInterface is an IdentInterface (to name the command) along with a
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:
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.
*******************************************************************************************/
class AUDACITY_DLL_API EffectDefinitionInterface /* not final */ : public CommandDefinitionInterface
class AUDACITY_DLL_API EffectDefinitionInterface /* not final */ : public IdentInterface, public ParamsInterface
{
public:
virtual ~EffectDefinitionInterface() {};

View File

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

View File

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

View File

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

View File

@ -1376,18 +1376,24 @@ void PluginDescriptor::SetImporterExtensions(const wxArrayString & extensions)
// ============================================================================
const PluginID &PluginManagerInterface::DefaultRegistrationCallback(
ModuleInterface *provider, CommandDefinitionInterface *pInterface )
ModuleInterface *provider, IdentInterface *pInterface )
{
EffectDefinitionInterface * pEInterface = dynamic_cast<EffectDefinitionInterface*>(pInterface);
if( pEInterface )
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(
ModuleInterface *provider, CommandDefinitionInterface *pInterface )
const PluginID &PluginManagerInterface::AudacityCommandRegistrationCallback(
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)
{
PluginDescriptor & plug = CreatePlugin(GetID(command), command, (PluginType)PluginTypeGeneric);
PluginDescriptor & plug = CreatePlugin(GetID(command), command, (PluginType)PluginTypeAudacityCommand);
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.SetValid(true);
@ -1840,7 +1839,7 @@ bool PluginManager::DropFile(const wxString &fileName)
std::vector<PluginID> ids;
std::vector<wxString> names;
nPlugIns = module->DiscoverPluginsAtPath(dstPath, errMsg,
[&](ModuleInterface *provider, CommandDefinitionInterface *ident){
[&](ModuleInterface *provider, IdentInterface *ident){
// Register as by default, but also collecting the PluginIDs
// and names
const PluginID * id = &PluginManagerInterface::DefaultRegistrationCallback(
@ -1911,7 +1910,7 @@ void PluginManager::Load()
// Now the rest
LoadGroup(&registry, PluginTypeEffect);
LoadGroup(&registry, PluginTypeGeneric );
LoadGroup(&registry, PluginTypeAudacityCommand );
LoadGroup(&registry, PluginTypeExporter);
LoadGroup(&registry, PluginTypeImporter);
@ -2209,7 +2208,7 @@ void PluginManager::Save()
// Save the individual groups
SaveGroup(&registry, PluginTypeEffect);
SaveGroup(&registry, PluginTypeExporter);
SaveGroup(&registry, PluginTypeGeneric);
SaveGroup(&registry, PluginTypeAudacityCommand);
SaveGroup(&registry, PluginTypeImporter);
SaveGroup(&registry, PluginTypeStub);
@ -2635,7 +2634,7 @@ PluginID PluginManager::GetID(ModuleInterface *module)
PluginID PluginManager::GetID(CommandDefinitionInterface *command)
{
return wxString::Format(wxT("%s_%s_%s_%s_%s"),
GetPluginTypeString(PluginTypeGeneric),
GetPluginTypeString(PluginTypeAudacityCommand),
wxEmptyString,
command->GetVendor(),
command->GetName(),
@ -2680,7 +2679,7 @@ wxString PluginManager::GetPluginTypeString(PluginType type)
case PluginTypeEffect:
str = wxT("Effect");
break;
case PluginTypeGeneric:
case PluginTypeAudacityCommand:
str = wxT("Generic");
break;
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
PluginTypeStub =1, // Used for plugins that have not yet been registered
PluginTypeEffect =1<<1,
PluginTypeGeneric=1<<2,
PluginTypeAudacityCommand=1<<2,
PluginTypeExporter=1<<3,
PluginTypeImporter=1<<4,
PluginTypeModule=1<<5,

View File

@ -326,9 +326,12 @@ void LongMessageDialog::AcceptText( const wxString & Text )
void LongMessageDialog::Flush()
{
if( pDlg ){
pDlg->mText += "\n\n";
pDlg->mTextCtrl->SetValue( pDlg->mText );
pDlg->mTextCtrl->ShowPosition( pDlg->mTextCtrl->GetLastPosition() );
if( !pDlg->mText.EndsWith( "\n\n" ))
{
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
- Clips
- Labels
- Keycodes
- Boxes
*//*******************************************************************/
@ -40,7 +39,7 @@ This class now lists
#include "../ShuttleGui.h"
#include "CommandContext.h"
const int nTypes =7;
const int nTypes =6;
static const wxString kTypes[nTypes] =
{
XO("Commands"),
@ -48,7 +47,6 @@ static const wxString kTypes[nTypes] =
XO("Tracks"),
XO("Clips"),
XO("Labels"),
XO("Keycodes"),
XO("Boxes")
};
@ -58,7 +56,6 @@ enum {
kTracks,
kClips,
kLabels,
kKeycodes,
kBoxes
};
@ -134,7 +131,6 @@ bool GetInfoCommand::ApplyInner(const CommandContext &context)
case kTracks : return SendTracks( context );
case kClips : return SendClips( context );
case kLabels : return SendLabels( context );
case kKeycodes : return SendKeycodes( context );
case kBoxes : return SendBoxes( context );
default:
context.Status( "Command options not recognised" );
@ -178,44 +174,20 @@ bool GetInfoCommand::SendCommands(const CommandContext &context )
PluginManager & pm = PluginManager::Get();
EffectManager & em = EffectManager::Get();
{
const PluginDescriptor *plug = pm.GetFirstPlugin(PluginTypeEffect | PluginTypeGeneric);
const PluginDescriptor *plug = pm.GetFirstPlugin(PluginTypeEffect | PluginTypeAudacityCommand);
while (plug)
{
auto command = em.GetCommandIdentifier(plug->GetID());
if (!command.IsEmpty()){
em.GetCommandDefinition( plug->GetID(), context );
}
plug = pm.GetNextPlugin(PluginTypeEffect | PluginTypeGeneric );
plug = pm.GetNextPlugin(PluginTypeEffect | PluginTypeAudacityCommand );
}
}
context.EndArray();
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)
{
//context.Status("Boxes");
@ -334,12 +306,6 @@ bool GetInfoCommand::SendLabels(const CommandContext &context)
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,
and may be recursive. 'Send' is the top level.

View File

@ -52,7 +52,6 @@ private:
bool SendTracks(const CommandContext & context);
bool SendLabels(const CommandContext & context);
bool SendClips(const CommandContext & context);
bool SendKeycodes(const CommandContext & context);
bool SendBoxes(const CommandContext & context);
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.
// Registers as TypeGeneric, not TypeEffect.
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)
{
CommandDefinitionInterface *command;
ParamsInterface *command;
command = GetEffect(ID);
if( !command )
command = GetAudacityCommand( ID );
@ -917,14 +917,14 @@ const PluginID & EffectManager::GetEffectByIdentifier(const wxString & strTarget
PluginManager & pm = PluginManager::Get();
// Effects OR Generic commands...
const PluginDescriptor *plug = pm.GetFirstPlugin(PluginTypeEffect | PluginTypeGeneric);
const PluginDescriptor *plug = pm.GetFirstPlugin(PluginTypeEffect | PluginTypeAudacityCommand);
while (plug)
{
if (GetCommandIdentifier(plug->GetID()).IsSameAs(strTarget))
{
return plug->GetID();
}
plug = pm.GetNextPlugin(PluginTypeEffect | PluginTypeGeneric);
plug = pm.GetNextPlugin(PluginTypeEffect | PluginTypeAudacityCommand);
}
return empty;;
}