From 7cf92638897c9d03461f294ca4252fed13f12cb7 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Thu, 26 Mar 2020 12:28:52 -0400 Subject: [PATCH] Simplify Loudness effect UI with a notebook... ... so that we don't need to recreate the validators and change label texts after constructing the dialog. This eliminates 4 uses of macro _ . --- src/effects/Loudness.cpp | 120 ++++++++++++++++++++++----------------- src/effects/Loudness.h | 8 ++- 2 files changed, 74 insertions(+), 54 deletions(-) diff --git a/src/effects/Loudness.cpp b/src/effects/Loudness.cpp index 9f13d696f..08b4ec3df 100644 --- a/src/effects/Loudness.cpp +++ b/src/effects/Loudness.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include "../Internat.h" @@ -55,7 +56,7 @@ Param( DualMono, bool, wxT("DualMono"), true, false, tr Param( NormalizeTo, int, wxT("NormalizeTo"), kLoudness , 0 , nAlgos-1, 1 ); BEGIN_EVENT_TABLE(EffectLoudness, wxEvtHandler) - EVT_CHOICE(wxID_ANY, EffectLoudness::OnUpdateUI) + EVT_CHOICE(wxID_ANY, EffectLoudness::OnChoice) EVT_CHECKBOX(wxID_ANY, EffectLoudness::OnUpdateUI) EVT_TEXT(wxID_ANY, EffectLoudness::OnUpdateUI) END_EVENT_TABLE() @@ -300,29 +301,69 @@ void EffectLoudness::PopulateOrExchange(ShuttleGui & S) S.AddVariableText(XO("&Normalize"), false, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT); - S + mChoice = S .Validator( &mNormalizeTo ) .AddChoice( {}, Msgids(kNormalizeTargetStrings, nAlgos), - mNormalizeTo - ); - S.AddVariableText(XO("t&o"), false, - wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT); + mNormalizeTo ); + S + .AddVariableText(XO("t&o"), false, + wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT); - mLevelTextCtrl = S - /* i18n-hint: LUFS is a particular method for measuring loudnesss */ - .Name( XO("Loudness LUFS") ) - .Validator>( - 2, &mLUFSLevel, - NumValidatorStyle::ONE_TRAILING_ZERO, - MIN_LUFSLevel, MAX_LUFSLevel - ) - .AddTextBox( {}, wxT(""), 10); - /* i18n-hint: LUFS is a particular method for measuring loudnesss */ - mLeveldB = S.AddVariableText(XO("LUFS"), false, - wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT); - mWarning = S.AddVariableText( {}, false, - wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT); + // Use a notebook so we can have two controls but show only one + // They target different variables with their validators + mBook = + S + .StartSimplebook(); + { + S.StartNotebookPage({}); + { + S.StartHorizontalLay(wxALIGN_LEFT, false); + { + S + /* i18n-hint: LUFS is a particular method for measuring loudnesss */ + .Name( XO("Loudness LUFS") ) + .Validator>( + 2, &mLUFSLevel, + NumValidatorStyle::ONE_TRAILING_ZERO, + MIN_LUFSLevel, MAX_LUFSLevel ) + .AddTextBox( {}, wxT(""), 10); + + /* i18n-hint: LUFS is a particular method for measuring loudnesss */ + S + .AddVariableText(XO("LUFS"), false, + wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT); + } + S.EndHorizontalLay(); + } + S.EndNotebookPage(); + + S.StartNotebookPage({}); + { + S.StartHorizontalLay(wxALIGN_LEFT, false); + { + S + .Name( XO("RMS dB") ) + .Validator>( + 2, &mRMSLevel, + NumValidatorStyle::ONE_TRAILING_ZERO, + MIN_RMSLevel, MAX_RMSLevel ) + .AddTextBox( {}, wxT(""), 10); + + S + .AddVariableText(XO("dB"), false, + wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT); + } + S.EndHorizontalLay(); + } + S.EndNotebookPage(); + } + S.EndSimplebook(); + + mWarning = + S + .AddVariableText( {}, false, + wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT); } S.EndHorizontalLay(); @@ -341,8 +382,6 @@ void EffectLoudness::PopulateOrExchange(ShuttleGui & S) S.EndMultiColumn(); } S.EndVerticalLay(); - // To ensure that the UpdateUI on creation sets the prompts correctly. - mGUINormalizeTo = !mNormalizeTo; } bool EffectLoudness::TransferDataToWindow() @@ -541,6 +580,14 @@ bool EffectLoudness::UpdateProgress() return !TotalProgress(mProgressVal, mProgressMsg); } +void EffectLoudness::OnChoice(wxCommandEvent & WXUNUSED(evt)) +{ + mChoice->GetValidator()->TransferFromWindow(); + mBook->SetSelection( mNormalizeTo ); + UpdateUI(); + mDualMonoCheckBox->Enable(mNormalizeTo == kLoudness); +} + void EffectLoudness::OnUpdateUI(wxCommandEvent & WXUNUSED(evt)) { UpdateUI(); @@ -557,33 +604,4 @@ void EffectLoudness::UpdateUI() } mWarning->SetLabel(wxT("")); EnableApply(true); - - // Changing the prompts causes an unwanted UpdateUI event. - // This 'guard' stops that becoming an infinite recursion. - if (mNormalizeTo != mGUINormalizeTo) - { - mGUINormalizeTo = mNormalizeTo; - if(mNormalizeTo == kLoudness) - { - FloatingPointValidator vldLevel(2, &mLUFSLevel, NumValidatorStyle::ONE_TRAILING_ZERO); - vldLevel.SetRange(MIN_LUFSLevel, MAX_LUFSLevel); - mLevelTextCtrl->SetValidator(vldLevel); - /* i18n-hint: LUFS is a particular method for measuring loudnesss */ - mLevelTextCtrl->SetName(_("Loudness LUFS")); - mLevelTextCtrl->SetValue(wxString::FromDouble(mLUFSLevel)); - /* i18n-hint: LUFS is a particular method for measuring loudnesss */ - mLeveldB->SetLabel(_("LUFS")); - } - else // RMS - { - FloatingPointValidator vldLevel(2, &mRMSLevel, NumValidatorStyle::ONE_TRAILING_ZERO); - vldLevel.SetRange(MIN_RMSLevel, MAX_RMSLevel); - mLevelTextCtrl->SetValidator(vldLevel); - mLevelTextCtrl->SetName(_("RMS dB")); - mLevelTextCtrl->SetValue(wxString::FromDouble(mRMSLevel)); - mLeveldB->SetLabel(_("dB")); - } - } - - mDualMonoCheckBox->Enable(mNormalizeTo == kLoudness); } diff --git a/src/effects/Loudness.h b/src/effects/Loudness.h index 49a957048..4ea00eaa4 100644 --- a/src/effects/Loudness.h +++ b/src/effects/Loudness.h @@ -22,6 +22,8 @@ #include "Biquad.h" #include "EBUR128.h" +class wxChoice; +class wxSimplebook; class ShuttleGui; class EffectLoudness final : public Effect @@ -72,6 +74,7 @@ private: sampleCount pos, size_t len); bool UpdateProgress(); + void OnChoice(wxCommandEvent & evt); void OnUpdateUI(wxCommandEvent & evt); void UpdateUI(); @@ -81,7 +84,6 @@ private: double mRMSLevel; bool mDualMono; int mNormalizeTo; - int mGUINormalizeTo; double mCurT0; double mCurT1; @@ -96,8 +98,8 @@ private: float mRMS[2]; std::unique_ptr mLoudnessProcessor; - wxTextCtrl *mLevelTextCtrl; - wxStaticText *mLeveldB; + wxSimplebook *mBook; + wxChoice *mChoice; wxStaticText *mWarning; wxCheckBox *mStereoIndCheckBox; wxCheckBox *mDualMonoCheckBox;