Audacity  3.0.3
AudacityCommand.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  AudacityCommand.h
6 
7  James Crook
8 
9 **********************************************************************/
10 
11 #ifndef __AUDACITY_COMMAND__
12 #define __AUDACITY_COMMAND__
13 
14 
15 
16 #include <set>
17 
18 #include <wx/defs.h>
19 #include <wx/event.h> // to inherit
20 
21 #include "../widgets/wxPanelWrapper.h" // to inherit
22 
23 #include "../include/audacity/ComponentInterface.h"
24 #include "../include/audacity/EffectAutomationParameters.h" // for command automation
25 
26 #include "../Registrar.h"
27 
28 class ShuttleGui;
29 
30 #define BUILTIN_GENERIC_COMMAND_PREFIX wxT("Built-in AudacityCommand: ")
31 
32 class AudacityCommand;
33 class AudacityProject;
34 class CommandContext;
36 class ProgressDialog;
37 
38 
39 class AUDACITY_DLL_API AudacityCommand /* not final */ : public wxEvtHandler,
40  public ComponentInterface
41 {
42  public:
43  //std::unique_ptr<CommandOutputTargets> mOutput;
44  //CommandOutputTargets * mOutput;
45  public:
47  virtual ~AudacityCommand();
48 
49  // Type of a registered function that, if it returns true,
50  // causes ShowInterface to return early without making any dialog
51  using VetoDialogHook = bool (*) ( wxDialog* );
52  static VetoDialogHook SetVetoDialogHook( VetoDialogHook hook );
53 
54  // ComponentInterface implementation
55 
56  //These four can be defaulted....
57  PluginPath GetPath() override;
58  VendorSymbol GetVendor() override;
59  wxString GetVersion() override;
60  // virtual wxString GetFamily();
61 
62  //These two must be implemented by instances.
65  {wxFAIL_MSG( "Implement a Description for this command");return XO("FAIL");};
66 
67  // Name of page in the Audacity alpha manual
68  virtual wxString ManualPage(){ return wxEmptyString;};
69  virtual bool IsBatchProcessing(){ return mIsBatch;}
70  virtual void SetBatchProcessing(bool start){ mIsBatch = start;};
71 
72  virtual bool Apply(const CommandContext & WXUNUSED(context) ) {return false;};
73 
74  bool ShowInterface(wxWindow *parent, bool forceModal = false);
75  virtual void SetHostUI(EffectUIHostInterface * WXUNUSED(host)){;};
76 
77  wxDialog *CreateUI(wxWindow *parent, AudacityCommand *client);
78 
79  virtual bool GetAutomationParameters(wxString & parms);
80  virtual bool SetAutomationParameters(const wxString & parms);
81 
82  bool DoAudacityCommand(wxWindow *parent, const CommandContext & context,bool shouldPrompt = true);
83 
84  // Nonvirtual
85  // Display a message box, using effect's (translated) name as the prefix
86  // for the title.
87  enum : long { DefaultMessageBoxStyle = wxOK | wxCENTRE };
88  int MessageBox(const TranslatableString& message,
89  long style = DefaultMessageBoxStyle,
90  const TranslatableString& titleStr = {});
91 
92 //
93 // protected virtual methods
94 //
95 // Each subclass of AudacityCommand overrides one or more of these methods to
96 // do its processing.
97 //
98 //protected:
99 
100  // Called once each time an effect is called. Perform any initialization;
101  // make sure that the command can be performed and
102  // return false otherwise
103  virtual bool Init();
104 
105  // If necessary, open a dialog to get parameters from the user.
106  // This method will not always be called (for example if a user
107  // repeats a command using 'repeat last command') but if it is called,
108  // it will be called after Init.
109  virtual bool PromptUser(wxWindow *parent);
110 
111  // Check whether command should be skipped
112  // Typically this is only useful in automation, for example
113  // detecting that zero noise reduction is to be done,
114  // or that normalisation is being done without Dc bias shift
115  // or amplitude modification
116  virtual bool CheckWhetherSkipAudacityCommand() { return false; }
117 
118  // clean up any temporary memory, needed only per invocation of the
119  // effect, after either successful or failed or exception-aborted processing.
120  // Invoked inside a "finally" block so it must be no-throw.
121  virtual void End(){;};
122  virtual void PopulateOrExchange(ShuttleGui & WXUNUSED(S)){return;};
123  virtual bool TransferDataToWindow();
124  virtual bool TransferDataFromWindow();
125 
126 protected:
127 
128  ProgressDialog *mProgress; // Temporary pointer, NOT deleted in destructor.
129  // UI
130  wxDialog *mUIDialog;
131  wxWindow *mUIParent;
133 
134 private:
135  bool mIsBatch;
136  bool mUIDebug;
138 };
139 
140 
141 // Base dialog for command dialog.
142 class AUDACITY_DLL_API AudacityCommandDialog /* not final */ : public wxDialogWrapper
143 {
144 public:
145  // constructors and destructors
146  AudacityCommandDialog(wxWindow * parent,
147  const TranslatableString & title,
148  AudacityCommand * pCommand,
149  int type = 0,
150  int flags = wxDEFAULT_DIALOG_STYLE,
151  int additionalButtons = 0);
152 
153  bool Init();// always returns true. The bool is for the future...
154 
155  bool TransferDataToWindow() override;
156  bool TransferDataFromWindow() override;
157  bool Validate() override;
158 
159  virtual void PopulateOrExchange(ShuttleGui & S);
160  virtual void OnOk(wxCommandEvent & evt);
161  virtual void OnCancel(wxCommandEvent & evt);
162  virtual void OnHelp(wxCommandEvent & evt);
163 
164 private:
165  int mType;
168 
169  DECLARE_EVENT_TABLE()
170  wxDECLARE_NO_COPY_CLASS(AudacityCommandDialog);
171 };
172 
173 
174 
175 #endif
AudacityCommand::mIsBatch
bool mIsBatch
Definition: AudacityCommand.h:135
Init
Definition: ModuleManager.h:142
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
AudacityCommand::CheckWhetherSkipAudacityCommand
virtual bool CheckWhetherSkipAudacityCommand()
Definition: AudacityCommand.h:116
AudacityCommand::PopulateOrExchange
virtual void PopulateOrExchange(ShuttleGui &WXUNUSED(S))
Definition: AudacityCommand.h:122
AudacityCommand::End
virtual void End()
Definition: AudacityCommand.h:121
AudacityCommand::GetDescription
virtual TranslatableString GetDescription() override
Definition: AudacityCommand.h:64
PluginPath
wxString PluginPath
type alias for identifying a Plugin supplied by a module, each module defining its own interpretation...
Definition: Identifier.h:214
AudacityCommand::mUIParent
wxWindow * mUIParent
Definition: AudacityCommand.h:131
XO
#define XO(s)
Definition: Internat.h:31
AudacityCommand::mUIDialog
wxDialog * mUIDialog
Definition: AudacityCommand.h:130
AudacityCommand::VetoDialogHook
bool(*)(wxDialog *) VetoDialogHook
Definition: AudacityCommand.h:51
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterface.h:61
AudacityCommand::IsBatchProcessing
virtual bool IsBatchProcessing()
Definition: AudacityCommand.h:69
ComponentInterface::GetVendor
virtual VendorSymbol GetVendor()=0
AudacityCommand::mNeedsInit
bool mNeedsInit
Definition: AudacityCommand.h:137
ProgressDialog
ProgressDialog Class.
Definition: ProgressDialog.h:56
CommandContext
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
Definition: CommandContext.h:22
ComponentInterface::GetPath
virtual PluginPath GetPath()=0
AudacityCommand::Apply
virtual bool Apply(const CommandContext &WXUNUSED(context))
Definition: AudacityCommand.h:72
AudacityCommand::GetSymbol
ComponentInterfaceSymbol GetSymbol() override=0
AudacityCommand
Base class for command in Audacity.
Definition: AudacityCommand.h:41
AudacityCommand::SetBatchProcessing
virtual void SetBatchProcessing(bool start)
Definition: AudacityCommand.h:70
AudacityCommand::mProgress
ProgressDialog * mProgress
Definition: AudacityCommand.h:128
EffectUIHostInterface
EffectUIHostInterface has nothing in it. It is provided so that an Effect can call SetHostUI passing ...
Definition: EffectInterface.h:216
AudacityCommandDialog::mpCommand
AudacityCommand * mpCommand
Definition: AudacityCommand.h:167
wxDialogWrapper
Definition: wxPanelWrapper.h:81
AudacityCommand::SetHostUI
virtual void SetHostUI(EffectUIHostInterface *WXUNUSED(host))
Definition: AudacityCommand.h:75
AudacityCommandDialog
Default dialog used for commands. Is populated using ShuttleGui.
Definition: AudacityCommand.h:143
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:112
AudacityCommandDialog::mAdditionalButtons
int mAdditionalButtons
Definition: AudacityCommand.h:166
AudacityCommand::ManualPage
virtual wxString ManualPage()
Definition: AudacityCommand.h:68
ComponentInterface
ComponentInterface provides name / vendor / version functions to identify plugins....
Definition: ComponentInterface.h:122
AudacityCommandDialog::mType
int mType
Definition: AudacityCommand.h:165
AudacityCommand::mUIResultID
int mUIResultID
Definition: AudacityCommand.h:132
ComponentInterface::GetVersion
virtual wxString GetVersion()=0
AudacityCommand::mUIDebug
bool mUIDebug
Definition: AudacityCommand.h:136
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:625