Skip to content

Commit

Permalink
fixed track size issue
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmattkc committed May 8, 2019
1 parent 2905dce commit 7c66c3b
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 45 deletions.
2 changes: 1 addition & 1 deletion global/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
2 changes: 1 addition & 1 deletion panels/timeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions panels/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
115 changes: 94 additions & 21 deletions timeline/sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Sequence::Sequence() :
workarea_out(0),
wrapper_sequence(false)
{
AddTrack(olive::kTypeVideo);
AddTrack(olive::kTypeAudio);
}

SequencePtr Sequence::copy() {
Expand Down Expand Up @@ -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++) {

for (int i=0;i<tracks.size();i++) {
if (tracks.at(i) == t) {
return 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);
Expand Down
9 changes: 8 additions & 1 deletion timeline/sequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class Sequence : public QObject {

long GetEndFrame();
QVector<Clip*> GetAllClips();
QVector<Track*> GetTrackList(olive::TrackType type);

/**
* @brief Close all open clips in a Sequence
Expand Down Expand Up @@ -124,6 +123,11 @@ class Sequence : public QObject {
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;

Expand All @@ -138,7 +142,10 @@ class Sequence : public QObject {
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);
Expand Down
18 changes: 7 additions & 11 deletions ui/timelinearea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 15 additions & 8 deletions ui/timelineview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
}

Expand All @@ -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 {
Expand All @@ -3346,23 +3349,27 @@ 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;
}

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;
}
Expand Down

0 comments on commit 7c66c3b

Please sign in to comment.