From 7c66c3bf4bb37246f81b010be16a38152bc843be Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Thu, 9 May 2019 01:54:14 +1000 Subject: [PATCH] fixed track size issue --- global/global.cpp | 2 +- panels/timeline.cpp | 2 +- panels/viewer.cpp | 4 +- timeline/sequence.cpp | 115 ++++++++++++++++++++++++++++++++++-------- timeline/sequence.h | 9 +++- ui/timelinearea.cpp | 18 +++---- ui/timelineview.cpp | 23 ++++++--- 7 files changed, 128 insertions(+), 45 deletions(-) diff --git a/global/global.cpp b/global/global.cpp index 5f0737fa4..e1bf29bc9 100644 --- a/global/global.cpp +++ b/global/global.cpp @@ -337,7 +337,7 @@ void OliveGlobal::PasteInternal(Sequence *s, bool insert) ClipPtr c = std::static_pointer_cast(olive::clipboard.Get(i)); // create copy of clip and offset by playhead - ClipPtr cc = c->copy(s->GetTrackList(c->track()->type()).at(c->track()->Index())); + ClipPtr cc = c->copy(s->TrackAt(c->track()->type(), c->track()->Index())); // convert frame rates cc->set_timeline_in(rescale_frame_number(cc->timeline_in(), c->cached_frame_rate(), s->frame_rate())); diff --git a/panels/timeline.cpp b/panels/timeline.cpp index 4e40ef88d..5af3267d3 100644 --- a/panels/timeline.cpp +++ b/panels/timeline.cpp @@ -343,7 +343,7 @@ void Timeline::nest() { ca->append(new DeleteClipAction(c)); // copy to new - Track* track = s->GetTrackList(c->type()).at(c->track()->Index()); + Track* track = s->TrackAt(c->type(), c->track()->Index()); ClipPtr copy = selected_clips.at(i)->copy(track); copy->set_timeline_in(copy->timeline_in() - earliest_point); copy->set_timeline_out(copy->timeline_out() - earliest_point); diff --git a/panels/viewer.cpp b/panels/viewer.cpp index b268032de..c77702bfa 100644 --- a/panels/viewer.cpp +++ b/panels/viewer.cpp @@ -746,7 +746,7 @@ void Viewer::set_media(Media* m) { new_sequence->set_frame_rate(video_stream.video_frame_rate * footage->speed); } - Track* first_track = new_sequence->GetTrackList(olive::kTypeVideo).first(); + Track* first_track = new_sequence->FirstTrack(olive::kTypeVideo); ClipPtr c = std::make_shared(first_track); c->set_media(media, video_stream.file_index); @@ -769,7 +769,7 @@ void Viewer::set_media(Media* m) { const FootageStream& audio_stream = footage->audio_tracks.at(0); new_sequence->set_audio_frequency(audio_stream.audio_frequency); - Track* track = new_sequence->GetTrackList(olive::kTypeAudio).first(); + Track* track = new_sequence->FirstTrack(olive::kTypeAudio); ClipPtr c = std::make_shared(track); c->set_media(media, audio_stream.file_index); c->set_timeline_in(0); diff --git a/timeline/sequence.cpp b/timeline/sequence.cpp index 57d0cffa2..a5f501b92 100644 --- a/timeline/sequence.cpp +++ b/timeline/sequence.cpp @@ -35,6 +35,8 @@ Sequence::Sequence() : workarea_out(0), wrapper_sequence(false) { + AddTrack(olive::kTypeVideo); + AddTrack(olive::kTypeAudio); } SequencePtr Sequence::copy() { @@ -1118,51 +1120,122 @@ Track *Sequence::PreviousTrack(Track *t) Track *Sequence::NextTrack(Track *t) { - // FIXME: The old code created extra tracks if it couldn't find one here + if (LastTrack(t->type()) == t) { - Track* next_track = nullptr; + return AddTrack(t->type()); - // Loop through tracks - for (int i=tracks_.size()-1;i>=0;i--) { + } else { + + Track* next_track = nullptr; + + for (int i=tracks_.size()-1;i>=0;i--) { + + if (tracks_.at(i) == t) { + break; + } + + if (tracks_.at(i)->type() == t->type()) { + next_track = tracks_.at(i); + } - if (tracks_.at(i) == t) { - // If this is the track, we'll know the previous track by now - break; - } else if (tracks_.at(i)->type() == t->type()) { - // Otherwise, we'll keep "track" of it - next_track = t; } - } - return next_track; + return next_track; + } } Track *Sequence::SiblingTrack(Track *t, int diff) { - // FIXME: The old code created extra tracks if it couldn't find one here - if (diff == 0) { return t; } - QVector tracks = GetTrackList(t->type()); - - return tracks.at(qMax(0, IndexOfTrack(t) + diff)); + return TrackAt(t->type(), qMax(0, IndexOfTrack(t) + diff)); } int Sequence::IndexOfTrack(Track *t) { - QVector tracks = GetTrackList(t->type()); + int counter = -1; - for (int i=0;itype() == t->type()) { + counter++; + } + + if (tracks_.at(i) == t) { + return counter; } } return -1; } +Track *Sequence::FirstTrack(olive::TrackType type) +{ + for (int i=0;itype() == type) { + return tracks_.at(i); + } + } + return nullptr; +} + +Track *Sequence::LastTrack(olive::TrackType type) +{ + for (int i=tracks_.size()-1;i>=0;i--) { + if (tracks_.at(i)->type() == type) { + return tracks_.at(i); + } + } + return nullptr; +} + +Track *Sequence::TrackAt(olive::TrackType type, int index) +{ + int counter = -1; + + for (int i=0;itype() == type) { + counter++; + } + + if (counter == index) { + return tracks_.at(i); + } + } + + Track* t; + + do { + t = AddTrack(type); + counter++; + } while (index > counter); + + return t; +} + +int Sequence::TrackCount(olive::TrackType type) +{ + int counter = 0; + + for (int i=0;itype() == type) { + counter++; + } + } + + return counter; +} + +Track* Sequence::AddTrack(olive::TrackType type) +{ + Track* track = new Track(this, type); + tracks_.append(track); + emit TrackCountChanged(); + return track; +} + ClipPtr Sequence::SplitClip(ComboAction *ca, bool transitions, Clip* pre, long frame) { return SplitClip(ca, transitions, pre, frame, frame); diff --git a/timeline/sequence.h b/timeline/sequence.h index a2a9b8fde..9dbe81027 100644 --- a/timeline/sequence.h +++ b/timeline/sequence.h @@ -57,7 +57,6 @@ public: long GetEndFrame(); QVector GetAllClips(); - QVector GetTrackList(olive::TrackType type); /** * @brief Close all open clips in a Sequence @@ -124,6 +123,11 @@ public: Track* NextTrack(Track* t); Track* SiblingTrack(Track* t, int diff); int IndexOfTrack(Track* t); + Track* FirstTrack(olive::TrackType type); + Track* LastTrack(olive::TrackType type); + Track* TrackAt(olive::TrackType type, int index); + int TrackCount(olive::TrackType type); + QVector GetTrackList(olive::TrackType type); long playhead; @@ -138,7 +142,10 @@ public: QVector markers; signals: void SequenceParametersChanged(); + void TrackCountChanged(); private: + Track *AddTrack(olive::TrackType type); + QVector tracks_; ClipPtr SplitClip(ComboAction* ca, bool transitions, Clip *clip, long frame); diff --git a/ui/timelinearea.cpp b/ui/timelinearea.cpp index 1a7016d92..9282a6664 100644 --- a/ui/timelinearea.cpp +++ b/ui/timelinearea.cpp @@ -51,26 +51,22 @@ TimelineArea::TimelineArea(Timeline* timeline, olive::timeline::Alignment alignm void TimelineArea::SetTrackType(Sequence *sequence, olive::TrackType track_type) { - /* FIXME - if (track_list_ != nullptr) { - disconnect(track_list_, SIGNAL(TrackCountChanged()), this, SLOT(RefreshLabels())); + if (sequence_ != nullptr) { + disconnect(sequence_, SIGNAL(TrackCountChanged()), this, SLOT(RefreshLabels())); } - if (sequence == nullptr) { + sequence_ = sequence; + type_ = track_type; - track_list_ = nullptr; + if (sequence_ != nullptr) { - } else { - - track_list_ = sequence->GetTrackList(track_type); - connect(track_list_, SIGNAL(TrackCountChanged()), this, SLOT(RefreshLabels())); + connect(sequence_, SIGNAL(TrackCountChanged()), this, SLOT(RefreshLabels())); } RefreshLabels(); - view_->SetTrackList(track_list_); - */ + view_->SetTrackType(sequence_, type_); } void TimelineArea::SetAlignment(olive::timeline::Alignment alignment) diff --git a/ui/timelineview.cpp b/ui/timelineview.cpp index 6e7ca1ef2..4b2d12bfd 100644 --- a/ui/timelineview.cpp +++ b/ui/timelineview.cpp @@ -325,7 +325,7 @@ void TimelineView::dragEnterEvent(QDragEnterEvent *event) { } else { entry_point = ParentTimeline()->getTimelineFrameFromScreenPoint(event->pos().x()); ParentTimeline()->drag_frame_start = entry_point + getFrameFromScreenPoint(ParentTimeline()->zoom, 50); - ParentTimeline()->drag_track_start = sequence_->GetTrackList(type_).first(); + ParentTimeline()->drag_track_start = sequence_->FirstTrack(type_); } ParentTimeline()->ghosts = olive::timeline::CreateGhostsFromMedia(seq, entry_point, media_list); @@ -3294,6 +3294,7 @@ Track *TimelineView::getTrackFromScreenPoint(int y) { } int TimelineView::getScreenPointFromTrack(Track *track) { + qDebug() << "Getting screen point from" << track << track->Index(); return getScreenPointFromTrackIndex(track->Index()); } @@ -3316,11 +3317,13 @@ int TimelineView::getTrackIndexFromScreenPoint(int y) int heights = 0; int i = 0; + + QVector track_list = sequence_->GetTrackList(type_); + while (true) { int new_heights = heights; - QVector track_list = sequence_->GetTrackList(type_); if (i < track_list.size()) { new_heights += track_list.at(i)->height(); } else { @@ -3346,13 +3349,18 @@ int TimelineView::getScreenPointFromTrackIndex(int track) int point = 0; - for (int i=0;i track_list = sequence_->GetTrackList(type_); - return qMax(height(), GetTotalAreaHeight()) - point - scroll - track_list.first()->height() - 1; + return qMax(height(), GetTotalAreaHeight()) - point - scroll - sequence_->FirstTrack(type_)->height() - 1; } return point - scroll; @@ -3360,9 +3368,8 @@ int TimelineView::getScreenPointFromTrackIndex(int track) int TimelineView::getTrackHeightFromTrackIndex(int track) { - QVector track_list = sequence_->GetTrackList(type_); - if (track < track_list.size()) { - return track_list.at(track)->height(); + if (track < sequence_->TrackCount(type_)) { + return sequence_->TrackAt(type_, track)->height(); } else { return olive::timeline::kTrackDefaultHeight; }