fixed track size issue

This commit is contained in:
itsmattkc
2019-05-09 01:54:14 +10:00
parent 2905dce3d9
commit 7c66c3bf4b
7 changed files with 128 additions and 45 deletions
+1 -1
View File
@@ -337,7 +337,7 @@ void OliveGlobal::PasteInternal(Sequence *s, bool insert)
ClipPtr c = std::static_pointer_cast<Clip>(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()));
+1 -1
View File
@@ -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);
+2 -2
View File
@@ -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<Clip>(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<Clip>(track);
c->set_media(media, audio_stream.file_index);
c->set_timeline_in(0);
+94 -21
View File
@@ -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<Track*> 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<Track*> tracks = GetTrackList(t->type());
int counter = -1;
for (int i=0;i<tracks.size();i++) {
if (tracks.at(i) == t) {
return i;
for (int i=0;i<tracks_.size();i++) {
if (tracks_.at(i)->type() == t->type()) {
counter++;
}
if (tracks_.at(i) == t) {
return counter;
}
}
return -1;
}
Track *Sequence::FirstTrack(olive::TrackType type)
{
for (int i=0;i<tracks_.size();i++) {
if (tracks_.at(i)->type() == 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;i<tracks_.size();i++) {
if (tracks_.at(i)->type() == 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;i<tracks_.size();i++) {
if (tracks_.at(i)->type() == 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);
+8 -1
View File
@@ -57,7 +57,6 @@ public:
long GetEndFrame();
QVector<Clip*> GetAllClips();
QVector<Track*> 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<Track*> GetTrackList(olive::TrackType type);
long playhead;
@@ -138,7 +142,10 @@ public:
QVector<Marker> markers;
signals:
void SequenceParametersChanged();
void TrackCountChanged();
private:
Track *AddTrack(olive::TrackType type);
QVector<Track*> tracks_;
ClipPtr SplitClip(ComboAction* ca, bool transitions, Clip *clip, long frame);
+7 -11
View File
@@ -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)
+15 -8
View File
@@ -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*> track_list = sequence_->GetTrackList(type_);
while (true) {
int new_heights = heights;
QVector<Track*> 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;i++) {
int loop_start = 0;
int loop_end = track;
if (alignment_ == olive::timeline::kAlignmentBottom) {
loop_start++;
loop_end++;
}
for (int i=loop_start;i<loop_end;i++) {
point += getTrackHeightFromTrackIndex(i) + 1;
}
if (alignment_ == olive::timeline::kAlignmentBottom) {
QVector<Track*> 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*> 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;
}