From e41db0e4b46890ad584936d631e9434a550ed45b Mon Sep 17 00:00:00 2001 From: Leland Lucius Date: Mon, 27 Apr 2015 05:02:56 -0500 Subject: [PATCH] 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. --- src/BatchCommandDialog.cpp | 24 +++++++--- src/BatchCommands.cpp | 8 ++-- src/BatchCommands.h | 6 +-- src/effects/Effect.cpp | 88 ++++++++++++++++++++++++++++++++--- src/effects/Effect.h | 4 +- src/effects/EffectManager.cpp | 44 ++++++++++++++++-- src/effects/EffectManager.h | 5 +- 7 files changed, 152 insertions(+), 27 deletions(-) diff --git a/src/BatchCommandDialog.cpp b/src/BatchCommandDialog.cpp index 7cf7228cc..fff2526c4 100644 --- a/src/BatchCommandDialog.cpp +++ b/src/BatchCommandDialog.cpp @@ -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); diff --git a/src/BatchCommands.cpp b/src/BatchCommands.cpp index 9ce4837a8..bb8fac5a9 100644 --- a/src/BatchCommands.cpp +++ b/src/BatchCommands.cpp @@ -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() diff --git a/src/BatchCommands.h b/src/BatchCommands.h index 033715c0c..60b79e194 100644 --- a/src/BatchCommands.h +++ b/src/BatchCommands.h @@ -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(); diff --git a/src/effects/Effect.cpp b/src/effects/Effect.cpp index 57d8f4155..1d00e707e 100644 --- a/src/effects/Effect.cpp +++ b/src/effects/Effect.cpp @@ -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; -} - diff --git a/src/effects/Effect.h b/src/effects/Effect.h index 6b03c29e0..ce6a61228 100644 --- a/src/effects/Effect.h +++ b/src/effects/Effect.h @@ -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); diff --git a/src/effects/EffectManager.cpp b/src/effects/EffectManager.cpp index 958ac6104..c68acb03d 100644 --- a/src/effects/EffectManager.cpp +++ b/src/effects/EffectManager.cpp @@ -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() { diff --git a/src/effects/EffectManager.h b/src/effects/EffectManager.h index a388f69ce..29317937a 100644 --- a/src/effects/EffectManager.h +++ b/src/effects/EffectManager.h @@ -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);