From fb296d0206f19e1f80c523d30ced8aeb6cb5cb77 Mon Sep 17 00:00:00 2001 From: martynshaw99 Date: Tue, 31 Aug 2010 22:27:37 +0000 Subject: [PATCH] Make the SelectionBar match up better with what is visually selected in the tracks. Shows up when zoomed in to sample level and looking at Start and Length. --- src/toolbars/SelectionBar.cpp | 9 ++++++++- src/widgets/TimeTextCtrl.cpp | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/toolbars/SelectionBar.cpp b/src/toolbars/SelectionBar.cpp index 0abde8ad4..6584983e7 100644 --- a/src/toolbars/SelectionBar.cpp +++ b/src/toolbars/SelectionBar.cpp @@ -400,7 +400,14 @@ void SelectionBar::ValuesToControls() if (mRightEndButton->GetValue()) mRightTime->SetTimeValue(mEnd); else - mRightTime->SetTimeValue(mEnd - mStart); + { // mRightTime is the length. + // Be sure to take into account the sub-sample offset. + // See TimeToLongSamples and LongSamplesToTime but here at the project rate. + double t = (sampleCount)floor(mEnd * mRate + 0.5); + t -= (sampleCount)floor(mStart * mRate + 0.5); + t /= mRate; + mRightTime->SetTimeValue(t); + } mAudioTime->SetTimeValue(mAudio); } diff --git a/src/widgets/TimeTextCtrl.cpp b/src/widgets/TimeTextCtrl.cpp index 101e331fb..b7c6f3f97 100644 --- a/src/widgets/TimeTextCtrl.cpp +++ b/src/widgets/TimeTextCtrl.cpp @@ -1315,7 +1315,8 @@ void TimeTextCtrl::ValueToControls() void TimeConverter::ValueToControls( double RawTime ) { - double theValue = RawTime * mScalingFactor + .000001; + RawTime = (double)((sampleCount)floor(RawTime * mSampleRate + 0.5)) / mSampleRate; // put on a sample + double theValue = RawTime * mScalingFactor + .000001; // what's this .000001 for? int t_int = int(theValue); double t_frac = (theValue - t_int); unsigned int i;