From b94e8fec9649994a0489507799c5fa5b6f9a4dc4 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Mon, 10 Sep 2018 23:00:28 -0400 Subject: [PATCH] Remove VisibleTrackIterator --- src/Track.cpp | 23 -------------------- src/Track.h | 20 ------------------ src/TrackPanel.cpp | 37 ++++++++++++++++++++++++++------- src/TrackPanel.h | 10 +++++++++ src/TrackPanelCellIterator.h | 2 +- src/commands/GetInfoCommand.cpp | 3 +-- 6 files changed, 42 insertions(+), 53 deletions(-) diff --git a/src/Track.cpp b/src/Track.cpp index 48cfd0d35..de856cc7e 100644 --- a/src/Track.cpp +++ b/src/Track.cpp @@ -607,29 +607,6 @@ bool SelectedTrackListOfKindIterator::Condition(Track *t) return TrackListOfKindIterator::Condition(t) && t->GetSelected(); } -// VisibleTrackIterator -// -// Based on TrackListIterator returns only the currently visible tracks. -// -VisibleTrackIterator::VisibleTrackIterator(AudacityProject *project) -: TrackListCondIterator(project->GetTracks()) -{ - mProject = project; - mPanelRect.SetTop(mProject->mViewInfo.vpos); - mPanelRect.SetSize(mProject->GetTPTracksUsableArea()); -} - -bool VisibleTrackIterator::Condition(Track *t) -{ - wxRect r(0, t->GetY(), 1, t->GetHeight()); - if( r.Intersects(mPanelRect) ) - return true; - auto partner = t->GetLink(); - if ( partner && t->GetLinked() ) - return Condition( partner ); - return false; -} - // SyncLockedTracksIterator // // Based on TrackListIterator returns only tracks belonging to the group diff --git a/src/Track.h b/src/Track.h index 412091e50..4745f0197 100644 --- a/src/Track.h +++ b/src/Track.h @@ -1224,26 +1224,6 @@ class AUDACITY_DLL_API SelectedTrackListOfKindIterator final : public TrackListO bool Condition(Track *t) override; }; -// -// VisibleTrackIterator -// -// Based on TrackListIterator returns only the currently visible tracks. -// -class AUDACITY_DLL_API VisibleTrackIterator final : public TrackListCondIterator -{ - public: - VisibleTrackIterator(AudacityProject *project); - virtual ~VisibleTrackIterator() {} - - protected: - bool Condition(Track *t) override; - - private: - AudacityProject *mProject; - wxRect mPanelRect; -}; - - // SyncLockedTracksIterator returns only tracks belonging to the sync-locked tracks // in which the starting track is a member. class AUDACITY_DLL_API SyncLockedTracksIterator final : public TrackListIterator diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index b093e0fac..56619fb27 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -1200,8 +1200,8 @@ void TrackPanel::DrawEverythingElse(TrackPanelDrawingContext &context, wxRect trackRect = clip; trackRect.height = 0; // for drawing background in no tracks case. - VisibleTrackIterator iter(GetProject()); - for (const Track *t = iter.First(); t; t = iter.Next()) { + for ( auto t : + GetTracks()->Any< const Track >() + IsVisibleTrack{ GetProject() } ) { t = t->SubstitutePendingChangedTrack().get(); trackRect.y = t->GetY() - mViewInfo->vpos; trackRect.height = t->GetHeight(); @@ -1220,8 +1220,8 @@ void TrackPanel::DrawEverythingElse(TrackPanelDrawingContext &context, } // If the previous track is linked to this one but isn't on the screen - // (and thus would have been skipped by VisibleTrackIterator) we need to - // draw that track's border instead. + // (and thus would have been skipped) we need to draw that track's border + // instead. const Track *borderTrack = t; wxRect borderRect = rect; @@ -2686,10 +2686,13 @@ IteratorRange< TrackPanelCellIterator > TrackPanel::Cells() TrackPanelCellIterator::TrackPanelCellIterator(TrackPanel *trackPanel, bool begin) : mPanel{ trackPanel } - , mIter{ trackPanel->GetProject() } + , mIter{ + trackPanel->GetTracks()->Any().begin() + .Filter( IsVisibleTrack( trackPanel->GetProject() ) ) + } { if (begin) { - mpTrack = Track::Pointer( mIter.First() ); + mpTrack = Track::Pointer( *mIter ); if (mpTrack) mpCell = mpTrack; else @@ -2707,7 +2710,7 @@ TrackPanelCellIterator &TrackPanelCellIterator::operator++ () { if ( mpTrack ) { if ( ++ mType == CellType::Background ) - mType = CellType::Track, mpTrack = Track::Pointer( mIter.Next() ); + mType = CellType::Track, mpTrack = Track::Pointer( * ++ mIter ); } if ( mpTrack ) { if ( mType == CellType::Label && @@ -2909,3 +2912,23 @@ unsigned TrackPanelCell::Char(wxKeyEvent &event, ViewInfo &, wxWindow *) event.Skip(); return RefreshCode::RefreshNone; } + +IsVisibleTrack::IsVisibleTrack(AudacityProject *project) + : mPanelRect { + wxPoint{ 0, project->mViewInfo.vpos }, + project->GetTPTracksUsableArea() + } +{} + +bool IsVisibleTrack::operator () (const Track *pTrack) const +{ + // Need to return true if this track or a later channel intersects + // the view + return + TrackList::Channels(pTrack).StartingWith(pTrack).any_of( + [this]( const Track *pT ) { + wxRect r(0, pT->GetY(), 1, pT->GetHeight()); + return r.Intersects(mPanelRect); + } + ); +} diff --git a/src/TrackPanel.h b/src/TrackPanel.h index 25630b6eb..6a80ac5ab 100644 --- a/src/TrackPanel.h +++ b/src/TrackPanel.h @@ -489,6 +489,16 @@ protected: friend class GetInfoCommand; }; +// A predicate class +struct IsVisibleTrack +{ + IsVisibleTrack(AudacityProject *project); + + bool operator () (const Track *pTrack) const; + + wxRect mPanelRect; +}; + // See big pictorial comment in TrackPanel for explanation of these numbers enum : int { kLeftInset = 4, diff --git a/src/TrackPanelCellIterator.h b/src/TrackPanelCellIterator.h index e34bd953e..e565be8ec 100644 --- a/src/TrackPanelCellIterator.h +++ b/src/TrackPanelCellIterator.h @@ -53,7 +53,7 @@ private: void UpdateRect(); TrackPanel *mPanel; - VisibleTrackIterator mIter; + TrackIter mIter; std::shared_ptr mpTrack; std::shared_ptr mpCell; CellType mType{ CellType::Track }; diff --git a/src/commands/GetInfoCommand.cpp b/src/commands/GetInfoCommand.cpp index bc0ee6d84..7396bfb42 100644 --- a/src/commands/GetInfoCommand.cpp +++ b/src/commands/GetInfoCommand.cpp @@ -484,8 +484,7 @@ void GetInfoCommand::ExploreTrackPanel( const CommandContext &context, wxRect trackRect = pWin->GetRect(); - VisibleTrackIterator iter(pProj); - for (Track *t = iter.First(); t; t = iter.Next()) { + for (auto t : pProj->GetTracks()->Any() + IsVisibleTrack{ pProj }) { trackRect.y = t->GetY() - pTP->mViewInfo->vpos; trackRect.height = t->GetHeight();