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 
45 
46 #define CommandsListID 7001
47 #define EditParamsButtonID 7002
48 #define UsePresetButtonID 7003
49 
50 BEGIN_EVENT_TABLE(BatchCommandDialog, wxDialogWrapper)
51  EVT_BUTTON(wxID_OK, BatchCommandDialog::OnOk)
52  EVT_BUTTON(wxID_CANCEL, BatchCommandDialog::OnCancel)
56  EVT_LIST_ITEM_SELECTED(CommandsListID, BatchCommandDialog::OnItemSelected)
58 
59 BatchCommandDialog::BatchCommandDialog(wxWindow * parent, wxWindowID id):
60  wxDialogWrapper(parent, id, _("Select Command"),
61  wxDefaultPosition, wxDefaultSize,
62  wxCAPTION | wxRESIZE_BORDER)
63 {
64  SetLabel(_("Select Command")); // Provide visual label
65  SetName(_("Select Command")); // Provide audible label
66  Populate();
67 }
68 
70 {
71  //------------------------- Main section --------------------
72  ShuttleGui S(this, eIsCreating);
74  // ----------------------- End of main section --------------
75 }
76 
78 {
79  S.StartVerticalLay(true);
80  {
81  S.StartMultiColumn(4, wxEXPAND);
82  {
83  S.SetStretchyCol(1);
84  mCommand = S.AddTextBox(_("&Command"), wxT(""), 20);
85  mCommand->SetEditable(false);
86  mEditParams = S.Id(EditParamsButtonID).AddButton(_("&Edit Parameters"));
87  mEditParams->Enable(false); // disable button as box is empty
88  mUsePreset = S.Id(UsePresetButtonID).AddButton(_("&Use Preset"));
89  mUsePreset->Enable(false); // disable button as box is empty
90  }
91  S.EndMultiColumn();
92 
93  S.StartMultiColumn(2, wxEXPAND);
94  {
95  S.SetStretchyCol(1);
96  mParameters = S.AddTextBox(_("&Parameters"), wxT(""), 0);
97  mParameters->SetEditable(false);
98  }
99  S.EndMultiColumn();
100 
101  S.StartStatic(_("C&hoose command"), true);
102  {
103  S.SetStyle(wxSUNKEN_BORDER | wxLC_LIST | wxLC_SINGLE_SEL);
105  }
106  S.EndStatic();
107  }
108  S.EndVerticalLay();
109 
110  S.AddStandardButtons();
111 
113 
114  SetMinSize(wxSize(500, 400));
115  Fit();
116  Center();
117 }
118 
120 {
122 
123  mChoices->DeleteAllItems();
124  for (size_t ii = 0, size = mCommandNames.size(); ii < size; ++ii)
125  // insert the user-facing string
126  mChoices->InsertItem( ii, mCommandNames[ii].first );
127 }
128 
129 #if 0
130 int BatchCommandDialog::GetSelectedItem()
131 {
132  int i;
133  mSelectedCommand = wxT("");
134  for(i=0;i<mChoices->GetItemCount();i++)
135  {
136  if( mChoices->GetItemState( i, wxLIST_STATE_FOCUSED) != 0)
137  {
138  mSelectedCommand = mChoices->GetItemText( i );
139  return i;
140  }
141  }
142  return -1;
143 }
144 #endif
145 
147 {
148 }
149 
150 void BatchCommandDialog::OnChoice(wxCommandEvent & WXUNUSED(event))
151 {
152 }
153 
154 void BatchCommandDialog::OnOk(wxCommandEvent & WXUNUSED(event))
155 {
156  mSelectedCommand = mInternalCommandName.Strip(wxString::both);
157  mSelectedParameters = mParameters->GetValue().Strip(wxString::trailing);
158  EndModal(true);
159 }
160 
161 void BatchCommandDialog::OnCancel(wxCommandEvent & WXUNUSED(event))
162 {
163  EndModal(false);
164 }
165 
166 void BatchCommandDialog::OnItemSelected(wxListEvent &event)
167 {
168  const auto &command = mCommandNames[ event.GetIndex() ];
169 
171  PluginID ID = em.GetEffectByIdentifier(command.second);
172 
173  // If ID is empty, then the effect wasn't found, in which case, the user must have
174  // selected one of the "special" commands.
175  mEditParams->Enable(!ID.IsEmpty());
176  mUsePreset->Enable(em.HasPresets(ID));
177 
178  if (command.first == mCommand->GetValue())
179  return;
180 
181  mCommand->SetValue(command.first);
182  mInternalCommandName = command.second;
183 
184  wxString params = BatchCommands::GetCurrentParamsFor(command.second);
185  if (params.IsEmpty())
186  {
187  params = em.GetDefaultPreset(ID);
188  }
189 
190  mParameters->SetValue(params);
191 }
192 
193 void BatchCommandDialog::OnEditParams(wxCommandEvent & WXUNUSED(event))
194 {
195  wxString command = mInternalCommandName;
196  wxString params = mParameters->GetValue();
197 
198  params = BatchCommands::PromptForParamsFor(command, params, this).Trim();
199 
200  mParameters->SetValue(params);
201  mParameters->Refresh();
202 }
203 
204 void BatchCommandDialog::OnUsePreset(wxCommandEvent & WXUNUSED(event))
205 {
206  wxString command = mInternalCommandName;
207  wxString params = mParameters->GetValue();
208 
209  wxString preset = BatchCommands::PromptForPresetFor(command, params, this).Trim();
210 
211  mParameters->SetValue(preset);
212  mParameters->Refresh();
213 }
214 
215 void BatchCommandDialog::SetCommandAndParams(const wxString &Command, const wxString &Params)
216 {
217  auto item = make_iterator_range(mCommandNames).index_if(
218  [&](const CommandName &name){ return Command == name.second; }
219  );
220 
221  mParameters->SetValue( Params );
222 
223  mInternalCommandName = Command;
224  if (item < 0)
225  mCommand->SetValue( Command );
226  else {
227  mCommand->SetValue( mCommandNames[item].first );
228  mChoices->SetItemState(item, 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 }
static wxString PromptForParamsFor(const wxString &command, const wxString &params, wxWindow *parent)
void OnUsePreset(wxCommandEvent &event)
#define EditParamsButtonID
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:366
bool HasPresets(const PluginID &ID)
void SetCommandAndParams(const wxString &Command, const wxString &Params)
wxString GetDefaultPreset(const PluginID &ID)
void EndMultiColumn()
const PluginID & GetEffectByIdentifier(const wxString &strTarget)
std::pair< wxString, wxString > CommandName
void OnItemSelected(wxListEvent &event)
void OnEditParams(wxCommandEvent &event)
static wxString PromptForPresetFor(const wxString &command, const wxString &params, wxWindow *parent)
Abstract base class for command interface. It implements Command::SetParameter() and defers all other...
Definition: Command.h:70
wxListCtrl * AddListControl()
Definition: ShuttleGui.cpp:599
wxTextCtrl * mParameters
Provides a list of configurable commands for use with BatchCommands.
void PopulateOrExchange(ShuttleGui &S)
void EndVerticalLay()
Definition: ShuttleGui.cpp:991
wxTextCtrl * AddTextBox(const wxString &Caption, const wxString &Value, const int nChars)
Definition: ShuttleGui.cpp:493
#define CommandsListID
static CommandNameVector GetAllCommands()
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:998
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
Definition: MemoryX.h:1058
ShuttleGui & Id(int id)
void SetStyle(int Style)
Definition: ShuttleGui.h:252
#define UsePresetButtonID
EffectManager is the class that handles effects and effect categories.
Definition: EffectManager.h:49
EVT_LIST_ITEM_ACTIVATED(wxID_ANY, SuccessDialog::OnItemActivated) ExportMultiple
void OnOk(wxCommandEvent &event)
static EffectManager & Get()
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
const wxChar * name
Definition: Distortion.cpp:94
wxStaticBox * StartStatic(const wxString &Str, int iProp=0)
Definition: ShuttleGui.cpp:701
void OnChoice(wxCommandEvent &event)
void AddStandardButtons(long buttons=eOkButton|eCancelButton, wxButton *extra=NULL)
END_EVENT_TABLE()
void OnCancel(wxCommandEvent &event)
CommandNameVector mCommandNames
EffectDistortion::Params params
Definition: Distortion.cpp:95
static wxString GetCurrentParamsFor(const wxString &command)
wxButton * AddButton(const wxString &Text, int PositionFlags=wxALIGN_CENTRE)
Definition: ShuttleGui.cpp:301
void SetStretchyCol(int i)
Used to modify an already placed FlexGridSizer to make a column stretchy.
Definition: ShuttleGui.cpp:192
EVT_LIST_ITEM_SELECTED(CurvesListID, EditCurvesDialog::OnListSelectionChange) EVT_LIST_ITEM_DESELECTED(CurvesListID
Constructor.
void StartVerticalLay(int iProp=1)
Definition: ShuttleGui.cpp:982