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

Bug 521 - Lower half of Waveform (dB) vertical scale does not show dB level.

Added a DbMirrorValue for two sided dB scale on Waveform VRuler when in dB view mode.
This commit is contained in:
James Crook 2018-03-24 20:32:28 +00:00
parent 37541de6be
commit 8ce8e7bcce
3 changed files with 32 additions and 5 deletions

View File

@ -702,6 +702,7 @@ void TrackArtist::UpdateVRuler(const Track *t, wxRect & rect)
min = tt->GetRangeLower() * 100.0;
max = tt->GetRangeUpper() * 100.0;
vruler->SetDbMirrorValue( 0.0 );
vruler->SetBounds(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height-1);
vruler->SetOrientation(wxVERTICAL);
vruler->SetRange(max, min);
@ -753,6 +754,7 @@ void TrackArtist::UpdateVRuler(const Track *t, wxRect & rect)
wt->SetDisplayBounds(min, max);
}
vruler->SetDbMirrorValue( 0.0 );
vruler->SetBounds(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height - 1);
vruler->SetOrientation(wxVERTICAL);
vruler->SetRange(max, min);
@ -792,13 +794,17 @@ void TrackArtist::UpdateVRuler(const Track *t, wxRect & rect)
max = 0.0;
max *= sign;
}
wt->SetDisplayBounds(min, max);
wt->SetDisplayBounds(min, max );
}
else if (dBRange != (lastdBRange = wt->GetLastdBRange())) {
wt->SetLastdBRange();
// Remap the max of the scale
const float sign = (max >= 0 ? 1 : -1);
float newMax = max;
// This commented out code is problematic.
// min and max may be correct, and this code cause them to change.
#ifdef ONLY_LABEL_POSITIVE
if (max != 0.) {
// Ugh, duplicating from TrackPanel.cpp
@ -815,16 +821,24 @@ void TrackArtist::UpdateVRuler(const Track *t, wxRect & rect)
if (min != 0.)
min = std::max(-extreme, newMax * min / max);
}
wt->SetDisplayBounds(min, newMax);
#endif
wt->SetDisplayBounds(min, newMax );
}
// Old code was if ONLY_LABEL_POSITIVE were defined.
// it uses the +1 to 0 range only.
// the enabled code uses +1 to -1, and relies on set ticks labelling knowing about
// the dB scale.
#ifdef ONLY_LABEL_POSITIVE
if (max > 0) {
#endif
int top = 0;
float topval = 0;
int bot = rect.height;
float botval = -dBRange;
#ifdef ONLY_LABEL_POSITIVE
if (min < 0) {
bot = top + (int)((max / (max - min))*(bot - top));
min = 0;
@ -841,13 +855,19 @@ void TrackArtist::UpdateVRuler(const Track *t, wxRect & rect)
if (min > 0) {
botval = -((1 - min) * dBRange);
}
#else
topval = -((1 - max) * dBRange);
botval = -((1 - min) * dBRange);
vruler->SetDbMirrorValue( dBRange );
#endif
vruler->SetBounds(rect.x, rect.y + top, rect.x + rect.width, rect.y + bot - 1);
vruler->SetOrientation(wxVERTICAL);
vruler->SetRange(topval, botval);
#ifdef ONLY_LABEL_POSITIVE
}
else
vruler->SetBounds(0.0, 0.0, 0.0, 0.0); // A.C.H I couldn't find a way to just disable it?
#endif
vruler->SetFormat(Ruler::RealLogFormat);
vruler->SetLabelEdges(true);
vruler->SetLog(false);
@ -858,6 +878,7 @@ void TrackArtist::UpdateVRuler(const Track *t, wxRect & rect)
const SpectrogramSettings &settings = wt->GetSpectrogramSettings();
float minFreq, maxFreq;
wt->GetSpectrumBounds(&minFreq, &maxFreq);
vruler->SetDbMirrorValue( 0.0 );
switch (settings.scaleType) {
default:

View File

@ -139,6 +139,7 @@ Ruler::Ruler()
mbTicksAtExtremes = false;
mTickColour = wxColour( theTheme.Colour( clrTrackPanelText ));
mPen.SetColour(mTickColour);
mDbMirrorValue = 0.0;
// Note: the font size is now adjusted automatically whenever
// Invalidate is called on a horizontal Ruler, unless the user
@ -768,7 +769,7 @@ void Ruler::Tick(int pos, double d, bool major, bool minor)
wxCoord strW, strH, strD, strL;
int strPos, strLen, strLeft, strTop;
// FIXME: We don't draw a tick if of end of our label arrays
// FIXME: We don't draw a tick if off end of our label arrays
// But we shouldn't have an array of labels.
if( mNumMinorMinor >= mLength )
return;
@ -792,6 +793,9 @@ void Ruler::Tick(int pos, double d, bool major, bool minor)
label->text = wxT("");
mDC->SetFont(major? *mMajorFont: minor? *mMinorFont : *mMinorMinorFont);
// Bug 521. dB view for waveforms needs a 2-sided scale.
if(( mDbMirrorValue > 1.0 ) && ( -d > mDbMirrorValue ))
d = -2*mDbMirrorValue - d;
l = LabelString(d, major);
mDC->GetTextExtent(l, &strW, &strH, &strD, &strL);

View File

@ -81,6 +81,7 @@ class AUDACITY_DLL_API Ruler {
// Specify the name of the units (like "dB") if you
// want numbers like "1.6" formatted as "1.6 dB".
void SetUnits(const wxString &units);
void SetDbMirrorValue( const double d ){ mDbMirrorValue = d ; };
// Logarithmic
void SetLog(bool log);
@ -223,6 +224,7 @@ private:
private:
int mOrientation;
int mSpacing;
double mDbMirrorValue;
bool mHasSetSpacing;
bool mLabelEdges;
RulerFormat mFormat;