From 78ec5cdf0b570cd6dbb5ce8150420685273ab37a Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Thu, 27 Aug 2015 14:18:25 -0400 Subject: [PATCH 1/3] Bug1161: maximum zoom-out in Waveform (dB) ruler should be +6.02 dB, not +2 dB --- src/TrackPanel.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index 0669c55e7..aeb857fd0 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -4713,15 +4713,20 @@ void TrackPanel::HandleWaveTrackVZoom } else { // Zoom out + const WaveformSettings &settings = track->GetWaveformSettings(); + const bool linear = settings.isLinear(); + const float top = linear + ? 2.0 + : (LINEAR_TO_DB(2.0) + settings.dBRange) / settings.dBRange; if (min <= -1.0 && max >= 1.0) { // Go to the maximal zoom-out - min = -2.0; - max = 2.0; + min = -top; + max = top; } else { // limit to +/- 1 range unless already outside that range... - float minRange = (min < -1) ? -2.0 : -1.0; - float maxRange = (max > 1) ? 2.0 : 1.0; + float minRange = (min < -1) ? -top : -1.0; + float maxRange = (max > 1) ? top : 1.0; // and enforce vertical zoom limits. const float p1 = (zoomStart - ypos) / (float)height; if (fixedMousePoint) { From 80d7ed36f04288c5a909bb4139a4d4c33f0a3b5d Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Thu, 27 Aug 2015 16:06:13 -0400 Subject: [PATCH 2/3] Bug1162: Be careful remapping db scale extremes, when the db limit value changes --- src/TrackArtist.cpp | 27 +++++++++++++++++++++++++++ src/WaveTrack.cpp | 7 +++++++ src/WaveTrack.h | 4 ++++ 3 files changed, 38 insertions(+) diff --git a/src/TrackArtist.cpp b/src/TrackArtist.cpp index 355466b27..61f3ff38b 100644 --- a/src/TrackArtist.cpp +++ b/src/TrackArtist.cpp @@ -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; diff --git a/src/WaveTrack.cpp b/src/WaveTrack.cpp index 9daee4877..16eecb496 100644 --- a/src/WaveTrack.cpp +++ b/src/WaveTrack.cpp @@ -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; diff --git a/src/WaveTrack.h b/src/WaveTrack.h index c21d7399e..b545c48c2 100644 --- a/src/WaveTrack.h +++ b/src/WaveTrack.h @@ -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; From 65b94d1fa540c6027565e0913ccd29a5ba9f6cdd Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Thu, 27 Aug 2015 16:51:08 -0400 Subject: [PATCH 3/3] travis --- src/TrackArtist.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TrackArtist.cpp b/src/TrackArtist.cpp index 61f3ff38b..d68b1d2b0 100644 --- a/src/TrackArtist.cpp +++ b/src/TrackArtist.cpp @@ -780,7 +780,7 @@ void TrackArtist::UpdateVRuler(Track *t, wxRect & rect) const float extreme = LINEAR_TO_DB(2); // recover dB value of max - const float dB = std::min(extreme, (fabs(max) * lastdBRange - lastdBRange)); + const float dB = std::min(extreme, (float(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);