From 2c5aee4d2e9d87359ba3665ffcd94e6024ae6614 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Wed, 24 Feb 2021 22:16:08 +1100 Subject: [PATCH] reimplement footage viewer in new structure --- app/project/item/footage/footage.cpp | 9 +++++++- app/project/project.cpp | 5 ++++ app/project/project.h | 8 +++++++ app/widget/viewer/footageviewer.cpp | 34 ++++++++++++++++++++-------- app/widget/viewer/footageviewer.h | 4 +--- 5 files changed, 46 insertions(+), 14 deletions(-) diff --git a/app/project/item/footage/footage.cpp b/app/project/item/footage/footage.cpp index 5e68581b3..a72340674 100644 --- a/app/project/item/footage/footage.cpp +++ b/app/project/item/footage/footage.cpp @@ -572,18 +572,25 @@ NodeValueTable Footage::Value(const QString &output, NodeValueDatabase &value) c if (QFileInfo(file).exists()) { FootageJob job(decoder_, filename(), ref.type()); + rational length; + if (ref.type() == Stream::kVideo) { VideoParams vp = GetVideoParams(ref.index()); // Ensure the colorspace is valid and not empty vp.set_colorspace(GetColorspaceToUse(vp)); + length = Timecode::timestamp_to_time(vp.duration(), vp.time_base()); job.set_video_params(vp); } else { - job.set_audio_params(GetAudioParams(ref.index())); + AudioParams ap = GetAudioParams(ref.index()); + job.set_audio_params(ap); job.set_cache_path(project()->cache_path()); + length = Timecode::timestamp_to_time(ap.duration(), ap.time_base()); } + table.Push(NodeValue::kRational, QVariant::fromValue(length), this, false, QStringLiteral("length")); + table.Push(NodeValue::kFootageJob, QVariant::fromValue(job), this); } diff --git a/app/project/project.cpp b/app/project/project.cpp index 74ed46e58..e42aa9039 100644 --- a/app/project/project.cpp +++ b/app/project/project.cpp @@ -46,6 +46,11 @@ Project::Project() : settings_->setParent(this); AddDefaultNode(settings_); + // Viewer node for connecting with the footage viewer + footage_viewer_ = new ViewerOutput(); + footage_viewer_->setParent(this); + AddDefaultNode(footage_viewer_); + // Folder root for project root_ = new Folder(); root_->setParent(this); diff --git a/app/project/project.h b/app/project/project.h index eeac418f3..8edced89f 100644 --- a/app/project/project.h +++ b/app/project/project.h @@ -25,6 +25,7 @@ #include #include "node/project/projectsettings/projectsettings.h" +#include "node/output/viewer/viewer.h" #include "render/colormanager.h" #include "project/item/folder/folder.h" #include "window/mainwindow/mainwindowlayoutinfo.h" @@ -72,6 +73,11 @@ public: QString cache_path() const; + ViewerOutput* footage_viewer() + { + return footage_viewer_; + } + signals: void NameChanged(); @@ -86,6 +92,8 @@ private: ProjectSettingsNode* settings_; + ViewerOutput* footage_viewer_; + bool is_modified_; bool autorecovery_saved_; diff --git a/app/widget/viewer/footageviewer.cpp b/app/widget/viewer/footageviewer.cpp index a28d3f05d..dfaf8fdf3 100644 --- a/app/widget/viewer/footageviewer.cpp +++ b/app/widget/viewer/footageviewer.cpp @@ -46,30 +46,44 @@ Footage *FootageViewerWidget::GetFootage() const void FootageViewerWidget::SetFootage(Footage *footage) { + if (footage && !footage->project()) { + qCritical() << "Failed to set footage in footage viewer - footage had no project"; + return; + } + if (footage_) { cached_timestamps_.insert(footage_, GetTimestamp()); + ViewerOutput* old_viewer = footage_->project()->footage_viewer(); + ConnectViewerNode(nullptr); - Node::DisconnectEdge(sequence_.GetConnectedOutput(ViewerOutput::kTextureInput), NodeInput(&sequence_, ViewerOutput::kTextureInput)); - Node::DisconnectEdge(sequence_.GetConnectedOutput(ViewerOutput::kSamplesInput), NodeInput(&sequence_, ViewerOutput::kSamplesInput)); + if (old_viewer->IsInputConnected(ViewerOutput::kTextureInput)) { + Node::DisconnectEdge(old_viewer->GetConnectedOutput(ViewerOutput::kTextureInput), NodeInput(old_viewer, ViewerOutput::kTextureInput)); + } + + if (old_viewer->IsInputConnected(ViewerOutput::kSamplesInput)) { + Node::DisconnectEdge(old_viewer->GetConnectedOutput(ViewerOutput::kSamplesInput), NodeInput(old_viewer, ViewerOutput::kSamplesInput)); + } } footage_ = footage; if (footage_) { + ViewerOutput* new_viewer = footage_->project()->footage_viewer(); + // Update sequence media name - sequence_.SetLabel(footage_->GetLabel()); + new_viewer->SetLabel(footage_->GetLabel()); // Reset parameters and then attempt to set from footage - sequence_.set_default_parameters(); - sequence_.set_parameters_from_footage({footage_}); + new_viewer->set_default_parameters(); + new_viewer->set_parameters_from_footage({footage_}); // Try to connect video stream - TryConnectingType(footage, Stream::kVideo); - TryConnectingType(footage, Stream::kAudio); + TryConnectingType(new_viewer, footage, Stream::kVideo); + TryConnectingType(new_viewer, footage, Stream::kAudio); - ConnectViewerNode(&sequence_, footage_->project()->color_manager()); + ConnectViewerNode(new_viewer); SetTimestamp(cached_timestamps_.value(footage_, 0)); } else { @@ -124,7 +138,7 @@ void FootageViewerWidget::StartFootageDragInternal(bool enable_video, bool enabl } } -void FootageViewerWidget::TryConnectingType(Footage *footage, Stream::Type type) +void FootageViewerWidget::TryConnectingType(ViewerOutput* viewer, Footage *footage, Stream::Type type) { int index = -1; @@ -165,7 +179,7 @@ void FootageViewerWidget::TryConnectingType(Footage *footage, Stream::Type type) input_param = ViewerOutput::kSamplesInput; } - Node::ConnectEdge(NodeOutput(footage, s), NodeInput(&sequence_, input_param)); + Node::ConnectEdge(NodeOutput(footage, s), NodeInput(viewer, input_param)); } } diff --git a/app/widget/viewer/footageviewer.h b/app/widget/viewer/footageviewer.h index 00ed0aa53..c25b5449b 100644 --- a/app/widget/viewer/footageviewer.h +++ b/app/widget/viewer/footageviewer.h @@ -43,12 +43,10 @@ protected: private: void StartFootageDragInternal(bool enable_video, bool enable_audio); - void TryConnectingType(Footage* footage, Stream::Type type); + void TryConnectingType(ViewerOutput *viewer, Footage* footage, Stream::Type type); Footage* footage_; - Sequence sequence_; - QHash cached_timestamps_; private slots: