IdentInterfaceSymbol in NumericTextCtrl; don't persist translated

This commit is contained in:
Paul Licameli 2017-10-06 11:05:15 -04:00
parent 9015dece06
commit 0fb02a8024
27 changed files with 282 additions and 256 deletions

View File

@ -59,6 +59,7 @@ typedef enum EffectType
EffectTypeTool, EffectTypeTool,
} EffectType; } EffectType;
using NumericFormatId = IdentInterfaceSymbol;
class ShuttleParams; class ShuttleParams;
/*************************************************************************************//** /*************************************************************************************//**
@ -149,7 +150,7 @@ public:
virtual double GetDefaultDuration() = 0; virtual double GetDefaultDuration() = 0;
virtual double GetDuration() = 0; virtual double GetDuration() = 0;
virtual wxString GetDurationFormat() = 0; virtual NumericFormatId GetDurationFormat() = 0;
virtual void SetDuration(double seconds) = 0; virtual void SetDuration(double seconds) = 0;
virtual bool Apply() = 0; virtual bool Apply() = 0;

View File

@ -58,7 +58,7 @@ class IdentInterfaceSymbol
{ {
public: public:
IdentInterfaceSymbol() = default; IdentInterfaceSymbol() = default;
// Allows implicit construction from a msgid re-used as an internal string // Allows implicit construction from a msgid re-used as an internal string
IdentInterfaceSymbol( const wxString &msgid ) IdentInterfaceSymbol( const wxString &msgid )
: mInternal{ msgid }, mMsgid{ msgid } : mInternal{ msgid }, mMsgid{ msgid }

View File

@ -98,7 +98,8 @@ LabelDialog::LabelDialog(wxWindow *parent,
int index, int index,
ViewInfo &viewinfo, ViewInfo &viewinfo,
double rate, double rate,
const wxString & format, const wxString &freqFormat) const NumericFormatId & format,
const NumericFormatId &freqFormat)
: wxDialogWrapper(parent, : wxDialogWrapper(parent,
wxID_ANY, wxID_ANY,
_("Edit Labels"), _("Edit Labels"),
@ -528,7 +529,8 @@ void LabelDialog::FindInitialRow()
void LabelDialog::OnUpdate(wxCommandEvent &event) void LabelDialog::OnUpdate(wxCommandEvent &event)
{ {
// Remember the NEW format and repopulate grid // Remember the NEW format and repopulate grid
mFormat = event.GetString(); mFormat = NumericConverter::LookupFormat(
NumericConverter::TIME, event.GetString() );
TransferDataToWindow(); TransferDataToWindow();
event.Skip(false); event.Skip(false);
@ -537,7 +539,8 @@ void LabelDialog::OnUpdate(wxCommandEvent &event)
void LabelDialog::OnFreqUpdate(wxCommandEvent &event) void LabelDialog::OnFreqUpdate(wxCommandEvent &event)
{ {
// Remember the NEW format and repopulate grid // Remember the NEW format and repopulate grid
mFreqFormat = event.GetString(); mFreqFormat = NumericConverter::LookupFormat(
NumericConverter::FREQUENCY, event.GetString() );
TransferDataToWindow(); TransferDataToWindow();
event.Skip(false); event.Skip(false);

View File

@ -48,7 +48,8 @@ class LabelDialog final : public wxDialogWrapper
ViewInfo &viewinfo, ViewInfo &viewinfo,
double rate, double rate,
const wxString & format, const wxString &freqFormat); const NumericFormatId & format,
const NumericFormatId &freqFormat);
~LabelDialog(); ~LabelDialog();
bool Show(bool show = true) override; bool Show(bool show = true) override;
@ -102,8 +103,7 @@ class LabelDialog final : public wxDialogWrapper
ViewInfo *mViewInfo; ViewInfo *mViewInfo;
wxArrayString mTrackNames; wxArrayString mTrackNames;
double mRate; double mRate;
wxString mFormat; NumericFormatId mFormat, mFreqFormat;
wxString mFreqFormat;
int mInitialRow; int mInitialRow;

View File

@ -3776,7 +3776,7 @@ void AudacityProject::OnSetLeftSelection(const CommandContext &WXUNUSED(context)
} }
else else
{ {
wxString fmt = GetSelectionFormat(); auto fmt = GetSelectionFormat();
TimeDialog dlg(this, _("Set Left Selection Boundary"), TimeDialog dlg(this, _("Set Left Selection Boundary"),
fmt, mRate, mViewInfo.selectedRegion.t0(), _("Position")); fmt, mRate, mViewInfo.selectedRegion.t0(), _("Position"));
@ -3808,7 +3808,7 @@ void AudacityProject::OnSetRightSelection(const CommandContext &WXUNUSED(context
} }
else else
{ {
wxString fmt = GetSelectionFormat(); auto fmt = GetSelectionFormat();
TimeDialog dlg(this, _("Set Right Selection Boundary"), TimeDialog dlg(this, _("Set Right Selection Boundary"),
fmt, mRate, mViewInfo.selectedRegion.t1(), _("Position")); fmt, mRate, mViewInfo.selectedRegion.t1(), _("Position"));
@ -8570,8 +8570,8 @@ void AudacityProject::OnAddLabelPlaying(const CommandContext &WXUNUSED(context)
void AudacityProject::DoEditLabels(LabelTrack *lt, int index) void AudacityProject::DoEditLabels(LabelTrack *lt, int index)
{ {
wxString format = GetSelectionFormat(), auto format = GetSelectionFormat();
freqFormat = GetFrequencySelectionFormatName(); auto freqFormat = GetFrequencySelectionFormatName();
LabelDialog dlg(this, *GetTrackFactory(), GetTracks(), LabelDialog dlg(this, *GetTrackFactory(), GetTracks(),
lt, index, lt, index,

View File

@ -923,9 +923,15 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id,
mRate((double) gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"), AudioIO::GetOptimalSupportedSampleRate())), mRate((double) gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleRate"), AudioIO::GetOptimalSupportedSampleRate())),
mDefaultFormat(QualityPrefs::SampleFormatChoice()), mDefaultFormat(QualityPrefs::SampleFormatChoice()),
mSnapTo(gPrefs->Read(wxT("/SnapTo"), SNAP_OFF)), mSnapTo(gPrefs->Read(wxT("/SnapTo"), SNAP_OFF)),
mSelectionFormat(gPrefs->Read(wxT("/SelectionFormat"), wxT(""))), mSelectionFormat( NumericTextCtrl::LookupFormat(
mFrequencySelectionFormatName(gPrefs->Read(wxT("/FrequencySelectionFormatName"), wxT(""))), NumericConverter::TIME,
mBandwidthSelectionFormatName(gPrefs->Read(wxT("/BandwidthSelectionFormatName"), wxT(""))), gPrefs->Read(wxT("/SelectionFormat"), wxT("")) ) ),
mFrequencySelectionFormatName( NumericTextCtrl::LookupFormat(
NumericConverter::FREQUENCY,
gPrefs->Read(wxT("/FrequencySelectionFormatName"), wxT("")) ) ),
mBandwidthSelectionFormatName( NumericTextCtrl::LookupFormat(
NumericConverter::BANDWIDTH,
gPrefs->Read(wxT("/BandwidthSelectionFormatName"), wxT("")) ) ),
mUndoManager(std::make_unique<UndoManager>()) mUndoManager(std::make_unique<UndoManager>())
{ {
mTracks = TrackList::Create(); mTracks = TrackList::Create();
@ -1539,16 +1545,16 @@ void AudacityProject::AS_SetSnapTo(int snap)
RedrawProject(); RedrawProject();
} }
const wxString & AudacityProject::AS_GetSelectionFormat() const NumericFormatId & AudacityProject::AS_GetSelectionFormat()
{ {
return GetSelectionFormat(); return GetSelectionFormat();
} }
void AudacityProject::AS_SetSelectionFormat(const wxString & format) void AudacityProject::AS_SetSelectionFormat(const NumericFormatId & format)
{ {
mSelectionFormat = format; mSelectionFormat = format;
gPrefs->Write(wxT("/SelectionFormat"), mSelectionFormat); gPrefs->Write(wxT("/SelectionFormat"), mSelectionFormat.Internal());
gPrefs->Flush(); gPrefs->Flush();
if (SnapSelection() && GetTrackPanel()) if (SnapSelection() && GetTrackPanel())
@ -1571,29 +1577,31 @@ double AudacityProject::SSBL_GetRate() const
return rate; return rate;
} }
const wxString & AudacityProject::SSBL_GetFrequencySelectionFormatName() const NumericFormatId & AudacityProject::SSBL_GetFrequencySelectionFormatName()
{ {
return GetFrequencySelectionFormatName(); return GetFrequencySelectionFormatName();
} }
void AudacityProject::SSBL_SetFrequencySelectionFormatName(const wxString & formatName) void AudacityProject::SSBL_SetFrequencySelectionFormatName(const NumericFormatId & formatName)
{ {
mFrequencySelectionFormatName = formatName; mFrequencySelectionFormatName = formatName;
gPrefs->Write(wxT("/FrequencySelectionFormatName"), mFrequencySelectionFormatName); gPrefs->Write(wxT("/FrequencySelectionFormatName"),
mFrequencySelectionFormatName.Internal());
gPrefs->Flush(); gPrefs->Flush();
} }
const wxString & AudacityProject::SSBL_GetBandwidthSelectionFormatName() const NumericFormatId & AudacityProject::SSBL_GetBandwidthSelectionFormatName()
{ {
return GetBandwidthSelectionFormatName(); return GetBandwidthSelectionFormatName();
} }
void AudacityProject::SSBL_SetBandwidthSelectionFormatName(const wxString & formatName) void AudacityProject::SSBL_SetBandwidthSelectionFormatName(const NumericFormatId & formatName)
{ {
mBandwidthSelectionFormatName = formatName; mBandwidthSelectionFormatName = formatName;
gPrefs->Write(wxT("/BandwidthSelectionFormatName"), mBandwidthSelectionFormatName); gPrefs->Write(wxT("/BandwidthSelectionFormatName"),
mBandwidthSelectionFormatName.Internal());
gPrefs->Flush(); gPrefs->Flush();
} }
@ -1615,12 +1623,12 @@ void AudacityProject::SSBL_ModifySpectralSelection(double &bottom, double &top,
#endif #endif
} }
const wxString & AudacityProject::GetFrequencySelectionFormatName() const const NumericFormatId & AudacityProject::GetFrequencySelectionFormatName() const
{ {
return mFrequencySelectionFormatName; return mFrequencySelectionFormatName;
} }
void AudacityProject::SetFrequencySelectionFormatName(const wxString & formatName) void AudacityProject::SetFrequencySelectionFormatName(const NumericFormatId & formatName)
{ {
SSBL_SetFrequencySelectionFormatName(formatName); SSBL_SetFrequencySelectionFormatName(formatName);
#ifdef EXPERIMENTAL_SPECTRAL_EDITING #ifdef EXPERIMENTAL_SPECTRAL_EDITING
@ -1630,12 +1638,12 @@ void AudacityProject::SetFrequencySelectionFormatName(const wxString & formatNam
#endif #endif
} }
const wxString & AudacityProject::GetBandwidthSelectionFormatName() const const NumericFormatId & AudacityProject::GetBandwidthSelectionFormatName() const
{ {
return mBandwidthSelectionFormatName; return mBandwidthSelectionFormatName;
} }
void AudacityProject::SetBandwidthSelectionFormatName(const wxString & formatName) void AudacityProject::SetBandwidthSelectionFormatName(const NumericFormatId & formatName)
{ {
SSBL_SetBandwidthSelectionFormatName(formatName); SSBL_SetBandwidthSelectionFormatName(formatName);
#ifdef EXPERIMENTAL_SPECTRAL_EDITING #ifdef EXPERIMENTAL_SPECTRAL_EDITING
@ -1645,7 +1653,7 @@ void AudacityProject::SetBandwidthSelectionFormatName(const wxString & formatNam
#endif #endif
} }
void AudacityProject::SetSelectionFormat(const wxString & format) void AudacityProject::SetSelectionFormat(const NumericFormatId & format)
{ {
AS_SetSelectionFormat(format); AS_SetSelectionFormat(format);
if (GetSelectionBar()) { if (GetSelectionBar()) {
@ -1653,7 +1661,7 @@ void AudacityProject::SetSelectionFormat(const wxString & format)
} }
} }
const wxString & AudacityProject::GetSelectionFormat() const const NumericFormatId & AudacityProject::GetSelectionFormat() const
{ {
return mSelectionFormat; return mSelectionFormat;
} }
@ -3499,13 +3507,16 @@ bool AudacityProject::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
} }
else if (!wxStrcmp(attr, wxT("selectionformat"))) else if (!wxStrcmp(attr, wxT("selectionformat")))
SetSelectionFormat(value); SetSelectionFormat(
NumericConverter::LookupFormat( NumericConverter::TIME, value) );
else if (!wxStrcmp(attr, wxT("frequencyformat"))) else if (!wxStrcmp(attr, wxT("frequencyformat")))
SetFrequencySelectionFormatName(value); SetFrequencySelectionFormatName(
NumericConverter::LookupFormat( NumericConverter::FREQUENCY, value ) );
else if (!wxStrcmp(attr, wxT("bandwidthformat"))) else if (!wxStrcmp(attr, wxT("bandwidthformat")))
SetBandwidthSelectionFormatName(value); SetBandwidthSelectionFormatName(
NumericConverter::LookupFormat( NumericConverter::BANDWIDTH, value ) );
} // while } // while
mViewInfo.UpdatePrefs(); mViewInfo.UpdatePrefs();
@ -3688,9 +3699,12 @@ void AudacityProject::WriteXML(XMLWriter &xmlFile, bool bWantSaveCompressed)
mViewInfo.WriteXMLAttributes(xmlFile); mViewInfo.WriteXMLAttributes(xmlFile);
xmlFile.WriteAttr(wxT("rate"), mRate); xmlFile.WriteAttr(wxT("rate"), mRate);
xmlFile.WriteAttr(wxT("snapto"), GetSnapTo() ? wxT("on") : wxT("off")); xmlFile.WriteAttr(wxT("snapto"), GetSnapTo() ? wxT("on") : wxT("off"));
xmlFile.WriteAttr(wxT("selectionformat"), GetSelectionFormat()); xmlFile.WriteAttr(wxT("selectionformat"),
xmlFile.WriteAttr(wxT("frequencyformat"), GetFrequencySelectionFormatName()); GetSelectionFormat().Internal());
xmlFile.WriteAttr(wxT("bandwidthformat"), GetBandwidthSelectionFormatName()); xmlFile.WriteAttr(wxT("frequencyformat"),
GetFrequencySelectionFormatName().Internal());
xmlFile.WriteAttr(wxT("bandwidthformat"),
GetBandwidthSelectionFormatName().Internal());
mTags->WriteXML(xmlFile); mTags->WriteXML(xmlFile);

View File

@ -104,6 +104,7 @@ class Track;
class WaveClip; class WaveClip;
class BackgroundCell; class BackgroundCell;
AudacityProject *CreateNewAudacityProject(); AudacityProject *CreateNewAudacityProject();
AUDACITY_DLL_API AudacityProject *GetActiveProject(); AUDACITY_DLL_API AudacityProject *GetActiveProject();
void RedrawAllProjects(); void RedrawAllProjects();
@ -438,16 +439,16 @@ public:
// Selection Format // Selection Format
void SetSelectionFormat(const wxString & format); void SetSelectionFormat(const NumericFormatId & format);
const wxString & GetSelectionFormat() const; const NumericFormatId & GetSelectionFormat() const;
// Spectral Selection Formats // Spectral Selection Formats
void SetFrequencySelectionFormatName(const wxString & format); void SetFrequencySelectionFormatName(const NumericFormatId & format);
const wxString & GetFrequencySelectionFormatName() const; const NumericFormatId & GetFrequencySelectionFormatName() const;
void SetBandwidthSelectionFormatName(const wxString & format); void SetBandwidthSelectionFormatName(const NumericFormatId & format);
const wxString & GetBandwidthSelectionFormatName() const; const NumericFormatId & GetBandwidthSelectionFormatName() const;
// Scrollbars // Scrollbars
@ -526,19 +527,19 @@ public:
void AS_SetRate(double rate) override; void AS_SetRate(double rate) override;
int AS_GetSnapTo() override; int AS_GetSnapTo() override;
void AS_SetSnapTo(int snap) override; void AS_SetSnapTo(int snap) override;
const wxString & AS_GetSelectionFormat() override; const NumericFormatId & AS_GetSelectionFormat() override;
void AS_SetSelectionFormat(const wxString & format) override; void AS_SetSelectionFormat(const NumericFormatId & format) override;
void AS_ModifySelection(double &start, double &end, bool done) override; void AS_ModifySelection(double &start, double &end, bool done) override;
// SpectralSelectionBarListener callback methods // SpectralSelectionBarListener callback methods
double SSBL_GetRate() const override; double SSBL_GetRate() const override;
const wxString & SSBL_GetFrequencySelectionFormatName() override; const NumericFormatId & SSBL_GetFrequencySelectionFormatName() override;
void SSBL_SetFrequencySelectionFormatName(const wxString & formatName) override; void SSBL_SetFrequencySelectionFormatName(const NumericFormatId & formatName) override;
const wxString & SSBL_GetBandwidthSelectionFormatName() override; const NumericFormatId & SSBL_GetBandwidthSelectionFormatName() override;
void SSBL_SetBandwidthSelectionFormatName(const wxString & formatName) override; void SSBL_SetBandwidthSelectionFormatName(const NumericFormatId & formatName) override;
void SSBL_ModifySpectralSelection(double &bottom, double &top, bool done) override; void SSBL_ModifySpectralSelection(double &bottom, double &top, bool done) override;
@ -631,9 +632,9 @@ public:
std::shared_ptr<TrackList> mTracks; std::shared_ptr<TrackList> mTracks;
int mSnapTo; int mSnapTo;
wxString mSelectionFormat; NumericFormatId mSelectionFormat;
wxString mFrequencySelectionFormatName; NumericFormatId mFrequencySelectionFormatName;
wxString mBandwidthSelectionFormatName; NumericFormatId mBandwidthSelectionFormatName;
std::shared_ptr<TrackList> mLastSavedTracks; std::shared_ptr<TrackList> mLastSavedTracks;

View File

@ -55,7 +55,7 @@ SnapManager::SnapManager(const TrackList *tracks,
mSnapTo = 0; mSnapTo = 0;
mRate = 0.0; mRate = 0.0;
mFormat.Empty(); mFormat = {};
// Two time points closer than this are considered the same // Two time points closer than this are considered the same
mEpsilon = 1 / 44100.0; mEpsilon = 1 / 44100.0;
@ -71,7 +71,7 @@ void SnapManager::Reinit()
{ {
int snapTo = mProject->GetSnapTo(); int snapTo = mProject->GetSnapTo();
double rate = mProject->GetRate(); double rate = mProject->GetRate();
wxString format = mProject->GetSelectionFormat(); auto format = mProject->GetSelectionFormat();
// No need to reinit if these are still the same // No need to reinit if these are still the same
if (snapTo == mSnapTo && rate == mRate && format == mFormat) if (snapTo == mSnapTo && rate == mRate && format == mFormat)

View File

@ -19,6 +19,7 @@
#include <wx/defs.h> #include <wx/defs.h>
#include <wx/string.h> #include <wx/string.h>
#include "widgets/NumericTextCtrl.h" #include "widgets/NumericTextCtrl.h"
#include "Internat.h"
class AudacityProject; class AudacityProject;
class Track; class Track;
@ -136,7 +137,7 @@ private:
int mSnapTo; int mSnapTo;
double mRate; double mRate;
wxString mFormat; NumericFormatId mFormat;
}; };
#endif #endif

View File

@ -30,7 +30,7 @@ END_EVENT_TABLE()
TimeDialog::TimeDialog(wxWindow *parent, TimeDialog::TimeDialog(wxWindow *parent,
const wxString &title, const wxString &title,
const wxString &format, const NumericFormatId &format,
double rate, double rate,
double time, double time,
const wxString &prompt) const wxString &prompt)
@ -100,7 +100,7 @@ const double TimeDialog::GetTimeValue()
return mTime; return mTime;
} }
void TimeDialog::SetFormatString(const wxString &formatString) void TimeDialog::SetFormatString(const NumericFormatId &formatString)
{ {
mFormat = formatString; mFormat = formatString;
TransferDataToWindow(); TransferDataToWindow();

View File

@ -27,12 +27,12 @@ class TimeDialog final : public wxDialogWrapper
TimeDialog(wxWindow *parent, TimeDialog(wxWindow *parent,
const wxString &title, const wxString &title,
const wxString &format, const NumericFormatId &format,
double rate, double rate,
double time, double time,
const wxString &prompt = _("Duration")); const wxString &prompt = _("Duration"));
void SetFormatString(const wxString &formatString); void SetFormatString(const NumericFormatId &formatString);
void SetSampleRate(double sampleRate); void SetSampleRate(double sampleRate);
void SetTimeValue(double newTime); void SetTimeValue(double newTime);
const double GetTimeValue(); const double GetTimeValue();
@ -48,7 +48,7 @@ class TimeDialog final : public wxDialogWrapper
private: private:
wxString mPrompt; wxString mPrompt;
wxString mFormat; NumericFormatId mFormat;
double mRate; double mRate;
double mTime; double mTime;

View File

@ -793,7 +793,7 @@ void TimerRecordDialog::PopulateOrExchange(ShuttleGui& S)
* The 'h' indicates the first number displayed is hours, the 'm' indicates the second number * The 'h' indicates the first number displayed is hours, the 'm' indicates the second number
* displayed is minutes, and the 's' indicates that the third number displayed is seconds. * displayed is minutes, and the 's' indicates that the third number displayed is seconds.
*/ */
wxString strFormat = _("099 h 060 m 060 s"); auto strFormat = _("099 h 060 m 060 s");
using Options = NumericTextCtrl::Options; using Options = NumericTextCtrl::Options;
S.StartStatic(_("Start Date and Time"), true); S.StartStatic(_("Start Date and Time"), true);
{ {
@ -811,7 +811,7 @@ void TimerRecordDialog::PopulateOrExchange(ShuttleGui& S)
m_pTimeTextCtrl_Start = safenew NumericTextCtrl( m_pTimeTextCtrl_Start = safenew NumericTextCtrl(
this, ID_TIMETEXT_START, NumericConverter::TIME, this, ID_TIMETEXT_START, NumericConverter::TIME,
wxEmptyString, 0, 44100, {}, 0, 44100,
Options{} Options{}
.MenuEnabled(false) .MenuEnabled(false)
.Format(strFormat) .Format(strFormat)
@ -840,7 +840,7 @@ void TimerRecordDialog::PopulateOrExchange(ShuttleGui& S)
m_pTimeTextCtrl_End = safenew NumericTextCtrl( m_pTimeTextCtrl_End = safenew NumericTextCtrl(
this, ID_TIMETEXT_END, NumericConverter::TIME, this, ID_TIMETEXT_END, NumericConverter::TIME,
wxEmptyString, 0, 44100, {}, 0, 44100,
Options{} Options{}
.MenuEnabled(false) .MenuEnabled(false)
.Format(strFormat) .Format(strFormat)
@ -860,10 +860,10 @@ void TimerRecordDialog::PopulateOrExchange(ShuttleGui& S)
* number displayed is minutes, and the 's' indicates that the fourth number displayed is * number displayed is minutes, and the 's' indicates that the fourth number displayed is
* seconds. * seconds.
*/ */
wxString strFormat1 = _("099 days 024 h 060 m 060 s"); auto strFormat1 = _("099 days 024 h 060 m 060 s");
m_pTimeTextCtrl_Duration = safenew NumericTextCtrl( m_pTimeTextCtrl_Duration = safenew NumericTextCtrl(
this, ID_TIMETEXT_DURATION, NumericConverter::TIME, this, ID_TIMETEXT_DURATION, NumericConverter::TIME,
wxEmptyString, 0, 44100, {}, 0, 44100,
Options{} Options{}
.MenuEnabled(false) .MenuEnabled(false)
.Format(strFormat1) .Format(strFormat1)

View File

@ -93,7 +93,7 @@ EffectChangeSpeed::EffectChangeSpeed()
mToVinyl = kVinyl_33AndAThird; mToVinyl = kVinyl_33AndAThird;
mFromLength = 0.0; mFromLength = 0.0;
mToLength = 0.0; mToLength = 0.0;
mFormat = _("hh:mm:ss + milliseconds"); mFormat = NumericConverter::DefaultSelectionFormat();
mbLoopDetect = false; mbLoopDetect = false;
SetLinearEffectFlag(true); SetLinearEffectFlag(true);
@ -153,7 +153,7 @@ bool EffectChangeSpeed::SetAutomationParameters(CommandParameters & parms)
bool EffectChangeSpeed::LoadFactoryDefaults() bool EffectChangeSpeed::LoadFactoryDefaults()
{ {
mFromVinyl = kVinyl_33AndAThird; mFromVinyl = kVinyl_33AndAThird;
mFormat = _("hh:mm:ss + milliseconds"); mFormat = NumericConverter::DefaultSelectionFormat();
return Effect::LoadFactoryDefaults(); return Effect::LoadFactoryDefaults();
} }
@ -188,8 +188,9 @@ bool EffectChangeSpeed::Startup()
// Retrieve last used control values // Retrieve last used control values
gPrefs->Read(base + wxT("PercentChange"), &m_PercentChange, 0); gPrefs->Read(base + wxT("PercentChange"), &m_PercentChange, 0);
// default format "4" is the same as the Selection toolbar: "hh:mm:ss + milliseconds"; wxString format;
gPrefs->Read(base + wxT("TimeFormat"), &mFormat, _("hh:mm:ss + milliseconds")); gPrefs->Read(base + wxT("TimeFormat"), &format, wxString{});
mFormat = NumericConverter::LookupFormat( NumericConverter::TIME, format );
gPrefs->Read(base + wxT("VinylChoice"), &mFromVinyl, 0); gPrefs->Read(base + wxT("VinylChoice"), &mFromVinyl, 0);
if (mFromVinyl == kVinyl_NA) if (mFromVinyl == kVinyl_NA)
@ -197,7 +198,7 @@ bool EffectChangeSpeed::Startup()
mFromVinyl = kVinyl_33AndAThird; mFromVinyl = kVinyl_33AndAThird;
} }
SetPrivateConfig(GetCurrentSettingsGroup(), wxT("TimeFormat"), mFormat); SetPrivateConfig(GetCurrentSettingsGroup(), wxT("TimeFormat"), mFormat.Internal());
SetPrivateConfig(GetCurrentSettingsGroup(), wxT("VinylChoice"), mFromVinyl); SetPrivateConfig(GetCurrentSettingsGroup(), wxT("VinylChoice"), mFromVinyl);
SaveUserPreset(GetCurrentSettingsGroup()); SaveUserPreset(GetCurrentSettingsGroup());
@ -294,7 +295,13 @@ bool EffectChangeSpeed::Process()
void EffectChangeSpeed::PopulateOrExchange(ShuttleGui & S) void EffectChangeSpeed::PopulateOrExchange(ShuttleGui & S)
{ {
GetPrivateConfig(GetCurrentSettingsGroup(), wxT("TimeFormat"), mFormat, mFormat); {
wxString formatId;
GetPrivateConfig(GetCurrentSettingsGroup(), wxT("TimeFormat"),
formatId, mFormat.Internal());
mFormat = NumericConverter::LookupFormat(
NumericConverter::TIME, formatId );
}
GetPrivateConfig(GetCurrentSettingsGroup(), wxT("VinylChoice"), mFromVinyl, mFromVinyl); GetPrivateConfig(GetCurrentSettingsGroup(), wxT("VinylChoice"), mFromVinyl, mFromVinyl);
S.SetBorder(5); S.SetBorder(5);
@ -451,7 +458,7 @@ bool EffectChangeSpeed::TransferDataFromWindow()
} }
m_PercentChange = exactPercent; m_PercentChange = exactPercent;
SetPrivateConfig(GetCurrentSettingsGroup(), wxT("TimeFormat"), mFormat); SetPrivateConfig(GetCurrentSettingsGroup(), wxT("TimeFormat"), mFormat.Internal());
SetPrivateConfig(GetCurrentSettingsGroup(), wxT("VinylChoice"), mFromVinyl); SetPrivateConfig(GetCurrentSettingsGroup(), wxT("VinylChoice"), mFromVinyl);
return true; return true;
@ -674,7 +681,8 @@ void EffectChangeSpeed::OnTimeCtrl_ToLength(wxCommandEvent & WXUNUSED(evt))
void EffectChangeSpeed::OnTimeCtrlUpdate(wxCommandEvent & evt) void EffectChangeSpeed::OnTimeCtrlUpdate(wxCommandEvent & evt)
{ {
mFormat = evt.GetString(); mFormat = NumericConverter::LookupFormat(
NumericConverter::TIME, evt.GetString() );
mpFromLengthCtrl->SetFormatName(mFormat); mpFromLengthCtrl->SetFormatName(mFormat);
// Update From/To Length controls (precision has changed). // Update From/To Length controls (precision has changed).

View File

@ -115,7 +115,7 @@ private:
// private effect parameters // private effect parameters
int mToVinyl; // to standard vinyl speed (rpm) int mToVinyl; // to standard vinyl speed (rpm)
double mToLength; // target length of selection double mToLength; // target length of selection
wxString mFormat; // time control format NumericFormatId mFormat; // time control format
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };

View File

@ -226,7 +226,7 @@ ContrastDialog::ContrastDialog(wxWindow * parent, wxWindowID id,
mForegroundStartT = safenew mForegroundStartT = safenew
NumericTextCtrl(this, ID_FOREGROUNDSTART_T, NumericTextCtrl(this, ID_FOREGROUNDSTART_T,
NumericConverter::TIME, NumericConverter::TIME,
_("hh:mm:ss + hundredths"), NumericConverter::HundredthsFormat(),
0.0, 0.0,
mProjectRate, mProjectRate,
options); options);
@ -239,7 +239,7 @@ ContrastDialog::ContrastDialog(wxWindow * parent, wxWindowID id,
mForegroundEndT = safenew mForegroundEndT = safenew
NumericTextCtrl(this, ID_FOREGROUNDEND_T, NumericTextCtrl(this, ID_FOREGROUNDEND_T,
NumericConverter::TIME, NumericConverter::TIME,
_("hh:mm:ss + hundredths"), NumericConverter::HundredthsFormat(),
0.0, 0.0,
mProjectRate, mProjectRate,
options); options);
@ -258,7 +258,7 @@ ContrastDialog::ContrastDialog(wxWindow * parent, wxWindowID id,
mBackgroundStartT = safenew mBackgroundStartT = safenew
NumericTextCtrl(this, ID_BACKGROUNDSTART_T, NumericTextCtrl(this, ID_BACKGROUNDSTART_T,
NumericConverter::TIME, NumericConverter::TIME,
_("hh:mm:ss + hundredths"), NumericConverter::HundredthsFormat(),
0.0, 0.0,
mProjectRate, mProjectRate,
options); options);
@ -271,7 +271,7 @@ ContrastDialog::ContrastDialog(wxWindow * parent, wxWindowID id,
mBackgroundEndT = safenew mBackgroundEndT = safenew
NumericTextCtrl(this, ID_BACKGROUNDEND_T, NumericTextCtrl(this, ID_BACKGROUNDEND_T,
NumericConverter::TIME, NumericConverter::TIME,
_("hh:mm:ss + hundredths"), NumericConverter::HundredthsFormat(),
0.0, 0.0,
mProjectRate, mProjectRate,
options); options);

View File

@ -55,6 +55,7 @@ greater use in future.
#include "nyquist/Nyquist.h" #include "nyquist/Nyquist.h"
#include "../widgets/HelpSystem.h" #include "../widgets/HelpSystem.h"
#include "../widgets/LinkingHtmlWindow.h" #include "../widgets/LinkingHtmlWindow.h"
#include "../widgets/NumericTextCtrl.h"
#include "../widgets/ErrorDialog.h" #include "../widgets/ErrorDialog.h"
#include "../FileNames.h" #include "../FileNames.h"
#include "../commands/AudacityCommand.h" #include "../commands/AudacityCommand.h"
@ -757,12 +758,12 @@ double Effect::GetDuration()
return mDuration; return mDuration;
} }
wxString Effect::GetDurationFormat() NumericFormatId Effect::GetDurationFormat()
{ {
return mDurationFormat; return mDurationFormat;
} }
wxString Effect::GetSelectionFormat() NumericFormatId Effect::GetSelectionFormat()
{ {
return GetActiveProject()->GetSelectionFormat(); return GetActiveProject()->GetSelectionFormat();
} }
@ -1221,7 +1222,9 @@ bool Effect::DoEffect(wxWindow *parent,
isSelection = true; isSelection = true;
} }
mDurationFormat = isSelection ? _("hh:mm:ss + samples") : _("hh:mm:ss + milliseconds"); mDurationFormat = isSelection
? NumericConverter::TimeAndSampleFormat()
: NumericConverter::DefaultSelectionFormat();
#ifdef EXPERIMENTAL_SPECTRAL_EDITING #ifdef EXPERIMENTAL_SPECTRAL_EDITING
mF0 = selectedRegion->f0(); mF0 = selectedRegion->f0();

View File

@ -165,8 +165,8 @@ class AUDACITY_DLL_API Effect /* not final */ : public wxEvtHandler,
double GetDefaultDuration() override; double GetDefaultDuration() override;
double GetDuration() override; double GetDuration() override;
wxString GetDurationFormat() override; NumericFormatId GetDurationFormat() override;
virtual wxString GetSelectionFormat() /* not override? */; // time format in Selection toolbar virtual NumericFormatId GetSelectionFormat() /* not override? */; // time format in Selection toolbar
void SetDuration(double duration) override; void SetDuration(double duration) override;
bool Apply() override; bool Apply() override;
@ -515,7 +515,7 @@ private:
bool mIsSelection; bool mIsSelection;
double mDuration; double mDuration;
wxString mDurationFormat; NumericFormatId mDurationFormat;
bool mIsPreview; bool mIsPreview;

View File

@ -203,8 +203,8 @@ auStaticText * SelectionBar::AddTitle( const wxString & Title, wxSizer * pSizer
NumericTextCtrl * SelectionBar::AddTime( const wxString Name, int id, wxSizer * pSizer ){ NumericTextCtrl * SelectionBar::AddTime( const wxString Name, int id, wxSizer * pSizer ){
wxString formatName = mListener ? mListener->AS_GetSelectionFormat() auto formatName = mListener ? mListener->AS_GetSelectionFormat()
: wxString(wxEmptyString); : NumericFormatId{};
auto pCtrl = safenew NumericTextCtrl( auto pCtrl = safenew NumericTextCtrl(
this, id, NumericConverter::TIME, formatName, 0.0, mRate); this, id, NumericConverter::TIME, formatName, 0.0, mRate);
pCtrl->SetName(Name); pCtrl->SetName(Name);
@ -426,8 +426,13 @@ void SelectionBar::SetListener(SelectionBarListener *l)
void SelectionBar::RegenerateTooltips() void SelectionBar::RegenerateTooltips()
{ {
#if wxUSE_TOOLTIPS #if wxUSE_TOOLTIPS
wxString formatName = mListener ? mListener->AS_GetSelectionFormat() : wxString(wxEmptyString); auto formatName =
mSnapTo->SetToolTip(wxString::Format(_("Snap Clicks/Selections to %s"), formatName)); mListener
? mListener->AS_GetSelectionFormat()
: NumericFormatId{};
mSnapTo->SetToolTip(
wxString::Format(
_("Snap Clicks/Selections to %s"), formatName.Translation() ));
#endif #endif
} }
@ -567,11 +572,11 @@ void SelectionBar::OnUpdate(wxCommandEvent &evt)
evt.Skip(false); evt.Skip(false);
wxString format;
// Save format name before recreating the controls so they resize properly // Save format name before recreating the controls so they resize properly
format = mStartTime->GetBuiltinName(index); {
mListener->AS_SetSelectionFormat(format); auto format = mStartTime->GetBuiltinName(index);
mListener->AS_SetSelectionFormat(format);
}
RegenerateTooltips(); RegenerateTooltips();
@ -587,7 +592,7 @@ void SelectionBar::OnUpdate(wxCommandEvent &evt)
ValuesToControls(); ValuesToControls();
format = mStartTime->GetBuiltinFormat(index); auto format = mStartTime->GetBuiltinFormat(index);
for( i=0;i<5;i++) for( i=0;i<5;i++)
(*Ctrls[i])->SetFormatString( format ); (*Ctrls[i])->SetFormatString( format );
@ -765,7 +770,7 @@ void SelectionBar::SetSnapTo(int snap)
mSnapTo->SetSelection(snap); mSnapTo->SetSelection(snap);
} }
void SelectionBar::SetSelectionFormat(const wxString & format) void SelectionBar::SetSelectionFormat(const NumericFormatId & format)
{ {
mStartTime->SetFormatString(mStartTime->GetBuiltinFormat(format)); mStartTime->SetFormatString(mStartTime->GetBuiltinFormat(format));

View File

@ -60,7 +60,7 @@ class SelectionBar final : public ToolBar {
void SetTimes(double start, double end, double audio); void SetTimes(double start, double end, double audio);
void SetField(const wxChar *msg, int fieldNum); void SetField(const wxChar *msg, int fieldNum);
void SetSnapTo(int); void SetSnapTo(int);
void SetSelectionFormat(const wxString & format); void SetSelectionFormat(const NumericFormatId & format);
void SetRate(double rate); void SetRate(double rate);
void SetListener(SelectionBarListener *l); void SetListener(SelectionBarListener *l);
void RegenerateTooltips() override; void RegenerateTooltips() override;

View File

@ -11,6 +11,8 @@
#ifndef __AUDACITY_SELECTION_BAR_LISTENER__ #ifndef __AUDACITY_SELECTION_BAR_LISTENER__
#define __AUDACITY_SELECTION_BAR_LISTENER__ #define __AUDACITY_SELECTION_BAR_LISTENER__
class IdentInterfaceSymbol;
using NumericFormatId = IdentInterfaceSymbol;
class SelectedRegion; class SelectedRegion;
class AUDACITY_DLL_API SelectionBarListener /* not final */ { class AUDACITY_DLL_API SelectionBarListener /* not final */ {
@ -24,8 +26,8 @@ class AUDACITY_DLL_API SelectionBarListener /* not final */ {
virtual void AS_SetRate(double rate) = 0; virtual void AS_SetRate(double rate) = 0;
virtual int AS_GetSnapTo() = 0; virtual int AS_GetSnapTo() = 0;
virtual void AS_SetSnapTo(int snap) = 0; virtual void AS_SetSnapTo(int snap) = 0;
virtual const wxString & AS_GetSelectionFormat() = 0; virtual const NumericFormatId & AS_GetSelectionFormat() = 0;
virtual void AS_SetSelectionFormat(const wxString & format) = 0; virtual void AS_SetSelectionFormat(const NumericFormatId & format) = 0;
virtual void AS_ModifySelection(double &start, double &end, bool done) = 0; virtual void AS_ModifySelection(double &start, double &end, bool done) = 0;
}; };

View File

@ -126,12 +126,12 @@ void SpectralSelectionBar::Populate()
* look-ups static because they depend on translations which are done at * look-ups static because they depend on translations which are done at
* runtime */ * runtime */
wxString frequencyFormatName = mListener auto frequencyFormatName = mListener
? mListener->SSBL_GetFrequencySelectionFormatName() ? mListener->SSBL_GetFrequencySelectionFormatName()
: wxString(wxEmptyString); : NumericFormatId{};
wxString bandwidthFormatName = mListener auto bandwidthFormatName = mListener
? mListener->SSBL_GetBandwidthSelectionFormatName() ? mListener->SSBL_GetBandwidthSelectionFormatName()
: wxString(wxEmptyString); : NumericFormatId{};
wxFlexGridSizer *mainSizer; wxFlexGridSizer *mainSizer;
Add((mainSizer = safenew wxFlexGridSizer(1, 1, 1)), 0,wxALIGN_TOP | wxLEFT | wxTOP, 5); Add((mainSizer = safenew wxFlexGridSizer(1, 1, 1)), 0,wxALIGN_TOP | wxLEFT | wxTOP, 5);
@ -352,12 +352,12 @@ void SpectralSelectionBar::OnUpdate(wxCommandEvent &evt)
wxEventType type = evt.GetEventType(); wxEventType type = evt.GetEventType();
if (type == EVT_FREQUENCYTEXTCTRL_UPDATED) { if (type == EVT_FREQUENCYTEXTCTRL_UPDATED) {
NumericTextCtrl *frequencyCtrl = (mbCenterAndWidth ? mCenterCtrl : mLowCtrl); NumericTextCtrl *frequencyCtrl = (mbCenterAndWidth ? mCenterCtrl : mLowCtrl);
wxString frequencyFormatName = frequencyCtrl->GetBuiltinName(index); auto frequencyFormatName = frequencyCtrl->GetBuiltinName(index);
mListener->SSBL_SetFrequencySelectionFormatName(frequencyFormatName); mListener->SSBL_SetFrequencySelectionFormatName(frequencyFormatName);
} }
else if (mbCenterAndWidth && else if (mbCenterAndWidth &&
type == EVT_BANDWIDTHTEXTCTRL_UPDATED) { type == EVT_BANDWIDTHTEXTCTRL_UPDATED) {
wxString bandwidthFormatName = mWidthCtrl->GetBuiltinName(index); auto bandwidthFormatName = mWidthCtrl->GetBuiltinName(index);
mListener->SSBL_SetBandwidthSelectionFormatName(bandwidthFormatName); mListener->SSBL_SetBandwidthSelectionFormatName(bandwidthFormatName);
} }
@ -431,7 +431,7 @@ void SpectralSelectionBar::SetFrequencies(double bottom, double top)
ValuesToControls(); ValuesToControls();
} }
void SpectralSelectionBar::SetFrequencySelectionFormatName(const wxString & formatName) void SpectralSelectionBar::SetFrequencySelectionFormatName(const NumericFormatId & formatName)
{ {
NumericTextCtrl *frequencyCtrl = (mbCenterAndWidth ? mCenterCtrl : mLowCtrl); NumericTextCtrl *frequencyCtrl = (mbCenterAndWidth ? mCenterCtrl : mLowCtrl);
frequencyCtrl->SetFormatName(formatName); frequencyCtrl->SetFormatName(formatName);
@ -441,7 +441,7 @@ void SpectralSelectionBar::SetFrequencySelectionFormatName(const wxString & form
OnUpdate(e); OnUpdate(e);
} }
void SpectralSelectionBar::SetBandwidthSelectionFormatName(const wxString & formatName) void SpectralSelectionBar::SetBandwidthSelectionFormatName(const NumericFormatId & formatName)
{ {
if (mbCenterAndWidth) { if (mbCenterAndWidth) {
mWidthCtrl->SetFormatName(formatName); mWidthCtrl->SetFormatName(formatName);

View File

@ -42,8 +42,8 @@ public:
void UpdatePrefs() override; void UpdatePrefs() override;
void SetFrequencies(double bottom, double top); void SetFrequencies(double bottom, double top);
void SetFrequencySelectionFormatName(const wxString & formatName); void SetFrequencySelectionFormatName(const NumericFormatId & formatName);
void SetBandwidthSelectionFormatName(const wxString & formatName); void SetBandwidthSelectionFormatName(const NumericFormatId & formatName);
void SetListener(SpectralSelectionBarListener *l); void SetListener(SpectralSelectionBarListener *l);
void RegenerateTooltips() override {}; void RegenerateTooltips() override {};

View File

@ -13,7 +13,8 @@
#include "../Audacity.h" #include "../Audacity.h"
class wxString; class IdentInterfaceSymbol;
using NumericFormatId = IdentInterfaceSymbol;
class AUDACITY_DLL_API SpectralSelectionBarListener /* not final */ { class AUDACITY_DLL_API SpectralSelectionBarListener /* not final */ {
@ -24,11 +25,11 @@ class AUDACITY_DLL_API SpectralSelectionBarListener /* not final */ {
virtual double SSBL_GetRate() const = 0; virtual double SSBL_GetRate() const = 0;
virtual const wxString & SSBL_GetFrequencySelectionFormatName() = 0; virtual const NumericFormatId & SSBL_GetFrequencySelectionFormatName() = 0;
virtual void SSBL_SetFrequencySelectionFormatName(const wxString & formatName) = 0; virtual void SSBL_SetFrequencySelectionFormatName(const NumericFormatId & formatName) = 0;
virtual const wxString & SSBL_GetBandwidthSelectionFormatName() = 0; virtual const NumericFormatId & SSBL_GetBandwidthSelectionFormatName() = 0;
virtual void SSBL_SetBandwidthSelectionFormatName(const wxString & formatName) = 0; virtual void SSBL_SetBandwidthSelectionFormatName(const NumericFormatId & formatName) = 0;
virtual void SSBL_ModifySpectralSelection(double &bottom, double &top, bool done) = 0; virtual void SSBL_ModifySpectralSelection(double &bottom, double &top, bool done) = 0;
}; };

View File

@ -29,7 +29,7 @@
#include "../Internat.h" #include "../Internat.h"
NumericEditor::NumericEditor NumericEditor::NumericEditor
(NumericConverter::Type type, const wxString &format, double rate) (NumericConverter::Type type, const NumericFormatId &format, double rate)
{ {
mType = type; mType = type;
mFormat = format; mFormat = format;
@ -131,7 +131,7 @@ wxString NumericEditor::GetValue() const
return wxString::Format(wxT("%g"), GetNumericTextControl()->GetValue()); return wxString::Format(wxT("%g"), GetNumericTextControl()->GetValue());
} }
wxString NumericEditor::GetFormat() const NumericFormatId NumericEditor::GetFormat() const
{ {
return mFormat; return mFormat;
} }
@ -141,7 +141,7 @@ double NumericEditor::GetRate() const
return mRate; return mRate;
} }
void NumericEditor::SetFormat(const wxString &format) void NumericEditor::SetFormat(const NumericFormatId &format)
{ {
mFormat = format; mFormat = format;
} }
@ -396,12 +396,14 @@ Grid::Grid(wxWindow *parent,
RegisterDataType(GRID_VALUE_TIME, RegisterDataType(GRID_VALUE_TIME,
safenew NumericRenderer{ NumericConverter::TIME }, safenew NumericRenderer{ NumericConverter::TIME },
safenew NumericEditor safenew NumericEditor
{ NumericTextCtrl::TIME, wxT("seconds"), 44100.0 }); { NumericTextCtrl::TIME,
NumericConverter::SecondsFormat(), 44100.0 });
RegisterDataType(GRID_VALUE_FREQUENCY, RegisterDataType(GRID_VALUE_FREQUENCY,
safenew NumericRenderer{ NumericConverter::FREQUENCY }, safenew NumericRenderer{ NumericConverter::FREQUENCY },
safenew NumericEditor safenew NumericEditor
{ NumericTextCtrl::FREQUENCY, wxT("Hz"), 44100.0 }); { NumericTextCtrl::FREQUENCY,
NumericConverter::HertzFormat(), 44100.0 });
RegisterDataType(GRID_VALUE_CHOICE, RegisterDataType(GRID_VALUE_CHOICE,
safenew wxGridCellStringRenderer, safenew wxGridCellStringRenderer,

View File

@ -20,6 +20,7 @@
#include <wx/string.h> #include <wx/string.h>
#include <wx/window.h> #include <wx/window.h>
#include "NumericTextCtrl.h" #include "NumericTextCtrl.h"
#include "../Internat.h"
#if wxUSE_ACCESSIBILITY #if wxUSE_ACCESSIBILITY
#include <wx/access.h> #include <wx/access.h>
@ -29,6 +30,7 @@ class GridAx;
#endif #endif
class NumericTextCtrl; class NumericTextCtrl;
using NumericFormatId = IdentInterfaceSymbol;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// NumericEditor // NumericEditor
@ -43,7 +45,7 @@ class NumericEditor /* not final */ : public wxGridCellEditor
public: public:
NumericEditor NumericEditor
(NumericConverter::Type type, const wxString &format, double rate); (NumericConverter::Type type, const NumericFormatId &format, double rate);
~NumericEditor(); ~NumericEditor();
@ -62,9 +64,9 @@ public:
void Reset() override; void Reset() override;
wxString GetFormat() const; NumericFormatId GetFormat() const;
double GetRate() const; double GetRate() const;
void SetFormat(const wxString &format); void SetFormat(const NumericFormatId &format);
void SetRate(double rate); void SetRate(double rate);
wxGridCellEditor *Clone() const override; wxGridCellEditor *Clone() const override;
@ -75,7 +77,7 @@ public:
private: private:
wxString mFormat; NumericFormatId mFormat;
double mRate; double mRate;
NumericConverter::Type mType; NumericConverter::Type mType;
double mOld; double mOld;

View File

@ -198,27 +198,12 @@ different formats.
* to the user */ * to the user */
struct BuiltinFormatString struct BuiltinFormatString
{ {
wxString name; NumericFormatId name;
wxString formatStr;
};
//
// ----------------------------------------------------------------------------
// UntranslatedBuiltinFormatString Struct
// ----------------------------------------------------------------------------
//
/** \brief struct to hold a formatting control string and its untranslated name
* Used in an array to hold the built-in time formats that are always available
* to the user */
struct UntranslatedBuiltinFormatString
{
wxString name;
wxString formatStr; wxString formatStr;
BuiltinFormatString Translate() const friend inline bool operator ==
{ (const BuiltinFormatString &a, const BuiltinFormatString &b)
return { wxGetTranslation( name ), wxGetTranslation( formatStr ) }; { return a.name == b.name; }
}
}; };
// //
@ -290,16 +275,14 @@ public:
namespace { namespace {
const std::vector<BuiltinFormatString> &TimeConverterFormats() {
/** \brief array of formats the control knows about internally /** \brief array of formats the control knows about internally
* array of string pairs for name of the format and the format string * array of string pairs for name of the format and the format string
* needed to create that format output. This is used for the pop-up * needed to create that format output. This is used for the pop-up
* list of formats to choose from in the control. */ * list of formats to choose from in the control. */
static const UntranslatedBuiltinFormatString TimeConverterFormats_[] = { static const BuiltinFormatString TimeConverterFormats_[] = {
{ {
/* i18n-hint: Name of time display format that shows time in seconds */ /* i18n-hint: Name of time display format that shows time in seconds */
XO("seconds"), { XO("seconds") },
/* i18n-hint: Format string for displaying time in seconds. Change the comma /* i18n-hint: Format string for displaying time in seconds. Change the comma
* in the middle to the 1000s separator for your locale, and the 'seconds' * in the middle to the 1000s separator for your locale, and the 'seconds'
* on the end to the word for seconds. Don't change the numbers. */ * on the end to the word for seconds. Don't change the numbers. */
@ -309,7 +292,7 @@ static const UntranslatedBuiltinFormatString TimeConverterFormats_[] = {
{ {
/* i18n-hint: Name of time display format that shows time in hours, minutes /* i18n-hint: Name of time display format that shows time in hours, minutes
* and seconds */ * and seconds */
XO("hh:mm:ss"), { XO("hh:mm:ss") },
/* i18n-hint: Format string for displaying time in hours, minutes and /* i18n-hint: Format string for displaying time in hours, minutes and
* seconds. Change the 'h' to the abbreviation for hours, 'm' to the * seconds. Change the 'h' to the abbreviation for hours, 'm' to the
* abbreviation for minutes and 's' to the abbreviation for seconds. Don't * abbreviation for minutes and 's' to the abbreviation for seconds. Don't
@ -321,7 +304,7 @@ static const UntranslatedBuiltinFormatString TimeConverterFormats_[] = {
{ {
/* i18n-hint: Name of time display format that shows time in days, hours, /* i18n-hint: Name of time display format that shows time in days, hours,
* minutes and seconds */ * minutes and seconds */
XO("dd:hh:mm:ss"), { XO("dd:hh:mm:ss") },
/* i18n-hint: Format string for displaying time in days, hours, minutes and /* i18n-hint: Format string for displaying time in days, hours, minutes and
* seconds. Change the 'days' to the word for days, 'h' to the abbreviation * seconds. Change the 'days' to the word for days, 'h' to the abbreviation
* for hours, 'm' to the abbreviation for minutes and 's' to the * for hours, 'm' to the abbreviation for minutes and 's' to the
@ -333,7 +316,7 @@ static const UntranslatedBuiltinFormatString TimeConverterFormats_[] = {
{ {
/* i18n-hint: Name of time display format that shows time in hours, /* i18n-hint: Name of time display format that shows time in hours,
* minutes, seconds and hundredths of a second (1/100 second) */ * minutes, seconds and hundredths of a second (1/100 second) */
XO("hh:mm:ss + hundredths"), { XO("hh:mm:ss + hundredths") },
/* i18n-hint: Format string for displaying time in hours, minutes, seconds /* i18n-hint: Format string for displaying time in hours, minutes, seconds
* and hundredths of a second. Change the 'h' to the abbreviation for hours, * and hundredths of a second. Change the 'h' to the abbreviation for hours,
* 'm' to the abbreviation for minutes and 's' to the abbreviation for seconds * 'm' to the abbreviation for minutes and 's' to the abbreviation for seconds
@ -345,7 +328,7 @@ static const UntranslatedBuiltinFormatString TimeConverterFormats_[] = {
{ {
/* i18n-hint: Name of time display format that shows time in hours, /* i18n-hint: Name of time display format that shows time in hours,
* minutes, seconds and milliseconds (1/1000 second) */ * minutes, seconds and milliseconds (1/1000 second) */
XO("hh:mm:ss + milliseconds"), { XO("hh:mm:ss + milliseconds") },
/* i18n-hint: Format string for displaying time in hours, minutes, seconds /* i18n-hint: Format string for displaying time in hours, minutes, seconds
* and milliseconds. Change the 'h' to the abbreviation for hours, 'm' to the * and milliseconds. Change the 'h' to the abbreviation for hours, 'm' to the
* abbreviation for minutes and 's' to the abbreviation for seconds (the * abbreviation for minutes and 's' to the abbreviation for seconds (the
@ -357,7 +340,7 @@ static const UntranslatedBuiltinFormatString TimeConverterFormats_[] = {
{ {
/* i18n-hint: Name of time display format that shows time in hours, /* i18n-hint: Name of time display format that shows time in hours,
* minutes, seconds and samples (at the current project sample rate) */ * minutes, seconds and samples (at the current project sample rate) */
XO("hh:mm:ss + samples"), { XO("hh:mm:ss + samples") },
/* i18n-hint: Format string for displaying time in hours, minutes, seconds /* i18n-hint: Format string for displaying time in hours, minutes, seconds
* and samples. Change the 'h' to the abbreviation for hours, 'm' to the * and samples. Change the 'h' to the abbreviation for hours, 'm' to the
* abbreviation for minutes, 's' to the abbreviation for seconds and * abbreviation for minutes, 's' to the abbreviation for seconds and
@ -371,7 +354,7 @@ static const UntranslatedBuiltinFormatString TimeConverterFormats_[] = {
* current project sample rate). For example the number of a sample at 1 * current project sample rate). For example the number of a sample at 1
* second into a recording at 44.1KHz would be 44,100. * second into a recording at 44.1KHz would be 44,100.
*/ */
XO("samples"), { XO("samples") },
/* i18n-hint: Format string for displaying time in samples (lots of samples). /* i18n-hint: Format string for displaying time in samples (lots of samples).
* Change the ',' to the 1000s separator for your locale, and translate * Change the ',' to the 1000s separator for your locale, and translate
* samples. If 1000s aren't a base multiple for your number system, then you * samples. If 1000s aren't a base multiple for your number system, then you
@ -382,7 +365,7 @@ static const UntranslatedBuiltinFormatString TimeConverterFormats_[] = {
{ {
/* i18n-hint: Name of time display format that shows time in hours, minutes, /* i18n-hint: Name of time display format that shows time in hours, minutes,
* seconds and frames at 24 frames per second (commonly used for films) */ * seconds and frames at 24 frames per second (commonly used for films) */
XO("hh:mm:ss + film frames (24 fps)"), { XO("hh:mm:ss + film frames (24 fps)") },
/* i18n-hint: Format string for displaying time in hours, minutes, seconds /* i18n-hint: Format string for displaying time in hours, minutes, seconds
* and frames at 24 frames per second. Change the 'h' to the abbreviation * and frames at 24 frames per second. Change the 'h' to the abbreviation
* for hours, 'm' to the abbreviation for minutes, 's' to the abbreviation * for hours, 'm' to the abbreviation for minutes, 's' to the abbreviation
@ -394,7 +377,7 @@ static const UntranslatedBuiltinFormatString TimeConverterFormats_[] = {
{ {
/* i18n-hint: Name of time display format that shows time in frames (lots of /* i18n-hint: Name of time display format that shows time in frames (lots of
* frames) at 24 frames per second (commonly used for films) */ * frames) at 24 frames per second (commonly used for films) */
XO("film frames (24 fps)"), { XO("film frames (24 fps)") },
/* i18n-hint: Format string for displaying time in frames at 24 frames per /* i18n-hint: Format string for displaying time in frames at 24 frames per
* second. Change the comma * second. Change the comma
* in the middle to the 1000s separator for your locale, * in the middle to the 1000s separator for your locale,
@ -406,7 +389,7 @@ static const UntranslatedBuiltinFormatString TimeConverterFormats_[] = {
/* i18n-hint: Name of time display format that shows time in hours, minutes, /* i18n-hint: Name of time display format that shows time in hours, minutes,
* seconds and frames at NTSC TV drop-frame rate (used for American / * seconds and frames at NTSC TV drop-frame rate (used for American /
* Japanese TV, and very odd) */ * Japanese TV, and very odd) */
XO("hh:mm:ss + NTSC drop frames"), { XO("hh:mm:ss + NTSC drop frames") },
/* i18n-hint: Format string for displaying time in hours, minutes, seconds /* i18n-hint: Format string for displaying time in hours, minutes, seconds
* and frames with NTSC drop frames. Change the 'h' to the abbreviation * and frames with NTSC drop frames. Change the 'h' to the abbreviation
* for hours, 'm' to the abbreviation for minutes, 's' to the abbreviation * for hours, 'm' to the abbreviation for minutes, 's' to the abbreviation
@ -418,7 +401,7 @@ static const UntranslatedBuiltinFormatString TimeConverterFormats_[] = {
/* i18n-hint: Name of time display format that shows time in hours, minutes, /* i18n-hint: Name of time display format that shows time in hours, minutes,
* seconds and frames at NTSC TV non-drop-frame rate (used for American / * seconds and frames at NTSC TV non-drop-frame rate (used for American /
* Japanese TV, and doesn't quite match wall time */ * Japanese TV, and doesn't quite match wall time */
XO("hh:mm:ss + NTSC non-drop frames"), { XO("hh:mm:ss + NTSC non-drop frames") },
/* i18n-hint: Format string for displaying time in hours, minutes, seconds /* i18n-hint: Format string for displaying time in hours, minutes, seconds
* and frames with NTSC drop frames. Change the 'h' to the abbreviation * and frames with NTSC drop frames. Change the 'h' to the abbreviation
* for hours, 'm' to the abbreviation for minutes, 's' to the abbreviation * for hours, 'm' to the abbreviation for minutes, 's' to the abbreviation
@ -430,7 +413,7 @@ static const UntranslatedBuiltinFormatString TimeConverterFormats_[] = {
{ {
/* i18n-hint: Name of time display format that shows time in frames at NTSC /* i18n-hint: Name of time display format that shows time in frames at NTSC
* TV frame rate (used for American / Japanese TV */ * TV frame rate (used for American / Japanese TV */
XO("NTSC frames"), { XO("NTSC frames") },
/* i18n-hint: Format string for displaying time in frames with NTSC frames. /* i18n-hint: Format string for displaying time in frames with NTSC frames.
* Change the comma * Change the comma
* in the middle to the 1000s separator for your locale, * in the middle to the 1000s separator for your locale,
@ -442,7 +425,7 @@ static const UntranslatedBuiltinFormatString TimeConverterFormats_[] = {
{ {
/* i18n-hint: Name of time display format that shows time in hours, minutes, /* i18n-hint: Name of time display format that shows time in hours, minutes,
* seconds and frames at PAL TV frame rate (used for European TV) */ * seconds and frames at PAL TV frame rate (used for European TV) */
XO("hh:mm:ss + PAL frames (25 fps)"), { XO("hh:mm:ss + PAL frames (25 fps)") },
/* i18n-hint: Format string for displaying time in hours, minutes, seconds /* i18n-hint: Format string for displaying time in hours, minutes, seconds
* and frames with PAL TV frames. Change the 'h' to the abbreviation * and frames with PAL TV frames. Change the 'h' to the abbreviation
* for hours, 'm' to the abbreviation for minutes, 's' to the abbreviation * for hours, 'm' to the abbreviation for minutes, 's' to the abbreviation
@ -453,7 +436,7 @@ static const UntranslatedBuiltinFormatString TimeConverterFormats_[] = {
{ {
/* i18n-hint: Name of time display format that shows time in frames at PAL /* i18n-hint: Name of time display format that shows time in frames at PAL
* TV frame rate (used for European TV) */ * TV frame rate (used for European TV) */
XO("PAL frames (25 fps)"), { XO("PAL frames (25 fps)") },
/* i18n-hint: Format string for displaying time in frames with NTSC frames. /* i18n-hint: Format string for displaying time in frames with NTSC frames.
* Change the comma * Change the comma
* in the middle to the 1000s separator for your locale, * in the middle to the 1000s separator for your locale,
@ -464,7 +447,7 @@ static const UntranslatedBuiltinFormatString TimeConverterFormats_[] = {
{ {
/* i18n-hint: Name of time display format that shows time in hours, minutes, /* i18n-hint: Name of time display format that shows time in hours, minutes,
* seconds and frames at CD Audio frame rate (75 frames per second) */ * seconds and frames at CD Audio frame rate (75 frames per second) */
XO("hh:mm:ss + CDDA frames (75 fps)"), { XO("hh:mm:ss + CDDA frames (75 fps)") },
/* i18n-hint: Format string for displaying time in hours, minutes, seconds /* i18n-hint: Format string for displaying time in hours, minutes, seconds
* and frames with CD Audio frames. Change the 'h' to the abbreviation * and frames with CD Audio frames. Change the 'h' to the abbreviation
* for hours, 'm' to the abbreviation for minutes, 's' to the abbreviation * for hours, 'm' to the abbreviation for minutes, 's' to the abbreviation
@ -475,7 +458,7 @@ static const UntranslatedBuiltinFormatString TimeConverterFormats_[] = {
{ {
/* i18n-hint: Name of time display format that shows time in frames at CD /* i18n-hint: Name of time display format that shows time in frames at CD
* Audio frame rate (75 frames per second) */ * Audio frame rate (75 frames per second) */
XO("CDDA frames (75 fps)"), { XO("CDDA frames (75 fps)") },
/* i18n-hint: Format string for displaying time in frames with CD Audio /* i18n-hint: Format string for displaying time in frames with CD Audio
* frames. Change the comma * frames. Change the comma
* in the middle to the 1000s separator for your locale, * in the middle to the 1000s separator for your locale,
@ -484,70 +467,36 @@ static const UntranslatedBuiltinFormatString TimeConverterFormats_[] = {
}, },
}; };
class FormatsArray final
: public TranslatableArray< std::vector< BuiltinFormatString > >
{
void Populate() override
{
for (auto &format : TimeConverterFormats_)
mContents.push_back( format.Translate() );
}
};
static FormatsArray theArray;
return theArray.Get();
} // end function
const std::vector<BuiltinFormatString> &FrequencyConverterFormats() {
/** \brief array of formats the control knows about internally /** \brief array of formats the control knows about internally
* array of string pairs for name of the format and the format string * array of string pairs for name of the format and the format string
* needed to create that format output. This is used for the pop-up * needed to create that format output. This is used for the pop-up
* list of formats to choose from in the control. */ * list of formats to choose from in the control. */
static const UntranslatedBuiltinFormatString FrequencyConverterFormats_[] = { static const BuiltinFormatString FrequencyConverterFormats_[] = {
/* i18n-hint: Name of display format that shows frequency in hertz */ /* i18n-hint: Name of display format that shows frequency in hertz */
{ {
XO("Hz"), { XO("Hz") },
/* i18n-hint: Format string for displaying frequency in hertz. Change /* i18n-hint: Format string for displaying frequency in hertz. Change
* the decimal point for your locale. Don't change the numbers. */ * the decimal point for your locale. Don't change the numbers. */
XO("0100000.0100 Hz") XO("0100000.0100 Hz")
}, },
{ {
XO("kHz"), { XO("kHz") },
/* i18n-hint: Format string for displaying frequency in kilohertz. Change /* i18n-hint: Format string for displaying frequency in kilohertz. Change
* the decimal point for your locale. Don't change the numbers. */ * the decimal point for your locale. Don't change the numbers. */
XO("01000.01000 kHz|0.001") XO("01000.01000 kHz|0.001")
}, },
}; };
class FormatsArray final
: public TranslatableArray< std::vector< BuiltinFormatString > >
{
void Populate() override
{
for (auto &format : FrequencyConverterFormats_)
mContents.push_back( format.Translate() );
}
};
static FormatsArray theArray;
return theArray.Get();
} // end function
const std::vector<BuiltinFormatString> &BandwidthConverterFormats() {
/** \brief array of formats the control knows about internally /** \brief array of formats the control knows about internally
* array of string pairs for name of the format and the format string * array of string pairs for name of the format and the format string
* needed to create that format output. This is used for the pop-up * needed to create that format output. This is used for the pop-up
* list of formats to choose from in the control. */ * list of formats to choose from in the control. */
static const UntranslatedBuiltinFormatString BandwidthConverterFormats_[] = { static const BuiltinFormatString BandwidthConverterFormats_[] = {
{ {
/* i18n-hint: Name of display format that shows log of frequency /* i18n-hint: Name of display format that shows log of frequency
* in octaves */ * in octaves */
XO("octaves"), { XO("octaves") },
/* i18n-hint: Format string for displaying log of frequency in octaves. /* i18n-hint: Format string for displaying log of frequency in octaves.
* Change the decimal points for your locale. Don't change the numbers. */ * Change the decimal points for your locale. Don't change the numbers. */
// Scale factor is 1 / ln (2) // Scale factor is 1 / ln (2)
@ -557,7 +506,7 @@ static const UntranslatedBuiltinFormatString BandwidthConverterFormats_[] = {
{ {
/* i18n-hint: Name of display format that shows log of frequency /* i18n-hint: Name of display format that shows log of frequency
* in semitones and cents */ * in semitones and cents */
XO("semitones + cents"), { XO("semitones + cents") },
/* i18n-hint: Format string for displaying log of frequency in semitones /* i18n-hint: Format string for displaying log of frequency in semitones
* and cents. * and cents.
* Change the decimal points for your locale. Don't change the numbers. */ * Change the decimal points for your locale. Don't change the numbers. */
@ -568,7 +517,7 @@ static const UntranslatedBuiltinFormatString BandwidthConverterFormats_[] = {
{ {
/* i18n-hint: Name of display format that shows log of frequency /* i18n-hint: Name of display format that shows log of frequency
* in decades */ * in decades */
XO("decades"), { XO("decades") },
/* i18n-hint: Format string for displaying log of frequency in decades. /* i18n-hint: Format string for displaying log of frequency in decades.
* Change the decimal points for your locale. Don't change the numbers. */ * Change the decimal points for your locale. Don't change the numbers. */
// Scale factor is 1 / ln (10) // Scale factor is 1 / ln (10)
@ -576,33 +525,31 @@ static const UntranslatedBuiltinFormatString BandwidthConverterFormats_[] = {
}, },
}; };
const BuiltinFormatString *ChooseBuiltinFormatStrings
class FormatsArray final
: public TranslatableArray< std::vector< BuiltinFormatString > >
{
void Populate() override
{
for (auto &format : BandwidthConverterFormats_)
mContents.push_back( format.Translate() );
}
};
static FormatsArray theArray;
return theArray.Get();
} // end function
const std::vector<BuiltinFormatString> &ChooseBuiltinFormatStrings
(NumericConverter::Type type) (NumericConverter::Type type)
{ {
switch (type) { switch (type) {
default: default:
case NumericConverter::TIME: case NumericConverter::TIME:
return TimeConverterFormats(); return TimeConverterFormats_;
case NumericConverter::FREQUENCY: case NumericConverter::FREQUENCY:
return FrequencyConverterFormats(); return FrequencyConverterFormats_;
case NumericConverter::BANDWIDTH: case NumericConverter::BANDWIDTH:
return BandwidthConverterFormats(); return BandwidthConverterFormats_;
}
}
size_t ChooseNBuiltinFormatStrings
(NumericConverter::Type type)
{
switch (type) {
default:
case NumericConverter::TIME:
return WXSIZEOF(TimeConverterFormats_);
case NumericConverter::FREQUENCY:
return WXSIZEOF(FrequencyConverterFormats_);
case NumericConverter::BANDWIDTH:
return WXSIZEOF(BandwidthConverterFormats_);
} }
} }
} }
@ -612,11 +559,42 @@ return theArray.Get();
// NumericConverter Class // NumericConverter Class
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// //
NumericFormatId NumericConverter::DefaultSelectionFormat()
{ return TimeConverterFormats_[4].name; }
NumericFormatId NumericConverter::TimeAndSampleFormat()
{ return TimeConverterFormats_[5].name; }
NumericFormatId NumericConverter::SecondsFormat()
{ return TimeConverterFormats_[0].name; }
NumericFormatId NumericConverter::HundredthsFormat()
{ return TimeConverterFormats_[3].name; }
NumericFormatId NumericConverter::HertzFormat()
{ return FrequencyConverterFormats_[0].name; }
NumericFormatId NumericConverter::LookupFormat( Type type, const wxString& id)
{
if (id.empty()) {
if (type == TIME)
return DefaultSelectionFormat();
else
return ChooseBuiltinFormatStrings(type)[0].name;
}
else {
auto begin = ChooseBuiltinFormatStrings(type);
auto end = begin + ChooseNBuiltinFormatStrings(type);
auto iter = std::find( begin, end, BuiltinFormatString{ id, {} } );
if (iter == end)
iter = begin;
return iter->name;
}
}
NumericConverter::NumericConverter(Type type, NumericConverter::NumericConverter(Type type,
const wxString & formatName, const NumericFormatId & formatName,
double value, double value,
double sampleRate) double sampleRate)
: mBuiltinFormatStrings( ChooseBuiltinFormatStrings( type ) ) : mBuiltinFormatStrings( ChooseBuiltinFormatStrings( type ) )
, mNBuiltins( ChooseNBuiltinFormatStrings( type ) )
{ {
ResetMinValue(); ResetMinValue();
ResetMaxValue(); ResetMaxValue();
@ -629,8 +607,6 @@ NumericConverter::NumericConverter(Type type,
if (type == NumericConverter::TIME ) if (type == NumericConverter::TIME )
mDefaultNdx = 4; // Default to "hh:mm:ss + milliseconds". mDefaultNdx = 4; // Default to "hh:mm:ss + milliseconds".
mNBuiltins = mBuiltinFormatStrings.size();
mPrefix = wxT(""); mPrefix = wxT("");
mValueTemplate = wxT(""); mValueTemplate = wxT("");
mValueMask = wxT(""); mValueMask = wxT("");
@ -992,7 +968,7 @@ void NumericConverter::ControlsToValue()
mValue = std::max(mMinValue, std::min(mMaxValue, t)); mValue = std::max(mMinValue, std::min(mMaxValue, t));
} }
void NumericConverter::SetFormatName(const wxString & formatName) void NumericConverter::SetFormatName(const NumericFormatId & formatName)
{ {
SetFormatString(GetBuiltinFormat(formatName)); SetFormatString(GetBuiltinFormat(formatName));
} }
@ -1055,11 +1031,6 @@ double NumericConverter::GetValue()
return mValue; return mValue;
} }
wxString NumericConverter::GetFormatString()
{
return mFormatString;
}
int NumericConverter::GetFormatIndex() int NumericConverter::GetFormatIndex()
{ {
// int ndx = 1; // int ndx = 1;
@ -1081,12 +1052,12 @@ int NumericConverter::GetNumBuiltins()
return mNBuiltins; return mNBuiltins;
} }
wxString NumericConverter::GetBuiltinName(const int index) NumericFormatId NumericConverter::GetBuiltinName(const int index)
{ {
if (index >= 0 && index < GetNumBuiltins()) if (index >= 0 && index < GetNumBuiltins())
return mBuiltinFormatStrings[index].name; return mBuiltinFormatStrings[index].name;
return wxEmptyString; return {};
} }
wxString NumericConverter::GetBuiltinFormat(const int index) wxString NumericConverter::GetBuiltinFormat(const int index)
@ -1094,20 +1065,17 @@ wxString NumericConverter::GetBuiltinFormat(const int index)
if (index >= 0 && index < GetNumBuiltins()) if (index >= 0 && index < GetNumBuiltins())
return mBuiltinFormatStrings[index].formatStr; return mBuiltinFormatStrings[index].formatStr;
return wxEmptyString; return {};
} }
wxString NumericConverter::GetBuiltinFormat(const wxString &name) wxString NumericConverter::GetBuiltinFormat(const NumericFormatId &name)
{ {
int ndx = mDefaultNdx; int ndx =
int i; std::find( mBuiltinFormatStrings, mBuiltinFormatStrings + mNBuiltins,
BuiltinFormatString{ name, {} } )
for (i = 0; i < GetNumBuiltins(); i++) { - mBuiltinFormatStrings;
if (name == GetBuiltinName(i)) { if (ndx == mNBuiltins)
ndx = i; ndx = mDefaultNdx;
break;
}
}
return GetBuiltinFormat(ndx); return GetBuiltinFormat(ndx);
} }
@ -1241,7 +1209,7 @@ IMPLEMENT_CLASS(NumericTextCtrl, wxControl)
NumericTextCtrl::NumericTextCtrl(wxWindow *parent, wxWindowID id, NumericTextCtrl::NumericTextCtrl(wxWindow *parent, wxWindowID id,
NumericConverter::Type type, NumericConverter::Type type,
const wxString &formatName, const NumericFormatId &formatName,
double timeValue, double timeValue,
double sampleRate, double sampleRate,
const Options &options, const Options &options,
@ -1314,7 +1282,7 @@ void NumericTextCtrl::UpdateAutoFocus()
} }
} }
void NumericTextCtrl::SetFormatName(const wxString & formatName) void NumericTextCtrl::SetFormatName(const NumericFormatId & formatName)
{ {
SetFormatString(GetBuiltinFormat(formatName)); SetFormatString(GetBuiltinFormat(formatName));
} }
@ -1570,7 +1538,7 @@ void NumericTextCtrl::OnContext(wxContextMenuEvent &event)
int currentSelection = -1; int currentSelection = -1;
for (i = 0; i < GetNumBuiltins(); i++) { for (i = 0; i < GetNumBuiltins(); i++) {
menu.AppendRadioItem(ID_MENU + i, GetBuiltinName(i)); menu.AppendRadioItem(ID_MENU + i, GetBuiltinName(i).Translation());
if (mFormatString == GetBuiltinFormat(i)) { if (mFormatString == GetBuiltinFormat(i)) {
menu.Check(ID_MENU + i, true); menu.Check(ID_MENU + i, true);
currentSelection = i; currentSelection = i;
@ -1606,7 +1574,7 @@ void NumericTextCtrl::OnContext(wxContextMenuEvent &event)
wxCommandEvent e(eventType, GetId()); wxCommandEvent e(eventType, GetId());
e.SetInt(i); e.SetInt(i);
e.SetString(GetBuiltinName(i)); e.SetString(GetBuiltinName(i).Internal());
GetParent()->GetEventHandler()->AddPendingEvent(e); GetParent()->GetEventHandler()->AddPendingEvent(e);
} }
} }

View File

@ -16,6 +16,7 @@
#define __AUDACITY_TIME_TEXT_CTRL__ #define __AUDACITY_TIME_TEXT_CTRL__
#include "../MemoryX.h" #include "../MemoryX.h"
#include "../../include/audacity/IdentInterface.h"
#include <vector> #include <vector>
#include <wx/defs.h> #include <wx/defs.h>
#include <wx/event.h> #include <wx/event.h>
@ -25,6 +26,7 @@
#include <wx/textctrl.h> #include <wx/textctrl.h>
#include "../Audacity.h" #include "../Audacity.h"
#include "../Internat.h"
#if wxUSE_ACCESSIBILITY #if wxUSE_ACCESSIBILITY
#include <wx/access.h> #include <wx/access.h>
@ -47,6 +49,8 @@ class NumericField;
class DigitInfo; class DigitInfo;
using NumericFormatId = IdentInterfaceSymbol;
class NumericConverter /* not final */ class NumericConverter /* not final */
{ {
public: public:
@ -57,8 +61,16 @@ public:
BANDWIDTH, BANDWIDTH,
}; };
static NumericFormatId DefaultSelectionFormat();
static NumericFormatId TimeAndSampleFormat();
static NumericFormatId SecondsFormat();
static NumericFormatId HundredthsFormat();
static NumericFormatId HertzFormat();
static NumericFormatId LookupFormat( Type type, const wxString& id);
NumericConverter(Type type, NumericConverter(Type type,
const wxString & formatName = wxEmptyString, const NumericFormatId & formatName = {},
double value = 0.0f, double value = 0.0f,
double sampleRate = 1.0f /* to prevent div by 0 */); double sampleRate = 1.0f /* to prevent div by 0 */);
@ -74,10 +86,12 @@ public:
// raw value (mValue). // raw value (mValue).
virtual void ControlsToValue(); virtual void ControlsToValue();
virtual void ParseFormatString(const wxString & format); private:
void ParseFormatString(const wxString & format);
public:
void PrintDebugInfo(); void PrintDebugInfo();
void SetFormatName(const wxString & formatName); void SetFormatName(const NumericFormatId & formatName);
void SetFormatString(const wxString & formatString); void SetFormatString(const wxString & formatString);
void SetSampleRate(double sampleRate); void SetSampleRate(double sampleRate);
void SetValue(double newValue); void SetValue(double newValue);
@ -90,13 +104,12 @@ public:
wxString GetString(); wxString GetString();
wxString GetFormatString();
int GetFormatIndex(); int GetFormatIndex();
int GetNumBuiltins(); int GetNumBuiltins();
wxString GetBuiltinName(const int index); NumericFormatId GetBuiltinName(const int index);
wxString GetBuiltinFormat(const int index); wxString GetBuiltinFormat(const int index);
wxString GetBuiltinFormat(const wxString & name); wxString GetBuiltinFormat(const NumericFormatId & name);
// Adjust the value by the number "steps" in the active format. // Adjust the value by the number "steps" in the active format.
// Increment if "dir" is 1, decrement if "dir" is -1. // Increment if "dir" is 1, decrement if "dir" is -1.
@ -130,8 +143,8 @@ protected:
int mFocusedDigit; int mFocusedDigit;
std::vector<DigitInfo> mDigits; std::vector<DigitInfo> mDigits;
const std::vector<BuiltinFormatString> &mBuiltinFormatStrings; const BuiltinFormatString *mBuiltinFormatStrings;
int mNBuiltins; const size_t mNBuiltins;
int mDefaultNdx; int mDefaultNdx;
}; };
@ -159,14 +172,16 @@ class NumericTextCtrl final : public wxControl, public NumericConverter
Options &MenuEnabled (bool value) { menuEnabled = value; return *this; } Options &MenuEnabled (bool value) { menuEnabled = value; return *this; }
Options &InvalidValue (bool has, double value = -1.0) Options &InvalidValue (bool has, double value = -1.0)
{ hasInvalidValue = has, invalidValue = value; return *this; } { hasInvalidValue = has, invalidValue = value; return *this; }
Options &Format (const wxString &value) { format = value; return *this; } // use a custom format not in the tables:
Options &Format (const wxString &value)
{ format = value; return *this; }
Options &Value (bool has, double v) Options &Value (bool has, double v)
{ hasValue = has, value = v; return *this; } { hasValue = has, value = v; return *this; }
}; };
NumericTextCtrl(wxWindow *parent, wxWindowID winid, NumericTextCtrl(wxWindow *parent, wxWindowID winid,
NumericConverter::Type type, NumericConverter::Type type,
const wxString &formatName = wxEmptyString, const NumericFormatId &formatName = {},
double value = 0.0, double value = 0.0,
double sampleRate = 44100, double sampleRate = 44100,
const Options &options = {}, const Options &options = {},
@ -181,7 +196,7 @@ class NumericTextCtrl final : public wxControl, public NumericConverter
void SetSampleRate(double sampleRate); void SetSampleRate(double sampleRate);
void SetValue(double newValue); void SetValue(double newValue);
void SetFormatString(const wxString & formatString); void SetFormatString(const wxString & formatString);
void SetFormatName(const wxString & formatName); void SetFormatName(const NumericFormatId & formatName);
void SetFieldFocus(int /* digit */); void SetFieldFocus(int /* digit */);