From 5f0debb7ec5b68a19f5605ad31289431e1740217 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Wed, 8 May 2019 19:32:31 +1000 Subject: [PATCH] removed tracklist layer --- global/global.cpp | 2 +- olive.pro | 2 - panels/timeline.cpp | 13 +- panels/viewer.cpp | 11 +- timeline/sequence.cpp | 275 +++++++++++++++++---------------- timeline/sequence.h | 10 +- timeline/timelinefunctions.cpp | 8 +- timeline/track.cpp | 31 +--- timeline/track.h | 9 +- timeline/tracklist.cpp | 107 ------------- timeline/tracklist.h | 38 ----- ui/timelinearea.cpp | 14 +- ui/timelinearea.h | 8 +- ui/timelineview.cpp | 71 +++++---- ui/timelineview.h | 5 +- 15 files changed, 234 insertions(+), 370 deletions(-) delete mode 100644 timeline/tracklist.cpp delete mode 100644 timeline/tracklist.h diff --git a/global/global.cpp b/global/global.cpp index b86719fe5..af45d11d5 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())->TrackAt(c->track()->Index())); + ClipPtr cc = c->copy(s->GetTrackList(c->track()->type()).at(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/olive.pro b/olive.pro index 2546af3ae..fe87cd8f7 100644 --- a/olive.pro +++ b/olive.pro @@ -177,7 +177,6 @@ SOURCES += \ rendering/pixelformats.cpp \ timeline/timelinefunctions.cpp \ timeline/track.cpp \ - timeline/tracklist.cpp \ project/savethread.cpp \ project/projectfunctions.cpp \ ui/timelinearea.cpp \ @@ -344,7 +343,6 @@ HEADERS += \ timeline/ghost.h \ timeline/timelinefunctions.h \ timeline/track.h \ - timeline/tracklist.h \ project/savethread.h \ project/projectfunctions.h \ ui/timelinearea.h \ diff --git a/panels/timeline.cpp b/panels/timeline.cpp index 516112508..bcd73da07 100644 --- a/panels/timeline.cpp +++ b/panels/timeline.cpp @@ -223,8 +223,8 @@ void Timeline::SetSequence(SequencePtr sequence) sequence_ = sequence; update_sequence(); - video_area->SetTrackList(sequence_.get(), olive::kTypeVideo); - audio_area->SetTrackList(sequence_.get(), olive::kTypeAudio); + video_area->SetTrackType(sequence_.get(), olive::kTypeVideo); + audio_area->SetTrackType(sequence_.get(), olive::kTypeAudio); repaint_timeline(); emit SequenceChanged(sequence_); @@ -343,7 +343,7 @@ void Timeline::nest() { ca->append(new DeleteClipAction(c)); // copy to new - Track* track = s->GetTrackList(c->type())->TrackAt(c->track()->Index()); + Track* track = s->GetTrackList(c->type()).at(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); @@ -782,9 +782,10 @@ QVector Timeline::GetTracksInRectangle(int global_top, int global_botto int rect_bottom = qMax(relative_tl.y(), relative_br.y()); // determine which clips are in this rectangular selection - TrackList* track_list = area->track_list(); - for (int j=0;jTrackCount();j++) { - Track* track = track_list->TrackAt(j); + QVector area_tracks = sequence_->GetTrackList(area->track_type()); + + for (int j=0;jview()->getScreenPointFromTrack(track); int track_bottom = track_top + track->height(); diff --git a/panels/viewer.cpp b/panels/viewer.cpp index 6a3d66872..af8840ae8 100644 --- a/panels/viewer.cpp +++ b/panels/viewer.cpp @@ -752,7 +752,9 @@ void Viewer::set_media(Media* m) { new_sequence->frame_rate = video_stream.video_frame_rate * footage->speed; } - ClipPtr c = std::make_shared(new_sequence->GetTrackList(olive::kTypeVideo)->First()); + Track* first_track = new_sequence->GetTrackList(olive::kTypeVideo).first(); + + ClipPtr c = std::make_shared(first_track); c->set_media(media, video_stream.file_index); c->set_timeline_in(0); c->set_timeline_out(footage->get_length_in_frames(new_sequence->frame_rate)); @@ -760,11 +762,10 @@ void Viewer::set_media(Media* m) { // FIXME: Move this magic number to Config c->set_timeline_out(150); } - Track* track = new_sequence->GetTrackList(olive::kTypeVideo)->First(); - c->set_track(track); + c->set_track(first_track); c->set_clip_in(0); c->refresh(); - track->AddClip(c); + first_track->AddClip(c); } else { new_sequence->width = olive::config.default_sequence_width; new_sequence->height = olive::config.default_sequence_height; @@ -774,7 +775,7 @@ void Viewer::set_media(Media* m) { const FootageStream& audio_stream = footage->audio_tracks.at(0); new_sequence->audio_frequency = audio_stream.audio_frequency; - Track* track = new_sequence->GetTrackList(olive::kTypeAudio)->First(); + Track* track = new_sequence->GetTrackList(olive::kTypeAudio).first(); 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 c5cea6677..d663dda3e 100644 --- a/timeline/sequence.cpp +++ b/timeline/sequence.cpp @@ -35,12 +35,6 @@ Sequence::Sequence() : workarea_out(0), wrapper_sequence(false) { - // Set up tracks - track_lists_.resize(olive::kTypeCount); - - for (int i=0;i(i)); - } } SequencePtr Sequence::copy() { @@ -52,10 +46,12 @@ SequencePtr Sequence::copy() { s->audio_frequency = audio_frequency; s->audio_layout = audio_layout; + /* FIXME // deep copy all of the sequence's clips for (int i=0;itrack_lists_[i] = track_lists_.at(i)->copy(s.get()); } + */ // copy all of the sequence's markers s->markers = markers; @@ -89,9 +85,11 @@ void Sequence::Save(QXmlStreamWriter &stream) QVector transition_save_cache; QVector transition_clip_save_cache; + /* FIXME for (int j=0;jSave(stream); } + */ for (int j=0;jTrackCount();i++) { - end_frame = qMax(track_list->TrackAt(i)->GetEndFrame(), end_frame); - } - + for (int i=0;iGetEndFrame(), end_frame); } return end_frame; @@ -120,22 +112,26 @@ QVector Sequence::GetAllClips() { QVector all_clips; - for (int j=0;jTrackCount();i++) { - all_clips.append(track_list->TrackAt(i)->GetAllClips()); - } + all_clips.append(tracks_.at(j)->GetAllClips()); } return all_clips; } -TrackList *Sequence::GetTrackList(olive::TrackType type) +QVector Sequence::GetTrackList(olive::TrackType type) { - return track_lists_.at(type); + QVector tracks; + + for (int i=0;itype() == type) { + tracks.append(tracks_.at(i)); + } + } + + return tracks; } void Sequence::Close() @@ -166,14 +162,10 @@ QVector Sequence::SelectedClips(bool containing) { QVector selected_clips; - for (int i=0;iTrackCount();j++) { - Track* t = tl->TrackAt(j); - - selected_clips.append(t->GetSelectedClips(containing)); - } + selected_clips.append(t->GetSelectedClips(containing)); } return selected_clips; @@ -340,14 +332,8 @@ void Sequence::EditToPoint(bool in, bool ripple) if (in_point >= 0) { - for (int i=0;iTrackCount();j++) { - areas.append(Selection(in_point, in_point+1, tl->TrackAt(j))); - } - + for (int j=0;jTrackCount();j++) { - areas.append(Selection(area_in, area_out, tl->TrackAt(j))); - } - + for (int j=0;j areas_to_delete; - for (int i=0;iTrackCount();j++) { - areas_to_delete.append(Selection(workarea_in, workarea_out, tl->TrackAt(j))); - } - + for (int j=0;jTrackCount();j++) { - Track* t = tl->TrackAt(j); - - t->set_height(t->height() + diff); - } + t->set_height(t->height() + diff); } } @@ -611,35 +581,30 @@ void Sequence::Split() // If we weren't able to split any selected clips above, see if there are arbitrary selections to split if (!split_occurred) { - TrackList* track_list; Track* track; - foreach (track_list, track_lists_) { + foreach (track, tracks_) { - QVector tracks = track_list->tracks(); - foreach (track, tracks) { + QVector track_selections = track->Selections(); + QVector split_positions; - QVector track_selections = track->Selections(); - QVector split_positions; + for (int j=0;jClipCount();i++) { - Clip* c = track->GetClip(i).get(); + if (!split_positions.contains(s.out())) { + split_positions.append(s.out()); + } + } - if (SplitClipAtPositions(ca, c, split_positions, false)) { - split_occurred = true; - } + for (int i=0;iClipCount();i++) { + Clip* c = track->GetClip(i).get(); + + if (SplitClipAtPositions(ca, c, split_positions, false)) { + split_occurred = true; } } } @@ -857,44 +822,40 @@ void Sequence::RippleDeleteEmptySpace(ComboAction* ca, Track* track, long point) void Sequence::RippleDeleteArea(ComboAction* ca, long ripple_point, long ripple_length) { - for (int i=0;iTrackCount();j++) { - Track* t = tl->TrackAt(j); + // We've already tested `track`, so we don't need to test it again + long first_in_point_after_point = LONG_MAX; + long out_point_just_before_first_in_point = LONG_MIN; - // We've already tested `track`, so we don't need to test it again - long first_in_point_after_point = LONG_MAX; - long out_point_just_before_first_in_point = LONG_MIN; + QVector track_clips = t->GetAllClips(); - QVector track_clips = t->GetAllClips(); + // Find the in point of the clip directly after the point + for (int k=0;ktimeline_in() >= ripple_point) { + first_in_point_after_point = qMin(first_in_point_after_point, c->timeline_in()); + } + } + + // Ensure we found a valid in point before proceeding + if (first_in_point_after_point != LONG_MAX) { + + // Find the out point of the clip directly before the clip found above for (int k=0;ktimeline_in() >= ripple_point) { - first_in_point_after_point = qMin(first_in_point_after_point, c->timeline_in()); + if (c->timeline_out() <= first_in_point_after_point) { + out_point_just_before_first_in_point = qMax(out_point_just_before_first_in_point, c->timeline_out()); } } - // Ensure we found a valid in point before proceeding - if (first_in_point_after_point != LONG_MAX) { + long ripple_test = first_in_point_after_point - out_point_just_before_first_in_point + ripple_length; - // Find the out point of the clip directly before the clip found above - for (int k=0;ktimeline_out() <= first_in_point_after_point) { - out_point_just_before_first_in_point = qMax(out_point_just_before_first_in_point, c->timeline_out()); - } - } - - long ripple_test = first_in_point_after_point - out_point_just_before_first_in_point + ripple_length; - - if (ripple_test < 0) { - ripple_length -= ripple_test; - } + if (ripple_test < 0) { + ripple_length -= ripple_test; } } } @@ -949,34 +910,22 @@ OldEffectNode *Sequence::GetSelectedGizmo() void Sequence::SelectAll() { - for (int j=0;jTrackCount();i++) { - tl->TrackAt(i)->SelectAll(); - } + for (int i=0;iSelectAll(); } } void Sequence::SelectAtPlayhead() { - for (int j=0;jTrackCount();i++) { - tl->TrackAt(i)->SelectAtPoint(playhead); - } + for (int i=0;iSelectAtPoint(playhead); } } void Sequence::ClearSelections() { - for (int j=0;jTrackCount();i++) { - tl->TrackAt(i)->ClearSelections(); - } + for (int i=0;iClearSelections(); } } @@ -1057,12 +1006,8 @@ QVector Sequence::Selections() { QVector selections; - for (int j=0;jTrackCount();i++) { - selections.append(tl->TrackAt(i)->Selections()); - } + for (int i=0;iSelections()); } return selections; @@ -1086,6 +1031,72 @@ void Sequence::TidySelections() SetSelections(selections); } +Track *Sequence::PreviousTrack(Track *t) +{ + Track* previous_track = nullptr; + + // Loop through tracks + for (int i=0;itype() == t->type()) { + // Otherwise, we'll keep "track" of it + previous_track = t; + } + } + + return previous_track; +} + +Track *Sequence::NextTrack(Track *t) +{ + // FIXME: The old code created extra tracks if it couldn't find one here + + Track* next_track = nullptr; + + // Loop through tracks + for (int i=tracks_.size()-1;i>=0;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; +} + +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)); +} + +int Sequence::IndexOfTrack(Track *t) +{ + QVector tracks = GetTrackList(t->type()); + + for (int i=0;i GetAllClips(); - TrackList* GetTrackList(olive::TrackType type); + QVector GetTrackList(olive::TrackType type); /** * @brief Close all open clips in a Sequence @@ -110,6 +109,11 @@ public: void SetSelections(const QVector& selections); void TidySelections(); + Track* PreviousTrack(Track* t); + Track* NextTrack(Track* t); + Track* SiblingTrack(Track* t, int diff); + int IndexOfTrack(Track* t); + long playhead; bool using_workarea; @@ -124,7 +128,7 @@ public: signals: void Changed(); private: - QVector track_lists_; + QVector tracks_; ClipPtr SplitClip(ComboAction* ca, bool transitions, Clip *clip, long frame); ClipPtr SplitClip(ComboAction* ca, bool transitions, Clip *clip, long frame, long post_in); diff --git a/timeline/timelinefunctions.cpp b/timeline/timelinefunctions.cpp index fbbd1985b..7ef8182e2 100644 --- a/timeline/timelinefunctions.cpp +++ b/timeline/timelinefunctions.cpp @@ -119,7 +119,7 @@ QVector olive::timeline::CreateGhostsFromMedia(Sequence *seq, || import_data.type() == olive::timeline::kImportBoth) { for (int j=0;jaudio_tracks.size();j++) { if (m->audio_tracks.at(j).enabled) { - g.track = seq->GetTrackList(olive::kTypeAudio)->TrackAt(j); + g.track = seq->GetTrackList(olive::kTypeAudio).at(j); g.media_stream = m->audio_tracks.at(j).file_index; ghosts.append(g); } @@ -130,7 +130,7 @@ QVector olive::timeline::CreateGhostsFromMedia(Sequence *seq, || import_data.type() == olive::timeline::kImportBoth) { for (int j=0;jvideo_tracks.size();j++) { if (m->video_tracks.at(j).enabled) { - g.track = seq->GetTrackList(olive::kTypeVideo)->TrackAt(j); + g.track = seq->GetTrackList(olive::kTypeVideo).at(j); g.media_stream = m->video_tracks.at(j).file_index; ghosts.append(g); } @@ -146,13 +146,13 @@ QVector olive::timeline::CreateGhostsFromMedia(Sequence *seq, if (import_data.type() == olive::timeline::kImportVideoOnly || import_data.type() == olive::timeline::kImportBoth) { - g.track = seq->GetTrackList(olive::kTypeVideo)->First(); + g.track = seq->GetTrackList(olive::kTypeVideo).first(); ghosts.append(g); } if (import_data.type() == olive::timeline::kImportAudioOnly || import_data.type() == olive::timeline::kImportBoth) { - g.track = seq->GetTrackList(olive::kTypeAudio)->First(); + g.track = seq->GetTrackList(olive::kTypeAudio).first(); ghosts.append(g); } diff --git a/timeline/track.cpp b/timeline/track.cpp index 2ba9cbbe6..cfe3f3c86 100644 --- a/timeline/track.cpp +++ b/timeline/track.cpp @@ -1,7 +1,6 @@ #include "track.h" #include "timeline/clip.h" -#include "timeline/tracklist.h" #include "timeline/sequence.h" #include "global/math.h" @@ -9,7 +8,7 @@ int olive::timeline::kTrackDefaultHeight = 40; int olive::timeline::kTrackMinHeight = 30; int olive::timeline::kTrackHeightIncrement = 10; -Track::Track(TrackList* parent, olive::TrackType type) : +Track::Track(Sequence* parent, olive::TrackType type) : parent_(parent), type_(type), muted_(false), @@ -19,7 +18,7 @@ Track::Track(TrackList* parent, olive::TrackType type) : { } -Track *Track::copy(TrackList *parent) +Track *Track::copy(Sequence *parent) { Track* t = new Track(parent, type_); @@ -35,11 +34,6 @@ Track *Track::copy(TrackList *parent) } Sequence *Track::sequence() -{ - return parent_->GetParent(); -} - -TrackList *Track::track_list() { return parent_; } @@ -210,27 +204,17 @@ bool Track::ContainsClip(Clip *c) Track *Track::Previous() { - int index = Index(); - - if (index == 0) { - return nullptr; - } - - return parent_->TrackAt(index - 1); + return parent_->PreviousTrack(this); } Track *Track::Next() { - return parent_->TrackAt(Index() + 1); + return parent_->NextTrack(this); } Track *Track::Sibling(int diff) { - if (diff == 0) { - return this; - } - - return track_list()->TrackAt(qMax(0, Index() + diff)); + return parent_->SiblingTrack(this, diff); } int Track::Index() @@ -394,8 +378,9 @@ bool Track::IsEffectivelyMuted() // Check if any tracks are soloed bool a_track_is_soloed = false; - for (int i=0;iTrackCount();i++) { - if (track_list()->TrackAt(i)->IsSoloed()) { + QVector siblings = parent_->GetTrackList(type_); + for (int i=0;iIsSoloed()) { a_track_is_soloed = true; break; } diff --git a/timeline/track.h b/timeline/track.h index 29a80e31c..7fbbf2fe3 100644 --- a/timeline/track.h +++ b/timeline/track.h @@ -35,17 +35,16 @@ namespace olive { } } -class TrackList; +class Sequence; class Track : public QObject { Q_OBJECT public: - Track(TrackList* parent, olive::TrackType type); - Track* copy(TrackList* parent); + Track(Sequence* parent, olive::TrackType type); + Track* copy(Sequence* parent); Sequence* sequence(); - TrackList* track_list(); void Save(QXmlStreamWriter& stream); @@ -108,7 +107,7 @@ signals: private: void ResizeClipArray(int new_size); - TrackList* parent_; + Sequence* parent_; olive::TrackType type_; int height_; QVector clips_; diff --git a/timeline/tracklist.cpp b/timeline/tracklist.cpp deleted file mode 100644 index a735750b2..000000000 --- a/timeline/tracklist.cpp +++ /dev/null @@ -1,107 +0,0 @@ -#include "tracklist.h" - -#include "timeline/sequence.h" - -TrackList::TrackList(Sequence *parent, olive::TrackType type) : - QObject(parent), - type_(type) -{ - // Ensure we have at least one track - AddTrack(); -} - -void TrackList::Save(QXmlStreamWriter &stream) -{ - stream.writeStartElement("Tracks"); - - for (int i=0;iSave(stream); - } - - stream.writeEndElement(); // Tracks -} - -TrackList* TrackList::copy(Sequence *parent) -{ - TrackList* t = new TrackList(parent, type_); - - t->ResizeTrackArray(tracks_.size()); - for (int i=0;itracks_[i] = tracks_.at(i)->copy(t); - } - - return t; -} - -void TrackList::AddTrack() -{ - Track* track = new Track(this, type_); - tracks_.append(track); - - emit TrackCountChanged(); -} - -void TrackList::RemoveTrack(int i) -{ - if (tracks_.size() == 1) { - return; - } - tracks_.removeAt(i); - - emit TrackCountChanged(); -} - -Track *TrackList::First() -{ - return tracks_.first(); -} - -Track *TrackList::Last() -{ - return tracks_.last(); -} - -int TrackList::TrackCount() -{ - return tracks_.size(); -} - -int TrackList::IndexOfTrack(Track *track) -{ - for (int i=0;i= tracks_.size()) { - AddTrack(); - } - - return tracks_.at(i); -} - -QVector TrackList::tracks() -{ - return tracks_; -} - -olive::TrackType TrackList::type() -{ - return type_; -} - -Sequence *TrackList::GetParent() -{ - return static_cast(parent()); -} - -void TrackList::ResizeTrackArray(int i) -{ - tracks_.resize(i); -} diff --git a/timeline/tracklist.h b/timeline/tracklist.h deleted file mode 100644 index 5b657aa06..000000000 --- a/timeline/tracklist.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef TRACKLIST_H -#define TRACKLIST_H - -#include "track.h" - -class TrackList : public QObject -{ - Q_OBJECT -public: - TrackList(Sequence* parent, olive::TrackType type); - TrackList* copy(Sequence* parent); - - void Save(QXmlStreamWriter& stream); - - void AddTrack(); - void RemoveTrack(int i); - Track* First(); - Track* Last(); - int TrackCount(); - int IndexOfTrack(Track* track); - Track* TrackAt(int i); - QVector tracks(); - - olive::TrackType type(); - - Sequence* GetParent(); - -signals: - void TrackCountChanged(); - -private: - void ResizeTrackArray(int i); - - olive::TrackType type_; - QVector tracks_; -}; - -#endif // TRACKLIST_H diff --git a/ui/timelinearea.cpp b/ui/timelinearea.cpp index e0c795ab8..1e368893e 100644 --- a/ui/timelinearea.cpp +++ b/ui/timelinearea.cpp @@ -49,8 +49,9 @@ TimelineArea::TimelineArea(Timeline* timeline, olive::timeline::Alignment alignm connect(view_, SIGNAL(requestScrollChange(int)), scrollbar_, SLOT(setValue(int))); } -void TimelineArea::SetTrackList(Sequence *sequence, olive::TrackType track_list) +void TimelineArea::SetTrackType(Sequence *sequence, olive::TrackType track_type) { + /* FIXME if (track_list_ != nullptr) { disconnect(track_list_, SIGNAL(TrackCountChanged()), this, SLOT(RefreshLabels())); } @@ -61,7 +62,7 @@ void TimelineArea::SetTrackList(Sequence *sequence, olive::TrackType track_list) } else { - track_list_ = sequence->GetTrackList(track_list); + track_list_ = sequence->GetTrackList(track_type); connect(track_list_, SIGNAL(TrackCountChanged()), this, SLOT(RefreshLabels())); } @@ -69,7 +70,7 @@ void TimelineArea::SetTrackList(Sequence *sequence, olive::TrackType track_list) RefreshLabels(); view_->SetTrackList(track_list_); - + */ } void TimelineArea::SetAlignment(olive::timeline::Alignment alignment) @@ -80,9 +81,9 @@ void TimelineArea::SetAlignment(olive::timeline::Alignment alignment) RefreshLabels(); } -TrackList *TimelineArea::track_list() +olive::TrackType TimelineArea::track_type() { - return track_list_; + return type_; } TimelineView *TimelineArea::view() @@ -162,6 +163,7 @@ void TimelineArea::RefreshLabels() } else { + /* FIXME labels_.resize(track_list_->TrackCount()); for (int i=0;i(); @@ -179,7 +181,7 @@ void TimelineArea::RefreshLabels() break; } } - + */ } } diff --git a/ui/timelinearea.h b/ui/timelinearea.h index c4c929bf8..df70e0c55 100644 --- a/ui/timelinearea.h +++ b/ui/timelinearea.h @@ -3,7 +3,6 @@ #include "timeline/sequence.h" #include "timeline/track.h" -#include "timeline/tracklist.h" #include "timeline/timelinefunctions.h" #include "ui/timelineview.h" #include "ui/timelinelabel.h" @@ -14,10 +13,10 @@ class TimelineArea : public QWidget public: TimelineArea(Timeline *timeline, olive::timeline::Alignment alignment = olive::timeline::kAlignmentTop); - void SetTrackList(Sequence* sequence, olive::TrackType track_list); + void SetTrackType(Sequence* sequence, olive::TrackType track_type); void SetAlignment(olive::timeline::Alignment alignment); - TrackList* track_list(); + olive::TrackType track_type(); TimelineView* view(); virtual void wheelEvent(QWheelEvent *event) override; @@ -27,7 +26,8 @@ protected: virtual void resizeEvent(QResizeEvent *event) override; private: Timeline* timeline_; - TrackList* track_list_; + Sequence* track_list_; + olive::TrackType type_; TimelineView* view_; QVector labels_; olive::timeline::Alignment alignment_; diff --git a/ui/timelineview.cpp b/ui/timelineview.cpp index 297fa596b..7f57fbe12 100644 --- a/ui/timelineview.cpp +++ b/ui/timelineview.cpp @@ -69,7 +69,8 @@ TimelineView::TimelineView(Timeline *parent) : timeline_(parent), self_created_sequence(nullptr), - track_list_(nullptr), + sequence_(nullptr), + type_(olive::kTypeCount), scroll(0), alignment_(olive::timeline::kAlignmentTop), track_resizing(false) @@ -92,9 +93,10 @@ void TimelineView::SetAlignment(olive::timeline::Alignment alignment) alignment_ = alignment; } -void TimelineView::SetTrackList(TrackList *tl) +void TimelineView::SetTrackType(Sequence* s, olive::TrackType type) { - track_list_ = tl; + sequence_ = s; + type_ = type; update(); } @@ -323,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 = track_list_->First(); + ParentTimeline()->drag_track_start = sequence_->GetTrackList(type_).first(); } ParentTimeline()->ghosts = olive::timeline::CreateGhostsFromMedia(seq, entry_point, media_list); @@ -625,15 +627,15 @@ void TimelineView::mousePressEvent(QMouseEvent *event) { } // if the track the user clicked is correct for the type of object we're adding - - if (track_list_->type() == create_type) { + if (type_ == create_type) { Ghost g; g.in = g.old_in = g.out = g.old_out = ParentTimeline()->drag_frame_start; g.track = ParentTimeline()->drag_track_start; if (g.track == nullptr) { - g.track = track_list_->Last(); - ParentTimeline()->drag_track_start = track_list_->Last(); + QVector track_list = sequence_->GetTrackList(type_); + g.track = track_list.last(); + ParentTimeline()->drag_track_start = track_list.last(); g.track_movement = getTrackIndexFromScreenPoint(event->pos().y()) - g.track->Index(); } @@ -981,8 +983,9 @@ int TimelineView::GetTotalAreaHeight() // start by adding a track height worth of padding int panel_height = olive::timeline::kTrackDefaultHeight; - for (int i=0;iTrackCount();i++) { - panel_height += track_list_->TrackAt(i)->height(); + QVector track_list = sequence_->GetTrackList(type_); + for (int i=0;iheight(); } return panel_height; @@ -1836,7 +1839,7 @@ void TimelineView::update_ghosts(const QPoint& mouse_pos, bool lock_frame) { // Prevent any clips from going below the "zeroeth" track - if (ParentTimeline()->importing || g.track->type() == track_list_->type()) { + if (ParentTimeline()->importing || g.track->type() == type_) { int track_validator = g.track->Index() + track_diff; if (track_validator < 0) { @@ -1929,7 +1932,7 @@ void TimelineView::update_ghosts(const QPoint& mouse_pos, bool lock_frame) { g.track_movement = getTrackIndexFromScreenPoint(mouse_pos.y()); - } else if (g.track->type() == track_list_->type() && g.transition == nullptr) { + } else if (g.track->type() == type_ && g.transition == nullptr) { g.track_movement = track_diff; @@ -2649,6 +2652,8 @@ void TimelineView::mouseMoveEvent(QMouseEvent *event) { } } else { + QVector track_list = sequence_->GetTrackList(type_); + // we didn't find a trim target, so we must be doing something else // (e.g. dragging a clip or resizing the track heights) @@ -2660,8 +2665,8 @@ void TimelineView::mouseMoveEvent(QMouseEvent *event) { // cursor range for resizing a track int test_range = 10; // FIXME magic number - for (int i=0;iTrackCount();i++) { - Track* track = track_list_->TrackAt(i); + for (int i=0;itype() == olive::node_library[ParentTimeline()->transition_tool_meta]->subtype()) { + if (type_ == olive::node_library[ParentTimeline()->transition_tool_meta]->subtype()) { // the range within which the transition tool will assume the user wants to make a shared transition // between two clips rather than just one transition on one clip @@ -2838,15 +2843,16 @@ void TimelineView::draw_transition(QPainter& p, Clip* c, const QRect& clip_rect, void TimelineView::paintEvent(QPaintEvent*) { // Draw clips - if (track_list_ != nullptr) { + if (sequence_ != nullptr) { QPainter p(this); // get widget width and height emit setScrollMaximum(GetTotalAreaHeight()); - for (int i=0;iTrackCount();i++) { + QVector track_list = sequence_->GetTrackList(type_); + for (int i=0;iTrackAt(i); + Track* track = track_list.at(i); int track_top = getScreenPointFromTrack(track); int track_bottom = track_top + track->height(); @@ -3205,7 +3211,7 @@ void TimelineView::paintEvent(QPaintEvent*) { for (int i=0;ighosts.size();i++) { const Ghost& g = ParentTimeline()->ghosts.at(i); first_ghost = qMin(first_ghost, g.in); - if (g.track->type() == track_list_->type()) { + if (g.track->type() == type_) { int ghost_x = ParentTimeline()->getTimelineScreenPointFromFrame(g.in); int ghost_y = getScreenPointFromTrackIndex(g.track->Index() + g.track_movement); @@ -3277,8 +3283,10 @@ Track *TimelineView::getTrackFromScreenPoint(int y) { int index = getTrackIndexFromScreenPoint(y); - if (index < track_list_->TrackCount()) { - return track_list_->TrackAt(index); + QVector track_list = sequence_->GetTrackList(type_); + + if (index < track_list.size()) { + return track_list.at(index); } return nullptr; @@ -3286,7 +3294,7 @@ Track *TimelineView::getTrackFromScreenPoint(int y) { } int TimelineView::getScreenPointFromTrack(Track *track) { - return getScreenPointFromTrackIndex(track_list_->IndexOfTrack(track)); + return getScreenPointFromTrackIndex(track->Index()); } int TimelineView::getTrackIndexFromScreenPoint(int y) @@ -3312,8 +3320,9 @@ int TimelineView::getTrackIndexFromScreenPoint(int y) int new_heights = heights; - if (i < track_list_->TrackCount()) { - new_heights += track_list_->TrackAt(i)->height(); + QVector track_list = sequence_->GetTrackList(type_); + if (i < track_list.size()) { + new_heights += track_list.at(i)->height(); } else { new_heights += olive::timeline::kTrackDefaultHeight; } @@ -3342,7 +3351,8 @@ int TimelineView::getScreenPointFromTrackIndex(int track) } if (alignment_ == olive::timeline::kAlignmentBottom) { - return qMax(height(), GetTotalAreaHeight()) - point - scroll - track_list_->First()->height() - 1; + QVector track_list = sequence_->GetTrackList(type_); + return qMax(height(), GetTotalAreaHeight()) - point - scroll - track_list.first()->height() - 1; } return point - scroll; @@ -3350,8 +3360,9 @@ int TimelineView::getScreenPointFromTrackIndex(int track) int TimelineView::getTrackHeightFromTrackIndex(int track) { - if (track < track_list_->TrackCount()) { - return track_list_->TrackAt(track)->height(); + QVector track_list = sequence_->GetTrackList(type_); + if (track < track_list.size()) { + return track_list.at(track)->height(); } else { return olive::timeline::kTrackDefaultHeight; } @@ -3364,11 +3375,7 @@ Timeline *TimelineView::ParentTimeline() Sequence *TimelineView::sequence() { - if (track_list_ == nullptr) { - return nullptr; - } - - return track_list_->GetParent(); + return sequence_; } void TimelineView::setScroll(int s) { diff --git a/ui/timelineview.h b/ui/timelineview.h index 6a9ab16c8..dd5f100ff 100644 --- a/ui/timelineview.h +++ b/ui/timelineview.h @@ -44,7 +44,7 @@ public: explicit TimelineView(Timeline *parent); void SetAlignment(olive::timeline::Alignment alignment); - void SetTrackList(TrackList* tl); + void SetTrackType(Sequence* s, olive::TrackType type); Track* getTrackFromScreenPoint(int y); int getScreenPointFromTrack(Track* track); @@ -91,7 +91,8 @@ private: Timeline* timeline_; olive::timeline::Alignment alignment_; - TrackList* track_list_; + Sequence* sequence_; + olive::TrackType type_; bool track_resizing; Track* track_target;