diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index f4c204f47..74e4f1696 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -2626,12 +2626,14 @@ void TrackPanel::StartSlide(wxMouseEvent & event) Track *partner = mTracks->GetLink(vt); if (mCapturedClip && partner && partner->GetKind() == Track::Wave) { // WaveClip::GetClipAtX doesn't work unless the clip is on the screen and can return bad info otherwise - // vt is guaranteed to be onscreen, so we ask for the approx. time at that point - - sampleCount xSample = mCapturedClip->GetSampleNumberAtX(event.m_x); - - if (xSample >= 0) { - WaveClip *clip = ((WaveTrack *)partner)->GetClipAtSample(xSample); + // instead calculate the time manually + double rate = ((WaveTrack*)partner)->GetRate(); + double pps = mViewInfo->zoom; + double tt = (event.m_x - GetLeftOffset()) / pps + mViewInfo->h; + sampleCount s0 = (sampleCount)(tt * rate + 0.5); + + if (s0 >= 0) { + WaveClip *clip = ((WaveTrack *)partner)->GetClipAtSample(s0); if (clip) { mCapturedClipArray.Add(TrackClip(partner, clip)); } diff --git a/src/WaveClip.cpp b/src/WaveClip.cpp index 3a158d28c..d167f0ddc 100644 --- a/src/WaveClip.cpp +++ b/src/WaveClip.cpp @@ -1030,18 +1030,6 @@ void WaveClip::GetDisplayRect(wxRect* r) *r = mDisplayRect; } -// only works if the clip is on screen an mDisplayRect is set. -sampleCount WaveClip::GetSampleNumberAtX(int xcoord) -{ - if (mDisplayRect.width > 0 && - xcoord >= mDisplayRect.x && xcoord < mDisplayRect.x + mDisplayRect.width) { - float cursor = (xcoord - mDisplayRect.x) / mDisplayRect.width; - return GetStartSample() + GetNumSamples() * cursor; - } - - return -1; -} - bool WaveClip::Append(samplePtr buffer, sampleFormat format, sampleCount len, unsigned int stride /* = 1 */, XMLWriter* blockFileLog /*=NULL*/) diff --git a/src/WaveClip.h b/src/WaveClip.h index dd63f95ea..98274c413 100644 --- a/src/WaveClip.h +++ b/src/WaveClip.h @@ -152,9 +152,6 @@ public: void ClearDisplayRect(); void SetDisplayRect(const wxRect& r); void GetDisplayRect(wxRect* r); - /// Get the absolute sample number at the x pixel specified by xcoord. - /// Only works if the clip is onscreen (returned by WaveTrack::GetClipAtX) - sampleCount GetSampleNumberAtX(int xcoord); /** Whenever you do an operation to the sequence that will change the number * of samples (that is, the length of the clip), you will want to call this