1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-08 16:37:44 +02:00

Remove indirection storing number scale in Ruler

This commit is contained in:
Paul Licameli 2020-01-23 12:52:36 -05:00
parent fec3b11674
commit 21306d6186
5 changed files with 20 additions and 25 deletions

View File

@ -24,6 +24,7 @@ enum NumberScaleType {
nstPeriod, nstPeriod,
nstNumScaleTypes, nstNumScaleTypes,
nstNone,
}; };
@ -31,7 +32,7 @@ class NumberScale
{ {
public: public:
NumberScale() NumberScale()
: mType(nstLinear), mValue0(0), mValue1(1) : mType(nstNone), mValue0(0), mValue1(1)
{} {}
NumberScale(NumberScaleType type, float value0, float value1) NumberScale(NumberScaleType type, float value0, float value1)
@ -39,6 +40,7 @@ public:
{ {
switch (mType) { switch (mType) {
case nstLinear: case nstLinear:
case nstNone:
{ {
mValue0 = value0; mValue0 = value0;
mValue1 = value1; mValue1 = value1;
@ -156,6 +158,7 @@ public:
default: default:
wxASSERT(false); wxASSERT(false);
case nstLinear: case nstLinear:
case nstNone:
return mValue0 + pp * (mValue1 - mValue0); return mValue0 + pp * (mValue1 - mValue0);
case nstLogarithmic: case nstLogarithmic:
return exp(mValue0 + pp * (mValue1 - mValue0)); return exp(mValue0 + pp * (mValue1 - mValue0));
@ -186,6 +189,7 @@ public:
default: default:
wxASSERT(false); wxASSERT(false);
case nstLinear: case nstLinear:
case nstNone:
case nstLogarithmic: case nstLogarithmic:
return mValue; return mValue;
case nstMel: case nstMel:
@ -203,6 +207,7 @@ public:
{ {
switch (mType) { switch (mType) {
case nstLinear: case nstLinear:
case nstNone:
case nstMel: case nstMel:
case nstBark: case nstBark:
case nstErb: case nstErb:
@ -230,6 +235,7 @@ public:
default: default:
wxASSERT(false); wxASSERT(false);
case nstLinear: case nstLinear:
case nstNone:
case nstMel: case nstMel:
case nstBark: case nstBark:
case nstErb: case nstErb:
@ -253,6 +259,7 @@ public:
default: default:
wxASSERT(false); wxASSERT(false);
case nstLinear: case nstLinear:
case nstNone:
return ((val - mValue0) / (mValue1 - mValue0)); return ((val - mValue0) / (mValue1 - mValue0));
case nstLogarithmic: case nstLogarithmic:
return ((log(val) - mValue0) / (mValue1 - mValue0)); return ((log(val) - mValue0) / (mValue1 - mValue0));

View File

@ -193,7 +193,7 @@ void SpectrumVRulerControls::DoUpdateVRuler(
NumberScale scale( NumberScale scale(
wt->GetSpectrogramSettings().GetScale( minFreq, maxFreq ) wt->GetSpectrogramSettings().GetScale( minFreq, maxFreq )
.Reversal() ); .Reversal() );
vruler->SetNumberScale(&scale); vruler->SetNumberScale(scale);
} }
break; break;
} }

View File

@ -120,7 +120,6 @@ void WaveformVZoomHandle::DoZoom(
const float halfrate = rate / 2; const float halfrate = rate / 2;
float maxFreq = 8000.0; float maxFreq = 8000.0;
const SpectrogramSettings &specSettings = pTrack->GetSpectrogramSettings(); const SpectrogramSettings &specSettings = pTrack->GetSpectrogramSettings();
NumberScale scale;
bool bDragZoom = WaveTrackVZoomHandle::IsDragZooming(zoomStart, zoomEnd); bool bDragZoom = WaveTrackVZoomHandle::IsDragZooming(zoomStart, zoomEnd);
// Add 100 if spectral to separate the kinds of zoom. // Add 100 if spectral to separate the kinds of zoom.

View File

@ -78,7 +78,6 @@ using std::max;
// //
Ruler::Ruler() Ruler::Ruler()
: mpNumberScale{}
{ {
mMin = mHiddenMin = 0.0; mMin = mHiddenMin = 0.0;
mMax = mHiddenMax = 100.0; mMax = mHiddenMax = 100.0;
@ -290,21 +289,13 @@ void Ruler::SetFonts(const wxFont &minorFont, const wxFont &majorFont, const wxF
Invalidate(); Invalidate();
} }
void Ruler::SetNumberScale(const NumberScale *pScale) void Ruler::SetNumberScale(const NumberScale &scale)
{ {
if (!pScale) { if ( mNumberScale != scale ) {
if (mpNumberScale) { mNumberScale = scale;
mpNumberScale.reset();
Invalidate(); Invalidate();
} }
} }
else {
if (!mpNumberScale || *mpNumberScale != *pScale) {
mpNumberScale = std::make_unique<NumberScale>(*pScale);
Invalidate();
}
}
}
void Ruler::OfflimitsPixels(int start, int end) void Ruler::OfflimitsPixels(int start, int end)
{ {
@ -886,7 +877,7 @@ struct Ruler::Updater {
const double mMin = mRuler.mMin; const double mMin = mRuler.mMin;
const double mMax = mRuler.mMax; const double mMax = mRuler.mMax;
const int mLeftOffset = mRuler.mLeftOffset; const int mLeftOffset = mRuler.mLeftOffset;
const NumberScale *mpNumberScale = mRuler.mpNumberScale.get(); const NumberScale mNumberScale = mRuler.mNumberScale;
struct TickOutputs; struct TickOutputs;
@ -1189,10 +1180,9 @@ void Ruler::Updater::Update(
else { else {
// log case // log case
NumberScale numberScale(mpNumberScale auto numberScale = ( mNumberScale == NumberScale{} )
? *mpNumberScale ? NumberScale( nstLogarithmic, mMin, mMax )
: NumberScale(nstLogarithmic, mMin, mMax) : mNumberScale;
);
double UPP = (mHiddenMax-mHiddenMin)/mLength; // Units per pixel double UPP = (mHiddenMax-mHiddenMin)/mLength; // Units per pixel
TickSizes tickSizes{ UPP, mOrientation, mFormat, true }; TickSizes tickSizes{ UPP, mOrientation, mFormat, true };

View File

@ -12,6 +12,7 @@
#define __AUDACITY_RULER__ #define __AUDACITY_RULER__
#include "wxPanelWrapper.h" // to inherit #include "wxPanelWrapper.h" // to inherit
#include "../NumberScale.h" // member variable
#include <wx/colour.h> // member variable #include <wx/colour.h> // member variable
#include <wx/pen.h> // member variable #include <wx/pen.h> // member variable
@ -20,7 +21,6 @@ class wxArrayString;
class wxDC; class wxDC;
class wxFont; class wxFont;
class NumberScale;
class Envelope; class Envelope;
class ZoomInfo; class ZoomInfo;
@ -105,8 +105,7 @@ class AUDACITY_DLL_API Ruler {
Fonts GetFonts() const Fonts GetFonts() const
{ return mFonts; } { return mFonts; }
// Copies *pScale if it is not NULL void SetNumberScale(const NumberScale &scale);
void SetNumberScale(const NumberScale *pScale);
// The ruler will not draw text within this (pixel) range. // The ruler will not draw text within this (pixel) range.
// Use this if you have another graphic object obscuring part // Use this if you have another graphic object obscuring part
@ -230,7 +229,7 @@ private:
const ZoomInfo *mUseZoomInfo; const ZoomInfo *mUseZoomInfo;
int mLeftOffset; int mLeftOffset;
std::unique_ptr<NumberScale> mpNumberScale; NumberScale mNumberScale;
}; };
class AUDACITY_DLL_API RulerPanel final : public wxPanelWrapper { class AUDACITY_DLL_API RulerPanel final : public wxPanelWrapper {