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.
This commit is contained in:
Paul Licameli 2018-01-30 20:03:46 -05:00
parent f846c25806
commit b256a4fd1a
13 changed files with 118 additions and 117 deletions

View File

@ -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);
}

View File

@ -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();

View File

@ -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();

View File

@ -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<double> vldAmp(precission, &mAmp, NumValidatorStyle::ONE_TRAILING_ZERO);
FloatingPointValidator<double> 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<double> vldNewPeak(precission + 1, &mNewPeak, NumValidatorStyle::ONE_TRAILING_ZERO);
FloatingPointValidator<double> 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);

View File

@ -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<double> vldFromLength(precission, &m_FromLength, NumValidatorStyle::TWO_TRAILING_ZEROES);
FloatingPointValidator<double> 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)

View File

@ -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)

View File

@ -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);

View File

@ -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();

View File

@ -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());

View File

@ -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();

View File

@ -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();

View File

@ -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();
}

View File

@ -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,