2010-01-23 19:44:49 +00:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
Audacity: A Digital Audio Editor
|
|
|
|
|
|
|
|
BatchCommandDialog.cpp
|
|
|
|
|
|
|
|
Dominic Mazzoni
|
|
|
|
James Crook
|
|
|
|
|
|
|
|
*******************************************************************//*!
|
|
|
|
|
2018-03-03 19:08:23 +00:00
|
|
|
\class MacroCommandDialog
|
|
|
|
\brief Provides a list of configurable commands for use with MacroCommands
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2014-06-03 20:30:19 +00:00
|
|
|
Provides a list of commands, mostly effects, which can be chained
|
2010-01-23 19:44:49 +00:00
|
|
|
together in a simple linear sequence. Can configure parameters on each
|
|
|
|
selected command.
|
|
|
|
|
|
|
|
*//*******************************************************************/
|
|
|
|
|
2021-05-09 15:16:56 +00:00
|
|
|
|
2018-11-10 19:47:12 +00:00
|
|
|
#include "BatchCommandDialog.h"
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2018-11-14 21:30:11 +00:00
|
|
|
#ifdef __WXMSW__
|
|
|
|
#include <wx/ownerdrw.h>
|
|
|
|
#endif
|
|
|
|
|
2018-11-10 19:47:12 +00:00
|
|
|
//
|
2010-01-23 19:44:49 +00:00
|
|
|
#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 "effects/EffectManager.h"
|
|
|
|
#include "ShuttleGui.h"
|
2018-03-03 10:15:09 +00:00
|
|
|
#include "widgets/HelpSystem.h"
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define CommandsListID 7001
|
|
|
|
#define EditParamsButtonID 7002
|
2015-04-26 21:41:05 +00:00
|
|
|
#define UsePresetButtonID 7003
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2018-03-03 19:08:23 +00:00
|
|
|
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)
|
2010-01-23 19:44:49 +00:00
|
|
|
END_EVENT_TABLE();
|
|
|
|
|
2019-05-22 01:04:18 +00:00
|
|
|
MacroCommandDialog::MacroCommandDialog(
|
|
|
|
wxWindow * parent, wxWindowID id, AudacityProject &project):
|
2019-12-08 05:25:47 +00:00
|
|
|
wxDialogWrapper(parent, id, XO("Select Command"),
|
2015-04-26 21:41:05 +00:00
|
|
|
wxDefaultPosition, wxDefaultSize,
|
2011-08-21 00:15:14 +00:00
|
|
|
wxCAPTION | wxRESIZE_BORDER)
|
2019-05-22 11:07:57 +00:00
|
|
|
, mCatalog{ &project }
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
2019-12-08 05:25:47 +00:00
|
|
|
SetLabel(XO("Select Command")); // Provide visual label
|
|
|
|
SetName(XO("Select Command")); // Provide audible label
|
2010-01-23 19:44:49 +00:00
|
|
|
Populate();
|
|
|
|
}
|
|
|
|
|
2018-03-03 19:08:23 +00:00
|
|
|
void MacroCommandDialog::Populate()
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
|
|
|
//------------------------- Main section --------------------
|
|
|
|
ShuttleGui S(this, eIsCreating);
|
|
|
|
PopulateOrExchange(S);
|
|
|
|
// ----------------------- End of main section --------------
|
|
|
|
}
|
|
|
|
|
2018-03-03 19:08:23 +00:00
|
|
|
void MacroCommandDialog::PopulateOrExchange(ShuttleGui &S)
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
|
|
|
S.StartVerticalLay(true);
|
|
|
|
{
|
2015-04-26 21:41:05 +00:00
|
|
|
S.StartMultiColumn(4, wxEXPAND);
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
|
|
|
S.SetStretchyCol(1);
|
2020-05-11 15:28:14 +00:00
|
|
|
mCommand = S.AddTextBox(XXO("&Command"), wxT(""), 20);
|
2010-01-23 19:44:49 +00:00
|
|
|
mCommand->SetEditable(false);
|
2019-11-19 16:34:36 +00:00
|
|
|
mEditParams = S.Id(EditParamsButtonID)
|
|
|
|
.Disable() // disable button as box is empty
|
2020-05-11 15:28:14 +00:00
|
|
|
.AddButton(XXO("&Edit Parameters"));
|
2019-11-19 16:34:36 +00:00
|
|
|
mUsePreset = S.Id(UsePresetButtonID)
|
|
|
|
.Disable() // disable button as box is empty
|
2020-05-11 15:28:14 +00:00
|
|
|
.AddButton(XXO("&Use Preset"));
|
2010-01-23 19:44:49 +00:00
|
|
|
}
|
|
|
|
S.EndMultiColumn();
|
|
|
|
|
|
|
|
S.StartMultiColumn(2, wxEXPAND);
|
|
|
|
{
|
|
|
|
S.SetStretchyCol(1);
|
2020-05-11 15:28:14 +00:00
|
|
|
mParameters = S.AddTextBox(XXO("&Parameters"), wxT(""), 0);
|
2010-01-23 19:44:49 +00:00
|
|
|
mParameters->SetEditable(false);
|
2020-05-11 15:28:14 +00:00
|
|
|
auto prompt = XXO("&Details");
|
2019-12-22 20:40:29 +00:00
|
|
|
S.Prop(0).AddPrompt(prompt);
|
2017-10-29 14:27:23 +00:00
|
|
|
mDetails = S
|
|
|
|
.Name( prompt )
|
|
|
|
.AddTextWindow( wxT(""));
|
2018-03-01 19:23:46 +00:00
|
|
|
mDetails->SetEditable(false);
|
2010-01-23 19:44:49 +00:00
|
|
|
}
|
|
|
|
S.EndMultiColumn();
|
|
|
|
|
2019-12-22 19:58:36 +00:00
|
|
|
S.Prop(10).StartStatic(XO("Choose command"), true);
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
2017-10-31 18:52:01 +00:00
|
|
|
mChoices = S.Id(CommandsListID)
|
|
|
|
.Style(wxSUNKEN_BORDER | wxLC_LIST | wxLC_SINGLE_SEL)
|
|
|
|
.AddListControl();
|
2010-01-23 19:44:49 +00:00
|
|
|
}
|
|
|
|
S.EndStatic();
|
|
|
|
}
|
|
|
|
S.EndVerticalLay();
|
|
|
|
|
2018-03-03 10:15:09 +00:00
|
|
|
S.AddStandardButtons( eOkButton | eCancelButton | eHelpButton);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
PopulateCommandList();
|
2018-08-14 12:17:39 +00:00
|
|
|
if (mChoices->GetItemCount() > 0) {
|
|
|
|
// set first item to be selected (and the focus when the
|
|
|
|
// list first becomes the focus)
|
|
|
|
mChoices->SetItemState(0, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED,
|
|
|
|
wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED);
|
|
|
|
}
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2018-03-01 19:23:46 +00:00
|
|
|
SetMinSize(wxSize(780, 560));
|
2015-04-26 21:41:05 +00:00
|
|
|
Fit();
|
2010-01-23 19:44:49 +00:00
|
|
|
Center();
|
|
|
|
}
|
|
|
|
|
2018-03-03 19:08:23 +00:00
|
|
|
void MacroCommandDialog::PopulateCommandList()
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
|
|
|
mChoices->DeleteAllItems();
|
2018-03-06 20:28:05 +00:00
|
|
|
long ii = 0;
|
|
|
|
for ( const auto &entry : mCatalog )
|
2018-01-10 02:49:49 +00:00
|
|
|
// insert the user-facing string
|
2019-12-15 15:58:19 +00:00
|
|
|
mChoices->InsertItem( ii++, entry.name.StrippedTranslation() );
|
2010-01-23 19:44:49 +00:00
|
|
|
}
|
|
|
|
|
2018-03-03 19:08:23 +00:00
|
|
|
void MacroCommandDialog::ValidateChoices()
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-03-03 19:08:23 +00:00
|
|
|
void MacroCommandDialog::OnChoice(wxCommandEvent & WXUNUSED(event))
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-03-03 19:08:23 +00:00
|
|
|
void MacroCommandDialog::OnOk(wxCommandEvent & WXUNUSED(event))
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
2019-02-27 18:14:25 +00:00
|
|
|
mSelectedCommand = mInternalCommandName
|
|
|
|
// .Strip(wxString::both) // PRL: used to do this, here only,
|
|
|
|
// but ultimately mSelectedCommand is looked up in the catalog without
|
|
|
|
// similar adjustment of whitespace in the comparison
|
|
|
|
;
|
2010-01-23 19:44:49 +00:00
|
|
|
mSelectedParameters = mParameters->GetValue().Strip(wxString::trailing);
|
|
|
|
EndModal(true);
|
|
|
|
}
|
|
|
|
|
2018-03-03 19:08:23 +00:00
|
|
|
void MacroCommandDialog::OnCancel(wxCommandEvent & WXUNUSED(event))
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
|
|
|
EndModal(false);
|
|
|
|
}
|
|
|
|
|
2018-03-03 19:08:23 +00:00
|
|
|
void MacroCommandDialog::OnHelp(wxCommandEvent & WXUNUSED(event))
|
2018-03-03 10:15:09 +00:00
|
|
|
{
|
2021-06-06 16:18:35 +00:00
|
|
|
const auto &page = GetHelpPageName();
|
2018-03-03 10:15:09 +00:00
|
|
|
HelpSystem::ShowHelp(this, page, true);
|
|
|
|
}
|
|
|
|
|
2018-03-03 19:08:23 +00:00
|
|
|
void MacroCommandDialog::OnItemSelected(wxListEvent &event)
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
2018-03-06 20:28:05 +00:00
|
|
|
const auto &command = mCatalog[ event.GetIndex() ];
|
2015-04-26 21:41:05 +00:00
|
|
|
|
|
|
|
EffectManager & em = EffectManager::Get();
|
2018-03-15 23:06:30 +00:00
|
|
|
PluginID ID = em.GetEffectByIdentifier( command.name.Internal() );
|
2015-05-12 15:26:27 +00:00
|
|
|
|
|
|
|
// If ID is empty, then the effect wasn't found, in which case, the user must have
|
|
|
|
// selected one of the "special" commands.
|
2019-02-12 00:10:48 +00:00
|
|
|
mEditParams->Enable(!ID.empty());
|
2015-04-26 21:41:05 +00:00
|
|
|
mUsePreset->Enable(em.HasPresets(ID));
|
2015-04-27 10:02:56 +00:00
|
|
|
|
2019-12-15 15:58:19 +00:00
|
|
|
auto value = command.name.StrippedTranslation();
|
|
|
|
if ( value == mCommand->GetValue() )
|
2018-03-15 23:06:30 +00:00
|
|
|
// This uses the assumption of uniqueness of translated names!
|
2015-04-27 10:02:56 +00:00
|
|
|
return;
|
|
|
|
|
2019-12-15 15:58:19 +00:00
|
|
|
mCommand->SetValue(value);
|
2018-03-15 23:06:30 +00:00
|
|
|
mInternalCommandName = command.name.Internal();
|
2015-05-12 15:26:27 +00:00
|
|
|
|
2018-03-03 19:08:23 +00:00
|
|
|
wxString params = MacroCommands::GetCurrentParamsFor(mInternalCommandName);
|
2019-02-12 00:10:48 +00:00
|
|
|
if (params.empty())
|
2015-04-27 10:02:56 +00:00
|
|
|
{
|
|
|
|
params = em.GetDefaultPreset(ID);
|
|
|
|
}
|
|
|
|
|
2019-02-27 18:14:25 +00:00
|
|
|
// using GET to expose a CommandID to the user!
|
2018-03-01 19:23:46 +00:00
|
|
|
// Cryptic command and category.
|
|
|
|
// Later we can put help information there, perhaps.
|
2019-02-27 18:14:25 +00:00
|
|
|
// Macro command details are one place that we do expose Identifier
|
|
|
|
// to (more sophisticated) users
|
2019-12-18 05:54:08 +00:00
|
|
|
mDetails->SetValue(
|
|
|
|
mInternalCommandName.GET() + "\r\n" + command.category.Translation() );
|
2015-04-27 10:02:56 +00:00
|
|
|
mParameters->SetValue(params);
|
2010-01-23 19:44:49 +00:00
|
|
|
}
|
|
|
|
|
2018-03-03 19:08:23 +00:00
|
|
|
void MacroCommandDialog::OnEditParams(wxCommandEvent & WXUNUSED(event))
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
2019-03-11 02:05:37 +00:00
|
|
|
auto command = mInternalCommandName;
|
2010-01-23 19:44:49 +00:00
|
|
|
wxString params = mParameters->GetValue();
|
2014-11-19 06:58:44 +00:00
|
|
|
|
2020-01-06 15:09:18 +00:00
|
|
|
params = MacroCommands::PromptForParamsFor(command, params, *this).Trim();
|
2015-04-27 14:22:47 +00:00
|
|
|
|
|
|
|
mParameters->SetValue(params);
|
|
|
|
mParameters->Refresh();
|
2010-01-23 19:44:49 +00:00
|
|
|
}
|
|
|
|
|
2018-03-03 19:08:23 +00:00
|
|
|
void MacroCommandDialog::OnUsePreset(wxCommandEvent & WXUNUSED(event))
|
2015-04-26 21:41:05 +00:00
|
|
|
{
|
2019-03-11 02:05:37 +00:00
|
|
|
auto command = mInternalCommandName;
|
2015-04-26 21:41:05 +00:00
|
|
|
wxString params = mParameters->GetValue();
|
|
|
|
|
2018-03-03 19:08:23 +00:00
|
|
|
wxString preset = MacroCommands::PromptForPresetFor(command, params, this).Trim();
|
2015-04-27 14:22:47 +00:00
|
|
|
|
|
|
|
mParameters->SetValue(preset);
|
|
|
|
mParameters->Refresh();
|
2015-04-26 21:41:05 +00:00
|
|
|
}
|
|
|
|
|
2019-03-11 02:05:37 +00:00
|
|
|
void MacroCommandDialog::SetCommandAndParams(const CommandID &Command, const wxString &Params)
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
2018-03-06 20:28:05 +00:00
|
|
|
auto iter = mCatalog.ByCommandId( Command );
|
2018-01-10 02:49:49 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
mParameters->SetValue( Params );
|
|
|
|
|
2018-01-10 02:49:49 +00:00
|
|
|
mInternalCommandName = Command;
|
2018-03-06 20:28:05 +00:00
|
|
|
if (iter == mCatalog.end())
|
2019-02-27 18:14:25 +00:00
|
|
|
// uh oh, using GET to expose an internal name to the user!
|
|
|
|
// in default of any better friendly name
|
|
|
|
mCommand->SetValue( Command.GET() );
|
2018-01-10 02:49:49 +00:00
|
|
|
else {
|
2019-12-15 15:58:19 +00:00
|
|
|
mCommand->SetValue( iter->name.StrippedTranslation() );
|
2019-02-27 18:14:25 +00:00
|
|
|
// using GET to expose a CommandID to the user!
|
|
|
|
// Macro command details are one place that we do expose Identifier
|
|
|
|
// to (more sophisticated) users
|
2019-12-18 05:54:08 +00:00
|
|
|
mDetails->SetValue(
|
|
|
|
iter->name.Internal() + "\r\n" + iter->category.Translation() );
|
2018-03-06 20:28:05 +00:00
|
|
|
mChoices->SetItemState(iter - mCatalog.begin(),
|
|
|
|
wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
|
2015-05-12 15:26:27 +00:00
|
|
|
|
|
|
|
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.
|
2019-02-12 00:10:48 +00:00
|
|
|
mEditParams->Enable(!ID.empty());
|
2015-05-12 15:26:27 +00:00
|
|
|
mUsePreset->Enable(em.HasPresets(ID));
|
2010-01-23 19:44:49 +00:00
|
|
|
}
|
|
|
|
}
|