diff --git a/src/WaveClip.cpp b/src/WaveClip.cpp index 9567281fe..83d027e02 100644 --- a/src/WaveClip.cpp +++ b/src/WaveClip.cpp @@ -1187,22 +1187,6 @@ void WaveClip::TimeToSamplesClip(double t0, sampleCount *s0) const *s0 = sampleCount( floor(((t0 - mOffset) * mRate) + 0.5) ); } -void WaveClip::ClearDisplayRect() const -{ - mDisplayRect.x = mDisplayRect.y = -1; - mDisplayRect.width = mDisplayRect.height = -1; -} - -void WaveClip::SetDisplayRect(const wxRect& r) const -{ - mDisplayRect = r; -} - -void WaveClip::GetDisplayRect(wxRect* r) -{ - *r = mDisplayRect; -} - /*! @excsafety{Strong} */ std::shared_ptr WaveClip::AppendNewBlock( samplePtr buffer, sampleFormat format, size_t len) diff --git a/src/WaveClip.h b/src/WaveClip.h index b5e5b2ae2..6eaf54863 100644 --- a/src/WaveClip.h +++ b/src/WaveClip.h @@ -272,12 +272,6 @@ public: double t0, double t1, bool mayThrow = true) const; float GetRMS(double t0, double t1, bool mayThrow = true) const; - // Set/clear/get rectangle that this WaveClip fills on screen. This is - // called by TrackArtist while actually drawing the tracks and clips. - void ClearDisplayRect() const; - void SetDisplayRect(const wxRect& r) const; - void GetDisplayRect(wxRect* r); - /** 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 * function to tell the envelope about it. */ @@ -366,8 +360,6 @@ public: mutable std::unique_ptr mSpecPxCache; protected: - mutable wxRect mDisplayRect {}; - double mOffset { 0 }; int mRate; int mDirty { 0 }; diff --git a/src/WaveTrack.cpp b/src/WaveTrack.cpp index 9ef8c9822..784e1ff37 100644 --- a/src/WaveTrack.cpp +++ b/src/WaveTrack.cpp @@ -2069,19 +2069,6 @@ void WaveTrack::GetEnvelopeValues(double *buffer, size_t bufferLen, } } -WaveClip* WaveTrack::GetClipAtX(int xcoord) -{ - for (const auto &clip: mClips) - { - wxRect r; - clip->GetDisplayRect(&r); - if (xcoord >= r.x && xcoord < r.x+r.width) - return clip.get(); - } - - return NULL; -} - WaveClip* WaveTrack::GetClipAtSample(sampleCount sample) { for (const auto &clip: mClips) @@ -2119,18 +2106,18 @@ WaveClip* WaveTrack::GetClipAtTime(double time) return p != clips.rend() ? *p : nullptr; } -Envelope* WaveTrack::GetEnvelopeAtX(int xcoord) +Envelope* WaveTrack::GetEnvelopeAtTime(double time) { - WaveClip* clip = GetClipAtX(xcoord); + WaveClip* clip = GetClipAtTime(time); if (clip) return clip->GetEnvelope(); else return NULL; } -Sequence* WaveTrack::GetSequenceAtX(int xcoord) +Sequence* WaveTrack::GetSequenceAtTime(double time) { - WaveClip* clip = GetClipAtX(xcoord); + WaveClip* clip = GetClipAtTime(time); if (clip) return clip->GetSequence(); else diff --git a/src/WaveTrack.h b/src/WaveTrack.h index e48fc65b6..45fe8e970 100644 --- a/src/WaveTrack.h +++ b/src/WaveTrack.h @@ -271,12 +271,11 @@ private: // // MM: We now have more than one sequence and envelope per track, so // instead of GetSequence() and GetEnvelope() we have the following - // function which give the sequence and envelope which is under the - // given X coordinate of the mouse pointer. + // function which give the sequence and envelope which contains the given + // time. // - WaveClip* GetClipAtX(int xcoord); - Sequence* GetSequenceAtX(int xcoord); - Envelope* GetEnvelopeAtX(int xcoord); + Sequence* GetSequenceAtTime(double time); + Envelope* GetEnvelopeAtTime(double time); WaveClip* GetClipAtSample(sampleCount sample); WaveClip* GetClipAtTime(double time); diff --git a/src/tracks/playabletrack/wavetrack/ui/SampleHandle.cpp b/src/tracks/playabletrack/wavetrack/ui/SampleHandle.cpp index 3480afb95..f327a32d1 100644 --- a/src/tracks/playabletrack/wavetrack/ui/SampleHandle.cpp +++ b/src/tracks/playabletrack/wavetrack/ui/SampleHandle.cpp @@ -119,9 +119,9 @@ UIHandlePtr SampleHandle::HitTest /// method that tells us if the mouse event landed on an /// editable sample const auto wavetrack = pTrack.get(); + const auto time = viewInfo.PositionToTime(state.m_x, rect.x); - const double tt = - adjustTime(wavetrack, viewInfo.PositionToTime(state.m_x, rect.x)); + const double tt = adjustTime(wavetrack, time); if (!SampleResolutionTest(viewInfo, wavetrack, tt, rect.width)) return {}; @@ -140,7 +140,7 @@ UIHandlePtr SampleHandle::HitTest wavetrack->GetDisplayBounds(&zoomMin, &zoomMax); double envValue = 1.0; - Envelope* env = wavetrack->GetEnvelopeAtX(state.GetX()); + Envelope* env = wavetrack->GetEnvelopeAtTime(time); if (env) // Calculate sample as it would be rendered, so quantize time envValue = env->GetValue( tt, 1.0 / wavetrack->GetRate() ); @@ -436,7 +436,7 @@ UIHandle::Result SampleHandle::Cancel(AudacityProject *pProject) } float SampleHandle::FindSampleEditingLevel - (const wxMouseEvent &event, const ViewInfo &, double t0) + (const wxMouseEvent &event, const ViewInfo &viewInfo, double t0) { // Calculate where the mouse is located vertically (between +/- 1) float zoomMin, zoomMax; @@ -450,7 +450,8 @@ float SampleHandle::FindSampleEditingLevel mClickedTrack->GetWaveformSettings().dBRange, zoomMin, zoomMax); //Take the envelope into account - Envelope *const env = mClickedTrack->GetEnvelopeAtX(event.m_x); + const auto time = viewInfo.PositionToTime(event.m_x, mRect.x); + Envelope *const env = mClickedTrack->GetEnvelopeAtTime(time); if (env) { // Calculate sample as it would be rendered, so quantize time diff --git a/src/tracks/playabletrack/wavetrack/ui/SpectrumView.cpp b/src/tracks/playabletrack/wavetrack/ui/SpectrumView.cpp index b49ed5bee..7f65e92b6 100644 --- a/src/tracks/playabletrack/wavetrack/ui/SpectrumView.cpp +++ b/src/tracks/playabletrack/wavetrack/ui/SpectrumView.cpp @@ -210,10 +210,6 @@ void DrawClipSpectrum(TrackPanelDrawingContext &context, const double &leftOffset = params.leftOffset; const wxRect &mid = params.mid; - // If we get to this point, the clip is actually visible on the - // screen, so remember the display rectangle. - clip->SetDisplayRect(hiddenMid); - double freqLo = SelectedRegion::UndefinedFrequency; double freqHi = SelectedRegion::UndefinedFrequency; #ifdef EXPERIMENTAL_SPECTRAL_EDITING @@ -644,10 +640,6 @@ void SpectrumView::Draw( const auto wt = std::static_pointer_cast( FindTrack()->SubstitutePendingChangedTrack()); - for (const auto &clip : wt->GetClips()) { - clip->ClearDisplayRect(); - } - const auto artist = TrackArtist::Get( context ); #if defined(__WXMAC__) diff --git a/src/tracks/playabletrack/wavetrack/ui/WaveformView.cpp b/src/tracks/playabletrack/wavetrack/ui/WaveformView.cpp index bc722ddb9..5754a8acf 100644 --- a/src/tracks/playabletrack/wavetrack/ui/WaveformView.cpp +++ b/src/tracks/playabletrack/wavetrack/ui/WaveformView.cpp @@ -84,7 +84,10 @@ std::vector WaveformView::DetailedHitTest( // Unconditional hits appropriate to the tool // If tools toolbar were eliminated, we would eliminate these case ToolCodes::envelopeTool: { - auto envelope = pTrack->GetEnvelopeAtX( st.state.m_x ); + auto &viewInfo = ViewInfo::Get(*pProject); + auto time = + viewInfo.PositionToTime(st.state.m_x, st.rect.GetX()); + auto envelope = pTrack->GetEnvelopeAtTime(time); result = EnvelopeHandle::HitAnywhere( view.mEnvelopeHandle, envelope, false); break; @@ -712,10 +715,6 @@ void DrawClipWaveform(TrackPanelDrawingContext &context, int iColorIndex = clip->GetColourIndex(); artist->SetColours( iColorIndex ); - // If we get to this point, the clip is actually visible on the - // screen, so remember the display rectangle. - clip->SetDisplayRect(hiddenMid); - // The bounds (controlled by vertical zooming; -1.0...1.0 // by default) float zoomMin, zoomMax; @@ -1012,10 +1011,6 @@ void WaveformView::Draw( const auto wt = std::static_pointer_cast( FindTrack()->SubstitutePendingChangedTrack()); - for (const auto &clip : wt->GetClips()) { - clip->ClearDisplayRect(); - } - const auto artist = TrackArtist::Get( context ); const auto hasSolo = artist->hasSolo; bool muted = (hasSolo || wt->GetMute()) && diff --git a/src/tracks/ui/EnvelopeHandle.cpp b/src/tracks/ui/EnvelopeHandle.cpp index bb20e27af..8a246f2a2 100644 --- a/src/tracks/ui/EnvelopeHandle.cpp +++ b/src/tracks/ui/EnvelopeHandle.cpp @@ -93,7 +93,9 @@ UIHandlePtr EnvelopeHandle::WaveTrackHitTest { /// method that tells us if the mouse event landed on an /// envelope boundary. - Envelope *const envelope = wt->GetEnvelopeAtX(state.GetX()); + auto &viewInfo = ViewInfo::Get(*pProject); + auto time = viewInfo.PositionToTime(state.m_x, rect.GetX()); + Envelope *const envelope = wt->GetEnvelopeAtTime(time); if (!envelope) return {}; @@ -194,7 +196,9 @@ UIHandle::Result EnvelopeHandle::Click mEnvelopeEditors.push_back( std::make_unique< EnvelopeEditor >( *mEnvelope, true ) ); else { - auto e2 = channel->GetEnvelopeAtX(event.GetX()); + auto time = + viewInfo.PositionToTime(event.GetX(), evt.rect.GetX()); + auto e2 = channel->GetEnvelopeAtTime(time); if (e2) mEnvelopeEditors.push_back( std::make_unique< EnvelopeEditor >( *e2, true ) ); diff --git a/src/tracks/ui/SelectHandle.cpp b/src/tracks/ui/SelectHandle.cpp index 1cbdbb0fa..59bcbf3ce 100644 --- a/src/tracks/ui/SelectHandle.cpp +++ b/src/tracks/ui/SelectHandle.cpp @@ -570,7 +570,8 @@ UIHandle::Result SelectHandle::Click // Special case: if we're over a clip in a WaveTrack, // select just that clip pTrack->TypeSwitch( [&] ( WaveTrack *wt ) { - WaveClip *const selectedClip = wt->GetClipAtX(event.m_x); + auto time = viewInfo.PositionToTime(event.m_x, mRect.x); + WaveClip *const selectedClip = wt->GetClipAtTime(time); if (selectedClip) { viewInfo.selectedRegion.setTimes( selectedClip->GetOffset(), selectedClip->GetEndTime());