mirror of
https://github.com/cookiengineer/audacity
synced 2025-11-21 16:37:12 +01:00
Eliminate some members from Ruler...
... Move some fields used only during formatting into a temporary structure. (And fixing a minor problem with uninitialized variables in case of logarithmic scale, which made it unpredictable how Plot Spectrum with logarithmic frequencely axis formatted numbers.)
This commit is contained in:
@@ -343,8 +343,19 @@ void Ruler::Invalidate()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ruler::FindLinearTickSizes(double UPP)
|
struct Ruler::TickSizes
|
||||||
{
|
{
|
||||||
|
|
||||||
|
double mMajor;
|
||||||
|
double mMinor;
|
||||||
|
|
||||||
|
int mDigits;
|
||||||
|
|
||||||
|
TickSizes( double UPP, int orientation, RulerFormat format, bool log )
|
||||||
|
{
|
||||||
|
//TODO: better dynamic digit computation for the log case
|
||||||
|
(void)log;
|
||||||
|
|
||||||
// Given the dimensions of the ruler, the range of values it
|
// Given the dimensions of the ruler, the range of values it
|
||||||
// has to display, and the format (i.e. Int, Real, Time),
|
// has to display, and the format (i.e. Int, Real, Time),
|
||||||
// figure out how many units are in one Minor tick, and
|
// figure out how many units are in one Minor tick, and
|
||||||
@@ -360,11 +371,11 @@ void Ruler::FindLinearTickSizes(double UPP)
|
|||||||
// minor tick. We want to show numbers like "-48"
|
// minor tick. We want to show numbers like "-48"
|
||||||
// in that space.
|
// in that space.
|
||||||
// If vertical, we don't need as much space.
|
// If vertical, we don't need as much space.
|
||||||
double units = ((mOrientation == wxHORIZONTAL) ? 22 : 16) * fabs(UPP);
|
double units = ((orientation == wxHORIZONTAL) ? 22 : 16) * fabs(UPP);
|
||||||
|
|
||||||
mDigits = 0;
|
mDigits = 0;
|
||||||
|
|
||||||
switch(mFormat) {
|
switch(format) {
|
||||||
case LinearDBFormat:
|
case LinearDBFormat:
|
||||||
if (units < 0.001) {
|
if (units < 0.001) {
|
||||||
mMinor = 0.001;
|
mMinor = 0.001;
|
||||||
@@ -576,7 +587,9 @@ void Ruler::FindLinearTickSizes(double UPP)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TranslatableString Ruler::LabelString(double d, bool major)
|
TranslatableString LabelString(
|
||||||
|
double d, bool major, RulerFormat format, const TranslatableString &units )
|
||||||
|
const
|
||||||
{
|
{
|
||||||
// Given a value, turn it into a string according
|
// Given a value, turn it into a string according
|
||||||
// to the current ruler format. The number of digits of
|
// to the current ruler format. The number of digits of
|
||||||
@@ -589,10 +602,10 @@ TranslatableString Ruler::LabelString(double d, bool major)
|
|||||||
// hour-minute-second, etc.?)
|
// hour-minute-second, etc.?)
|
||||||
|
|
||||||
// Replace -0 with 0
|
// Replace -0 with 0
|
||||||
if (d < 0.0 && (d+mMinor > 0.0) && ( mFormat != RealLogFormat ))
|
if (d < 0.0 && (d+mMinor > 0.0) && ( format != RealLogFormat ))
|
||||||
d = 0.0;
|
d = 0.0;
|
||||||
|
|
||||||
switch(mFormat) {
|
switch( format ) {
|
||||||
case IntFormat:
|
case IntFormat:
|
||||||
s.Printf(wxT("%d"), (int)floor(d+0.5));
|
s.Printf(wxT("%d"), (int)floor(d+0.5));
|
||||||
break;
|
break;
|
||||||
@@ -722,13 +735,16 @@ TranslatableString Ruler::LabelString(double d, bool major)
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto result = Verbatim( s );
|
auto result = Verbatim( s );
|
||||||
if (!mUnits.empty())
|
if (!units.empty())
|
||||||
result += mUnits;
|
result += units;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ruler::Tick(int pos, double d, bool major, bool minor)
|
}; // struct Ruler::TickSizes
|
||||||
|
|
||||||
|
void Ruler::Tick(
|
||||||
|
int pos, double d, bool major, bool minor, const TickSizes &tickSizes )
|
||||||
{
|
{
|
||||||
wxCoord strW, strH, strD, strL;
|
wxCoord strW, strH, strD, strL;
|
||||||
int strPos, strLen, strLeft, strTop;
|
int strPos, strLen, strLeft, strTop;
|
||||||
@@ -760,7 +776,7 @@ void Ruler::Tick(int pos, double d, bool major, bool minor)
|
|||||||
// Bug 521. dB view for waveforms needs a 2-sided scale.
|
// Bug 521. dB view for waveforms needs a 2-sided scale.
|
||||||
if(( mDbMirrorValue > 1.0 ) && ( -d > mDbMirrorValue ))
|
if(( mDbMirrorValue > 1.0 ) && ( -d > mDbMirrorValue ))
|
||||||
d = -2*mDbMirrorValue - d;
|
d = -2*mDbMirrorValue - d;
|
||||||
auto l = LabelString(d, major);
|
auto l = tickSizes.LabelString( d, major, mFormat, mUnits );
|
||||||
mDC->GetTextExtent(l.Translation(), &strW, &strH, &strD, &strL);
|
mDC->GetTextExtent(l.Translation(), &strW, &strH, &strD, &strL);
|
||||||
|
|
||||||
if (mOrientation == wxHORIZONTAL) {
|
if (mOrientation == wxHORIZONTAL) {
|
||||||
@@ -1084,16 +1100,17 @@ void Ruler::Update(const Envelope* envelope)// Envelope *speedEnv, long minSpeed
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if(mLog==false) {
|
}
|
||||||
|
else if( !mLog ) {
|
||||||
|
|
||||||
// Use the "hidden" min and max to determine the tick size.
|
// Use the "hidden" min and max to determine the tick size.
|
||||||
// That may make a difference with fisheye.
|
// That may make a difference with fisheye.
|
||||||
// Otherwise you may see the tick size for the whole ruler change
|
// Otherwise you may see the tick size for the whole ruler change
|
||||||
// when the fisheye approaches start or end.
|
// when the fisheye approaches start or end.
|
||||||
double UPP = (mHiddenMax-mHiddenMin)/mLength; // Units per pixel
|
double UPP = (mHiddenMax-mHiddenMin)/mLength; // Units per pixel
|
||||||
FindLinearTickSizes(UPP);
|
TickSizes tickSizes{ UPP, mOrientation, mFormat, false };
|
||||||
|
|
||||||
auto TickAtValue = [this, zoomInfo]( double value ) -> int {
|
auto TickAtValue = [this, zoomInfo, &tickSizes]( double value ) -> int {
|
||||||
// Make a tick only if the value is strictly between the bounds
|
// Make a tick only if the value is strictly between the bounds
|
||||||
if ( value <= std::min( mMin, mMax ) )
|
if ( value <= std::min( mMin, mMax ) )
|
||||||
return -1;
|
return -1;
|
||||||
@@ -1112,7 +1129,7 @@ void Ruler::Update(const Envelope* envelope)// Envelope *speedEnv, long minSpeed
|
|||||||
|
|
||||||
const int iMaxPos = (mOrientation == wxHORIZONTAL) ? mRight : mBottom - 5;
|
const int iMaxPos = (mOrientation == wxHORIZONTAL) ? mRight : mBottom - 5;
|
||||||
if (mid >= 0 && mid < iMaxPos)
|
if (mid >= 0 && mid < iMaxPos)
|
||||||
Tick(mid, value, true, false);
|
Tick( mid, value, true, false, tickSizes );
|
||||||
else
|
else
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@@ -1135,8 +1152,8 @@ void Ruler::Update(const Envelope* envelope)// Envelope *speedEnv, long minSpeed
|
|||||||
|
|
||||||
// Extreme values
|
// Extreme values
|
||||||
if (mLabelEdges) {
|
if (mLabelEdges) {
|
||||||
Tick(0, mMin, true, false);
|
Tick( 0, mMin, true, false, tickSizes );
|
||||||
Tick(mLength, mMax, true, false);
|
Tick( mLength, mMax, true, false, tickSizes );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !mDbMirrorValue ) {
|
if ( !mDbMirrorValue ) {
|
||||||
@@ -1149,7 +1166,7 @@ void Ruler::Update(const Envelope* envelope)// Envelope *speedEnv, long minSpeed
|
|||||||
int nDroppedMinorLabels=0;
|
int nDroppedMinorLabels=0;
|
||||||
// Major and minor ticks
|
// Major and minor ticks
|
||||||
for (int jj = 0; jj < 2; ++jj) {
|
for (int jj = 0; jj < 2; ++jj) {
|
||||||
const double denom = jj == 0 ? mMajor : mMinor;
|
const double denom = jj == 0 ? tickSizes.mMajor : tickSizes.mMinor;
|
||||||
i = -1; j = 0;
|
i = -1; j = 0;
|
||||||
double d, warpedD, nextD;
|
double d, warpedD, nextD;
|
||||||
|
|
||||||
@@ -1189,7 +1206,7 @@ void Ruler::Update(const Envelope* envelope)// Envelope *speedEnv, long minSpeed
|
|||||||
if (floor(sg * warpedD / denom) > step) {
|
if (floor(sg * warpedD / denom) > step) {
|
||||||
step = floor(sg * warpedD / denom);
|
step = floor(sg * warpedD / denom);
|
||||||
bool major = jj == 0;
|
bool major = jj == 0;
|
||||||
Tick(i, sg * step * denom, major, !major);
|
Tick( i, sg * step * denom, major, !major, tickSizes );
|
||||||
if( !major && mMinorLabels[mNumMinor-1].text.empty() ){
|
if( !major && mMinorLabels[mNumMinor-1].text.empty() ){
|
||||||
nDroppedMinorLabels++;
|
nDroppedMinorLabels++;
|
||||||
}
|
}
|
||||||
@@ -1210,8 +1227,8 @@ void Ruler::Update(const Envelope* envelope)// Envelope *speedEnv, long minSpeed
|
|||||||
|
|
||||||
// Left and Right Edges
|
// Left and Right Edges
|
||||||
if (mLabelEdges) {
|
if (mLabelEdges) {
|
||||||
Tick(0, mMin, true, false);
|
Tick( 0, mMin, true, false, tickSizes );
|
||||||
Tick(mLength, mMax, true, false);
|
Tick( mLength, mMax, true, false, tickSizes );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -1222,7 +1239,11 @@ void Ruler::Update(const Envelope* envelope)// Envelope *speedEnv, long minSpeed
|
|||||||
: NumberScale(nstLogarithmic, mMin, mMax)
|
: NumberScale(nstLogarithmic, mMin, mMax)
|
||||||
);
|
);
|
||||||
|
|
||||||
mDigits=2; //TODO: implement dynamic digit computation
|
double UPP = (mHiddenMax-mHiddenMin)/mLength; // Units per pixel
|
||||||
|
TickSizes tickSizes{ UPP, mOrientation, mFormat, true };
|
||||||
|
|
||||||
|
tickSizes.mDigits = 2; //TODO: implement dynamic digit computation
|
||||||
|
|
||||||
double loLog = log10(mMin);
|
double loLog = log10(mMin);
|
||||||
double hiLog = log10(mMax);
|
double hiLog = log10(mMax);
|
||||||
int loDecade = (int) floor(loLog);
|
int loDecade = (int) floor(loLog);
|
||||||
@@ -1240,7 +1261,7 @@ void Ruler::Update(const Envelope* envelope)// Envelope *speedEnv, long minSpeed
|
|||||||
{ val = decade;
|
{ val = decade;
|
||||||
if(val >= rMin && val < rMax) {
|
if(val >= rMin && val < rMax) {
|
||||||
const int pos(0.5 + mLength * numberScale.ValueToPosition(val));
|
const int pos(0.5 + mLength * numberScale.ValueToPosition(val));
|
||||||
Tick(pos, val, true, false);
|
Tick( pos, val, true, false, tickSizes );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
decade *= step;
|
decade *= step;
|
||||||
@@ -1260,7 +1281,7 @@ void Ruler::Update(const Envelope* envelope)// Envelope *speedEnv, long minSpeed
|
|||||||
val = decade * j;
|
val = decade * j;
|
||||||
if(val >= rMin && val < rMax) {
|
if(val >= rMin && val < rMax) {
|
||||||
const int pos(0.5 + mLength * numberScale.ValueToPosition(val));
|
const int pos(0.5 + mLength * numberScale.ValueToPosition(val));
|
||||||
Tick(pos, val, false, true);
|
Tick( pos, val, false, true, tickSizes );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
decade *= step;
|
decade *= step;
|
||||||
@@ -1282,7 +1303,7 @@ void Ruler::Update(const Envelope* envelope)// Envelope *speedEnv, long minSpeed
|
|||||||
val = decade * f / 10;
|
val = decade * f / 10;
|
||||||
if (val >= rMin && val < rMax) {
|
if (val >= rMin && val < rMax) {
|
||||||
const int pos(0.5 + mLength * numberScale.ValueToPosition(val));
|
const int pos(0.5 + mLength * numberScale.ValueToPosition(val));
|
||||||
Tick(pos, val, false, false);
|
Tick( pos, val, false, false, tickSizes );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,13 +152,13 @@ class AUDACITY_DLL_API Ruler {
|
|||||||
void Invalidate();
|
void Invalidate();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct TickSizes;
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
void Update(const Envelope* envelope);
|
void Update(const Envelope* envelope);
|
||||||
void FindTickSizes();
|
|
||||||
void FindLinearTickSizes(double UPP);
|
|
||||||
TranslatableString LabelString(double d, bool major);
|
|
||||||
|
|
||||||
void Tick(int pos, double d, bool major, bool minor);
|
void Tick(
|
||||||
|
int pos, double d, bool major, bool minor, const TickSizes &tickSizes );
|
||||||
|
|
||||||
// Another tick generator for custom ruler case (noauto) .
|
// Another tick generator for custom ruler case (noauto) .
|
||||||
void TickCustom(int labelIdx, bool major, bool minor);
|
void TickCustom(int labelIdx, bool major, bool minor);
|
||||||
@@ -184,11 +184,6 @@ private:
|
|||||||
double mMin, mMax;
|
double mMin, mMax;
|
||||||
double mHiddenMin, mHiddenMax;
|
double mHiddenMin, mHiddenMax;
|
||||||
|
|
||||||
double mMajor;
|
|
||||||
double mMinor;
|
|
||||||
|
|
||||||
int mDigits;
|
|
||||||
|
|
||||||
ArrayOf<int> mUserBits;
|
ArrayOf<int> mUserBits;
|
||||||
ArrayOf<int> mBits;
|
ArrayOf<int> mBits;
|
||||||
int mUserBitLen;
|
int mUserBitLen;
|
||||||
|
|||||||
Reference in New Issue
Block a user