use strings to connect nodes

This makes the node system somewhat more high-level with the intent of making
working with them far more flexible and stable. By making the architecture more
abstracted, it becomes far less rigid which should allow us to do even more
with it and make it much less crash prone.
This commit is contained in:
itsmattkc
2021-02-09 15:48:37 +11:00
parent d1a3e22eaa
commit 81c1922911
138 changed files with 4487 additions and 3913 deletions
+1
View File
@@ -16,6 +16,7 @@
set(OLIVE_SOURCES
${OLIVE_SOURCES}
render/job/acceleratedjob.cpp
render/job/acceleratedjob.h
render/job/generatejob.h
render/job/samplejob.h
+32
View File
@@ -0,0 +1,32 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2020 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "acceleratedjob.h"
#include "node/node.h"
namespace olive {
void AcceleratedJob::InsertValue(const Node* node, const QString& input, NodeValueDatabase& value)
{
InsertValue(input, value[input].TakeWithMeta(node->GetInputDataType(input)));
}
}
+3 -16
View File
@@ -21,8 +21,8 @@
#ifndef ACCELERATEDJOB_H
#define ACCELERATEDJOB_H
#include "node/input.h"
#include "node/value.h"
#include "node/param.h"
#include "node/valuedatabase.h"
namespace olive {
@@ -30,31 +30,18 @@ class AcceleratedJob {
public:
AcceleratedJob() = default;
NodeValue GetValue(NodeInput* input) const
{
return value_map_.value(input->id());
}
NodeValue GetValue(const QString& input) const
{
return value_map_.value(input);
}
void InsertValue(NodeInput* input, NodeValueDatabase& value)
{
InsertValue(input->id(), value[input].TakeWithMeta(input->GetDataType()));
}
void InsertValue(const Node* node, const QString& input, NodeValueDatabase& value);
void InsertValue(const QString& input, const NodeValue& value)
{
value_map_.insert(input, value);
}
void InsertValue(NodeInput* input, const NodeValue& value)
{
value_map_.insert(input->id(), value);
}
const NodeValueMap &GetValues() const
{
return value_map_;
+1 -1
View File
@@ -38,7 +38,7 @@ public:
samples_ = value.data().value<SampleBufferPtr>();
}
SampleJob(NodeInput* from, NodeValueDatabase& db)
SampleJob(const QString& from, NodeValueDatabase& db)
{
samples_ = db[from].Take(NodeValue::kSamples).value<SampleBufferPtr>();
}
+4 -4
View File
@@ -46,9 +46,9 @@ public:
shader_id_ = id;
}
void SetIterations(int iterations, NodeInput* iterative_input)
void SetIterations(int iterations, const NodeInput& iterative_input)
{
SetIterations(iterations, iterative_input->id());
SetIterations(iterations, iterative_input.input());
}
void SetIterations(int iterations, const QString& iterative_input)
@@ -72,9 +72,9 @@ public:
return interpolation_.value(id, Texture::kDefaultInterpolation);
}
void SetInterpolation(NodeInput* input, Texture::Interpolation interp)
void SetInterpolation(const NodeInput& input, Texture::Interpolation interp)
{
interpolation_.insert(input->id(), interp);
interpolation_.insert(input.input(), interp);
}
void SetInterpolation(const QString& id, Texture::Interpolation interp)
+27 -29
View File
@@ -65,7 +65,7 @@ void PreviewAutoCacher::GenerateHashes(ViewerOutput *viewer, FrameHashCache* cac
foreach (const rational& time, times) {
// See if hash already exists in disk cache
QByteArray hash = RenderManager::Hash(viewer->texture_input()->GetConnectedNode(), viewer->video_params(), time);
QByteArray hash = RenderManager::Hash(viewer->GetConnectedNode(ViewerOutput::kTextureInput), viewer->video_params(), time);
// Check memory list since disk checking is slow
bool hash_exists = (std::find(existing_hashes.begin(), existing_hashes.end(), hash) != existing_hashes.end());
@@ -256,13 +256,13 @@ void PreviewAutoCacher::ProcessUpdateQueue()
RemoveNode(job.node);
break;
case QueuedJob::kEdgeAdded:
AddEdge(job.node, job.input, job.element);
AddEdge(job.output, job.input);
break;
case QueuedJob::kEdgeRemoved:
RemoveEdge(job.node, job.input, job.element);
RemoveEdge(job.output, job.input);
break;
case QueuedJob::kValueChanged:
CopyValue(job.input, job.element);
CopyValue(job.input);
break;
case QueuedJob::kVideoParamsChanged:
UpdateVideoParams();
@@ -305,26 +305,26 @@ void PreviewAutoCacher::RemoveNode(Node *node)
delete copy;
}
void PreviewAutoCacher::AddEdge(Node *output, NodeInput *input, int element)
void PreviewAutoCacher::AddEdge(const NodeOutput &output, const NodeInput &input)
{
Node* our_output = copy_map_.value(output);
NodeInput* our_input = copy_map_.value(input->parent())->GetInputWithID(input->id());
Node* our_output = copy_map_.value(output.node());
Node* our_input = copy_map_.value(input.node());
Node::ConnectEdge(our_output, our_input, element);
Node::ConnectEdge(NodeOutput(our_output, output.output()), NodeInput(our_input, input.input(), input.element()));
}
void PreviewAutoCacher::RemoveEdge(Node *output, NodeInput *input, int element)
void PreviewAutoCacher::RemoveEdge(const NodeOutput &output, const NodeInput &input)
{
Node* our_output = copy_map_.value(output);
NodeInput* our_input = copy_map_.value(input->parent())->GetInputWithID(input->id());
Node* our_output = copy_map_.value(output.node());
Node* our_input = copy_map_.value(input.node());
Node::DisconnectEdge(our_output, our_input, element);
Node::DisconnectEdge(NodeOutput(our_output, output.output()), NodeInput(our_input, input.input(), input.element()));
}
void PreviewAutoCacher::CopyValue(NodeInput *input, int element)
void PreviewAutoCacher::CopyValue(const NodeInput &input)
{
NodeInput* our_input = copy_map_.value(input->parent())->GetInputWithID(input->id());
NodeInput::CopyValuesOfElement(input, our_input, element);
Node* our_input = copy_map_.value(input.node());
Node::CopyValuesOfElement(input.node(), our_input, input.input(), input.element());
}
void PreviewAutoCacher::UpdateVideoParams()
@@ -423,27 +423,27 @@ void PreviewAutoCacher::ClearVideoDownloadQueue(bool wait)
void PreviewAutoCacher::NodeAdded(Node *node)
{
graph_update_queue_.append({QueuedJob::kNodeAdded, node, nullptr, -1});
graph_update_queue_.append({QueuedJob::kNodeAdded, node, NodeInput(), NodeOutput()});
}
void PreviewAutoCacher::NodeRemoved(Node *node)
{
graph_update_queue_.append({QueuedJob::kNodeRemoved, node, nullptr, -1});
graph_update_queue_.append({QueuedJob::kNodeRemoved, node, NodeInput(), NodeOutput()});
}
void PreviewAutoCacher::EdgeAdded(Node *output, NodeInput *input, int element)
void PreviewAutoCacher::EdgeAdded(const NodeOutput &output, const NodeInput &input)
{
graph_update_queue_.append({QueuedJob::kEdgeAdded, output, input, element});
graph_update_queue_.append({QueuedJob::kEdgeAdded, nullptr, input, output});
}
void PreviewAutoCacher::EdgeRemoved(Node *output, NodeInput *input, int element)
void PreviewAutoCacher::EdgeRemoved(const NodeOutput &output, const NodeInput &input)
{
graph_update_queue_.append({QueuedJob::kEdgeRemoved, output, input, element});
graph_update_queue_.append({QueuedJob::kEdgeRemoved, nullptr, input, output});
}
void PreviewAutoCacher::ValueChanged(NodeInput *input, int element)
void PreviewAutoCacher::ValueChanged(const NodeInput &input)
{
graph_update_queue_.append({QueuedJob::kValueChanged, nullptr, input, element});
graph_update_queue_.append({QueuedJob::kValueChanged, nullptr, input, NodeOutput()});
}
void PreviewAutoCacher::VideoParamsChanged()
@@ -451,14 +451,14 @@ void PreviewAutoCacher::VideoParamsChanged()
// In case the user is pressing the mouse at this exact moment
IgnoreNextMouseButton();
graph_update_queue_.append({QueuedJob::kVideoParamsChanged, nullptr, nullptr, -1});
graph_update_queue_.append({QueuedJob::kVideoParamsChanged, nullptr, NodeInput(), NodeOutput()});
ClearVideoQueue();
TryRender();
}
void PreviewAutoCacher::AudioParamsChanged()
{
graph_update_queue_.append({QueuedJob::kAudioParamsChanged, nullptr, nullptr, -1});
graph_update_queue_.append({QueuedJob::kAudioParamsChanged, nullptr, NodeInput(), NodeOutput()});
ClearAudioQueue();
TryRender();
}
@@ -677,10 +677,8 @@ void PreviewAutoCacher::SetViewerNode(ViewerOutput *viewer_node)
// Add all connections
foreach (Node* node, graph->nodes()) {
foreach (NodeInput* input, node->inputs()) {
for (auto it=input->edges().cbegin(); it!=input->edges().cend(); it++) {
AddEdge(it->second, input, it->first);
}
for (auto it=node->input_connections().cbegin(); it!=node->input_connections().cend(); it++) {
AddEdge(it->second, it->first);
}
}
+8 -8
View File
@@ -107,9 +107,9 @@ private:
void AddNode(Node* node);
void RemoveNode(Node* node);
void AddEdge(Node* output, NodeInput* input, int element);
void RemoveEdge(Node* output, NodeInput* input, int element);
void CopyValue(NodeInput* input, int element);
void AddEdge(const NodeOutput& output, const NodeInput& input);
void RemoveEdge(const NodeOutput& output, const NodeInput& input);
void CopyValue(const NodeInput& input);
void UpdateVideoParams();
void UpdateAudioParams();
@@ -127,8 +127,8 @@ private:
Type type;
Node* node;
NodeInput* input;
int element;
NodeInput input;
NodeOutput output;
};
ViewerOutput* viewer_node_;
@@ -201,11 +201,11 @@ private slots:
void NodeRemoved(Node* node);
void EdgeAdded(Node* output, NodeInput* input, int element);
void EdgeAdded(const NodeOutput& output, const NodeInput& input);
void EdgeRemoved(Node* output, NodeInput* input, int element);
void EdgeRemoved(const NodeOutput& output, const NodeInput& input);
void ValueChanged(NodeInput* input, int element);
void ValueChanged(const NodeInput& input);
void VideoParamsChanged();
+6 -14
View File
@@ -58,7 +58,7 @@ void RenderProcessor::Run()
const VideoParams& video_params = ticket_->property("vparam").value<VideoParams>();
rational time = ticket_->property("time").value<rational>();
NodeValueTable table = ProcessInput(viewer->texture_input(),
NodeValueTable table = ProcessInput(viewer, ViewerOutput::kTextureInput,
TimeRange(time, time + video_params.time_base()));
TexturePtr texture = table.Get(NodeValue::kTexture).value<TexturePtr>();
@@ -133,7 +133,7 @@ void RenderProcessor::Run()
ViewerOutput* viewer = Node::ValueToPtr<ViewerOutput>(ticket_->property("viewer"));
TimeRange time = ticket_->property("time").value<TimeRange>();
NodeValueTable table = ProcessInput(viewer->samples_input(), time);
NodeValueTable table = ProcessInput(viewer, ViewerOutput::kSamplesInput, time);
ticket_->Finish(table.Get(NodeValue::kSamples), IsCancelled());
break;
@@ -219,10 +219,10 @@ NodeValueTable RenderProcessor::GenerateBlockTable(const Track *track, const Tim
}
// FIXME: Doesn't handle reversing
if (b->speed_input()->IsKeyframing() || b->speed_input()->IsConnected()) {
if (b->IsInputKeyframing(Block::kSpeedInput) || b->IsInputConnected(Block::kSpeedInput)) {
// FIXME: We'll need to calculate the speed hoo boy
} else {
double speed_value = b->speed_input()->GetStandardValue().toDouble();
double speed_value = b->GetStandardValue(Block::kSpeedInput).toDouble();
if (qIsNull(speed_value)) {
// Just silence, don't think there's any other practical application of 0 speed audio
@@ -450,16 +450,8 @@ QVariant RenderProcessor::ProcessSamples(const Node *node, const TimeRange &rang
rational this_sample_time = rational::fromDouble(range.in().toDouble() + sample_to_second);
// Update all non-sample and non-footage inputs
NodeValueMap::const_iterator j;
for (j=job.GetValues().constBegin(); j!=job.GetValues().constEnd(); j++) {
NodeValueTable value;
NodeInput* corresponding_input = node->GetInputWithID(j.key());
if (corresponding_input) {
value = ProcessInput(corresponding_input, TimeRange(this_sample_time, this_sample_time));
} else {
value.Push(j.value());
}
for (auto j=job.GetValues().constBegin(); j!=job.GetValues().constEnd(); j++) {
NodeValueTable value = ProcessInput(node, j.key(), TimeRange(this_sample_time, this_sample_time));
value_db.Insert(j.key(), value);
}