From 86e9288bbdfcbd0ccf77ecf04335b5f6afb7cb6d Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sat, 21 Dec 2019 11:51:03 -0500 Subject: [PATCH] return pitch names as TranslatableString --- src/FreqWindow.cpp | 41 +++++++++++++++++-------------------- src/PitchName.cpp | 10 ++++----- src/PitchName.h | 6 +++--- src/effects/ChangePitch.cpp | 7 ++++--- 4 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/FreqWindow.cpp b/src/FreqWindow.cpp index ff76bed52..63a643ac7 100644 --- a/src/FreqWindow.cpp +++ b/src/FreqWindow.cpp @@ -949,35 +949,32 @@ void FrequencyPlotDialog::PlotPaint(wxPaintEvent & event) value = mAnalyst->GetProcessedValue(xPos, xPos + xStep); } - wxString cursor; - wxString peak; - wxString xpitch; - wxString peakpitch; - const wxChar *xp; - const wxChar *pp; + TranslatableString cursor; + TranslatableString peak; if (mAlg == SpectrumAnalyst::Spectrum) { - xpitch = PitchName_Absolute(FreqToMIDInote(xPos)); - peakpitch = PitchName_Absolute(FreqToMIDInote(bestpeak)); - xp = xpitch; - pp = peakpitch; + auto xp = PitchName_Absolute(FreqToMIDInote(xPos)); + auto pp = PitchName_Absolute(FreqToMIDInote(bestpeak)); /* i18n-hint: The %d's are replaced by numbers, the %s by musical notes, e.g. A#*/ - cursor.Printf(_("%d Hz (%s) = %d dB"), (int)(xPos + 0.5), xp, (int)(value + 0.5)); - peak.Printf(_("%d Hz (%s) = %.1f dB"), (int)(bestpeak + 0.5), pp, bestValue); + cursor = XO("%d Hz (%s) = %d dB") + .Format( (int)(xPos + 0.5), xp, (int)(value + 0.5)); + /* i18n-hint: The %d's are replaced by numbers, the %s by musical notes, e.g. A#*/ + peak = XO("%d Hz (%s) = %.1f dB") + .Format( (int)(bestpeak + 0.5), pp, bestValue ); } else if (xPos > 0.0 && bestpeak > 0.0) { - xpitch = PitchName_Absolute(FreqToMIDInote(1.0 / xPos)); - peakpitch = PitchName_Absolute(FreqToMIDInote(1.0 / bestpeak)); - xp = xpitch; - pp = peakpitch; + auto xp = PitchName_Absolute(FreqToMIDInote(1.0 / xPos)); + auto pp = PitchName_Absolute(FreqToMIDInote(1.0 / bestpeak)); /* i18n-hint: The %d's are replaced by numbers, the %s by musical notes, e.g. A# * the %.4f are numbers, and 'sec' should be an abbreviation for seconds */ - cursor.Printf(_("%.4f sec (%d Hz) (%s) = %f"), - xPos, (int)(1.0 / xPos + 0.5), xp, value); - peak.Printf(_("%.4f sec (%d Hz) (%s) = %.3f"), - bestpeak, (int)(1.0 / bestpeak + 0.5), pp, bestValue); + cursor = XO("%.4f sec (%d Hz) (%s) = %f") + .Format( xPos, (int)(1.0 / xPos + 0.5), xp, value ); + /* i18n-hint: The %d's are replaced by numbers, the %s by musical notes, e.g. A# + * the %.4f are numbers, and 'sec' should be an abbreviation for seconds */ + peak = XO("%.4f sec (%d Hz) (%s) = %.3f") + .Format( bestpeak, (int)(1.0 / bestpeak + 0.5), pp, bestValue ); } - mCursorText->SetValue(cursor); - mPeakText->SetValue(peak); + mCursorText->SetValue( cursor.Translation() ); + mPeakText->SetValue( peak.Translation() ); } else { mCursorText->SetValue(wxT("")); diff --git a/src/PitchName.cpp b/src/PitchName.cpp index 72df476c3..37871a0fc 100644 --- a/src/PitchName.cpp +++ b/src/PitchName.cpp @@ -57,7 +57,7 @@ int PitchOctave(const double dMIDInote) } -wxString PitchName(const double dMIDInote, const PitchNameChoice choice) +TranslatableString PitchName(const double dMIDInote, const PitchNameChoice choice) { static const TranslatableString sharpnames[12] = { /* i18n-hint: Name of a musical note in the 12-tone chromatic scale */ @@ -148,14 +148,14 @@ wxString PitchName(const double dMIDInote, const PitchNameChoice choice) default: wxASSERT(false); break; } - return table[PitchIndex(dMIDInote)].Translation(); + return table[PitchIndex(dMIDInote)]; } -wxString PitchName_Absolute(const double dMIDInote, const PitchNameChoice choice) +TranslatableString PitchName_Absolute(const double dMIDInote, const PitchNameChoice choice) { // The format string is not localized. Should it be? - return wxString::Format( - wxT("%s%d"), PitchName(dMIDInote, choice), PitchOctave(dMIDInote) ); + return Verbatim( wxT("%s%d") ) + .Format( PitchName(dMIDInote, choice), PitchOctave(dMIDInote) ); } double PitchToMIDInote(const unsigned int nPitchIndex, const int nPitchOctave) diff --git a/src/PitchName.h b/src/PitchName.h index 8d97273ea..24ed88de9 100644 --- a/src/PitchName.h +++ b/src/PitchName.h @@ -18,7 +18,7 @@ #ifndef __AUDACITY_PITCHNAME__ #define __AUDACITY_PITCHNAME__ -class wxString; +class TranslatableString; // FreqToMIDInote takes a frequency in Hz (exponential scale relative to // alphabetic pitch names) and returns a pitch ID number (linear @@ -44,14 +44,14 @@ enum class PitchNameChoice { Sharps, Flats, Both }; // PitchName takes dMIDInote (per result from // FreqToMIDInote) and returns a standard pitch/note name [C, C#, etc.). -wxString PitchName( +TranslatableString PitchName( const double dMIDInote, const PitchNameChoice choice = PitchNameChoice::Sharps ); // PitchName_Absolute does the same thing as PitchName, but appends // the octave number, e.g., instead of "C" it will return "C4" // if the dMIDInote corresonds to middle C, i.e., is 60. -wxString PitchName_Absolute( +TranslatableString PitchName_Absolute( const double dMIDInote, const PitchNameChoice choice = PitchNameChoice::Sharps); diff --git a/src/effects/ChangePitch.cpp b/src/effects/ChangePitch.cpp index 9e25203fb..9bf0e5c6b 100644 --- a/src/effects/ChangePitch.cpp +++ b/src/effects/ChangePitch.cpp @@ -255,7 +255,7 @@ void EffectChangePitch::PopulateOrExchange(ShuttleGui & S) wxArrayStringEx pitch; for (int ii = 0; ii < 12; ++ii) - pitch.push_back( PitchName( ii, PitchNameChoice::Both ) ); + pitch.push_back( PitchName( ii, PitchNameChoice::Both ).Translation() ); S.SetBorder(5); @@ -265,8 +265,9 @@ void EffectChangePitch::PopulateOrExchange(ShuttleGui & S) { S.AddTitle(_("Change Pitch without Changing Tempo")); S.AddTitle( - wxString::Format(_("Estimated Start Pitch: %s%d (%.3f Hz)"), - pitch[m_nFromPitch], m_nFromOctave, m_FromFrequency)); + XO("Estimated Start Pitch: %s%d (%.3f Hz)") + .Format( pitch[m_nFromPitch], m_nFromOctave, m_FromFrequency) + .Translation() ); } S.EndVerticalLay();