mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-25 08:38:39 +02:00
Rewrite iteration over visible tracks in TrackArtist...
... also eliminating AudacityProject::GetFirstVisible.
This commit is contained in:
parent
51e0ae0447
commit
0c0c2c0d1e
@ -2051,25 +2051,6 @@ void AudacityProject::FixScrollbars()
|
|||||||
GetTrackPanel()->HandleCursorForPresentMouseState(); } );
|
GetTrackPanel()->HandleCursorForPresentMouseState(); } );
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Track> AudacityProject::GetFirstVisible()
|
|
||||||
{
|
|
||||||
std::shared_ptr<Track> pTrack;
|
|
||||||
if (GetTracks()) {
|
|
||||||
TrackListIterator iter(GetTracks());
|
|
||||||
for (Track *t = iter.First(); t; t = iter.Next()) {
|
|
||||||
int y = t->GetY();
|
|
||||||
int h = t->GetHeight();
|
|
||||||
if (y + h - 1 >= mViewInfo.vpos) {
|
|
||||||
// At least the bottom row of pixels is not scrolled away above
|
|
||||||
pTrack = Track::Pointer(t);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return pTrack;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AudacityProject::UpdateLayout()
|
void AudacityProject::UpdateLayout()
|
||||||
{
|
{
|
||||||
if (!mTrackPanel)
|
if (!mTrackPanel)
|
||||||
|
@ -213,8 +213,6 @@ class AUDACITY_DLL_API AudacityProject final : public wxFrame,
|
|||||||
const ViewInfo &GetViewInfo() const { return mViewInfo; }
|
const ViewInfo &GetViewInfo() const { return mViewInfo; }
|
||||||
ViewInfo &GetViewInfo() { return mViewInfo; }
|
ViewInfo &GetViewInfo() { return mViewInfo; }
|
||||||
|
|
||||||
std::shared_ptr<Track> GetFirstVisible();
|
|
||||||
|
|
||||||
void GetPlayRegion(double* playRegionStart, double *playRegionEnd);
|
void GetPlayRegion(double* playRegionStart, double *playRegionEnd);
|
||||||
bool IsPlayRegionLocked() { return mLockPlayRegion; }
|
bool IsPlayRegionLocked() { return mLockPlayRegion; }
|
||||||
void SetPlayRegionLocked(bool value) { mLockPlayRegion = value; }
|
void SetPlayRegionLocked(bool value) { mLockPlayRegion = value; }
|
||||||
|
@ -341,7 +341,6 @@ void TrackArtist::SetMargins(int left, int top, int right, int bottom)
|
|||||||
|
|
||||||
void TrackArtist::DrawTracks(TrackPanelDrawingContext &context,
|
void TrackArtist::DrawTracks(TrackPanelDrawingContext &context,
|
||||||
const TrackList * tracks,
|
const TrackList * tracks,
|
||||||
Track * start,
|
|
||||||
const wxRegion & reg,
|
const wxRegion & reg,
|
||||||
const wxRect & rect,
|
const wxRect & rect,
|
||||||
const wxRect & clip,
|
const wxRect & clip,
|
||||||
@ -351,13 +350,11 @@ void TrackArtist::DrawTracks(TrackPanelDrawingContext &context,
|
|||||||
bool bigPoints,
|
bool bigPoints,
|
||||||
bool drawSliders)
|
bool drawSliders)
|
||||||
{
|
{
|
||||||
|
// Copy the horizontal extent of rect; will later change only the vertical.
|
||||||
wxRect trackRect = rect;
|
wxRect trackRect = rect;
|
||||||
wxRect stereoTrackRect;
|
|
||||||
TrackListConstIterator iter(tracks);
|
|
||||||
const Track *t;
|
|
||||||
|
|
||||||
bool hasSolo = false;
|
bool hasSolo = false;
|
||||||
for (t = iter.First(); t; t = iter.Next()) {
|
for (const Track *t : *tracks) {
|
||||||
t = t->SubstitutePendingChangedTrack().get();
|
t = t->SubstitutePendingChangedTrack().get();
|
||||||
auto pt = dynamic_cast<const PlayableTrack *>(t);
|
auto pt = dynamic_cast<const PlayableTrack *>(t);
|
||||||
if (pt && pt->GetSolo()) {
|
if (pt && pt->GetSolo()) {
|
||||||
@ -381,60 +378,52 @@ void TrackArtist::DrawTracks(TrackPanelDrawingContext &context,
|
|||||||
|
|
||||||
gPrefs->Read(wxT("/GUI/ShowTrackNameInWaveform"), &mbShowTrackNameInWaveform, false);
|
gPrefs->Read(wxT("/GUI/ShowTrackNameInWaveform"), &mbShowTrackNameInWaveform, false);
|
||||||
|
|
||||||
t = iter.StartWith(start);
|
for(auto leader : tracks->Leaders()) {
|
||||||
while (t) {
|
auto group = TrackList::Channels( leader );
|
||||||
t = t->SubstitutePendingChangedTrack().get();
|
leader = leader->SubstitutePendingChangedTrack().get();
|
||||||
trackRect.y = t->GetY() - zoomInfo.vpos;
|
|
||||||
trackRect.height = t->GetHeight();
|
|
||||||
|
|
||||||
if (trackRect.y > clip.GetBottom() && !t->GetLinked()) {
|
trackRect.y = leader->GetY() - zoomInfo.vpos;
|
||||||
|
trackRect.height = group.sum( [&] (const Track *channel) {
|
||||||
|
channel = channel->SubstitutePendingChangedTrack().get();
|
||||||
|
return channel->GetHeight();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (trackRect.GetBottom() < clip.GetTop())
|
||||||
|
continue;
|
||||||
|
else if (trackRect.GetTop() > clip.GetBottom())
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
for (auto t : group) {
|
||||||
|
t = t->SubstitutePendingChangedTrack().get();
|
||||||
|
|
||||||
#if defined(DEBUG_CLIENT_AREA)
|
#if defined(DEBUG_CLIENT_AREA)
|
||||||
// Filled rectangle to show the interior of the client area
|
// Filled rectangle to show the interior of the client area
|
||||||
wxRect zr = trackRect;
|
wxRect zr = trackRect;
|
||||||
zr.x+=1; zr.y+=5; zr.width-=7; zr.height-=7;
|
zr.x+=1; zr.y+=5; zr.width-=7; zr.height-=7;
|
||||||
dc.SetPen(*wxCYAN_PEN);
|
dc.SetPen(*wxCYAN_PEN);
|
||||||
dc.SetBrush(*wxRED_BRUSH);
|
dc.SetBrush(*wxRED_BRUSH);
|
||||||
dc.DrawRectangle(zr);
|
dc.DrawRectangle(zr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
stereoTrackRect = trackRect;
|
// For various reasons, the code will break if we display one
|
||||||
|
// of a stereo pair of tracks but not the other - for example,
|
||||||
|
// if you try to edit the envelope of one track when its linked
|
||||||
|
// pair is off the screen, then it won't be able to edit the
|
||||||
|
// offscreen envelope. So we compute the rect of the track and
|
||||||
|
// its linked partner, and see if any part of that rect is on-screen.
|
||||||
|
// If so, we draw both. Otherwise, we can safely draw neither.
|
||||||
|
|
||||||
// For various reasons, the code will break if we display one
|
if (trackRect.Intersects(clip) && reg.Contains(trackRect)) {
|
||||||
// of a stereo pair of tracks but not the other - for example,
|
wxRect rr = trackRect;
|
||||||
// if you try to edit the envelope of one track when its linked
|
rr.x += mMarginLeft;
|
||||||
// pair is off the screen, then it won't be able to edit the
|
rr.y += mMarginTop;
|
||||||
// offscreen envelope. So we compute the rect of the track and
|
rr.width -= (mMarginLeft + mMarginRight);
|
||||||
// its linked partner, and see if any part of that rect is on-screen.
|
rr.height -= (mMarginTop + mMarginBottom);
|
||||||
// If so, we draw both. Otherwise, we can safely draw neither.
|
DrawTrack(context, t, rr,
|
||||||
|
selectedRegion, zoomInfo,
|
||||||
Track *link = t->GetLink();
|
drawEnvelope, bigPoints, drawSliders, hasSolo);
|
||||||
if (link) {
|
|
||||||
if (t->GetLinked()) {
|
|
||||||
// If we're the first track
|
|
||||||
stereoTrackRect.height += link->GetHeight();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// We're the second of two
|
|
||||||
stereoTrackRect.y -= link->GetHeight();
|
|
||||||
stereoTrackRect.height += link->GetHeight();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stereoTrackRect.Intersects(clip) && reg.Contains(stereoTrackRect)) {
|
|
||||||
wxRect rr = trackRect;
|
|
||||||
rr.x += mMarginLeft;
|
|
||||||
rr.y += mMarginTop;
|
|
||||||
rr.width -= (mMarginLeft + mMarginRight);
|
|
||||||
rr.height -= (mMarginTop + mMarginBottom);
|
|
||||||
DrawTrack(context, t, rr,
|
|
||||||
selectedRegion, zoomInfo,
|
|
||||||
drawEnvelope, bigPoints, drawSliders, hasSolo);
|
|
||||||
}
|
|
||||||
|
|
||||||
t = iter.Next();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -480,8 +469,7 @@ void TrackArtist::DrawTrack(TrackPanelDrawingContext &context,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (mbShowTrackNameInWaveform &&
|
if (mbShowTrackNameInWaveform &&
|
||||||
// Exclude right channel of stereo track
|
wt->IsLeader() &&
|
||||||
!(!wt->GetLinked() && wt->GetLink()) &&
|
|
||||||
// Exclude empty name.
|
// Exclude empty name.
|
||||||
!wt->GetName().IsEmpty()) {
|
!wt->GetName().IsEmpty()) {
|
||||||
wxBrush Brush;
|
wxBrush Brush;
|
||||||
|
@ -55,7 +55,7 @@ class AUDACITY_DLL_API TrackArtist {
|
|||||||
|
|
||||||
void SetColours(int iColorIndex);
|
void SetColours(int iColorIndex);
|
||||||
void DrawTracks(TrackPanelDrawingContext &context,
|
void DrawTracks(TrackPanelDrawingContext &context,
|
||||||
const TrackList *tracks, Track *start,
|
const TrackList *tracks,
|
||||||
const wxRegion & reg,
|
const wxRegion & reg,
|
||||||
const wxRect & rect, const wxRect & clip,
|
const wxRect & rect, const wxRect & clip,
|
||||||
const SelectedRegion &selectedRegion, const ZoomInfo &zoomInfo,
|
const SelectedRegion &selectedRegion, const ZoomInfo &zoomInfo,
|
||||||
|
@ -1156,8 +1156,7 @@ void TrackPanel::DrawTracks(wxDC * dc)
|
|||||||
TrackPanelDrawingContext context{ *dc, Target(), mLastMouseState };
|
TrackPanelDrawingContext context{ *dc, Target(), mLastMouseState };
|
||||||
|
|
||||||
// The track artist actually draws the stuff inside each track
|
// The track artist actually draws the stuff inside each track
|
||||||
auto first = GetProject()->GetFirstVisible();
|
mTrackArtist->DrawTracks(context, GetTracks(),
|
||||||
mTrackArtist->DrawTracks(context, GetTracks(), first.get(),
|
|
||||||
region, tracksRect, clip,
|
region, tracksRect, clip,
|
||||||
mViewInfo->selectedRegion, *mViewInfo,
|
mViewInfo->selectedRegion, *mViewInfo,
|
||||||
envelopeFlag, bigPointsFlag, sliderFlag);
|
envelopeFlag, bigPointsFlag, sliderFlag);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user