1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-20 06:10:06 +02:00

Remove VisibleTrackIterator

This commit is contained in:
Paul Licameli 2018-09-10 23:00:28 -04:00
parent ae2ce1ad90
commit b94e8fec96
6 changed files with 42 additions and 53 deletions

View File

@ -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

View File

@ -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

View File

@ -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);
}
);
}

View File

@ -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,

View File

@ -53,7 +53,7 @@ private:
void UpdateRect();
TrackPanel *mPanel;
VisibleTrackIterator mIter;
TrackIter<Track> mIter;
std::shared_ptr<Track> mpTrack;
std::shared_ptr<TrackPanelCell> mpCell;
CellType mType{ CellType::Track };

View File

@ -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();