1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-09-19 09:30:52 +02:00

Bug 986 and other changes for more consistent zoom all and zoom fit...

... when there is audio before time zero.
This commit is contained in:
Paul Licameli 2015-05-28 20:22:42 -04:00
parent 6e1f76d60d
commit c84eeabe97
3 changed files with 25 additions and 13 deletions

View File

@ -4986,7 +4986,11 @@ void AudacityProject::OnZoomNormal()
void AudacityProject::OnZoomFit() 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) if (len <= 0.0)
return; return;
@ -4996,7 +5000,7 @@ void AudacityProject::OnZoomFit()
w -= 10; w -= 10;
Zoom(w / len); Zoom(w / len);
TP_ScrollWindow(0.0); TP_ScrollWindow(start);
} }
void AudacityProject::DoZoomFitV() void AudacityProject::DoZoomFitV()
@ -5049,7 +5053,11 @@ void AudacityProject::OnZoomFitV()
void AudacityProject::OnZoomSel() 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; return;
// LL: The "-1" is just a hack to get around an issue where zooming to // 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. // 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 // I know this isn't right, but until the real rounding or 1-off issue is
// found, this will have to work. // found, this will have to work.
Zoom(((mViewInfo.zoom * mViewInfo.screen) - 1) / Zoom(((mViewInfo.zoom * mViewInfo.screen) - 1) / denom);
(mViewInfo.selectedRegion.t1() - mViewInfo.selectedRegion.t0()));
TP_ScrollWindow(mViewInfo.selectedRegion.t0()); TP_ScrollWindow(mViewInfo.selectedRegion.t0());
} }

View File

@ -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) void AudacityProject::SetHorizontalThumb(double scrollto)
{ {
const double timeOffset = mScrollBeyondZero ? mViewInfo.screen / 2.0 : 0; const double timeOffset = -ScrollingLowerBoundTime();
int pos = (int) ( int pos = (int) (
(scrollto + timeOffset) * mViewInfo.zoom * mViewInfo.sbarScale (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 // so that any point within the union of the selection and the track duration
// may be scrolled to the midline. // may be scrolled to the midline.
// May add even more to the end, so that you can always scroll the starting time to zero. // 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 const double additional = mScrollBeyondZero
? halfScreen + std::max(halfScreen, mViewInfo.screen - LastTime) ? -lowerBound + std::max(halfScreen, mViewInfo.screen - LastTime)
: mViewInfo.screen / 4.0; : mViewInfo.screen / 4.0;
const double lowerBound = mScrollBeyondZero ? -halfScreen : 0.0;
mViewInfo.total = LastTime + additional; mViewInfo.total = LastTime + additional;
@ -1823,11 +1830,8 @@ void AudacityProject::OnScroll(wxScrollEvent & WXUNUSED(event))
{ {
const wxInt64 hlast = mViewInfo.sbarH; const wxInt64 hlast = mViewInfo.sbarH;
const wxInt64 offset = mScrollBeyondZero const double lowerBound = ScrollingLowerBoundTime();
? (0.5 + (mViewInfo.zoom * mViewInfo.screen / 2.0)) const wxInt64 offset = 0.5 + -lowerBound * mViewInfo.zoom;
: 0.0;
const double lowerBound = mScrollBeyondZero
? -mViewInfo.screen / 2.0 : 0.0;
mViewInfo.sbarH = mViewInfo.sbarH =
(wxInt64)(mHsbar->GetThumbPosition() / mViewInfo.sbarScale) - offset; (wxInt64)(mHsbar->GetThumbPosition() / mViewInfo.sbarScale) - offset;

View File

@ -348,6 +348,7 @@ class AUDACITY_DLL_API AudacityProject: public wxFrame,
void SafeDisplayStatusMessage(const wxChar *msg); void SafeDisplayStatusMessage(const wxChar *msg);
double ScrollingLowerBoundTime() const;
void SetHorizontalThumb(double scrollto); void SetHorizontalThumb(double scrollto);
// TrackPanel access // TrackPanel access