added ability to open viewers on any viewer node or derivative

Fixes #1362

Also fixes some other bugs that impeded this from working.
This commit is contained in:
itsmattkc
2021-04-12 22:58:34 +10:00
parent 17f40cf91f
commit c03c197412
26 changed files with 173 additions and 85 deletions
+2
View File
@@ -61,6 +61,7 @@ void NodeGraph::childEvent(QChildEvent *event)
connect(node, &Node::ValueChanged, this, &NodeGraph::ValueChanged);
emit NodeAdded(node);
emit node->AddedToGraph(this);
} else if (event->type() == QEvent::ChildRemoved) {
@@ -72,6 +73,7 @@ void NodeGraph::childEvent(QChildEvent *event)
disconnect(node, &Node::ValueChanged, this, &NodeGraph::ValueChanged);
emit NodeRemoved(node);
emit node->RemovedFromGraph(this);
}
}
+4
View File
@@ -926,6 +926,10 @@ signals:
void InputDataTypeChanged(const QString& id, NodeValue::Type type);
void AddedToGraph(NodeGraph* graph);
void RemovedFromGraph(NodeGraph* graph);
private:
class ArrayInsertCommand : public UndoCommand
{
+9 -7
View File
@@ -160,13 +160,15 @@ public:
static Type TypeFromString(const QString& s)
{
if (s.at(1) == ':') {
if (s.at(0) == 'v') {
// Video stream
return Track::kVideo;
} else if (s.at(0) == 'a') {
// Audio stream
return Track::kAudio;
if (s.size() >= 3) {
if (s.at(1) == ':') {
if (s.at(0) == 'v') {
// Video stream
return Track::kVideo;
} else if (s.at(0) == 'a') {
// Audio stream
return Track::kAudio;
}
}
}
+31 -29
View File
@@ -54,6 +54,7 @@ ViewerOutput::ViewerOutput(bool create_default_streams) :
if (create_default_streams) {
AddStream(Track::kVideo, QVariant());
AddStream(Track::kAudio, QVariant());
set_default_parameters();
}
}
@@ -302,39 +303,19 @@ void ViewerOutput::Retranslate()
void ViewerOutput::VerifyLength()
{
NodeTraverser traverser;
rational video_length, audio_length, subtitle_length;
{
video_length = GetCustomLength(Track::kVideo);
if (video_length.isNull() && IsInputConnected(kTextureInput)) {
NodeValueTable t = traverser.GenerateTable(GetConnectedOutput(kTextureInput), TimeRange(0, 0));
video_length = t.Get(NodeValue::kRational, QStringLiteral("length")).value<rational>();
}
if (cache_enabled_) {
video_frame_cache_.SetLength(video_length);
}
video_length = VerifyLengthInternal(Track::kVideo);
if (cache_enabled_) {
video_frame_cache_.SetLength(video_length);
}
{
audio_length = GetCustomLength(Track::kAudio);
if (audio_length.isNull() && IsInputConnected(kSamplesInput)) {
NodeValueTable t = traverser.GenerateTable(GetConnectedOutput(kSamplesInput), TimeRange(0, 0));
audio_length = t.Get(NodeValue::kRational, QStringLiteral("length")).value<rational>();
}
if (cache_enabled_) {
audio_playback_cache_.SetLength(audio_length);
}
audio_length = VerifyLengthInternal(Track::kAudio);
if (cache_enabled_) {
audio_playback_cache_.SetLength(audio_length);
}
{
subtitle_length = GetCustomLength(Track::kSubtitle);
}
subtitle_length = VerifyLengthInternal(Track::kSubtitle);
rational real_length = qMax(subtitle_length, qMax(video_length, audio_length));
@@ -362,9 +343,30 @@ void ViewerOutput::InputDisconnectedEvent(const QString &input, int element, con
super::InputDisconnectedEvent(input, element, output);
}
rational ViewerOutput::GetCustomLength(Track::Type type) const
rational ViewerOutput::VerifyLengthInternal(Track::Type type) const
{
Q_UNUSED(type)
NodeTraverser traverser;
switch (type) {
case Track::kVideo:
if (IsInputConnected(kTextureInput)) {
NodeValueTable t = traverser.GenerateTable(GetConnectedOutput(kTextureInput), TimeRange(0, 0));
qDebug() << "Got video length:" << t.Get(NodeValue::kRational, QStringLiteral("length")).value<rational>();
return t.Get(NodeValue::kRational, QStringLiteral("length")).value<rational>();
}
break;
case Track::kAudio:
if (IsInputConnected(kSamplesInput)) {
NodeValueTable t = traverser.GenerateTable(GetConnectedOutput(kSamplesInput), TimeRange(0, 0));
return t.Get(NodeValue::kRational, QStringLiteral("length")).value<rational>();
}
break;
case Track::kNone:
case Track::kSubtitle:
case Track::kCount:
break;
}
return rational();
}
+1 -1
View File
@@ -174,7 +174,7 @@ protected:
virtual void InputDisconnectedEvent(const QString &input, int element, const NodeOutput &output) override;
virtual rational GetCustomLength(Track::Type type) const;
virtual rational VerifyLengthInternal(Track::Type type) const;
virtual void ShiftVideoEvent(const rational &from, const rational &to);
+2 -2
View File
@@ -180,7 +180,7 @@ void Footage::InputValueChangedEvent(const QString &input, int element)
}
}
rational Footage::GetCustomLength(Track::Type type) const
rational Footage::VerifyLengthInternal(Track::Type type) const
{
if (type == Track::kVideo) {
VideoParams first_stream = GetFirstEnabledVideoStream();
@@ -196,7 +196,7 @@ rational Footage::GetCustomLength(Track::Type type) const
}
}
return super::GetCustomLength(type);
return super::VerifyLengthInternal(type);
}
QString Footage::GetColorspaceToUse(const VideoParams &params) const
+2 -2
View File
@@ -58,7 +58,7 @@ public:
virtual QString Name() const override
{
return tr("Footage");
return tr("Media");
}
virtual QString id() const override
@@ -195,7 +195,7 @@ protected:
virtual void InputValueChangedEvent(const QString &input, int element) override;
virtual rational GetCustomLength(Track::Type type) const override;
virtual rational VerifyLengthInternal(Track::Type type) const override;
private:
QString GetColorspaceToUse(const VideoParams& params) const;
-6
View File
@@ -430,9 +430,6 @@ void ProjectViewModel::ConnectItem(Node *n)
connect(f, &Folder::BeginRemoveItem, this, &ProjectViewModel::FolderBeginRemoveItem);
connect(f, &Folder::EndRemoveItem, this, &ProjectViewModel::FolderEndRemoveItem);
connect(f, &Folder::BeginInsertItem, this, &ProjectViewModel::ItemAdded);
connect(f, &Folder::BeginRemoveItem, this, &ProjectViewModel::ItemRemoved);
foreach (Node* c, f->children()) {
ConnectItem(c);
}
@@ -450,9 +447,6 @@ void ProjectViewModel::DisconnectItem(Node *n)
disconnect(f, &Folder::BeginRemoveItem, this, &ProjectViewModel::FolderBeginRemoveItem);
disconnect(f, &Folder::EndRemoveItem, this, &ProjectViewModel::FolderEndRemoveItem);
disconnect(f, &Folder::BeginInsertItem, this, &ProjectViewModel::ItemAdded);
disconnect(f, &Folder::BeginRemoveItem, this, &ProjectViewModel::ItemRemoved);
foreach (Node* c, f->children()) {
DisconnectItem(c);
}
-5
View File
@@ -104,11 +104,6 @@ public:
*/
QModelIndex CreateIndexFromItem(Node *item, int column = 0);
signals:
void ItemAdded(Node* node);
void ItemRemoved(Node* node);
private:
/**
* @brief Retrieve the index of `item` in its parent
+1 -1
View File
@@ -107,7 +107,7 @@ void Sequence::Retranslate()
}
}
rational Sequence::GetCustomLength(Track::Type type) const
rational Sequence::VerifyLengthInternal(Track::Type type) const
{
if (!track_lists_.isEmpty()) {
switch (type) {
+1 -1
View File
@@ -103,7 +103,7 @@ protected:
virtual void InputDisconnectedEvent(const QString &input, int element, const NodeOutput &output) override;
virtual rational GetCustomLength(Track::Type type) const override;
virtual rational VerifyLengthInternal(Track::Type type) const override;
signals:
void TrackAdded(Track* track);
+17 -5
View File
@@ -382,14 +382,26 @@ NodeValueTable NodeValueTable::Merge(QList<NodeValueTable> tables)
NodeValueTable merged_table;
// Slipstreams all tables together
foreach (const NodeValueTable& t, tables) {
if (row >= t.Count()) {
continue;
while (true) {
bool all_merged = true;
foreach (const NodeValueTable& t, tables) {
if (row < t.Count()) {
all_merged = false;
} else {
continue;
}
int row_index = t.Count() - 1 - row;
merged_table.Prepend(t.at(row_index));
}
int row_index = t.Count() - 1 - row;
row++;
merged_table.Prepend(t.at(row_index));
if (all_merged) {
break;
}
}
return merged_table;