Merge pull request #150 from RaphaelMarinier/optimize_selection_bar_update_master

Optimize the refresh of the selection bar while Audacity is playing.
This commit is contained in:
Paul Licameli 2016-08-15 22:04:42 -04:00 committed by GitHub
commit 1cad18c479
2 changed files with 23 additions and 1 deletions

View File

@ -1800,8 +1800,19 @@ void NumericTextCtrl::Updated(bool keyup /* = false */)
void NumericTextCtrl::ValueToControls()
{
const wxString previousValueString = mValueString;
NumericConverter::ValueToControls(mValue);
Refresh(false);
if (mValueString != previousValueString) {
// Doing this only when needed is an optimization.
// NumerixTextCtrls are used in the selection bar at the bottom
// of Audacity, and are updated at high frequency through
// SetValue() when Audacity is playing. This consumes a
// significant amount of CPU. Typically, when a track is
// playing, only one of the NumericTextCtrl actually changes
// (the audio position). We save CPU by updating the control
// only when needed.
Refresh(false);
}
}

View File

@ -66,9 +66,16 @@ public:
virtual ~NumericConverter();
// ValueToControls() formats a raw value (either provided as
// argument, or mValue, depending on the version of the function
// called). The result is stored to mValueString.
virtual void ValueToControls();
virtual void ValueToControls(double rawValue, bool nearest = true);
// Converts the stored formatted string (mValueString) back to a
// raw value (mValue).
virtual void ControlsToValue();
virtual void ParseFormatString(const wxString & format);
void PrintDebugInfo();
@ -115,6 +122,7 @@ protected:
wxString mPrefix;
wxString mValueTemplate;
wxString mValueMask;
// Formatted mValue, by ValueToControls().
wxString mValueString;
double mScalingFactor;
@ -181,6 +189,9 @@ private:
void OnFocus(wxFocusEvent &event);
void OnContext(wxContextMenuEvent &event);
// Formats mValue into mValueString, using the method of the base class.
// Triggers a refresh of the wx window only when the value actually
// changed since last time a refresh was triggered.
void ValueToControls() override;
void ControlsToValue() override;