Preload the "Select Preset" with current setting

Also, loads the command parameters box with the default preset if
the selected effect doesn't expose any automation parameters.
This commit is contained in:
Leland Lucius 2015-04-27 05:02:56 -05:00
parent cb147e5605
commit e41db0e4b4
7 changed files with 152 additions and 27 deletions

View File

@ -165,17 +165,27 @@ void BatchCommandDialog::OnCancel(wxCommandEvent & WXUNUSED(event))
void BatchCommandDialog::OnItemSelected(wxListEvent &event)
{
int itemNo = event.GetIndex();
wxString command = mChoices->GetItemText( itemNo );
mCommand->SetValue( command );
wxString params = BatchCommands::GetCurrentParamsFor( command );
mParameters->SetValue( params );
wxString command = mChoices->GetItemText(event.GetIndex());
EffectManager & em = EffectManager::Get();
PluginID ID = em.GetEffectByIdentifier( command );
PluginID ID = em.GetEffectByIdentifier(command);
wxASSERT(!ID.IsEmpty());
mEditParams->Enable(true);
mUsePreset->Enable(em.HasPresets(ID));
if (command == mCommand->GetValue())
{
return;
}
mCommand->SetValue(command);
wxString params = BatchCommands::GetCurrentParamsFor(command);
if (params.IsEmpty())
{
params = em.GetDefaultPreset(ID);
}
mParameters->SetValue(params);
}
void BatchCommandDialog::OnEditParams(wxCommandEvent & WXUNUSED(event))
@ -201,7 +211,7 @@ void BatchCommandDialog::OnUsePreset(wxCommandEvent & WXUNUSED(event))
wxString command = mCommand->GetValue();
wxString params = mParameters->GetValue();
wxString preset = BatchCommands::PromptForPresetFor(command, this);
wxString preset = BatchCommands::PromptForPresetFor(command, params, this);
if (!preset.IsEmpty())
{
mParameters->SetValue(preset);

View File

@ -305,7 +305,7 @@ wxArrayString BatchCommands::GetAllCommands()
}
wxString BatchCommands::GetCurrentParamsFor(wxString command)
wxString BatchCommands::GetCurrentParamsFor(const wxString & command)
{
const PluginID & ID = EffectManager::Get().GetEffectByIdentifier(command);
if( ID.empty() )
@ -316,7 +316,7 @@ wxString BatchCommands::GetCurrentParamsFor(wxString command)
return EffectManager::Get().GetEffectParameters(ID);
}
bool BatchCommands::PromptForParamsFor(wxString command, wxWindow *parent)
bool BatchCommands::PromptForParamsFor(const wxString & command, wxWindow *parent)
{
const PluginID & ID = EffectManager::Get().GetEffectByIdentifier(command);
@ -328,7 +328,7 @@ bool BatchCommands::PromptForParamsFor(wxString command, wxWindow *parent)
return EffectManager::Get().PromptUser(ID, parent);
}
wxString BatchCommands::PromptForPresetFor(wxString command, wxWindow *parent)
wxString BatchCommands::PromptForPresetFor(const wxString & command, const wxString & params, wxWindow *parent)
{
const PluginID & ID = EffectManager::Get().GetEffectByIdentifier(command);
@ -337,7 +337,7 @@ wxString BatchCommands::PromptForPresetFor(wxString command, wxWindow *parent)
return wxEmptyString; // effect not found.
}
return EffectManager::Get().GetPreset(ID, parent);
return EffectManager::Get().GetPreset(ID, params, parent);
}
double BatchCommands::GetEndTime()

View File

@ -40,10 +40,10 @@ class BatchCommands {
// These commands do not depend on the command list.
wxArrayString GetNames();
static bool PromptForParamsFor( wxString command, wxWindow *parent );
static wxString GetCurrentParamsFor( wxString command );
static bool PromptForParamsFor(const wxString & command, wxWindow *parent );
static wxString GetCurrentParamsFor(const wxString & command);
static bool SetCurrentParametersFor(const wxString & command, const wxString & params);
static wxString PromptForPresetFor( wxString command, wxWindow *parent );
static wxString PromptForPresetFor( const wxString & command, const wxString & params, wxWindow *parent );
static bool SetCurrentPresetFor(const wxString & command, const wxString & preset);
static wxArrayString GetAllCommands();

View File

@ -1104,12 +1104,13 @@ bool Effect::HasFactoryDefaults()
return HasPrivateConfigGroup(GetFactoryDefaultsGroup());
}
wxString Effect::GetPreset(wxWindow * parent)
wxString Effect::GetPreset(wxWindow * parent, const wxString & parms)
{
EffectPresetsDialog dlg(parent, this);
dlg.Layout();
dlg.Fit();
dlg.SetSize(dlg.GetMinSize());
dlg.SetSelected(parms);
if (dlg.ShowModal())
{
@ -3612,6 +3613,85 @@ EffectPresetsDialog::~EffectPresetsDialog()
{
}
wxString EffectPresetsDialog::GetSelected() const
{
return mSelection;
}
void EffectPresetsDialog::SetSelected(const wxString & parms)
{
wxString preset = parms;
if (preset.StartsWith(Effect::kUserPresetIdent))
{
preset.Replace(Effect::kUserPresetIdent, wxEmptyString, false);
SetPrefix(_("User Presets"), preset);
}
else if (preset.StartsWith(Effect::kFactoryPresetIdent))
{
preset.Replace(Effect::kFactoryPresetIdent, wxEmptyString, false);
SetPrefix(_("Factory Presets"), preset);
}
else if (preset.StartsWith(Effect::kCurrentSettingsIdent))
{
SetPrefix(_("Current Settings"), wxEmptyString);
}
else if (preset.StartsWith(Effect::kFactoryDefaultsIdent))
{
SetPrefix(_("Factory Defaults"), wxEmptyString);
}
}
void EffectPresetsDialog::SetPrefix(const wxString & type, const wxString & prefix)
{
mType->SetStringSelection(type);
int selected;
if (type.IsSameAs(_("User Presets")))
{
mPresets->Clear();
mPresets->Append(mUserPresets);
mPresets->Enable(true);
mPresets->SetStringSelection(prefix);
if (mPresets->GetSelection() == wxNOT_FOUND)
{
mPresets->SetSelection(0);
}
mSelection = Effect::kUserPresetIdent + mPresets->GetStringSelection();
}
else if (type.IsSameAs(_("Factory Presets")))
{
mPresets->Clear();
for (size_t i = 0, cnt = mFactoryPresets.GetCount(); i < cnt; i++)
{
wxString label = mFactoryPresets[i];
if (label.IsEmpty())
{
label = _("None");
}
mPresets->Append(label);
}
mPresets->Enable(true);
mPresets->SetStringSelection(prefix);
if (mPresets->GetSelection() == wxNOT_FOUND)
{
mPresets->SetSelection(0);
}
mSelection = Effect::kFactoryPresetIdent + mPresets->GetStringSelection();
}
else if (type.IsSameAs(_("Current Settings")))
{
mPresets->Clear();
mPresets->Enable(false);
mSelection = Effect::kCurrentSettingsIdent;
}
else if (type.IsSameAs(_("Factory Defaults")))
{
mPresets->Clear();
mPresets->Enable(false);
mSelection = Effect::kFactoryDefaultsIdent;
}
}
void EffectPresetsDialog::UpdateUI()
{
int selected = mType->GetSelection();
@ -3690,9 +3770,3 @@ void EffectPresetsDialog::OnCancel(wxCommandEvent & WXUNUSED(evt))
EndModal(false);
}
wxString EffectPresetsDialog::GetSelected() const
{
return mSelection;
}

View File

@ -211,7 +211,7 @@ class AUDACITY_DLL_API Effect : public wxEvtHandler,
virtual wxArrayString GetUserPresets();
virtual bool HasCurrentSettings();
virtual bool HasFactoryDefaults();
virtual wxString GetPreset(wxWindow * parent);
virtual wxString GetPreset(wxWindow * parent, const wxString & parms);
virtual bool IsBatchProcessing();
virtual void SetBatchProcessing(bool enable);
@ -566,8 +566,10 @@ public:
virtual ~EffectPresetsDialog();
wxString GetSelected() const;
void SetSelected(const wxString & parms);
private:
void SetPrefix(const wxString & type, const wxString & prefix);
void UpdateUI();
void OnType(wxCommandEvent & evt);

View File

@ -230,7 +230,7 @@ bool EffectManager::HasPresets(const PluginID & ID)
effect->HasFactoryDefaults();
}
wxString EffectManager::GetPreset(const PluginID & ID, wxWindow * parent)
wxString EffectManager::GetPreset(const PluginID & ID, const wxString & params, wxWindow * parent)
{
Effect *effect = GetEffect(ID);
@ -239,13 +239,21 @@ wxString EffectManager::GetPreset(const PluginID & ID, wxWindow * parent)
return wxEmptyString;
}
wxString preset = effect->GetPreset(parent);
EffectAutomationParameters eap(params);
wxString preset;
if (eap.HasEntry(wxT("Use Preset")))
{
preset = eap.Read(wxT("Use Preset"));
}
preset = effect->GetPreset(parent, preset);
if (preset.IsEmpty())
{
return preset;
}
EffectAutomationParameters eap;
eap.DeleteAll();
eap.Write(wxT("Use Preset"), preset);
eap.GetParameters(preset);
@ -253,6 +261,36 @@ wxString EffectManager::GetPreset(const PluginID & ID, wxWindow * parent)
return preset;
}
wxString EffectManager::GetDefaultPreset(const PluginID & ID)
{
Effect *effect = GetEffect(ID);
if (!effect)
{
return wxEmptyString;
}
wxString preset;
if (effect->HasCurrentSettings())
{
preset = Effect::kCurrentSettingsIdent;
}
else if (effect->HasFactoryDefaults())
{
preset = Effect::kFactoryDefaultsIdent;
}
if (!preset.IsEmpty())
{
EffectAutomationParameters eap;
eap.Write(wxT("Use Preset"), preset);
eap.GetParameters(preset);
}
return preset;
}
#if defined(EXPERIMENTAL_EFFECTS_RACK)
EffectRack *EffectManager::GetRack()
{

View File

@ -84,9 +84,10 @@ public:
bool SetEffectParameters(const PluginID & ID, const wxString & params);
bool PromptUser(const PluginID & ID, wxWindow *parent);
bool HasPresets(const PluginID & ID);
wxString GetPreset(const PluginID & ID, wxWindow * parent);
wxString GetPreset(const PluginID & ID, const wxString & params, wxWindow * parent);
wxString GetDefaultPreset(const PluginID & ID);
// Realtime effect processing
// Realtime effect processing
bool RealtimeIsActive();
bool RealtimeIsSuspended();
void RealtimeAddEffect(Effect *effect);