From 691eee681ca24bbe4d541ccdbc73da549aa4a7eb Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 12 Jun 2019 22:52:52 -0400 Subject: [PATCH] Move DoAudacityCommand out of PluginMenus --- src/BatchCommands.cpp | 46 ++++++++++++++++++++++++++++++++++++++- src/BatchCommands.h | 3 +++ src/Menus.h | 2 -- src/menus/PluginMenus.cpp | 46 ++------------------------------------- 4 files changed, 50 insertions(+), 47 deletions(-) diff --git a/src/BatchCommands.cpp b/src/BatchCommands.cpp index 0b32f90b7..0ac91e8fa 100644 --- a/src/BatchCommands.cpp +++ b/src/BatchCommands.cpp @@ -27,6 +27,7 @@ processing. See also MacrosWindow and ApplyMacroDialog. #include "Project.h" #include "ProjectHistory.h" #include "ProjectSettings.h" +#include "ProjectWindow.h" #include "commands/CommandManager.h" #include "effects/EffectManager.h" #include "FileNames.h" @@ -702,6 +703,49 @@ bool MacroCommands::ApplySpecialCommand( } // end CLEANSPEECH remnant +/// DoAudacityCommand() takes a PluginID and executes the assocated command. +/// +/// At the moment flags are used only to indicate whether to prompt for +/// parameters +bool MacroCommands::DoAudacityCommand( + const PluginID & ID, const CommandContext & context, unsigned flags ) +{ + auto &project = context.project; + auto &window = ProjectWindow::Get( project ); + const PluginDescriptor *plug = PluginManager::Get().GetPlugin(ID); + if (!plug) + return false; + + if (flags & EffectManager::kConfigured) + { + TransportActions::DoStop(project); +// SelectAllIfNone(); + } + + EffectManager & em = EffectManager::Get(); + bool success = em.DoAudacityCommand(ID, + context, + &window, + (flags & EffectManager::kConfigured) == 0); + + if (!success) + return false; + +/* + if (em.GetSkipStateFlag()) + flags = flags | OnEffectFlags::kSkipState; + + if (!(flags & OnEffectFlags::kSkipState)) + { + wxString shortDesc = em.GetCommandName(ID); + wxString longDesc = em.GetCommandDescription(ID); + PushState(longDesc, shortDesc); + } +*/ + window.RedrawProject(); + return true; +} + bool MacroCommands::ApplyEffectCommand( const PluginID & ID, const wxString &friendlyCommand, const CommandID & command, const wxString & params, @@ -734,7 +778,7 @@ bool MacroCommands::ApplyEffectCommand( { if( plug->GetPluginType() == PluginTypeAudacityCommand ) // and apply the effect... - res = PluginActions::DoAudacityCommand(ID, + res = DoAudacityCommand(ID, Context, EffectManager::kConfigured | EffectManager::kSkipState | diff --git a/src/BatchCommands.h b/src/BatchCommands.h index 642840950..0d8887f8a 100644 --- a/src/BatchCommands.h +++ b/src/BatchCommands.h @@ -54,6 +54,9 @@ private: // Stores information for one macro class MacroCommands final { public: + static bool DoAudacityCommand( + const PluginID & ID, const CommandContext & context, unsigned flags ); + // constructors and destructors MacroCommands(); public: diff --git a/src/Menus.h b/src/Menus.h index b8f1786d7..34cf4cf36 100644 --- a/src/Menus.h +++ b/src/Menus.h @@ -142,8 +142,6 @@ void DoRecord( AudacityProject & ); namespace PluginActions { bool DoEffect( const PluginID & ID, const CommandContext & context, unsigned flags ); -bool DoAudacityCommand( - const PluginID & ID, const CommandContext & context, unsigned flags ); } /// Namespace for functions for Help menu diff --git a/src/menus/PluginMenus.cpp b/src/menus/PluginMenus.cpp index b6f9fa56b..afb374eb5 100644 --- a/src/menus/PluginMenus.cpp +++ b/src/menus/PluginMenus.cpp @@ -546,49 +546,6 @@ bool DoEffect( return true; } -/// DoAudacityCommand() takes a PluginID and executes the assocated command. -/// -/// At the moment flags are used only to indicate whether to prompt for -/// parameters -bool DoAudacityCommand( - const PluginID & ID, const CommandContext & context, unsigned flags ) -{ - auto &project = context.project; - auto &window = ProjectWindow::Get( project ); - const PluginDescriptor *plug = PluginManager::Get().GetPlugin(ID); - if (!plug) - return false; - - if (flags & EffectManager::kConfigured) - { - TransportActions::DoStop(project); -// SelectAllIfNone(); - } - - EffectManager & em = EffectManager::Get(); - bool success = em.DoAudacityCommand(ID, - context, - &window, - (flags & EffectManager::kConfigured) == 0); - - if (!success) - return false; - -/* - if (em.GetSkipStateFlag()) - flags = flags | OnEffectFlags::kSkipState; - - if (!(flags & OnEffectFlags::kSkipState)) - { - wxString shortDesc = em.GetCommandName(ID); - wxString longDesc = em.GetCommandDescription(ID); - PushState(longDesc, shortDesc); - } -*/ - window.RedrawProject(); - return true; -} - // Menu handler functions struct Handler : CommandHandlerObject { @@ -742,7 +699,8 @@ void OnAudacityCommand(const CommandContext & ctx) // using GET in a log message for devs' eyes only wxLogDebug( "Command was: %s", ctx.parameter.GET()); // Not configured, so prompt user. - DoAudacityCommand(EffectManager::Get().GetEffectByIdentifier(ctx.parameter), + MacroCommands::DoAudacityCommand( + EffectManager::Get().GetEffectByIdentifier(ctx.parameter), ctx, EffectManager::kNone); }