Audacity  2.2.2
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 #include "../Audacity.h"
17 #include "BatchEvalCommand.h"
18 #include "CommandContext.h"
19 
21 {
22  return { wxT("BatchCommand"), XO("Batch Command") };
23 }
24 
26 {
27  auto commandNameValidator = std::make_unique<DefaultValidator>();
28  signature.AddParameter(wxT("CommandName"), wxT(""), std::move(commandNameValidator));
29  auto paramValidator = std::make_unique<DefaultValidator>();
30  signature.AddParameter(wxT("ParamString"), wxT(""), std::move(paramValidator));
31  auto macroValidator = std::make_unique<DefaultValidator>();
32  signature.AddParameter(wxT("MacroName"), wxT(""), std::move(macroValidator));
33 }
34 
35 OldStyleCommandPointer BatchEvalCommandType::Create(std::unique_ptr<CommandOutputTargets> && WXUNUSED(target))
36 {
37  return std::make_shared<BatchEvalCommand>(*this);
38 }
39 
41 {
42  // Uh oh, I need to build a catalog, expensively
43  // Maybe it can be built in one long-lived place and shared among command
44  // objects instead?
45  MacroCommandsCatalog catalog(&context.project);
46 
47  wxString macroName = GetString(wxT("MacroName"));
48  if (macroName != wxT(""))
49  {
50  MacroCommands batch;
51  batch.ReadMacro(macroName);
52  return batch.ApplyMacro(catalog);
53  }
54 
55  wxString cmdName = GetString(wxT("CommandName"));
56  wxString cmdParams = GetString(wxT("ParamString"));
57  auto iter = catalog.ByCommandId(cmdName);
58  const wxString &friendly = (iter == catalog.end())
59  ? cmdName // Expose internal name to user, in default of a better one!
60  : iter->name.Translated();
61 
62  // Create a Batch that will have just one command in it...
63  MacroCommands Batch;
64  bool bResult = Batch.ApplyCommand(friendly, cmdName, cmdParams, &context);
65  // Relay messages, if any.
66  wxString Message = Batch.GetMessage();
67  if( !Message.IsEmpty() )
68  context.Status( Message );
69  return bResult;
70 }
71 
73 { }
void BuildSignature(CommandSignature &signature) override
Postcondition: signature is a 'signature' map containing parameter.
wxString GetString(const wxString &paramName)
Definition: Command.cpp:240
virtual void Status(const wxString &message, bool bFlush=false) const
void AddParameter(const wxString &name, const wxVariant &dft, std::unique_ptr< Validator > &&valid)
#define XO(s)
Definition: Internat.h:33
bool ApplyMacro(const MacroCommandsCatalog &catalog, const wxString &filename=wxT(""))
CommandContext provides addiitonal information to an 'Apply()' command. It provides the project...
Maintains the list of commands for batch/macro processing. See also MacrosWindow and ApplyMacroDialog...
Definition: BatchCommands.h:52
bool Apply() override
Definition: Command.h:122
bool ApplyCommand(const wxString &friendlyCommand, const wxString &command, const wxString &params, CommandContext const *pContext=NULL)
virtual ~BatchEvalCommand()
IdentInterfaceSymbol pairs a persistent string identifier used internally with an optional...
OldStyleCommandPointer Create(std::unique_ptr< CommandOutputTargets > &&target) override
bool ReadMacro(const wxString &macro)
AudacityProject & project
Entries::const_iterator ByCommandId(const wxString &commandId) const
Entries::const_iterator end() const
Definition: BatchCommands.h:44
OldStyleCommandPointer is a unique_ptr to an OldStyleCommand.
wxString GetMessage()
Class that maps parameter names to default values and validators.
IdentInterfaceSymbol BuildName() override