From 2544c5e832cfa3abbb3418e82f08327819489e24 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Sun, 29 Mar 2020 03:29:18 +1100 Subject: [PATCH] mathnode: added support for adding samples together --- app/node/math/math.cpp | 47 ++++++++++++++++++++++++++--- app/node/math/math.h | 5 +++ app/node/output/track/tracklist.cpp | 29 +++++++++++++++--- 3 files changed, 72 insertions(+), 9 deletions(-) diff --git a/app/node/math/math.cpp b/app/node/math/math.cpp index 3345df20c..c63fff934 100644 --- a/app/node/math/math.cpp +++ b/app/node/math/math.cpp @@ -51,8 +51,6 @@ Node::Capabilities MathNode::GetCapabilities(const NodeValueDatabase &input) con { if (input[param_a_in_].Has(NodeParam::kTexture) || input[param_b_in_].Has(NodeParam::kTexture)) { return kShader; - } else if (input[param_a_in_].Has(NodeParam::kSamples) || input[param_b_in_].Has(NodeParam::kSamples)) { - return kSampleProcessor; } else { return kNormal; } @@ -102,12 +100,53 @@ NodeValue MathNode::InputValueFromTable(NodeInput *input, const NodeValueTable & return Node::InputValueFromTable(input, table); } +NodeValueTable MathNode::Value(const NodeValueDatabase &value) const +{ + NodeValueTable output = value.Merge(); + + if (value[param_a_in_].Has(NodeParam::kSamples) && value[param_b_in_].Has(NodeParam::kSamples)) { + QByteArray samples_a_bytes = value[param_a_in_].Get(NodeParam::kSamples).toByteArray(); + QByteArray samples_b_bytes = value[param_b_in_].Get(NodeParam::kSamples).toByteArray(); + + QByteArray mixed_bytes; + + if (samples_a_bytes.size() > samples_b_bytes.size()) { + mixed_bytes = samples_a_bytes; + } else { + mixed_bytes = samples_b_bytes; + } + + // FIXME: Assumes float + float* samples_a = reinterpret_cast(samples_a_bytes.data()); + float* samples_b = reinterpret_cast(samples_b_bytes.data()); + float* mixed = reinterpret_cast(mixed_bytes.data()); + + int nb_samples = qMin(samples_a_bytes.size(), samples_b_bytes.size()) / sizeof(float); + + for (int i=0;ioutput()->IsConnected()) { foreach (NodeEdgePtr edge, last_track->output()->edges()) { if (!track_input_->ContainsSubParameter(edge->input())) { - Node* blend = NodeFactory::CreateFromID(QStringLiteral("org.olivevideoeditor.Olive.alphaoverblend")); - GetParentGraph()->AddNode(blend); + switch (type_) { + case Timeline::kTrackTypeVideo: + { + Node* blend = NodeFactory::CreateFromID(QStringLiteral("org.olivevideoeditor.Olive.alphaoverblend")); + GetParentGraph()->AddNode(blend); - NodeParam::ConnectEdge(track->output(), static_cast(blend->GetParameterWithID("blend_in"))); - NodeParam::ConnectEdge(last_track->output(), static_cast(blend->GetParameterWithID("base_in"))); - NodeParam::ConnectEdge(blend->output(), edge->input()); + NodeParam::ConnectEdge(track->output(), static_cast(blend->GetParameterWithID("blend_in"))); + NodeParam::ConnectEdge(last_track->output(), static_cast(blend->GetParameterWithID("base_in"))); + NodeParam::ConnectEdge(blend->output(), edge->input()); + break; + } + case Timeline::kTrackTypeAudio: + { + MathNode* add = new MathNode(); + GetParentGraph()->AddNode(add); + + NodeParam::ConnectEdge(track->output(), add->param_a_in()); + NodeParam::ConnectEdge(last_track->output(), add->param_b_in()); + NodeParam::ConnectEdge(add->output(), edge->input()); + break; + } + default: + break; + } } } }