From c84eeabe9721ecc6b4e81d1cc7a44a6167b9ce5d Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Thu, 28 May 2015 20:22:42 -0400 Subject: [PATCH] Bug 986 and other changes for more consistent zoom all and zoom fit... ... when there is audio before time zero. --- src/Menus.cpp | 17 ++++++++++++----- src/Project.cpp | 20 ++++++++++++-------- src/Project.h | 1 + 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/Menus.cpp b/src/Menus.cpp index d8b755636..65f3fe65c 100755 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -4986,7 +4986,11 @@ void AudacityProject::OnZoomNormal() void AudacityProject::OnZoomFit() { - double len = mTracks->GetEndTime(); + const double end = mTracks->GetEndTime(); + const double start = mScrollBeyondZero + ? std::min(mTracks->GetStartTime(), 0.0) + : 0; + const double len = end - start; if (len <= 0.0) return; @@ -4996,7 +5000,7 @@ void AudacityProject::OnZoomFit() w -= 10; Zoom(w / len); - TP_ScrollWindow(0.0); + TP_ScrollWindow(start); } void AudacityProject::DoZoomFitV() @@ -5049,7 +5053,11 @@ void AudacityProject::OnZoomFitV() void AudacityProject::OnZoomSel() { - if (mViewInfo.selectedRegion.isPoint()) + const double lowerBound = + std::max(mViewInfo.selectedRegion.t0(), ScrollingLowerBoundTime()); + const double denom = + mViewInfo.selectedRegion.t1() - lowerBound; + if (denom <= 0.0) return; // LL: The "-1" is just a hack to get around an issue where zooming to @@ -5058,8 +5066,7 @@ void AudacityProject::OnZoomSel() // where the selected region may be scrolled off the left of the screen. // I know this isn't right, but until the real rounding or 1-off issue is // found, this will have to work. - Zoom(((mViewInfo.zoom * mViewInfo.screen) - 1) / - (mViewInfo.selectedRegion.t1() - mViewInfo.selectedRegion.t0())); + Zoom(((mViewInfo.zoom * mViewInfo.screen) - 1) / denom); TP_ScrollWindow(mViewInfo.selectedRegion.t0()); } diff --git a/src/Project.cpp b/src/Project.cpp index 10ebf11f9..c7b524dd6 100755 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -1459,9 +1459,16 @@ void AudacityProject::OnScrollRightButton(wxScrollEvent & event) } +double AudacityProject::ScrollingLowerBoundTime() const +{ + return mScrollBeyondZero + ? std::min(mTracks->GetStartTime(), -mViewInfo.screen / 2.0) + : 0; +} + void AudacityProject::SetHorizontalThumb(double scrollto) { - const double timeOffset = mScrollBeyondZero ? mViewInfo.screen / 2.0 : 0; + const double timeOffset = -ScrollingLowerBoundTime(); int pos = (int) ( (scrollto + timeOffset) * mViewInfo.zoom * mViewInfo.sbarScale ); @@ -1544,10 +1551,10 @@ void AudacityProject::FixScrollbars() // so that any point within the union of the selection and the track duration // may be scrolled to the midline. // May add even more to the end, so that you can always scroll the starting time to zero. + const double lowerBound = ScrollingLowerBoundTime(); const double additional = mScrollBeyondZero - ? halfScreen + std::max(halfScreen, mViewInfo.screen - LastTime) + ? -lowerBound + std::max(halfScreen, mViewInfo.screen - LastTime) : mViewInfo.screen / 4.0; - const double lowerBound = mScrollBeyondZero ? -halfScreen : 0.0; mViewInfo.total = LastTime + additional; @@ -1823,11 +1830,8 @@ void AudacityProject::OnScroll(wxScrollEvent & WXUNUSED(event)) { const wxInt64 hlast = mViewInfo.sbarH; - const wxInt64 offset = mScrollBeyondZero - ? (0.5 + (mViewInfo.zoom * mViewInfo.screen / 2.0)) - : 0.0; - const double lowerBound = mScrollBeyondZero - ? -mViewInfo.screen / 2.0 : 0.0; + const double lowerBound = ScrollingLowerBoundTime(); + const wxInt64 offset = 0.5 + -lowerBound * mViewInfo.zoom; mViewInfo.sbarH = (wxInt64)(mHsbar->GetThumbPosition() / mViewInfo.sbarScale) - offset; diff --git a/src/Project.h b/src/Project.h index 19c38d9b5..05353bbaa 100755 --- a/src/Project.h +++ b/src/Project.h @@ -348,6 +348,7 @@ class AUDACITY_DLL_API AudacityProject: public wxFrame, void SafeDisplayStatusMessage(const wxChar *msg); + double ScrollingLowerBoundTime() const; void SetHorizontalThumb(double scrollto); // TrackPanel access