Audacity  2.2.2
BatchCommandDialog.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  BatchCommandDialog.cpp
6 
7  Dominic Mazzoni
8  James Crook
9 
10 *******************************************************************//*******************************************************************/
20 
21 #include "Audacity.h"
22 
23 #include <wx/defs.h>
24 #include <wx/checkbox.h>
25 #include <wx/choice.h>
26 #include <wx/intl.h>
27 #include <wx/sizer.h>
28 #include <wx/statbox.h>
29 #include <wx/stattext.h>
30 #include <wx/textctrl.h>
31 #include <wx/listctrl.h>
32 #include <wx/radiobut.h>
33 #include <wx/button.h>
34 #include <wx/string.h>
35 #include <wx/dialog.h>
36 
37 
38 #include "Project.h"
39 #include "BatchCommandDialog.h"
41 #include "effects/EffectManager.h"
42 #include "BatchCommands.h"
43 #include "ShuttleGui.h"
44 #include "widgets/HelpSystem.h"
45 
46 
47 #define CommandsListID 7001
48 #define EditParamsButtonID 7002
49 #define UsePresetButtonID 7003
50 
51 BEGIN_EVENT_TABLE(MacroCommandDialog, wxDialogWrapper)
52  EVT_BUTTON(wxID_OK, MacroCommandDialog::OnOk)
53  EVT_BUTTON(wxID_CANCEL, MacroCommandDialog::OnCancel)
54  EVT_BUTTON(wxID_HELP, MacroCommandDialog::OnHelp)
58  EVT_LIST_ITEM_SELECTED(CommandsListID, MacroCommandDialog::OnItemSelected)
60 
61 MacroCommandDialog::MacroCommandDialog(wxWindow * parent, wxWindowID id):
62  wxDialogWrapper(parent, id, _("Select Command"),
63  wxDefaultPosition, wxDefaultSize,
64  wxCAPTION | wxRESIZE_BORDER)
65  , mCatalog( GetActiveProject() )
66 {
67  SetLabel(_("Select Command")); // Provide visual label
68  SetName(_("Select Command")); // Provide audible label
69  Populate();
70 }
71 
73 {
74  //------------------------- Main section --------------------
75  ShuttleGui S(this, eIsCreating);
77  // ----------------------- End of main section --------------
78 }
79 
81 {
82  S.StartVerticalLay(true);
83  {
84  S.StartMultiColumn(4, wxEXPAND);
85  {
86  S.SetStretchyCol(1);
87  mCommand = S.AddTextBox(_("&Command"), wxT(""), 20);
88  mCommand->SetEditable(false);
89  mEditParams = S.Id(EditParamsButtonID).AddButton(_("&Edit Parameters"));
90  mEditParams->Enable(false); // disable button as box is empty
91  mUsePreset = S.Id(UsePresetButtonID).AddButton(_("&Use Preset"));
92  mUsePreset->Enable(false); // disable button as box is empty
93  }
94  S.EndMultiColumn();
95 
96  S.StartMultiColumn(2, wxEXPAND);
97  {
98  S.SetStretchyCol(1);
99  mParameters = S.AddTextBox(_("&Parameters"), wxT(""), 0);
100  mParameters->SetEditable(false);
101  S.Prop(0).AddPrompt( _("&Details" ) );
102  mDetails = S.AddTextWindow( wxT(""));
103  mDetails->SetEditable(false);
104  }
105  S.EndMultiColumn();
106 
107  S.Prop(10).StartStatic(_("C&hoose command"), true);
108  {
109  S.SetStyle(wxSUNKEN_BORDER | wxLC_LIST | wxLC_SINGLE_SEL);
111  }
112  S.EndStatic();
113  }
114  S.EndVerticalLay();
115 
117 
119 
120  SetMinSize(wxSize(780, 560));
121  Fit();
122  Center();
123 }
124 
126 {
127  mChoices->DeleteAllItems();
128  long ii = 0;
129  for ( const auto &entry : mCatalog )
130  // insert the user-facing string
131  mChoices->InsertItem( ii++, entry.name.Translated() );
132 }
133 
135 {
136 }
137 
138 void MacroCommandDialog::OnChoice(wxCommandEvent & WXUNUSED(event))
139 {
140 }
141 
142 void MacroCommandDialog::OnOk(wxCommandEvent & WXUNUSED(event))
143 {
144  mSelectedCommand = mInternalCommandName.Strip(wxString::both);
145  mSelectedParameters = mParameters->GetValue().Strip(wxString::trailing);
146  EndModal(true);
147 }
148 
149 void MacroCommandDialog::OnCancel(wxCommandEvent & WXUNUSED(event))
150 {
151  EndModal(false);
152 }
153 
154 void MacroCommandDialog::OnHelp(wxCommandEvent & WXUNUSED(event))
155 {
156  wxString page = GetHelpPageName();
157  HelpSystem::ShowHelp(this, page, true);
158 }
159 
160 void MacroCommandDialog::OnItemSelected(wxListEvent &event)
161 {
162  const auto &command = mCatalog[ event.GetIndex() ];
163 
165  PluginID ID = em.GetEffectByIdentifier( command.name.Internal() );
166 
167  // If ID is empty, then the effect wasn't found, in which case, the user must have
168  // selected one of the "special" commands.
169  mEditParams->Enable(!ID.IsEmpty());
170  mUsePreset->Enable(em.HasPresets(ID));
171 
172  if ( command.name.Translated() == mCommand->GetValue() )
173  // This uses the assumption of uniqueness of translated names!
174  return;
175 
176  mCommand->SetValue(command.name.Translated());
177  mInternalCommandName = command.name.Internal();
178 
180  if (params.IsEmpty())
181  {
182  params = em.GetDefaultPreset(ID);
183  }
184 
185  // Cryptic command and category.
186  // Later we can put help information there, perhaps.
187  mDetails->SetValue( mInternalCommandName + "\r\n" + command.category );
188  mParameters->SetValue(params);
189 }
190 
191 void MacroCommandDialog::OnEditParams(wxCommandEvent & WXUNUSED(event))
192 {
193  wxString command = mInternalCommandName;
194  wxString params = mParameters->GetValue();
195 
196  params = MacroCommands::PromptForParamsFor(command, params, this).Trim();
197 
198  mParameters->SetValue(params);
199  mParameters->Refresh();
200 }
201 
202 void MacroCommandDialog::OnUsePreset(wxCommandEvent & WXUNUSED(event))
203 {
204  wxString command = mInternalCommandName;
205  wxString params = mParameters->GetValue();
206 
207  wxString preset = MacroCommands::PromptForPresetFor(command, params, this).Trim();
208 
209  mParameters->SetValue(preset);
210  mParameters->Refresh();
211 }
212 
213 void MacroCommandDialog::SetCommandAndParams(const wxString &Command, const wxString &Params)
214 {
215  auto iter = mCatalog.ByCommandId( Command );
216 
217  mParameters->SetValue( Params );
218 
219  mInternalCommandName = Command;
220  if (iter == mCatalog.end())
221  // Expose an internal name to the user in default of any friendly name
222  // -- AVOID THIS!
223  mCommand->SetValue( Command );
224  else {
225  mCommand->SetValue( iter->name.Translated() );
226  mDetails->SetValue( iter->name.Internal() + "\r\n" + iter->category );
227  mChoices->SetItemState(iter - mCatalog.begin(),
228  wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
229 
231  PluginID ID = em.GetEffectByIdentifier(Command);
232 
233  // If ID is empty, then the effect wasn't found, in which case, the user must have
234  // selected one of the "special" commands.
235  mEditParams->Enable(!ID.IsEmpty());
236  mUsePreset->Enable(em.HasPresets(ID));
237  }
238 }
void OnOk(wxCommandEvent &event)
#define EditParamsButtonID
const MacroCommandsCatalog mCatalog
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:409
bool HasPresets(const PluginID &ID)
Entries::const_iterator begin() const
Definition: BatchCommands.h:43
static wxString PromptForPresetFor(const wxString &command, const wxString &params, wxWindow *parent)
void OnCancel(wxCommandEvent &event)
wxString GetDefaultPreset(const PluginID &ID)
void EndMultiColumn()
const PluginID & GetEffectByIdentifier(const wxString &strTarget)
wxString PluginID
Definition: Types.h:209
void SetCommandAndParams(const wxString &Command, const wxString &Params)
wxListCtrl * AddListControl()
Definition: ShuttleGui.cpp:661
void PopulateOrExchange(ShuttleGui &S)
void AddPrompt(const wxString &Prompt)
Right aligned text string.
Definition: ShuttleGui.cpp:239
void EndVerticalLay()
void OnHelp(wxCommandEvent &event)
wxTextCtrl * AddTextBox(const wxString &Caption, const wxString &Value, const int nChars)
Definition: ShuttleGui.cpp:540
#define CommandsListID
void OnChoice(wxCommandEvent &event)
void OnEditParams(wxCommandEvent &event)
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
ShuttleGui & Id(int id)
void SetStyle(int Style)
Definition: ShuttleGui.h:287
#define UsePresetButtonID
void OnItemSelected(wxListEvent &event)
EffectManager is the class that handles effects and effect categories.
Definition: EffectManager.h:45
static void ShowHelp(wxWindow *parent, const wxString &localFileName, const wxString &remoteURL, bool bModal=false, bool alwaysDefaultBrowser=false)
Definition: HelpSystem.cpp:194
static wxString PromptForParamsFor(const wxString &command, const wxString &params, wxWindow *parent)
EVT_LIST_ITEM_ACTIVATED(wxID_ANY, SuccessDialog::OnItemActivated) ExportMultiple
static EffectManager & Get()
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
wxTextCtrl * mParameters
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
Entries::const_iterator ByCommandId(const wxString &commandId) const
wxTextCtrl * AddTextWindow(const wxString &Value)
Multiline text box that grows.
Definition: ShuttleGui.cpp:608
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
void OnUsePreset(wxCommandEvent &event)
wxStaticBox * StartStatic(const wxString &Str, int iProp=0)
Definition: ShuttleGui.cpp:763
Entries::const_iterator end() const
Definition: BatchCommands.h:44
ShuttleGui & Prop(int iProp)
Definition: ShuttleGui.h:418
void AddStandardButtons(long buttons=eOkButton|eCancelButton, wxButton *extra=NULL)
END_EVENT_TABLE()
EffectDistortion::Params params
Definition: Distortion.cpp:95
Provides a list of configurable commands for use with MacroCommands.
wxButton * AddButton(const wxString &Text, int PositionFlags=wxALIGN_CENTRE)
Definition: ShuttleGui.cpp:341
static wxString GetCurrentParamsFor(const wxString &command)
void SetStretchyCol(int i)
Used to modify an already placed FlexGridSizer to make a column stretchy.
Definition: ShuttleGui.cpp:203
EVT_LIST_ITEM_SELECTED(CurvesListID, EditCurvesDialog::OnListSelectionChange) EVT_LIST_ITEM_DESELECTED(CurvesListID
Constructor.
void StartVerticalLay(int iProp=1)