Audacity 3.2.0
BatchEvalCommand.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity - A Digital Audio Editor
4 Copyright 1999-2009 Audacity Team
5 File License: wxWidgets
6
7 Dan Horgan
8
9******************************************************************//*******************************************************************/
15
16
17#include "BatchEvalCommand.h"
18
19#include "CommandContext.h"
20#include "CommandDirectory.h"
21#include "Project.h"
22
24 std::make_unique<BatchEvalCommandType>()
25};
26
28{
29 return { wxT("BatchCommand"), XO("Batch Command") };
30}
31
33{
34 auto commandNameValidator = std::make_unique<DefaultValidator>();
35 signature.AddParameter(wxT("CommandName"), wxT(""), std::move(commandNameValidator));
36 auto paramValidator = std::make_unique<DefaultValidator>();
37 signature.AddParameter(wxT("ParamString"), wxT(""), std::move(paramValidator));
38 auto macroValidator = std::make_unique<DefaultValidator>();
39 signature.AddParameter(wxT("MacroName"), wxT(""), std::move(macroValidator));
40}
41
43 std::unique_ptr<CommandOutputTargets> && WXUNUSED(target))
44{
45 return std::make_shared<BatchEvalCommand>(project, *this);
46}
47
49{
50 // Uh oh, I need to build a catalog, expensively
51 // Maybe it can be built in one long-lived place and shared among command
52 // objects instead?
53 // The catalog though may change during a session, as it includes the
54 // names of macro commands - so the long-lived copy will need to
55 // be refreshed after macros are added/deleted.
56 MacroCommandsCatalog catalog(&context.project);
57
58 wxString macroName = GetString(wxT("MacroName"));
59 if (!macroName.empty())
60 {
61 MacroCommands batch{ context.project };
62 batch.ReadMacro(macroName);
63 return batch.ApplyMacro(catalog);
64 }
65
66 auto cmdName = GetString(wxT("CommandName"));
67 wxString cmdParams = GetString(wxT("ParamString"));
68 auto iter = catalog.ByCommandId(cmdName);
69 const auto friendly = (iter == catalog.end())
70 ? Verbatim( cmdName ) // Expose internal name to user, in default of a better one!
71 : iter->name.Msgid().Stripped();
72
73 // Create a Batch that will have just one command in it...
74 MacroCommands Batch{ context.project };
75 bool bResult = Batch.ApplyCommandInBatchMode(friendly, cmdName, cmdParams, &context);
76 // Relay messages, if any.
77 wxString Message = Batch.GetMessage();
78 if( !Message.empty() )
79 context.Status( Message );
80 return bResult;
81}
82
84{ }
wxT("CloseDown"))
static CommandDirectory::RegisterType sRegisterType
Contains declarations for CommandDirectory class.
XO("Cut/Copy/Paste")
const auto project
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
virtual ~BatchEvalCommand()
void BuildSignature(CommandSignature &signature) override
Postcondition: signature is a 'signature' map containing parameter.
ComponentInterfaceSymbol BuildName() const override
OldStyleCommandPointer Create(AudacityProject &project, std::unique_ptr< CommandOutputTargets > &&target) override
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
virtual void Status(const wxString &message, bool bFlush=false) const
AudacityProject & project
bool Apply() override
Definition: Command.h:121
wxString GetString(const wxString &paramName)
Definition: Command.cpp:240
Class that maps parameter names to default values and validators.
void AddParameter(const wxString &name, const wxVariant &dft, std::unique_ptr< Validator > &&valid)
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Entries::const_iterator ByCommandId(const CommandID &commandId) const
Entries::const_iterator end() const
Definition: BatchCommands.h:49
Maintains the list of commands for batch/macro processing. See also MacrosWindow and ApplyMacroDialog...
Definition: BatchCommands.h:57
OldStyleCommandPointer is a unique_ptr to an OldStyleCommand.
TranslatableString Stripped(unsigned options=MenuCodes) const
non-mutating, constructs another TranslatableString object
TranslatableString Message(unsigned trackCount)