1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-03 17:19:43 +02:00

Bug1162: Be careful remapping db scale extremes, when the db limit value changes

This commit is contained in:
Paul Licameli 2015-08-27 16:06:13 -04:00
parent 78ec5cdf0b
commit 80d7ed36f0
3 changed files with 38 additions and 0 deletions

View File

@ -708,6 +708,7 @@ void TrackArtist::UpdateVRuler(Track *t, wxRect & rect)
{
// do a translation into the linear space
wt->SetLastScaleType();
wt->SetLastdBRange();
float sign = (min >= 0 ? 1 : -1);
if (min != 0.) {
min = DB_TO_LINEAR(fabs(min) * dBRange - dBRange);
@ -742,12 +743,14 @@ void TrackArtist::UpdateVRuler(Track *t, wxRect & rect)
float min, max;
wt->GetDisplayBounds(&min, &max);
float lastdBRange;
if (wt->GetLastScaleType() != scaleType &&
wt->GetLastScaleType() != -1)
{
// do a translation into the dB space
wt->SetLastScaleType();
wt->SetLastdBRange();
float sign = (min >= 0 ? 1 : -1);
if (min != 0.) {
min = (LINEAR_TO_DB(fabs(min)) + dBRange) / dBRange;
@ -765,6 +768,30 @@ void TrackArtist::UpdateVRuler(Track *t, wxRect & rect)
}
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;
if (max != 0.) {
// Ugh, duplicating from TrackPanel.cpp
#define ZOOMLIMIT 0.001f
const float extreme = LINEAR_TO_DB(2);
// recover dB value of max
const float dB = std::min(extreme, (fabs(max) * lastdBRange - lastdBRange));
// find new scale position, but old max may get trimmed if the db limit rises
// Don't trim it to zero though, but leave max and limit distinct
newMax = sign * std::max(ZOOMLIMIT, (dBRange + dB) / dBRange);
// Adjust the min of the scale if we can,
// so the db Limit remains where it was on screen, but don't violate extremes
if (min != 0.)
min = std::max(-extreme, newMax * min / max);
}
wt->SetDisplayBounds(min, newMax);
}
if (max > 0) {
int top = 0;

View File

@ -109,6 +109,7 @@ WaveTrack::WaveTrack(DirManager *projDirManager, sampleFormat format, double rat
mDisplayLocations = NULL;
mDisplayNumLocationsAllocated = 0;
mLastScaleType = -1;
mLastdBRange = -1;
mAutoSaveIdent = 0;
}
@ -121,6 +122,7 @@ WaveTrack::WaveTrack(WaveTrack &orig):
? new WaveformSettings(*orig.mpWaveformSettings) : 0)
{
mLastScaleType = -1;
mLastdBRange = -1;
mLegacyProjectFileOffset = 0;
@ -288,6 +290,11 @@ void WaveTrack::SetLastScaleType()
mLastScaleType = GetWaveformSettings().scaleType;
}
void WaveTrack::SetLastdBRange()
{
mLastdBRange = GetWaveformSettings().dBRange;
}
void WaveTrack::GetDisplayBounds(float *min, float *max)
{
*min = mDisplayMin;

View File

@ -435,6 +435,9 @@ class AUDACITY_DLL_API WaveTrack : public Track {
int GetLastScaleType() { return mLastScaleType; }
void SetLastScaleType();
int GetLastdBRange() { return mLastdBRange; }
void SetLastdBRange();
WaveTrackDisplay GetDisplay() const { return mDisplay; }
void SetDisplay(WaveTrackDisplay display) { mDisplay = display; }
@ -463,6 +466,7 @@ class AUDACITY_DLL_API WaveTrack : public Track {
float mDisplayMax;
WaveTrackDisplay mDisplay;
int mLastScaleType; // last scale type choice
int mLastdBRange;
int mDisplayNumLocations;
int mDisplayNumLocationsAllocated;
Location* mDisplayLocations;