Audacity 3.2.0
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
22#include "BatchCommandDialog.h"
23
24#ifdef __WXMSW__
25 #include <wx/ownerdrw.h>
26#endif
27
28//
29#include <wx/defs.h>
30#include <wx/checkbox.h>
31#include <wx/choice.h>
32#include <wx/statbox.h>
33#include <wx/stattext.h>
34#include <wx/textctrl.h>
35#include <wx/listctrl.h>
36#include <wx/button.h>
37
38#include "DoEffect.h"
39#include "EffectManager.h"
40#include "HelpSystem.h"
41#include "PluginManager.h"
42#include "Project.h"
43#include "ShuttleGui.h"
44
45#define CommandsListID 7001
46#define EditParamsButtonID 7002
47#define UsePresetButtonID 7003
48
49BEGIN_EVENT_TABLE(MacroCommandDialog, wxDialogWrapper)
58
60 wxWindow* parent, wxWindowID id, AudacityProject& project)
62 parent, id, XO("Select Command"), wxDefaultPosition, wxDefaultSize,
63 wxCAPTION | wxRESIZE_BORDER)
64 , mProject { project }
65 , mCatalog { &project }
66{
67 SetLabel(XO("Select Command")); // Provide visual label
68 SetName(XO("Select Command")); // Provide audible label
69 Populate();
70}
71
73{
74 //------------------------- Main section --------------------
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(XXO("&Command"), wxT(""), 20);
88 mCommand->SetEditable(false);
90 .Disable() // disable button as box is empty
91 .AddButton(XXO("&Edit Parameters"));
93 .Disable() // disable button as box is empty
94 .AddButton(XXO("&Use Preset"));
95 }
96 S.EndMultiColumn();
97
98 S.StartMultiColumn(2, wxEXPAND);
99 {
100 S.SetStretchyCol(1);
101 mParameters = S.AddTextBox(XXO("&Parameters"), wxT(""), 0);
102 mParameters->SetEditable(false);
103 auto prompt = XXO("&Details");
104 S.Prop(0).AddPrompt(prompt);
105 mDetails = S
106 .Name( prompt )
107 .AddTextWindow( wxT(""));
108 mDetails->SetEditable(false);
109 }
110 S.EndMultiColumn();
111
112 S.Prop(10).StartStatic(XO("Choose command"), true);
113 {
115 .Style( wxLC_LIST | wxLC_SINGLE_SEL)
116 .AddListControl();
117 }
118 S.EndStatic();
119 }
120 S.EndVerticalLay();
121
122 S.AddStandardButtons( eOkButton | eCancelButton | eHelpButton);
123
125 if (mChoices->GetItemCount() > 0) {
126 // set first item to be selected (and the focus when the
127 // list first becomes the focus)
128 mChoices->SetItemState(0, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED,
129 wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED);
130 }
131
132 SetMinSize(wxSize(780, 560));
133 Fit();
134 Center();
135}
136
138{
139 mChoices->DeleteAllItems();
140 long ii = 0;
141 for ( const auto &entry : mCatalog )
142 // insert the user-facing string
143 mChoices->InsertItem( ii++, entry.name.StrippedTranslation() );
144}
145
147{
148}
149
150void MacroCommandDialog::OnChoice(wxCommandEvent & WXUNUSED(event))
151{
152}
153
154void MacroCommandDialog::OnOk(wxCommandEvent & WXUNUSED(event))
155{
157 // .Strip(wxString::both) // PRL: used to do this, here only,
158 // but ultimately mSelectedCommand is looked up in the catalog without
159 // similar adjustment of whitespace in the comparison
160 ;
161 mSelectedParameters = mParameters->GetValue().Strip(wxString::trailing);
162 EndModal(true);
163}
164
165void MacroCommandDialog::OnCancel(wxCommandEvent & WXUNUSED(event))
166{
167 EndModal(false);
168}
169
170void MacroCommandDialog::OnHelp(wxCommandEvent & WXUNUSED(event))
171{
172 const auto &page = GetHelpPageName();
173 HelpSystem::ShowHelp(this, page, true);
174}
175
177{
178 const auto &command = mCatalog[ event.GetIndex() ];
179
181 PluginID ID =
182 PluginManager::Get().GetByCommandIdentifier(command.name.Internal());
183
184 // If ID is empty, then the effect wasn't found, in which case, the user must have
185 // selected one of the "special" commands.
186 mEditParams->Enable(!ID.empty());
187 mUsePreset->Enable(em.HasPresets(ID));
188
189 auto value = command.name.StrippedTranslation();
190 if ( value == mCommand->GetValue() )
191 // This uses the assumption of uniqueness of translated names!
192 return;
193
194 mCommand->SetValue(value);
195 mInternalCommandName = command.name.Internal();
196
198 if (params.empty())
199 {
200 params = em.GetDefaultPreset(ID);
201 }
202
203 // using GET to expose a CommandID to the user!
204 // Cryptic command and category.
205 // Later we can put help information there, perhaps.
206 // Macro command details are one place that we do expose Identifier
207 // to (more sophisticated) users
208 mDetails->SetValue(
209 mInternalCommandName.GET() + "\r\n" + command.category.Translation() );
210 mParameters->SetValue(params);
211}
212
213void MacroCommandDialog::OnEditParams(wxCommandEvent & WXUNUSED(event))
214{
215 auto command = mInternalCommandName;
216 wxString params = mParameters->GetValue();
217
219
220 mParameters->SetValue(params);
221 mParameters->Refresh();
222}
223
224void MacroCommandDialog::OnUsePreset(wxCommandEvent & WXUNUSED(event))
225{
226 auto command = mInternalCommandName;
227 wxString params = mParameters->GetValue();
228
229 wxString preset = MacroCommands::PromptForPresetFor(command, params, this).Trim();
230
231 mParameters->SetValue(preset);
232 mParameters->Refresh();
233}
234
236{
237 auto iter = mCatalog.ByCommandId( Command );
238
239 mParameters->SetValue( Params );
240
242 if (iter == mCatalog.end())
243 // uh oh, using GET to expose an internal name to the user!
244 // in default of any better friendly name
245 mCommand->SetValue( Command.GET() );
246 else {
247 mCommand->SetValue( iter->name.StrippedTranslation() );
248 // using GET to expose a CommandID to the user!
249 // Macro command details are one place that we do expose Identifier
250 // to (more sophisticated) users
251 mDetails->SetValue(
252 iter->name.Internal() + "\r\n" + iter->category.Translation() );
253 mChoices->SetItemState(iter - mCatalog.begin(),
254 wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
255
257
258 // If ID is empty, then the effect wasn't found, in which case, the user must have
259 // selected one of the "special" commands.
260 mEditParams->Enable(!ID.empty());
261 mUsePreset->Enable(EffectManager::Get().HasPresets(ID));
262 }
263}
wxT("CloseDown"))
#define EditParamsButtonID
#define UsePresetButtonID
#define CommandsListID
END_EVENT_TABLE()
wxString PluginID
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
EffectDistortionSettings params
EVT_LIST_ITEM_SELECTED(CurvesListID, EqualizationCurvesDialog::OnListSelectionChange) EVT_LIST_ITEM_DESELECTED(CurvesListID
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
static ProjectFileIORegistry::AttributeWriterEntry entry
ReverbSettings preset
Definition: ReverbBase.cpp:25
@ eIsCreating
Definition: ShuttleGui.h:37
@ eOkButton
Definition: ShuttleGui.h:609
@ eCancelButton
Definition: ShuttleGui.h:610
@ eHelpButton
Definition: ShuttleGui.h:613
const auto project
#define S(N)
Definition: ToChars.cpp:64
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
EffectManager is the class that handles effects and effect categories.
Definition: EffectManager.h:52
bool HasPresets(const PluginID &ID)
static EffectManager & Get()
wxString GetDefaultPreset(const PluginID &ID)
static void ShowHelp(wxWindow *parent, const FilePath &localFileName, const URLString &remoteURL, bool bModal=false, bool alwaysDefaultBrowser=false)
Definition: HelpSystem.cpp:231
const wxString & GET() const
Explicit conversion to wxString, meant to be ugly-looking and demanding of a comment why it's correct...
Definition: Identifier.h:66
Provides a list of configurable commands for use with MacroCommands.
void OnOk(wxCommandEvent &event)
AudacityProject & mProject
void OnCancel(wxCommandEvent &event)
void OnUsePreset(wxCommandEvent &event)
const MacroCommandsCatalog mCatalog
CommandID mInternalCommandName
void OnHelp(wxCommandEvent &event)
void OnEditParams(wxCommandEvent &event)
void PopulateOrExchange(ShuttleGui &S)
void OnItemSelected(wxListEvent &event)
void SetCommandAndParams(const CommandID &Command, const wxString &Params)
void OnChoice(wxCommandEvent &event)
ManualPageID GetHelpPageName()
wxTextCtrl * mParameters
Entries::const_iterator ByCommandId(const CommandID &commandId) const
Entries::const_iterator end() const
Definition: BatchCommands.h:52
Entries::const_iterator begin() const
Definition: BatchCommands.h:51
static wxString PromptForParamsFor(const CommandID &command, const wxString &params, AudacityProject &project)
static wxString PromptForPresetFor(const CommandID &command, const wxString &params, wxWindow *parent)
static wxString GetCurrentParamsFor(const CommandID &command)
const PluginID & GetByCommandIdentifier(const CommandID &strTarget)
static PluginManager & Get()
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:640
constexpr auto Command
Definition: MenuRegistry.h:456