1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-11-23 17:30:17 +01:00

Move Y position, height, and minimized state into TrackView...

... and eliminate some unnecessary calls to SubstitutePendingChangedTrack,
because the track and the substitute store Y and height in their shared
TrackView object.

Also make GetMinimizedHeight() virtual to avoid inclusion of TrackPanel.h in
TrackView.cpp.
This commit is contained in:
Paul Licameli
2019-06-18 11:32:26 -04:00
parent 3797a5227a
commit 66e32ca35d
28 changed files with 244 additions and 225 deletions

View File

@@ -41,8 +41,6 @@ and TimeTrack.
#include "InconsistencyException.h"
#include "TrackPanel.h" // for TrackInfo
#include "tracks/ui/TrackView.h"
#ifdef _MSC_VER
@@ -57,8 +55,6 @@ Track::Track(const std::shared_ptr<DirManager> &projDirManager)
mSelected = false;
mLinked = false;
mY = 0;
mHeight = DefaultHeight;
mIndex = 0;
mOffset = 0.0;
@@ -69,7 +65,6 @@ Track::Track(const std::shared_ptr<DirManager> &projDirManager)
Track::Track(const Track &orig)
: vrulerSize( orig.vrulerSize )
{
mY = 0;
mIndex = 0;
Init(orig);
mOffset = orig.mOffset;
@@ -87,7 +82,6 @@ void Track::Init(const Track &orig)
mSelected = orig.mSelected;
mLinked = orig.mLinked;
mHeight = orig.mHeight;
mChannel = orig.mChannel;
}
@@ -146,16 +140,6 @@ void Track::SetOwner
mNode = node;
}
int Track::GetMinimizedHeight() const
{
auto height = TrackInfo::MinimumTrackHeight();
auto channels = TrackList::Channels(this->SubstituteOriginalTrack().get());
auto nChannels = channels.size();
auto begin = channels.begin();
auto index = std::distance(begin, std::find(begin, channels.end(), this));
return (height * (index + 1) / nChannels) - (height * index / nChannels);
}
int Track::GetIndex() const
{
return mIndex;
@@ -166,67 +150,6 @@ void Track::SetIndex(int index)
mIndex = index;
}
int Track::GetY() const
{
return mY;
}
void Track::SetY(int y)
{
auto pList = mList.lock();
if (pList && !pList->mPendingUpdates.empty()) {
auto orig = pList->FindById( GetId() );
if (orig && orig != this) {
// delegate, and rely on the update to copy back
orig->SetY(y);
pList->UpdatePendingTracks();
return;
}
}
DoSetY(y);
}
void Track::DoSetY(int y)
{
mY = y;
}
#include "tracks/ui/TrackView.h"
int Track::GetHeight() const
{
if ( TrackView::Get( *this ).GetMinimized() ) {
return GetMinimizedHeight();
}
return mHeight;
}
void Track::SetHeight(int h)
{
auto pList = mList.lock();
if (pList && !pList->mPendingUpdates.empty()) {
auto orig = pList->FindById( GetId() );
if (orig && orig != this) {
// delegate, and rely on RecalcPositions to copy back
orig->SetHeight(h);
return;
}
}
DoSetHeight(h);
if (pList) {
pList->RecalcPositions(mNode);
pList->ResizingEvent(mNode);
}
}
void Track::DoSetHeight(int h)
{
mHeight = h;
}
void Track::SetLinked(bool l)
{
auto pList = mList.lock();
@@ -615,15 +538,17 @@ void TrackList::RecalcPositions(TrackNodePointer node)
if ( !isNull( prev ) ) {
t = prev.first->get();
i = t->GetIndex() + 1;
y = t->GetY() + t->GetHeight();
auto &view = TrackView::Get( *t );
y = view.GetY() + view.GetHeight();
}
const auto theEnd = end();
for (auto n = Find( node.first->get() ); n != theEnd; ++n) {
t = *n;
auto &view = TrackView::Get( *t );
t->SetIndex(i++);
t->DoSetY(y);
y += t->GetHeight();
view.SetY(y);
y += view.GetHeight();
}
UpdatePendingTracks();
@@ -921,7 +846,9 @@ Track *TrackList::GetPrev(Track * t, bool linked) const
/// For stereo track combined height of both channels.
int TrackList::GetGroupHeight(const Track * t) const
{
return Channels(t).sum( &Track::GetHeight );
const auto GetHeight = []( const Track *track )
{ return TrackView::Get( *track ).GetHeight(); };
return Channels(t).sum( GetHeight );
}
bool TrackList::CanMoveUp(Track * t) const
@@ -1049,7 +976,8 @@ int TrackList::GetHeight() const
if (!empty()) {
auto track = getPrev( getEnd() ).first->get();
height = track->GetY() + track->GetHeight();
auto &view = TrackView::Get( *track );
height = view.GetY() + view.GetHeight();
}
return height;
@@ -1128,8 +1056,6 @@ void TrackList::UpdatePendingTracks()
if (pendingTrack && src) {
if (updater)
updater( *pendingTrack, *src );
pendingTrack->DoSetY(src->GetY());
pendingTrack->DoSetHeight(src->GetActualHeight());
pendingTrack->DoSetLinked(src->GetLinked());
}
++pUpdater;
@@ -1272,8 +1198,9 @@ void Track::WriteCommonXMLAttributes(
xmlFile.WriteAttr(wxT("name"), GetName());
xmlFile.WriteAttr(wxT("isSelected"), this->GetSelected());
}
xmlFile.WriteAttr(wxT("height"), this->GetActualHeight());
xmlFile.WriteAttr(wxT("minimized"), TrackView::Get( *this ).GetMinimized());
auto &view = TrackView::Get( *this );
xmlFile.WriteAttr(wxT("height"), view.GetActualHeight());
xmlFile.WriteAttr(wxT("minimized"), view.GetMinimized());
}
// Return true iff the attribute is recognized.
@@ -1288,7 +1215,7 @@ bool Track::HandleCommonXMLAttribute(const wxChar *attr, const wxChar *value)
}
else if (!wxStrcmp(attr, wxT("height")) &&
XMLValueChecker::IsGoodInt(strValue) && strValue.ToLong(&nValue)) {
SetHeight(nValue);
TrackView::Get( *this ).SetHeight(nValue);
return true;
}
else if (!wxStrcmp(attr, wxT("minimized")) &&