diff --git a/app/task/project/loadotio/loadotio.cpp b/app/task/project/loadotio/loadotio.cpp index 3d374c0cb..3861eb2e6 100644 --- a/app/task/project/loadotio/loadotio.cpp +++ b/app/task/project/loadotio/loadotio.cpp @@ -32,6 +32,7 @@ #include "node/input/media/media.h" #include "project/item/folder/folder.h" #include "project/item/sequence/sequence.h" +#include "widget/timelinewidget/timelineundo.h" #define OTIO opentimelineio::v1_0 @@ -92,23 +93,21 @@ bool LoadOTIOTask::Run() auto otio_track = static_cast(c.value); // Create a new track - TrackOutput* track = nullptr; + Track* track = nullptr; // Determine what kind of track it is - if (otio_track->kind() == "Video") { - track = seq_viewer->track_list(Timeline::kTrackTypeVideo)->AddTrack(); + if (otio_track->kind() == "Video" || otio_track->kind() == "Audio") { + Track::Type type; - if (seq_viewer->track_list(Timeline::kTrackTypeVideo)->GetTrackCount() == 1) { - // If this is the first track, connect it to the viewer - NodeParam::ConnectEdge(track->output(), seq_viewer->texture_input()); + if (otio_track->kind() == "Video") { + type = Track::kVideo; + } else { + type = Track::kAudio; } - } else if (otio_track->kind() == "Audio") { - track = seq_viewer->track_list(Timeline::kTrackTypeAudio)->AddTrack(); - if (seq_viewer->track_list(Timeline::kTrackTypeAudio)->GetTrackCount() == 1) { - // If this is the first track, connect it to the viewer - NodeParam::ConnectEdge(track->output(), seq_viewer->samples_input()); - } + TimelineAddTrackCommand t(seq_viewer->track_list(type)); + t.redo(); + track = t.track(); } else { qWarning() << "Found unknown track type:" << otio_track->kind().c_str(); continue; @@ -150,7 +149,7 @@ bool LoadOTIOTask::Run() block->set_media_in(start_time); block->set_length_and_media_out(duration); - sequence->AddNode(block); + block->setParent(sequence); track->AppendBlock(block); if (otio_block->schema_name() == "Clip") { @@ -172,14 +171,14 @@ bool LoadOTIOTask::Run() if (probed_item && probed_item->type() == Item::kFootage) { MediaInput* media = new MediaInput(); - if (track->track_type() == Timeline::kTrackTypeVideo) { + if (track->type() == Track::kVideo) { media->SetStream(probed_item->get_first_enabled_stream_of_type(Stream::kVideo)); } else { media->SetStream(probed_item->get_first_enabled_stream_of_type(Stream::kAudio)); } - sequence->AddNode(media); + media->setParent(sequence); - NodeParam::ConnectEdge(media->output(), static_cast(block)->texture_input()); + Node::ConnectEdge(media, static_cast(block)->texture_input()); } else { // FIXME: Add to some kind of list that we couldn't find it } diff --git a/app/task/project/saveotio/saveotio.cpp b/app/task/project/saveotio/saveotio.cpp index bca7e07e5..f0e1b5d3f 100644 --- a/app/task/project/saveotio/saveotio.cpp +++ b/app/task/project/saveotio/saveotio.cpp @@ -95,8 +95,8 @@ opentimelineio::v1_0::Timeline *SaveOTIOTask::SerializeTimeline(Sequence *sequen { auto otio_timeline = new opentimelineio::v1_0::Timeline(sequence->name().toStdString()); - if (!SerializeTrackList(sequence->viewer_output()->track_list(Timeline::kTrackTypeVideo), otio_timeline) - || !SerializeTrackList(sequence->viewer_output()->track_list(Timeline::kTrackTypeAudio), otio_timeline)) { + if (!SerializeTrackList(sequence->viewer_output()->track_list(Track::kVideo), otio_timeline) + || !SerializeTrackList(sequence->viewer_output()->track_list(Track::kAudio), otio_timeline)) { otio_timeline->possibly_delete(); return nullptr; } @@ -104,21 +104,21 @@ opentimelineio::v1_0::Timeline *SaveOTIOTask::SerializeTimeline(Sequence *sequen return otio_timeline; } -opentimelineio::v1_0::Track *SaveOTIOTask::SerializeTrack(TrackOutput *track) +opentimelineio::v1_0::Track *SaveOTIOTask::SerializeTrack(Track *track) { auto otio_track = new opentimelineio::v1_0::Track(); opentimelineio::v1_0::ErrorStatus es; - switch (track->track_type()) { - case Timeline::kTrackTypeVideo: + switch (track->type()) { + case Track::kVideo: otio_track->set_kind("Video"); break; - case Timeline::kTrackTypeAudio: + case Track::kAudio: otio_track->set_kind("Audio"); break; default: - qWarning() << "Don't know OTIO track kind for native type" << track->track_type(); + qWarning() << "Don't know OTIO track kind for native type" << track->type(); goto fail; } @@ -188,7 +188,7 @@ bool SaveOTIOTask::SerializeTrackList(TrackList *list, opentimelineio::v1_0::Tim { opentimelineio::v1_0::ErrorStatus es; - foreach (TrackOutput* track, list->GetTracks()) { + foreach (Track* track, list->GetTracks()) { auto otio_track = SerializeTrack(track); if (!otio_track) { diff --git a/app/task/project/saveotio/saveotio.h b/app/task/project/saveotio/saveotio.h index bad9ef050..b50ac4381 100644 --- a/app/task/project/saveotio/saveotio.h +++ b/app/task/project/saveotio/saveotio.h @@ -41,7 +41,7 @@ protected: private: opentimelineio::v1_0::Timeline* SerializeTimeline(Sequence* sequence); - opentimelineio::v1_0::Track* SerializeTrack(TrackOutput* track); + opentimelineio::v1_0::Track* SerializeTrack(Track* track); bool SerializeTrackList(TrackList* list, opentimelineio::v1_0::Timeline *otio_timeline); diff --git a/app/widget/slider/floatslider.cpp b/app/widget/slider/floatslider.cpp index 8baa4000b..cbd8f6eda 100644 --- a/app/widget/slider/floatslider.cpp +++ b/app/widget/slider/floatslider.cpp @@ -20,6 +20,7 @@ #include "floatslider.h" +#include #include #include diff --git a/app/widget/timelinewidget/timelineundo.h b/app/widget/timelinewidget/timelineundo.h index 88b3fc5d3..cf2d328c0 100644 --- a/app/widget/timelinewidget/timelineundo.h +++ b/app/widget/timelinewidget/timelineundo.h @@ -1356,12 +1356,13 @@ private: class TimelineAddTrackCommand : public UndoCommand { public: TimelineAddTrackCommand(TrackList *timeline) : - timeline_(timeline) + timeline_(timeline), + direct_(nullptr) { track_ = new Track(); track_->setParent(&memory_manager_); - if (Config::Current()[QStringLiteral("AutoMergeTracks")].toBool()) { + if (timeline->GetTrackCount() > 0 && Config::Current()[QStringLiteral("AutoMergeTracks")].toBool()) { if (timeline_->type() == Track::kVideo) { MergeNode* merge = new MergeNode(); base_ = merge->base_in(); @@ -1379,6 +1380,11 @@ public: } } + Track* track() const + { + return track_; + } + virtual Project* GetRelevantProject() const override { return timeline_->GetParentGraph()->project(); @@ -1409,6 +1415,21 @@ public: // Connect this as the "blend" track Node::ConnectEdge(track_, blend_); Node::ConnectEdge(last_track, base_); + } else if (timeline_->GetTrackCount() == 1) { + // If this was the first track we added, + NodeInput* relevant_input; + + if (timeline_->type() == Track::kVideo) { + relevant_input = timeline_->parent()->texture_input(); + } else { + relevant_input = timeline_->parent()->samples_input(); + } + + if (!relevant_input->IsConnected()) { + Node::ConnectEdge(track_, relevant_input); + + direct_ = relevant_input; + } } } @@ -1429,6 +1450,8 @@ public: } merge_->setParent(&memory_manager_); + } else if (direct_) { + Node::DisconnectEdge(track_, direct_); } // Remove track @@ -1445,6 +1468,8 @@ private: NodeInput* base_; NodeInput* blend_; + NodeInput* direct_; + QObject memory_manager_; };