mathnode: added support for adding samples together

This commit is contained in:
itsmattkc
2020-03-29 03:29:18 +11:00
parent 7100d00060
commit 2544c5e832
3 changed files with 72 additions and 9 deletions
+43 -4
View File
@@ -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<float*>(samples_a_bytes.data());
float* samples_b = reinterpret_cast<float*>(samples_b_bytes.data());
float* mixed = reinterpret_cast<float*>(mixed_bytes.data());
int nb_samples = qMin(samples_a_bytes.size(), samples_b_bytes.size()) / sizeof(float);
for (int i=0;i<nb_samples;i++) {
mixed[i] = samples_a[i] + samples_b[i];
}
output.Push(NodeParam::kSamples, mixed_bytes);
}
return output;
}
NodeInput *MathNode::param_a_in() const
{
return param_a_in_;
}
NodeInput *MathNode::param_b_in() const
{
return param_b_in_;
}
NodeParam::DataType MathNode::GuessTypeFromTable(const NodeValueTable &table)
{
if (table.Has(NodeParam::kTexture)) {
return NodeParam::kTexture;
} else if (table.Has(NodeParam::kSamples)) {
return NodeParam::kSamples;
} else {
return NodeParam::kFloat;
}
+5
View File
@@ -23,6 +23,11 @@ public:
virtual NodeValue InputValueFromTable(NodeInput* input, const NodeValueTable& table) const override;
virtual NodeValueTable Value(const NodeValueDatabase& value) const override;
NodeInput* param_a_in() const;
NodeInput* param_b_in() const;
private:
enum Operation {
kOpAdd,
+24 -5
View File
@@ -21,6 +21,7 @@
#include "tracklist.h"
#include "node/factory.h"
#include "node/math/math.h"
#include "node/output/viewer/viewer.h"
TrackList::TrackList(ViewerOutput *parent, const Timeline::TrackType &type, NodeInputArray *track_input) :
@@ -111,12 +112,30 @@ TrackOutput* TrackList::AddTrack()
if (last_track && last_track->output()->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<NodeInput*>(blend->GetParameterWithID("blend_in")));
NodeParam::ConnectEdge(last_track->output(), static_cast<NodeInput*>(blend->GetParameterWithID("base_in")));
NodeParam::ConnectEdge(blend->output(), edge->input());
NodeParam::ConnectEdge(track->output(), static_cast<NodeInput*>(blend->GetParameterWithID("blend_in")));
NodeParam::ConnectEdge(last_track->output(), static_cast<NodeInput*>(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;
}
}
}
}