1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-17 16:40:07 +02:00

Rearrange setting time & freq formats for numeric controls...

... Just one low-level function for each that simply sets; just one high-level
function for each that also pushes notifications; and to make that work,
toolbars need some rewriting to avoid recursion when the notifications they
post come back to them.
This commit is contained in:
Paul Licameli 2019-05-27 07:45:13 -04:00
parent 441763cabd
commit 35892fc869
6 changed files with 87 additions and 57 deletions

View File

@ -1574,13 +1574,15 @@ const NumericFormatSymbol & AudacityProject::AS_GetSelectionFormat()
void AudacityProject::AS_SetSelectionFormat(const NumericFormatSymbol & format) void AudacityProject::AS_SetSelectionFormat(const NumericFormatSymbol & format)
{ {
auto &project = *this; auto &project = *this;
mSelectionFormat = format; SetSelectionFormat( format );
gPrefs->Write(wxT("/SelectionFormat"), mSelectionFormat.Internal()); gPrefs->Write(wxT("/SelectionFormat"), mSelectionFormat.Internal());
gPrefs->Flush(); gPrefs->Flush();
if (SnapSelection()) if (SnapSelection())
TrackPanel::Get( project ).Refresh(false); TrackPanel::Get( project ).Refresh(false);
SelectionBar::Get( project ).SetSelectionFormat(format);
} }
double AudacityProject::SSBL_GetRate() const double AudacityProject::SSBL_GetRate() const
@ -1599,11 +1601,17 @@ const NumericFormatSymbol & AudacityProject::SSBL_GetFrequencySelectionFormatNam
void AudacityProject::SSBL_SetFrequencySelectionFormatName(const NumericFormatSymbol & formatName) void AudacityProject::SSBL_SetFrequencySelectionFormatName(const NumericFormatSymbol & formatName)
{ {
mFrequencySelectionFormatName = formatName; auto &project = *this;
SetFrequencySelectionFormatName( formatName );
gPrefs->Write(wxT("/FrequencySelectionFormatName"), gPrefs->Write(wxT("/FrequencySelectionFormatName"),
mFrequencySelectionFormatName.Internal()); mFrequencySelectionFormatName.Internal());
gPrefs->Flush(); gPrefs->Flush();
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
SpectralSelectionBar::Get( project ).SetFrequencySelectionFormatName(formatName);
#endif
} }
const NumericFormatSymbol & AudacityProject::SSBL_GetBandwidthSelectionFormatName() const NumericFormatSymbol & AudacityProject::SSBL_GetBandwidthSelectionFormatName()
@ -1613,11 +1621,17 @@ const NumericFormatSymbol & AudacityProject::SSBL_GetBandwidthSelectionFormatNam
void AudacityProject::SSBL_SetBandwidthSelectionFormatName(const NumericFormatSymbol & formatName) void AudacityProject::SSBL_SetBandwidthSelectionFormatName(const NumericFormatSymbol & formatName)
{ {
mBandwidthSelectionFormatName = formatName; auto &project = *this;
SetBandwidthSelectionFormatName( formatName );
gPrefs->Write(wxT("/BandwidthSelectionFormatName"), gPrefs->Write(wxT("/BandwidthSelectionFormatName"),
mBandwidthSelectionFormatName.Internal()); mBandwidthSelectionFormatName.Internal());
gPrefs->Flush(); gPrefs->Flush();
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
SpectralSelectionBar::Get( project ).SetBandwidthSelectionFormatName(formatName);
#endif
} }
void AudacityProject::SSBL_ModifySpectralSelection(double &bottom, double &top, bool done) void AudacityProject::SSBL_ModifySpectralSelection(double &bottom, double &top, bool done)
@ -1649,11 +1663,7 @@ const NumericFormatSymbol & AudacityProject::GetFrequencySelectionFormatName() c
void AudacityProject::SetFrequencySelectionFormatName(const NumericFormatSymbol & formatName) void AudacityProject::SetFrequencySelectionFormatName(const NumericFormatSymbol & formatName)
{ {
auto &project = *this; mFrequencySelectionFormatName = formatName;
SSBL_SetFrequencySelectionFormatName(formatName);
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
SpectralSelectionBar::Get( project ).SetFrequencySelectionFormatName(formatName);
#endif
} }
const NumericFormatSymbol & AudacityProject::GetBandwidthSelectionFormatName() const const NumericFormatSymbol & AudacityProject::GetBandwidthSelectionFormatName() const
@ -1663,18 +1673,12 @@ const NumericFormatSymbol & AudacityProject::GetBandwidthSelectionFormatName() c
void AudacityProject::SetBandwidthSelectionFormatName(const NumericFormatSymbol & formatName) void AudacityProject::SetBandwidthSelectionFormatName(const NumericFormatSymbol & formatName)
{ {
auto &project = *this; mBandwidthSelectionFormatName = formatName;
SSBL_SetBandwidthSelectionFormatName(formatName);
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
SpectralSelectionBar::Get( project ).SetBandwidthSelectionFormatName(formatName);
#endif
} }
void AudacityProject::SetSelectionFormat(const NumericFormatSymbol & format) void AudacityProject::SetSelectionFormat(const NumericFormatSymbol & format)
{ {
auto &project = *this; mSelectionFormat = format;
AS_SetSelectionFormat(format);
SelectionBar::Get( project ).SetSelectionFormat(format);
} }
const NumericFormatSymbol & AudacityProject::GetSelectionFormat() const const NumericFormatSymbol & AudacityProject::GetSelectionFormat() const
@ -3496,15 +3500,15 @@ bool AudacityProject::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
} }
else if (!wxStrcmp(attr, wxT("selectionformat"))) else if (!wxStrcmp(attr, wxT("selectionformat")))
SetSelectionFormat( AS_SetSelectionFormat(
NumericConverter::LookupFormat( NumericConverter::TIME, value) ); NumericConverter::LookupFormat( NumericConverter::TIME, value) );
else if (!wxStrcmp(attr, wxT("frequencyformat"))) else if (!wxStrcmp(attr, wxT("frequencyformat")))
SetFrequencySelectionFormatName( SSBL_SetFrequencySelectionFormatName(
NumericConverter::LookupFormat( NumericConverter::FREQUENCY, value ) ); NumericConverter::LookupFormat( NumericConverter::FREQUENCY, value ) );
else if (!wxStrcmp(attr, wxT("bandwidthformat"))) else if (!wxStrcmp(attr, wxT("bandwidthformat")))
SetBandwidthSelectionFormatName( SSBL_SetBandwidthSelectionFormatName(
NumericConverter::LookupFormat( NumericConverter::BANDWIDTH, value ) ); NumericConverter::LookupFormat( NumericConverter::BANDWIDTH, value ) );
} // while } // while

View File

@ -306,10 +306,6 @@ class AUDACITY_DLL_API TrackPanel final
void DisplaySelection(); void DisplaySelection();
// These two are neither used nor defined as of Nov-2011
// void SetSelectionFormat(int iformat)
// void SetSnapTo(int snapto)
void HandlePageUpKey(); void HandlePageUpKey();
void HandlePageDownKey(); void HandlePageDownKey();
AudacityProject * GetProject() const override; AudacityProject * GetProject() const override;

View File

@ -666,11 +666,15 @@ void SelectionBar::SetSnapTo(int snap)
void SelectionBar::SetSelectionFormat(const NumericFormatSymbol & format) void SelectionBar::SetSelectionFormat(const NumericFormatSymbol & format)
{ {
mStartTime->SetFormatString(mStartTime->GetBuiltinFormat(format)); bool changed =
mStartTime->SetFormatString(mStartTime->GetBuiltinFormat(format));
wxCommandEvent e; // Test first whether changed, to avoid infinite recursion from OnUpdate
e.SetInt(mStartTime->GetFormatIndex()); if ( changed ) {
OnUpdate(e); wxCommandEvent e;
e.SetInt(mStartTime->GetFormatIndex());
OnUpdate(e);
}
} }
void SelectionBar::SetRate(double rate) void SelectionBar::SetRate(double rate)

View File

@ -467,21 +467,27 @@ void SpectralSelectionBar::SetFrequencies(double bottom, double top)
void SpectralSelectionBar::SetFrequencySelectionFormatName(const NumericFormatSymbol & formatName) void SpectralSelectionBar::SetFrequencySelectionFormatName(const NumericFormatSymbol & formatName)
{ {
NumericTextCtrl *frequencyCtrl = (mbCenterAndWidth ? mCenterCtrl : mLowCtrl); NumericTextCtrl *frequencyCtrl = (mbCenterAndWidth ? mCenterCtrl : mLowCtrl);
frequencyCtrl->SetFormatName(formatName); bool changed =
frequencyCtrl->SetFormatName(formatName);
wxCommandEvent e(EVT_FREQUENCYTEXTCTRL_UPDATED); // Test first whether changed, to avoid infinite recursion from OnUpdate
e.SetInt(frequencyCtrl->GetFormatIndex()); if (changed) {
OnUpdate(e); wxCommandEvent e(EVT_FREQUENCYTEXTCTRL_UPDATED);
e.SetInt(frequencyCtrl->GetFormatIndex());
OnUpdate(e);
}
} }
void SpectralSelectionBar::SetBandwidthSelectionFormatName(const NumericFormatSymbol & formatName) void SpectralSelectionBar::SetBandwidthSelectionFormatName(const NumericFormatSymbol & formatName)
{ {
if (mbCenterAndWidth) { if (mbCenterAndWidth) {
mWidthCtrl->SetFormatName(formatName); bool changed =
mWidthCtrl->SetFormatName(formatName);
wxCommandEvent e(EVT_BANDWIDTHTEXTCTRL_UPDATED); // Test first whether changed, to avoid infinite recursion from OnUpdate
e.SetInt(mWidthCtrl->GetFormatIndex()); if (changed) {
OnUpdate(e); wxCommandEvent e(EVT_BANDWIDTHTEXTCTRL_UPDATED);
e.SetInt(mWidthCtrl->GetFormatIndex());
OnUpdate(e);
}
} }
} }

View File

@ -1051,17 +1051,23 @@ void NumericConverter::ControlsToValue()
mValue = std::max(mMinValue, std::min(mMaxValue, t)); mValue = std::max(mMinValue, std::min(mMaxValue, t));
} }
void NumericConverter::SetFormatName(const NumericFormatSymbol & formatName) bool NumericConverter::SetFormatName(const NumericFormatSymbol & formatName)
{ {
SetFormatString(GetBuiltinFormat(formatName)); return
SetFormatString(GetBuiltinFormat(formatName));
} }
void NumericConverter::SetFormatString(const wxString & formatString) bool NumericConverter::SetFormatString(const wxString & formatString)
{ {
mFormatString = formatString; if (mFormatString != formatString) {
ParseFormatString(mFormatString); mFormatString = formatString;
ValueToControls(); ParseFormatString(mFormatString);
ControlsToValue(); ValueToControls();
ControlsToValue();
return true;
}
else
return false;
} }
void NumericConverter::SetSampleRate(double sampleRate) void NumericConverter::SetSampleRate(double sampleRate)
@ -1366,19 +1372,24 @@ void NumericTextCtrl::UpdateAutoFocus()
} }
} }
void NumericTextCtrl::SetFormatName(const NumericFormatSymbol & formatName) bool NumericTextCtrl::SetFormatName(const NumericFormatSymbol & formatName)
{ {
SetFormatString(GetBuiltinFormat(formatName)); return
SetFormatString(GetBuiltinFormat(formatName));
} }
void NumericTextCtrl::SetFormatString(const wxString & formatString) bool NumericTextCtrl::SetFormatString(const wxString & formatString)
{ {
NumericConverter::SetFormatString(formatString); auto result =
Layout(); NumericConverter::SetFormatString(formatString);
Fit(); if (result) {
ValueToControls(); Layout();
ControlsToValue(); Fit();
UpdateAutoFocus(); ValueToControls();
ControlsToValue();
UpdateAutoFocus();
}
return result;
} }
void NumericTextCtrl::SetSampleRate(double sampleRate) void NumericTextCtrl::SetSampleRate(double sampleRate)

View File

@ -83,8 +83,13 @@ private:
public: public:
void PrintDebugInfo(); void PrintDebugInfo();
void SetFormatName(const NumericFormatSymbol & formatName);
void SetFormatString(const wxString & formatString); // returns true iff the format name really changed:
bool SetFormatName(const NumericFormatSymbol & formatName);
// returns true iff the format string really changed:
bool SetFormatString(const wxString & formatString);
void SetSampleRate(double sampleRate); void SetSampleRate(double sampleRate);
void SetValue(double newValue); void SetValue(double newValue);
void SetMinValue(double minValue); void SetMinValue(double minValue);
@ -187,8 +192,12 @@ 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 SetFormatName(const NumericFormatSymbol & formatName); // returns true iff the format string really changed:
bool SetFormatString(const wxString & formatString);
// returns true iff the format name really changed:
bool SetFormatName(const NumericFormatSymbol & formatName);
void SetFieldFocus(int /* digit */); void SetFieldFocus(int /* digit */);