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 "ComponentInterface.h"
24 #include "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;
35 class EffectUIHostInterface;
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:
46    AudacityCommand();
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.
63    ComponentInterfaceSymbol GetSymbol() override = 0;
GetDescription()64    virtual TranslatableString GetDescription() override
65    {wxFAIL_MSG( "Implement a Description for this command");return XO("FAIL");};
66 
67    // Name of page in the Audacity alpha manual
ManualPage()68    virtual ManualPageID ManualPage(){ return {}; }
IsBatchProcessing()69    virtual bool IsBatchProcessing(){ return mIsBatch;}
SetBatchProcessing(bool start)70    virtual void SetBatchProcessing(bool start){ mIsBatch = start;};
71 
Apply(const CommandContext & WXUNUSED (context))72    virtual bool Apply(const CommandContext & WXUNUSED(context) ) {return false;};
73 
74    bool ShowInterface(wxWindow *parent, bool forceModal = false);
SetHostUI(EffectUIHostInterface * WXUNUSED (host))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
CheckWhetherSkipAudacityCommand()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.
End()121    virtual void End(){;};
PopulateOrExchange(ShuttleGui & WXUNUSED (S))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;
132    int             mUIResultID;
133 
134 private:
135    bool mIsBatch;
136    bool mUIDebug;
137    bool mNeedsInit;
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;
166    int mAdditionalButtons;
167    AudacityCommand * mpCommand;
168 
169    DECLARE_EVENT_TABLE()
170    wxDECLARE_NO_COPY_CLASS(AudacityCommandDialog);
171 };
172 
173 
174 
175 #endif
176