From b256a4fd1a4ade3369b68faf7c1d058106ed7897 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 30 Jan 2018 20:03:46 -0500 Subject: [PATCH] Less code directly inside ShuttleGui code blocks... ... Trying to reduce that just to chained calls on S, or conditional and looping logic for variations in layout. Lift some declarations to higher scope; or use expressions that avoid local variables; or even use lambdas for more complicated computation of arguments for the member functions of S. --- src/FFmpeg.cpp | 20 +++---- src/Screenshot.cpp | 10 ++-- src/SoundActivatedRecord.cpp | 9 ++- src/effects/Amplify.cpp | 11 ++-- src/effects/ChangeTempo.cpp | 9 +-- src/effects/Contrast.cpp | 10 ++-- src/effects/Distortion.cpp | 7 ++- src/effects/Effect.cpp | 20 +++---- src/effects/Normalize.cpp | 11 +--- src/export/ExportFFmpeg.cpp | 20 +++---- src/export/ExportMP3.cpp | 103 +++++++++++++++++---------------- src/prefs/RecordingPrefs.cpp | 3 +- src/toolbars/DeviceToolBar.cpp | 2 +- 13 files changed, 118 insertions(+), 117 deletions(-) diff --git a/src/FFmpeg.cpp b/src/FFmpeg.cpp index 6de1e8676..9154f6e84 100644 --- a/src/FFmpeg.cpp +++ b/src/FFmpeg.cpp @@ -465,19 +465,17 @@ public: void PopulateOrExchange(ShuttleGui & S) { - wxString text; - S.SetBorder(10); S.StartVerticalLay(true); { - text.Printf(_("Audacity needs the file '%s' to import and export audio via FFmpeg."), mName); - S.AddTitle(text); + S.AddTitle( wxString::Format( + _("Audacity needs the file '%s' to import and export audio via FFmpeg."), + mName)); S.SetBorder(3); S.StartHorizontalLay(wxALIGN_LEFT, true); { - text.Printf(_("Location of '%s':"), mName); - S.AddTitle(text); + S.AddTitle( wxString::Format(_("Location of '%s':"), mName) ); } S.EndHorizontalLay(); @@ -485,8 +483,8 @@ public: S.SetStretchyCol(0); { if (mLibPath.GetFullPath().empty()) { - text.Printf(_("To find '%s', click here -->"), mName); - mPathText = S.AddTextBox( {}, text, 0); + mPathText = S.AddTextBox( {}, + wxString::Format(_("To find '%s', click here -->"), mName), 0); } else { mPathText = S.AddTextBox( {}, mLibPath.GetFullPath(), 0); @@ -586,9 +584,9 @@ To use FFmpeg import, go to Edit > Preferences > Libraries\n\ to download or locate the FFmpeg libraries." )); - int dontShowDlg = 0; - gPrefs->Read(wxT("/FFmpeg/NotFoundDontShow"),&dontShowDlg,0); - mDontShow = S.AddCheckBox(_("Do not show this warning again"),dontShowDlg); + mDontShow = S + .AddCheckBox(_("Do not show this warning again"), + gPrefs->ReadBool(wxT("/FFmpeg/NotFoundDontShow"), false) ); S.AddStandardButtons(eOkButton); } diff --git a/src/Screenshot.cpp b/src/Screenshot.cpp index 012982303..b3aaac77e 100644 --- a/src/Screenshot.cpp +++ b/src/Screenshot.cpp @@ -326,12 +326,12 @@ void ScreenFrame::PopulateOrExchange(ShuttleGui & S) { S.SetStretchyCol(1); - wxString dir = - gPrefs->Read(wxT("/ScreenshotPath"), - wxFileName::GetHomeDir()); mDirectoryTextBox = - S.Id(IdDirectory).AddTextBox(_("Save images to:"), - dir, 30); + S.Id(IdDirectory).AddTextBox( + _("Save images to:"), + gPrefs->Read(wxT("/ScreenshotPath"), wxFileName::GetHomeDir()), + 30 + ); S.Id(IdDirChoose).AddButton(_("Choose...")); } S.EndMultiColumn(); diff --git a/src/SoundActivatedRecord.cpp b/src/SoundActivatedRecord.cpp index fb2e1f050..6e4276e8d 100644 --- a/src/SoundActivatedRecord.cpp +++ b/src/SoundActivatedRecord.cpp @@ -53,9 +53,12 @@ void SoundActivatedRecord::PopulateOrExchange(ShuttleGui & S) S.StartVerticalLay(); { S.StartMultiColumn(2, wxEXPAND); - S.SetStretchyCol(1); - dBRange = gPrefs->Read(ENV_DB_KEY, ENV_DB_RANGE); - S.TieSlider(_("Activation level (dB):"), {wxT("/AudioIO/SilenceLevel"), -50}, 0, -dBRange); + S.SetStretchyCol(1); + S.TieSlider( + _("Activation level (dB):"), + {wxT("/AudioIO/SilenceLevel"), -50}, + 0, -gPrefs->Read(ENV_DB_KEY, ENV_DB_RANGE) + ); S.EndMultiColumn(); } S.EndVerticalLay(); diff --git a/src/effects/Amplify.cpp b/src/effects/Amplify.cpp index 0289023e6..946c20d64 100644 --- a/src/effects/Amplify.cpp +++ b/src/effects/Amplify.cpp @@ -207,6 +207,8 @@ void EffectAmplify::Preview(bool dryOnly) void EffectAmplify::PopulateOrExchange(ShuttleGui & S) { + enum{ precision = 3 }; // allow (a generous) 3 decimal places for Amplification (dB) + if (IsBatchProcessing()) { mPeak = 1.0; @@ -228,11 +230,10 @@ void EffectAmplify::PopulateOrExchange(ShuttleGui & S) S.StartVerticalLay(0); { - int precission = 3; // allow (a generous) 3 decimal places for Amplification (dB) // Amplitude S.StartMultiColumn(2, wxCENTER); { - FloatingPointValidator vldAmp(precission, &mAmp, NumValidatorStyle::ONE_TRAILING_ZERO); + FloatingPointValidator vldAmp(precision, &mAmp, NumValidatorStyle::ONE_TRAILING_ZERO); vldAmp.SetRange(MIN_Amp, MAX_Amp); mAmpT = S.Id(ID_Amp).AddTextBox(_("Amplification (dB):"), wxT(""), 12); mAmpT->SetValidator(vldAmp); @@ -252,13 +253,13 @@ void EffectAmplify::PopulateOrExchange(ShuttleGui & S) S.StartMultiColumn(2, wxCENTER); { // One extra decimal place so that rounding is visible to user (see: bug 958) - FloatingPointValidator vldNewPeak(precission + 1, &mNewPeak, NumValidatorStyle::ONE_TRAILING_ZERO); + FloatingPointValidator vldNewPeak(precision + 1, &mNewPeak, NumValidatorStyle::ONE_TRAILING_ZERO); double minAmp = MIN_Amp + LINEAR_TO_DB(mPeak); double maxAmp = MAX_Amp + LINEAR_TO_DB(mPeak); // min and max need same precision as what we're validating (bug 963) - minAmp = Internat::CompatibleToDouble(Internat::ToString(minAmp, precission +1)); - maxAmp = Internat::CompatibleToDouble(Internat::ToString(maxAmp, precission +1)); + minAmp = Internat::CompatibleToDouble(Internat::ToString(minAmp, precision +1)); + maxAmp = Internat::CompatibleToDouble(Internat::ToString(maxAmp, precision +1)); vldNewPeak.SetRange(minAmp, maxAmp); mNewPeakT = S.Id(ID_Peak).AddTextBox(_("New Peak Amplitude (dB):"), wxT(""), 12); diff --git a/src/effects/ChangeTempo.cpp b/src/effects/ChangeTempo.cpp index c6daa34cb..2f8e42713 100644 --- a/src/effects/ChangeTempo.cpp +++ b/src/effects/ChangeTempo.cpp @@ -221,6 +221,8 @@ bool EffectChangeTempo::Process() void EffectChangeTempo::PopulateOrExchange(ShuttleGui & S) { + enum { precision = 2 }; + S.StartVerticalLay(0); { S.AddSpace(0, 5); @@ -273,8 +275,7 @@ void EffectChangeTempo::PopulateOrExchange(ShuttleGui & S) { S.StartHorizontalLay(wxALIGN_CENTER); { - int precission = 2; - FloatingPointValidator vldFromLength(precission, &m_FromLength, NumValidatorStyle::TWO_TRAILING_ZEROES); + FloatingPointValidator vldFromLength(precision, &m_FromLength, NumValidatorStyle::TWO_TRAILING_ZEROES); m_pTextCtrl_FromLength = S.Id(ID_FromLength) .AddTextBox(_("from"), wxT(""), 12); m_pTextCtrl_FromLength->SetValidator(vldFromLength); @@ -285,8 +286,8 @@ void EffectChangeTempo::PopulateOrExchange(ShuttleGui & S) // min and max need same precision as what we're validating (bug 963) double minLength = (m_FromLength * 100.0) / (100.0 + MAX_Percentage); double maxLength = (m_FromLength * 100.0) / (100.0 + MIN_Percentage); - minLength = Internat::CompatibleToDouble(Internat::ToString(minLength, precission)); - maxLength = Internat::CompatibleToDouble(Internat::ToString(maxLength, precission)); + minLength = Internat::CompatibleToDouble(Internat::ToString(minLength, precision)); + maxLength = Internat::CompatibleToDouble(Internat::ToString(maxLength, precision)); vldToLength.SetRange(minLength, maxLength); m_pTextCtrl_ToLength = S.Id(ID_ToLength) diff --git a/src/effects/Contrast.cpp b/src/effects/Contrast.cpp index 5854e5daf..7c82caaf7 100644 --- a/src/effects/Contrast.cpp +++ b/src/effects/Contrast.cpp @@ -197,6 +197,11 @@ ContrastDialog::ContrastDialog(wxWindow * parent, wxWindowID id, const auto &settings = ProjectSettings::Get( *p ); mProjectRate = settings.GetRate(); + const auto options = NumericTextCtrl::Options{} + .AutoPos(true) + .MenuEnabled(false) + .ReadOnly(true); + ShuttleGui S(this, eIsCreating); S.SetBorder(5); @@ -218,11 +223,6 @@ ContrastDialog::ContrastDialog(wxWindow * parent, wxWindowID id, S.AddFixedText( {} ); // spacer S.AddFixedText(_("Volume ")); - const auto options = NumericTextCtrl::Options{} - .AutoPos(true) - .MenuEnabled(false) - .ReadOnly(true); - //Foreground S.AddFixedText(_("&Foreground:"), false); if (S.GetMode() == eIsCreating) diff --git a/src/effects/Distortion.cpp b/src/effects/Distortion.cpp index 88e3ff303..2c5eb93ac 100644 --- a/src/effects/Distortion.cpp +++ b/src/effects/Distortion.cpp @@ -402,9 +402,10 @@ void EffectDistortion::PopulateOrExchange(ShuttleGui & S) mThresholdT->SetValidator(vldThreshold); S.SetStyle(wxSL_HORIZONTAL); - double maxLin = DB_TO_LINEAR(MAX_Threshold_dB) * SCL_Threshold_dB; - double minLin = DB_TO_LINEAR(MIN_Threshold_dB) * SCL_Threshold_dB; - mThresholdS = S.Id(ID_Threshold).AddSlider( {}, 0, maxLin, minLin); + mThresholdS = S.Id(ID_Threshold) + .AddSlider( {}, 0, + DB_TO_LINEAR(MAX_Threshold_dB) * SCL_Threshold_dB, + DB_TO_LINEAR(MIN_Threshold_dB) * SCL_Threshold_dB); mThresholdS->SetName(defaultLabel(0)); S.AddSpace(20, 0); diff --git a/src/effects/Effect.cpp b/src/effects/Effect.cpp index 4087aa676..0b7db0328 100644 --- a/src/effects/Effect.cpp +++ b/src/effects/Effect.cpp @@ -2479,22 +2479,22 @@ EffectDialog::EffectDialog(wxWindow * parent, void EffectDialog::Init() { + long buttons = eOkButton; + if ((mType != EffectTypeAnalyze) && (mType != EffectTypeTool)) + { + buttons |= eCancelButton; + if (mType == EffectTypeProcess) + { + buttons |= ePreviewButton; + } + } + ShuttleGui S(this, eIsCreating); S.SetBorder(5); S.StartVerticalLay(true); { PopulateOrExchange(S); - - long buttons = eOkButton; - if ((mType != EffectTypeAnalyze) && (mType != EffectTypeTool)) - { - buttons |= eCancelButton; - if (mType == EffectTypeProcess) - { - buttons |= ePreviewButton; - } - } S.AddStandardButtons(buttons|mAdditionalButtons); } S.EndVerticalLay(); diff --git a/src/effects/Normalize.cpp b/src/effects/Normalize.cpp index 636367602..855dd0b25 100644 --- a/src/effects/Normalize.cpp +++ b/src/effects/Normalize.cpp @@ -299,14 +299,9 @@ void EffectNormalize::PopulateOrExchange(ShuttleGui & S) S.StartHorizontalLay(wxALIGN_LEFT, false); { - // The checkbox needs to be sized for the longer prompt, and - // which that is will depend on translation. So decide that here. - // (strictly we should count pixels, not characters). - wxString prompt1 = _("Normalize peak amplitude to"); - wxString longerPrompt = prompt1 + " "; - // Now make the checkbox. - mGainCheckBox = S.AddCheckBox(longerPrompt, - mGain); + mGainCheckBox = S + .AddCheckBox(_("Normalize peak amplitude to "), + mGain); mGainCheckBox->SetValidator(wxGenericValidator(&mGain)); mGainCheckBox->SetMinSize( mGainCheckBox->GetSize()); diff --git a/src/export/ExportFFmpeg.cpp b/src/export/ExportFFmpeg.cpp index 1172f5a9a..ad49dfbd5 100644 --- a/src/export/ExportFFmpeg.cpp +++ b/src/export/ExportFFmpeg.cpp @@ -1001,7 +1001,6 @@ int ExportFFmpeg::AskResample(int bitrate, int rate, int lowrate, int highrate, d.SetName(d.GetTitle()); wxChoice *choice; ShuttleGui S(&d, eIsCreating); - wxString text; int selected = -1; @@ -1012,15 +1011,16 @@ int ExportFFmpeg::AskResample(int bitrate, int rate, int lowrate, int highrate, { S.StartHorizontalLay(wxALIGN_CENTER, false); { - if (bitrate == 0) { - text.Printf(_("The project sample rate (%d) is not supported by the current output\nfile format. "), rate); - } - else { - text.Printf(_("The project sample rate (%d) and bit rate (%d kbps) combination is not\nsupported by the current output file format. "), rate, bitrate/1024); - } - - text += _("You may resample to one of the rates below."); - S.AddTitle(text); + S.AddTitle( + (bitrate == 0 + ? wxString::Format( + _("The project sample rate (%d) is not supported by the current output\nfile format. "), + rate) + : wxString::Format( + _("The project sample rate (%d) and bit rate (%d kbps) combination is not\nsupported by the current output file format. "), + rate, bitrate/1024)) + + _("You may resample to one of the rates below.") + ); } S.EndHorizontalLay(); diff --git a/src/export/ExportMP3.cpp b/src/export/ExportMP3.cpp index ff7127b43..6ed86c091 100644 --- a/src/export/ExportMP3.cpp +++ b/src/export/ExportMP3.cpp @@ -325,6 +325,43 @@ static EnumSetting< MP3ChannelMode > MP3ChannelModeSetting{ /// void ExportMP3Options::PopulateOrExchange(ShuttleGui & S) { + bool mono = false; + gPrefs->Read(wxT("/FileFormats/MP3ForceMono"), &mono, 0); + + const wxArrayStringEx *choices = nullptr; + const std::vector< int > *codes = nullptr; + bool enable; + int defrate; + + switch( MP3RateModeSetting.ReadEnum() ) { + case MODE_SET: + choices = &setRateNames; + enable = true; + defrate = mSetRate; + break; + + case MODE_VBR: + choices = &varRateNames; + enable = true; + defrate = mVbrRate; + break; + + case MODE_ABR: + choices = &fixRateNames; + codes = &fixRateValues; + enable = false; + defrate = mAbrRate; + break; + + case MODE_CBR: + default: + choices = &fixRateNames; + codes = &fixRateValues; + enable = false; + defrate = mCbrRate; + break; + } + S.StartVerticalLay(); { S.StartHorizontalLay(wxCENTER); @@ -347,35 +384,6 @@ void ExportMP3Options::PopulateOrExchange(ShuttleGui & S) S.EndRadioButtonGroup(); } S.EndHorizontalLay(); - - const wxArrayStringEx *choices = nullptr; - const std::vector< int > *codes = nullptr; - bool enable; - int defrate; - - if (mSET->GetValue()) { - choices = &setRateNames; - enable = true; - defrate = mSetRate; - } - else if (mVBR->GetValue()) { - choices = &varRateNames; - enable = true; - defrate = mVbrRate; - } - else if (mABR->GetValue()) { - choices = &fixRateNames; - codes = &fixRateValues; - enable = false; - defrate = mAbrRate; - } - else { - mCBR->SetValue(true); - choices = &fixRateNames; - codes = &fixRateValues; - enable = false; - defrate = mCbrRate; - } mRate = S.Id(ID_QUALITY).TieNumberAsChoice( _("Quality"), @@ -393,9 +401,6 @@ void ExportMP3Options::PopulateOrExchange(ShuttleGui & S) S.AddPrompt(_("Channel Mode:")); S.StartMultiColumn(3, wxEXPAND); { - bool mono = false; - gPrefs->Read(wxT("/FileFormats/MP3ForceMono"), &mono, 0); - S.StartRadioButtonGroup(MP3ChannelModeSetting); { mJoint = S.TieRadioButton(); @@ -566,19 +571,17 @@ public: void PopulateOrExchange(ShuttleGui & S) { - wxString text; - S.SetBorder(10); S.StartVerticalLay(true); { - text.Printf(_("Audacity needs the file %s to create MP3s."), mName); - S.AddTitle(text); + S.AddTitle( + wxString::Format(_("Audacity needs the file %s to create MP3s."), + mName)); S.SetBorder(3); S.StartHorizontalLay(wxALIGN_LEFT, true); { - text.Printf(_("Location of %s:"), mName); - S.AddTitle(text); + S.AddTitle( wxString::Format(_("Location of %s:"), mName) ); } S.EndHorizontalLay(); @@ -587,8 +590,8 @@ public: { if (mLibPath.GetFullPath().empty()) { /* i18n-hint: There is a button to the right of the arrow.*/ - text.Printf(_("To find %s, click here -->"), mName); - mPathText = S.AddTextBox( {}, text, 0); + mPathText = S.AddTextBox( {}, + wxString::Format(_("To find %s, click here -->"), mName), 0); } else { mPathText = S.AddTextBox( {}, mLibPath.GetFullPath(), 0); @@ -2000,7 +2003,6 @@ int ExportMP3::AskResample(int bitrate, int rate, int lowrate, int highrate) d.SetName(d.GetTitle()); wxChoice *choice; ShuttleGui S(&d, eIsCreating); - wxString text; int selected = -1; @@ -2011,15 +2013,16 @@ int ExportMP3::AskResample(int bitrate, int rate, int lowrate, int highrate) { S.StartHorizontalLay(wxALIGN_CENTER, false); { - if (bitrate == 0) { - text.Printf(_("The project sample rate (%d) is not supported by the MP3\nfile format. "), rate); - } - else { - text.Printf(_("The project sample rate (%d) and bit rate (%d kbps) combination is not\nsupported by the MP3 file format. "), rate, bitrate); - } - - text += _("You may resample to one of the rates below."); - S.AddTitle(text); + S.AddTitle( + ((bitrate == 0) + ? wxString::Format( + _("The project sample rate (%d) is not supported by the MP3\nfile format. "), + rate) + : wxString::Format( + _("The project sample rate (%d) and bit rate (%d kbps) combination is not\nsupported by the MP3 file format. "), + rate, bitrate)) + + _("You may resample to one of the rates below.") + ); } S.EndHorizontalLay(); diff --git a/src/prefs/RecordingPrefs.cpp b/src/prefs/RecordingPrefs.cpp index d3df4e19a..1c86b03f6 100644 --- a/src/prefs/RecordingPrefs.cpp +++ b/src/prefs/RecordingPrefs.cpp @@ -133,12 +133,11 @@ void RecordingPrefs::PopulateOrExchange(ShuttleGui & S) { S.SetStretchyCol(1); - int dBRange = gPrefs->Read(ENV_DB_KEY, ENV_DB_RANGE); S.TieSlider(_("Le&vel (dB):"), {wxT("/AudioIO/SilenceLevel"), -50}, 0, - -dBRange); + -gPrefs->Read(ENV_DB_KEY, ENV_DB_RANGE)); } S.EndMultiColumn(); } diff --git a/src/toolbars/DeviceToolBar.cpp b/src/toolbars/DeviceToolBar.cpp index 258636e80..f42341bbd 100644 --- a/src/toolbars/DeviceToolBar.cpp +++ b/src/toolbars/DeviceToolBar.cpp @@ -843,7 +843,7 @@ void DeviceToolBar::ShowComboDialog(wxChoice *combo, const wxString &title) S.StartVerticalLay(true); { - S.StartHorizontalLay(wxCENTER, false); + S.StartHorizontalLay(wxCENTER, false); { c = S.AddChoice(combo->GetName(), inputSources,