From 088b0543eb39624f1b0aa168813d6502f06db431 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Thu, 19 Sep 2019 00:51:45 +1000 Subject: [PATCH] footage combobox returns streams rather than footage --- app/node/input/media/media.cpp | 13 +++++------ app/node/input/media/media.h | 2 +- app/project/item/footage/audiostream.cpp | 7 ++++++ app/project/item/footage/audiostream.h | 2 ++ app/project/item/footage/footage.cpp | 5 ++++ app/project/item/footage/footage.h | 5 ++++ app/project/item/footage/imagestream.cpp | 7 ++++++ app/project/item/footage/imagestream.h | 2 ++ app/project/item/footage/stream.cpp | 23 +++++++++++++++++++ app/project/item/footage/stream.h | 6 +++++ app/project/item/footage/videostream.cpp | 7 ++++++ app/project/item/footage/videostream.h | 2 ++ .../footagecombobox/footagecombobox.cpp | 20 ++++++++++------ app/widget/footagecombobox/footagecombobox.h | 8 +++---- .../nodeparamviewwidgetbridge.cpp | 6 ++--- app/widget/timelineview/tool/import.cpp | 2 +- 16 files changed, 94 insertions(+), 23 deletions(-) diff --git a/app/node/input/media/media.cpp b/app/node/input/media/media.cpp index 7a2547615..7a94db510 100644 --- a/app/node/input/media/media.cpp +++ b/app/node/input/media/media.cpp @@ -95,9 +95,9 @@ NodeOutput *MediaInput::texture_output() return texture_output_; } -void MediaInput::SetFootage(Footage *f) +void MediaInput::SetFootage(StreamPtr f) { - footage_input_->set_value(PtrToValue(f)); + footage_input_->set_value(QVariant::fromValue(f)); } void MediaInput::Hash(QCryptographicHash *hash, NodeOutput *from, const rational &time) @@ -284,10 +284,10 @@ bool MediaInput::SetupDecoder() } // Get currently selected Footage - Footage* footage = ValueToPtr(footage_input_->get_value(0)); + StreamPtr stream = footage_input_->get_value(0).value(); // If no footage is selected, return nothing - if (footage == nullptr) { + if (stream == nullptr) { return false; } @@ -295,13 +295,12 @@ bool MediaInput::SetupDecoder() // Determine which decoder to use if (decoder_ == nullptr - && (decoder_ = Decoder::CreateFromID(footage->decoder())) == nullptr) { + && (decoder_ = Decoder::CreateFromID(stream->footage()->decoder())) == nullptr) { return false; } if (decoder_->stream() == nullptr) { - // FIXME: Hardcoded stream 0 - decoder_->set_stream(footage->stream(0)); + decoder_->set_stream(stream); } return true; diff --git a/app/node/input/media/media.h b/app/node/input/media/media.h index 26bb9ccd0..c1dede3d0 100644 --- a/app/node/input/media/media.h +++ b/app/node/input/media/media.h @@ -49,7 +49,7 @@ public: NodeOutput* texture_output(); - void SetFootage(Footage* f); + void SetFootage(StreamPtr f); virtual void Hash(QCryptographicHash *hash, NodeOutput* from, const rational &time) override; diff --git a/app/project/item/footage/audiostream.cpp b/app/project/item/footage/audiostream.cpp index 20bba0449..e909a369a 100644 --- a/app/project/item/footage/audiostream.cpp +++ b/app/project/item/footage/audiostream.cpp @@ -25,6 +25,13 @@ AudioStream::AudioStream() set_type(kAudio); } +QString AudioStream::description() +{ + return QCoreApplication::translate("Stream", "%1: Audio - %2 Channels, %3Hz").arg(QString::number(index()), + QString::number(channels()), + QString::number(sample_rate())); +} + const int &AudioStream::channels() { return channels_; diff --git a/app/project/item/footage/audiostream.h b/app/project/item/footage/audiostream.h index a6135196c..4635c21b0 100644 --- a/app/project/item/footage/audiostream.h +++ b/app/project/item/footage/audiostream.h @@ -32,6 +32,8 @@ class AudioStream : public Stream public: AudioStream(); + virtual QString description() override; + const int& channels(); void set_channels(const int& channels); diff --git a/app/project/item/footage/footage.cpp b/app/project/item/footage/footage.cpp index 284d550e9..cae7d7c5d 100644 --- a/app/project/item/footage/footage.cpp +++ b/app/project/item/footage/footage.cpp @@ -91,6 +91,11 @@ StreamPtr Footage::stream(int index) return streams_.at(index); } +const QList &Footage::streams() +{ + return streams_; +} + int Footage::stream_count() { return streams_.size(); diff --git a/app/project/item/footage/footage.h b/app/project/item/footage/footage.h index 4f00df0d9..740c4f728 100644 --- a/app/project/item/footage/footage.h +++ b/app/project/item/footage/footage.h @@ -174,6 +174,11 @@ public: */ StreamPtr stream(int index); + /** + * @brief Returns a list of the streams in this Footage + */ + const QList& streams(); + /** * @brief Retrieve total number of streams in this Footage file */ diff --git a/app/project/item/footage/imagestream.cpp b/app/project/item/footage/imagestream.cpp index c704838bf..d538ce068 100644 --- a/app/project/item/footage/imagestream.cpp +++ b/app/project/item/footage/imagestream.cpp @@ -25,6 +25,13 @@ ImageStream::ImageStream() set_type(kImage); } +QString ImageStream::description() +{ + return QCoreApplication::translate("Stream", "%1: Image - %2x%3").arg(QString::number(index()), + QString::number(width()), + QString::number(height())); +} + const int &ImageStream::width() { return width_; diff --git a/app/project/item/footage/imagestream.h b/app/project/item/footage/imagestream.h index f905adc3f..e5d292a25 100644 --- a/app/project/item/footage/imagestream.h +++ b/app/project/item/footage/imagestream.h @@ -31,6 +31,8 @@ class ImageStream : public Stream public: ImageStream(); + virtual QString description() override; + const int& width(); void set_width(const int& width); diff --git a/app/project/item/footage/stream.cpp b/app/project/item/footage/stream.cpp index 866a6ea4c..c1b89c9eb 100644 --- a/app/project/item/footage/stream.cpp +++ b/app/project/item/footage/stream.cpp @@ -20,6 +20,8 @@ #include "stream.h" +#include "ui/icons/icons.h" + Stream::Stream() : footage_(nullptr), type_(kUnknown) @@ -31,6 +33,11 @@ Stream::~Stream() { } +QString Stream::description() +{ + return QCoreApplication::translate("Stream", "%1: Unknown").arg(index()); +} + const Stream::Type &Stream::type() { return type_; @@ -80,3 +87,19 @@ void Stream::set_duration(const int64_t &duration) { duration_ = duration; } + +QIcon Stream::IconFromType(const Stream::Type &type) +{ + switch (type) { + case Stream::kVideo: + return olive::icon::Video; + case Stream::kImage: + return olive::icon::Image; + case Stream::kAudio: + return olive::icon::Audio; + default: + break; + } + + return QIcon(); +} diff --git a/app/project/item/footage/stream.h b/app/project/item/footage/stream.h index a4339844c..23106d8e2 100644 --- a/app/project/item/footage/stream.h +++ b/app/project/item/footage/stream.h @@ -22,6 +22,8 @@ #define STREAM_H #include +#include +#include #include "common/rational.h" @@ -59,6 +61,8 @@ public: */ virtual ~Stream(); + virtual QString description(); + const Type& type(); void set_type(const Type& type); @@ -74,6 +78,8 @@ public: const int64_t& duration() const; void set_duration(const int64_t& duration); + static QIcon IconFromType(const Type& type); + private: Footage* footage_; diff --git a/app/project/item/footage/videostream.cpp b/app/project/item/footage/videostream.cpp index f8e1ac2be..d38eac54f 100644 --- a/app/project/item/footage/videostream.cpp +++ b/app/project/item/footage/videostream.cpp @@ -24,3 +24,10 @@ VideoStream::VideoStream() { set_type(kVideo); } + +QString VideoStream::description() +{ + return QCoreApplication::translate("Stream", "%1: Video - %2x%3").arg(QString::number(index()), + QString::number(width()), + QString::number(height())); +} diff --git a/app/project/item/footage/videostream.h b/app/project/item/footage/videostream.h index 2e59240c3..1f01415be 100644 --- a/app/project/item/footage/videostream.h +++ b/app/project/item/footage/videostream.h @@ -27,6 +27,8 @@ class VideoStream : public ImageStream { public: VideoStream(); + + virtual QString description() override; }; using VideoStreamPtr = std::shared_ptr; diff --git a/app/widget/footagecombobox/footagecombobox.cpp b/app/widget/footagecombobox/footagecombobox.cpp index baf7e626e..1ad5d5a57 100644 --- a/app/widget/footagecombobox/footagecombobox.cpp +++ b/app/widget/footagecombobox/footagecombobox.cpp @@ -4,13 +4,14 @@ #include #include +#include "ui/icons/icons.h" + FootageComboBox::FootageComboBox(QWidget *parent) : QComboBox(parent), root_(nullptr), footage_(nullptr), only_show_ready_footage_(true) { - } void FootageComboBox::showPopup() @@ -33,7 +34,7 @@ void FootageComboBox::showPopup() addItem(selected->text()); - footage_ = reinterpret_cast(selected->data().value()); + footage_ = selected->data().value(); emit FootageChanged(footage_); } @@ -51,12 +52,12 @@ void FootageComboBox::SetOnlyShowReadyFootage(bool e) only_show_ready_footage_ = e; } -Footage *FootageComboBox::SelectedFootage() +StreamPtr FootageComboBox::SelectedFootage() { return footage_; } -void FootageComboBox::SetFootage(Footage *f) +void FootageComboBox::SetFootage(StreamPtr f) { // Remove existing single item used to show the footage name clear(); @@ -65,7 +66,7 @@ void FootageComboBox::SetFootage(Footage *f) if (footage_ != nullptr) { // Use combobox functions to show the footage name - addItem(footage_->name()); + addItem(footage_->footage()->name()); } } @@ -83,8 +84,13 @@ void FootageComboBox::TraverseFolder(const Folder *f, QMenu *m) Footage* footage = static_cast(child); if (!only_show_ready_footage_ || footage->status() == Footage::kReady) { - QAction* footage_action = m->addAction(child->name()); - footage_action->setData(reinterpret_cast(child)); + QMenu* stream_menu = m->addMenu(footage->name()); + + foreach (StreamPtr stream, footage->streams()) { + QAction* stream_action = stream_menu->addAction(stream->description()); + stream_action->setData(QVariant::fromValue(stream)); + stream_action->setIcon(Stream::IconFromType(stream->type())); + } } } } diff --git a/app/widget/footagecombobox/footagecombobox.h b/app/widget/footagecombobox/footagecombobox.h index 5c9fa8218..36c77b7c1 100644 --- a/app/widget/footagecombobox/footagecombobox.h +++ b/app/widget/footagecombobox/footagecombobox.h @@ -19,20 +19,20 @@ public: void SetOnlyShowReadyFootage(bool e); - Footage* SelectedFootage(); + StreamPtr SelectedFootage(); public slots: - void SetFootage(Footage* f); + void SetFootage(StreamPtr f); signals: - void FootageChanged(Footage* f); + void FootageChanged(StreamPtr f); private: void TraverseFolder(const Folder *f, QMenu* m); const Folder* root_; - Footage* footage_; + StreamPtr footage_; bool only_show_ready_footage_; }; diff --git a/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp b/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp index d463a674e..26cb72479 100644 --- a/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp +++ b/app/widget/nodeparamview/nodeparamviewwidgetbridge.cpp @@ -175,9 +175,9 @@ void NodeParamViewWidgetBridge::CreateWidgets() footage_combobox->SetRoot(pp->project()->root()); // Use multiple values - footage_combobox->SetFootage(Node::ValueToPtr(base_input->get_value(0))); + footage_combobox->SetFootage(base_input->get_value(0).value()); - connect(footage_combobox, SIGNAL(FootageChanged(Footage*)), this, SLOT(WidgetCallback())); + connect(footage_combobox, SIGNAL(FootageChanged(StreamPtr)), this, SLOT(WidgetCallback())); // End test code widgets_.append(footage_combobox); @@ -308,7 +308,7 @@ void NodeParamViewWidgetBridge::WidgetCallback() { // Widget is a FootageComboBox FootageComboBox* footage_combobox = static_cast(sender()); - input->set_value(Node::PtrToValue(footage_combobox->SelectedFootage())); + input->set_value(QVariant::fromValue(footage_combobox->SelectedFootage())); break; } } diff --git a/app/widget/timelineview/tool/import.cpp b/app/widget/timelineview/tool/import.cpp index dc5132bd6..49e38a87d 100644 --- a/app/widget/timelineview/tool/import.cpp +++ b/app/widget/timelineview/tool/import.cpp @@ -179,7 +179,7 @@ void TimelineView::ImportTool::DragDrop(QDropEvent *event) opacity->setParent(&node_memory_manager); clip->set_length(ghost->Length()); - media->SetFootage(ghost->data(0).value()->footage()); + media->SetFootage(ghost->data(0).value()); NodeParam::ConnectEdge(opacity->texture_output(), clip->texture_input()); NodeParam::ConnectEdge(media->texture_output(), opacity->texture_input());