forked from audacity/audacity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBatchCommandDialog.cpp
More file actions
238 lines (192 loc) · 7.16 KB
/
Copy pathBatchCommandDialog.cpp
File metadata and controls
238 lines (192 loc) · 7.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/**********************************************************************
Audacity: A Digital Audio Editor
BatchCommandDialog.cpp
Dominic Mazzoni
James Crook
*******************************************************************//*!
\class MacroCommandDialog
\brief Provides a list of configurable commands for use with MacroCommands
Provides a list of commands, mostly effects, which can be chained
together in a simple linear sequence. Can configure parameters on each
selected command.
*//*******************************************************************/
#include "Audacity.h"
#include <wx/defs.h>
#include <wx/checkbox.h>
#include <wx/choice.h>
#include <wx/intl.h>
#include <wx/sizer.h>
#include <wx/statbox.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/listctrl.h>
#include <wx/radiobut.h>
#include <wx/button.h>
#include <wx/string.h>
#include <wx/dialog.h>
#include "Project.h"
#include "BatchCommandDialog.h"
#include "commands/CommandManager.h"
#include "effects/EffectManager.h"
#include "BatchCommands.h"
#include "ShuttleGui.h"
#include "widgets/HelpSystem.h"
#define CommandsListID 7001
#define EditParamsButtonID 7002
#define UsePresetButtonID 7003
BEGIN_EVENT_TABLE(MacroCommandDialog, wxDialogWrapper)
EVT_BUTTON(wxID_OK, MacroCommandDialog::OnOk)
EVT_BUTTON(wxID_CANCEL, MacroCommandDialog::OnCancel)
EVT_BUTTON(wxID_HELP, MacroCommandDialog::OnHelp)
EVT_BUTTON(EditParamsButtonID, MacroCommandDialog::OnEditParams)
EVT_BUTTON(UsePresetButtonID, MacroCommandDialog::OnUsePreset)
EVT_LIST_ITEM_ACTIVATED(CommandsListID, MacroCommandDialog::OnItemSelected)
EVT_LIST_ITEM_SELECTED(CommandsListID, MacroCommandDialog::OnItemSelected)
END_EVENT_TABLE();
MacroCommandDialog::MacroCommandDialog(wxWindow * parent, wxWindowID id):
wxDialogWrapper(parent, id, _("Select Command"),
wxDefaultPosition, wxDefaultSize,
wxCAPTION | wxRESIZE_BORDER)
, mCatalog( GetActiveProject() )
{
SetLabel(_("Select Command")); // Provide visual label
SetName(_("Select Command")); // Provide audible label
Populate();
}
void MacroCommandDialog::Populate()
{
//------------------------- Main section --------------------
ShuttleGui S(this, eIsCreating);
PopulateOrExchange(S);
// ----------------------- End of main section --------------
}
void MacroCommandDialog::PopulateOrExchange(ShuttleGui &S)
{
S.StartVerticalLay(true);
{
S.StartMultiColumn(4, wxEXPAND);
{
S.SetStretchyCol(1);
mCommand = S.AddTextBox(_("&Command"), wxT(""), 20);
mCommand->SetEditable(false);
mEditParams = S.Id(EditParamsButtonID).AddButton(_("&Edit Parameters"));
mEditParams->Enable(false); // disable button as box is empty
mUsePreset = S.Id(UsePresetButtonID).AddButton(_("&Use Preset"));
mUsePreset->Enable(false); // disable button as box is empty
}
S.EndMultiColumn();
S.StartMultiColumn(2, wxEXPAND);
{
S.SetStretchyCol(1);
mParameters = S.AddTextBox(_("&Parameters"), wxT(""), 0);
mParameters->SetEditable(false);
S.Prop(0).AddPrompt( _("&Details" ) );
mDetails = S.AddTextWindow( wxT(""));
mDetails->SetEditable(false);
}
S.EndMultiColumn();
S.Prop(10).StartStatic(_("C&hoose command"), true);
{
S.SetStyle(wxSUNKEN_BORDER | wxLC_LIST | wxLC_SINGLE_SEL);
mChoices = S.Id(CommandsListID).AddListControl();
}
S.EndStatic();
}
S.EndVerticalLay();
S.AddStandardButtons( eOkButton | eCancelButton | eHelpButton);
PopulateCommandList();
SetMinSize(wxSize(780, 560));
Fit();
Center();
}
void MacroCommandDialog::PopulateCommandList()
{
mChoices->DeleteAllItems();
long ii = 0;
for ( const auto &entry : mCatalog )
// insert the user-facing string
mChoices->InsertItem( ii++, entry.name.Translated() );
}
void MacroCommandDialog::ValidateChoices()
{
}
void MacroCommandDialog::OnChoice(wxCommandEvent & WXUNUSED(event))
{
}
void MacroCommandDialog::OnOk(wxCommandEvent & WXUNUSED(event))
{
mSelectedCommand = mInternalCommandName.Strip(wxString::both);
mSelectedParameters = mParameters->GetValue().Strip(wxString::trailing);
EndModal(true);
}
void MacroCommandDialog::OnCancel(wxCommandEvent & WXUNUSED(event))
{
EndModal(false);
}
void MacroCommandDialog::OnHelp(wxCommandEvent & WXUNUSED(event))
{
wxString page = GetHelpPageName();
HelpSystem::ShowHelp(this, page, true);
}
void MacroCommandDialog::OnItemSelected(wxListEvent &event)
{
const auto &command = mCatalog[ event.GetIndex() ];
EffectManager & em = EffectManager::Get();
PluginID ID = em.GetEffectByIdentifier( command.name.Internal() );
// If ID is empty, then the effect wasn't found, in which case, the user must have
// selected one of the "special" commands.
mEditParams->Enable(!ID.IsEmpty());
mUsePreset->Enable(em.HasPresets(ID));
if ( command.name.Translated() == mCommand->GetValue() )
// This uses the assumption of uniqueness of translated names!
return;
mCommand->SetValue(command.name.Translated());
mInternalCommandName = command.name.Internal();
wxString params = MacroCommands::GetCurrentParamsFor(mInternalCommandName);
if (params.IsEmpty())
{
params = em.GetDefaultPreset(ID);
}
// Cryptic command and category.
// Later we can put help information there, perhaps.
mDetails->SetValue( mInternalCommandName + "\r\n" + command.category );
mParameters->SetValue(params);
}
void MacroCommandDialog::OnEditParams(wxCommandEvent & WXUNUSED(event))
{
wxString command = mInternalCommandName;
wxString params = mParameters->GetValue();
params = MacroCommands::PromptForParamsFor(command, params, this).Trim();
mParameters->SetValue(params);
mParameters->Refresh();
}
void MacroCommandDialog::OnUsePreset(wxCommandEvent & WXUNUSED(event))
{
wxString command = mInternalCommandName;
wxString params = mParameters->GetValue();
wxString preset = MacroCommands::PromptForPresetFor(command, params, this).Trim();
mParameters->SetValue(preset);
mParameters->Refresh();
}
void MacroCommandDialog::SetCommandAndParams(const wxString &Command, const wxString &Params)
{
auto iter = mCatalog.ByCommandId( Command );
mParameters->SetValue( Params );
mInternalCommandName = Command;
if (iter == mCatalog.end())
// Expose an internal name to the user in default of any friendly name
// -- AVOID THIS!
mCommand->SetValue( Command );
else {
mCommand->SetValue( iter->name.Translated() );
mDetails->SetValue( iter->name.Internal() + "\r\n" + iter->category );
mChoices->SetItemState(iter - mCatalog.begin(),
wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
EffectManager & em = EffectManager::Get();
PluginID ID = em.GetEffectByIdentifier(Command);
// If ID is empty, then the effect wasn't found, in which case, the user must have
// selected one of the "special" commands.
mEditParams->Enable(!ID.IsEmpty());
mUsePreset->Enable(em.HasPresets(ID));
}
}