From 5e70fd45347960eea1deccfd2490b67749002e87 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Wed, 18 Jul 2018 13:17:14 +0100 Subject: [PATCH] fixed linking bug --- io/config.cpp | 1 - io/media.cpp | 2 +- io/media.h | 1 + panels/project.cpp | 19 ++++++++++--------- panels/timeline.cpp | 22 +++++++++++++++++++--- ui/timelinewidget.cpp | 44 ++++++++++++++++++++++--------------------- ui/viewerwidget.cpp | 2 +- 7 files changed, 55 insertions(+), 36 deletions(-) diff --git a/io/config.cpp b/io/config.cpp index c42235ab8..30ae35d9e 100644 --- a/io/config.cpp +++ b/io/config.cpp @@ -5,7 +5,6 @@ #include #endif -const char* version = "Olive (May 2018 | Pre-Alpha)"; float scale = 1.0f; bool vsync = true; bool hwaccel = false; diff --git a/io/media.cpp b/io/media.cpp index 9d50afe97..880ac10f0 100644 --- a/io/media.cpp +++ b/io/media.cpp @@ -6,7 +6,7 @@ extern "C" { #include } -Media::Media() {} +Media::Media() : ready(false) {} Media::~Media() { for (int i=0;i video_tracks; QVector audio_tracks; int save_id; + bool ready; long get_length_in_frames(float frame_rate); MediaStream* get_stream_from_file_index(int index); }; diff --git a/panels/project.cpp b/panels/project.cpp index f4349bda9..6b0705edb 100644 --- a/panels/project.cpp +++ b/panels/project.cpp @@ -115,7 +115,11 @@ QTreeWidgetItem* Project::import_file(QString file) { char* filename = new char[ba.size()+1]; strcpy(filename, ba.data()); - QTreeWidgetItem* item = NULL; + QTreeWidgetItem* item = new_item(); + Media* m = new Media(); + m->url = file; + m->name = file.mid(file.lastIndexOf('/')+1); + item->setText(0, m->name); AVFormatContext* pFormatCtx = NULL; int errCode = avformat_open_input(&pFormatCtx, filename, NULL, NULL); @@ -132,10 +136,6 @@ QTreeWidgetItem* Project::import_file(QString file) { } else { av_dump_format(pFormatCtx, 0, filename, 0); - Media* m = new Media(); - m->url = file; - m->name = file.mid(file.lastIndexOf('/')+1); - // detect video/audio streams in file for (int i=0;i<(int)pFormatCtx->nb_streams;i++) { // Find the decoder for the video stream @@ -159,17 +159,14 @@ QTreeWidgetItem* Project::import_file(QString file) { } m->length = pFormatCtx->duration; - item = new_item(); if (m->video_tracks.size() == 0) { item->setIcon(0, QIcon(":/icons/audiosource.png")); } else { item->setIcon(0, QIcon(":/icons/videosource.png")); } - item->setText(0, m->name); item->setText(1, QString::number(m->length)); - set_media_of_tree(item, m); - project_changed = true; + m->ready = true; // generate waveform/thumbnail in another thread PreviewGenerator* pg = new PreviewGenerator(); @@ -180,6 +177,10 @@ QTreeWidgetItem* Project::import_file(QString file) { } } + set_media_of_tree(item, m); + + project_changed = true; + delete [] filename; return item; } diff --git a/panels/timeline.cpp b/panels/timeline.cpp index f7aa1bd53..2c434642d 100644 --- a/panels/timeline.cpp +++ b/panels/timeline.cpp @@ -846,9 +846,25 @@ void Timeline::toggle_links() { LinkCommand* command = new LinkCommand(); for (int i=0;iclip_count();i++) { Clip* c = sequence->get_clip(i); - command->clips.append(c); - if (c->linked.size() > 0) { - command->link = false; // prioritize unlinking + if (c != NULL && is_clip_selected(c, true)) { + command->clips.append(c); + if (c->linked.size() > 0) { + command->link = false; // prioritize unlinking + + for (int j=0;jlinked.size();j++) { // add links to the command + bool found = false; + Clip* link = sequence->get_clip(c->linked.at(j)); + for (int k=0;kclips.size();k++) { + if (command->clips.at(k) == link) { + found = true; + break; + } + } + if (!found) { + command->clips.append(link); + } + } + } } } if (command->clips.size() > 0) { diff --git a/ui/timelinewidget.cpp b/ui/timelinewidget.cpp index 7d8317b2c..fec5a125e 100644 --- a/ui/timelinewidget.cpp +++ b/ui/timelinewidget.cpp @@ -64,27 +64,29 @@ void TimelineWidget::dragEnterEvent(QDragEnterEvent *event) { QTreeWidgetItem* item = items.at(i); if (panel_project->get_type_from_tree(item) == MEDIA_TYPE_FOOTAGE) { Media* m = panel_project->get_media_from_tree(item); - Ghost g; - g.clip = -1; - g.media = m; - g.old_clip_in = g.clip_in = 0; - g.in = entry_point; - if (m->video_tracks.size() > 0 && m->video_tracks[0]->infinite_length && m->audio_tracks.size() == 0) { - g.out = g.in + 100; - } else { - g.out = entry_point + m->get_length_in_frames(sequence->frame_rate); - } - entry_point = g.out; - g.trimming = false; - for (int j=0;jaudio_tracks.size();j++) { - g.track = j; - g.media_stream = m->audio_tracks.at(j); - panel_timeline->ghosts.append(g); - } - for (int j=0;jvideo_tracks.size();j++) { - g.track = -1-j; - g.media_stream = m->video_tracks.at(j); - panel_timeline->ghosts.append(g); + if (m->ready) { + Ghost g; + g.clip = -1; + g.media = m; + g.old_clip_in = g.clip_in = 0; + g.in = entry_point; + if (m->video_tracks.size() > 0 && m->video_tracks[0]->infinite_length && m->audio_tracks.size() == 0) { + g.out = g.in + 100; + } else { + g.out = entry_point + m->get_length_in_frames(sequence->frame_rate); + } + entry_point = g.out; + g.trimming = false; + for (int j=0;jaudio_tracks.size();j++) { + g.track = j; + g.media_stream = m->audio_tracks.at(j); + panel_timeline->ghosts.append(g); + } + for (int j=0;jvideo_tracks.size();j++) { + g.track = -1-j; + g.media_stream = m->video_tracks.at(j); + panel_timeline->ghosts.append(g); + } } } } diff --git a/ui/viewerwidget.cpp b/ui/viewerwidget.cpp index ada49f39d..6fea28c4d 100644 --- a/ui/viewerwidget.cpp +++ b/ui/viewerwidget.cpp @@ -73,7 +73,7 @@ void ViewerWidget::paintGL() { // if clip starts within one second and/or hasn't finished yet if (c != NULL) { - if (is_clip_active(c, panel_timeline->playhead)) { + if (c->media->ready && is_clip_active(c, panel_timeline->playhead)) { // if thread is already working, we don't want to touch this, // but we also don't want to hang the UI thread if (!c->open) {