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:
+26
-21
@@ -22,19 +22,22 @@
|
||||
|
||||
namespace olive {
|
||||
|
||||
const QString MathNode::kMethodIn = QStringLiteral("method_in");
|
||||
const QString MathNode::kParamAIn = QStringLiteral("param_a_in");
|
||||
const QString MathNode::kParamBIn = QStringLiteral("param_b_in");
|
||||
const QString MathNode::kParamCIn = QStringLiteral("param_c_in");
|
||||
|
||||
MathNode::MathNode()
|
||||
{
|
||||
method_in_ = new NodeInput(this, QStringLiteral("method_in"), NodeValue::kCombo);
|
||||
method_in_->SetConnectable(false);
|
||||
method_in_->SetKeyframable(false);
|
||||
AddInput(kMethodIn, NodeValue::kCombo, InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable));
|
||||
|
||||
param_a_in_ = new NodeInput(this, QStringLiteral("param_a_in"), NodeValue::kFloat, 0.0);
|
||||
param_a_in_->setProperty("decimalplaces", 8);
|
||||
param_a_in_->setProperty("autotrim", true);
|
||||
AddInput(kParamAIn, NodeValue::kFloat, 0.0);
|
||||
SetInputProperty(kParamAIn, QStringLiteral("decimalplaces"), 8);
|
||||
SetInputProperty(kParamAIn, QStringLiteral("autotrim"), true);
|
||||
|
||||
param_b_in_ = new NodeInput(this, QStringLiteral("param_b_in"), NodeValue::kFloat, 0.0);
|
||||
param_b_in_->setProperty("decimalplaces", 8);
|
||||
param_b_in_->setProperty("autotrim", true);
|
||||
AddInput(kParamBIn, NodeValue::kFloat, 0.0);
|
||||
SetInputProperty(kParamBIn, QStringLiteral("decimalplaces"), 8);
|
||||
SetInputProperty(kParamBIn, QStringLiteral("autotrim"), true);
|
||||
}
|
||||
|
||||
Node *MathNode::copy() const
|
||||
@@ -66,9 +69,9 @@ void MathNode::Retranslate()
|
||||
{
|
||||
Node::Retranslate();
|
||||
|
||||
method_in_->set_name(tr("Method"));
|
||||
param_a_in_->set_name(tr("Value"));
|
||||
param_b_in_->set_name(tr("Value"));
|
||||
SetInputName(kMethodIn, tr("Method"));
|
||||
SetInputName(kParamAIn, tr("Value"));
|
||||
SetInputName(kParamBIn, tr("Value"));
|
||||
|
||||
QStringList operations = {tr("Add"),
|
||||
tr("Subtract"),
|
||||
@@ -77,19 +80,21 @@ void MathNode::Retranslate()
|
||||
QString(),
|
||||
tr("Power")};
|
||||
|
||||
method_in_->set_combobox_strings(operations);
|
||||
SetComboBoxStrings(kMethodIn, operations);
|
||||
}
|
||||
|
||||
ShaderCode MathNode::GetShaderCode(const QString &shader_id) const
|
||||
{
|
||||
return GetShaderCodeInternal(shader_id, param_a_in_, param_b_in_);
|
||||
return GetShaderCodeInternal(shader_id, kParamAIn, kParamBIn);
|
||||
}
|
||||
|
||||
NodeValueTable MathNode::Value(NodeValueDatabase &value) const
|
||||
NodeValueTable MathNode::Value(const QString &output, NodeValueDatabase &value) const
|
||||
{
|
||||
Q_UNUSED(output)
|
||||
|
||||
// Auto-detect what values to operate with
|
||||
// FIXME: Add manual override for this
|
||||
PairingCalculator calc(value[param_a_in_], value[param_b_in_]);
|
||||
PairingCalculator calc(value[kParamAIn], value[kParamBIn]);
|
||||
|
||||
// Do nothing if no pairing was found
|
||||
if (!calc.FoundMostLikelyPairing()) {
|
||||
@@ -97,23 +102,23 @@ NodeValueTable MathNode::Value(NodeValueDatabase &value) const
|
||||
}
|
||||
|
||||
NodeValue val_a = calc.GetMostLikelyValueA();
|
||||
value[param_a_in_].Remove(val_a);
|
||||
value[kParamAIn].Remove(val_a);
|
||||
|
||||
NodeValue val_b = calc.GetMostLikelyValueB();
|
||||
value[param_b_in_].Remove(val_b);
|
||||
value[kParamBIn].Remove(val_b);
|
||||
|
||||
return ValueInternal(value,
|
||||
GetOperation(),
|
||||
calc.GetMostLikelyPairing(),
|
||||
param_a_in_,
|
||||
kParamAIn,
|
||||
val_a,
|
||||
param_b_in_,
|
||||
kParamBIn,
|
||||
val_b);
|
||||
}
|
||||
|
||||
void MathNode::ProcessSamples(NodeValueDatabase &values, const SampleBufferPtr input, SampleBufferPtr output, int index) const
|
||||
{
|
||||
return ProcessSamplesInternal(values, GetOperation(), param_a_in_, param_b_in_, input, output, index);
|
||||
return ProcessSamplesInternal(values, GetOperation(), kParamAIn, kParamBIn, input, output, index);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,34 +44,22 @@ public:
|
||||
|
||||
Operation GetOperation() const
|
||||
{
|
||||
return static_cast<Operation>(method_in_->GetStandardValue().toInt());
|
||||
return static_cast<Operation>(GetStandardValue(kMethodIn).toInt());
|
||||
}
|
||||
|
||||
void SetOperation(Operation o)
|
||||
{
|
||||
method_in_->SetStandardValue(o);
|
||||
SetStandardValue(kMethodIn, o);
|
||||
}
|
||||
|
||||
NodeInput* param_a_in() const
|
||||
{
|
||||
return param_a_in_;
|
||||
}
|
||||
|
||||
NodeInput* param_b_in() const
|
||||
{
|
||||
return param_b_in_;
|
||||
}
|
||||
|
||||
virtual NodeValueTable Value(NodeValueDatabase &value) const override;
|
||||
virtual NodeValueTable Value(const QString& output, NodeValueDatabase &value) const override;
|
||||
|
||||
virtual void ProcessSamples(NodeValueDatabase &values, const SampleBufferPtr input, SampleBufferPtr output, int index) const override;
|
||||
|
||||
private:
|
||||
NodeInput* method_in_;
|
||||
|
||||
NodeInput* param_a_in_;
|
||||
|
||||
NodeInput* param_b_in_;
|
||||
static const QString kMethodIn;
|
||||
static const QString kParamAIn;
|
||||
static const QString kParamBIn;
|
||||
static const QString kParamCIn;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
namespace olive {
|
||||
|
||||
ShaderCode MathNodeBase::GetShaderCodeInternal(const QString &shader_id, NodeInput *param_a_in, olive::NodeInput *param_b_in) const
|
||||
ShaderCode MathNodeBase::GetShaderCodeInternal(const QString &shader_id, const QString& param_a_in, const QString& param_b_in) const
|
||||
{
|
||||
QStringList code_id = shader_id.split('.');
|
||||
|
||||
@@ -43,11 +43,11 @@ ShaderCode MathNodeBase::GetShaderCodeInternal(const QString &shader_id, NodeInp
|
||||
if (pairing == kPairTextureMatrix && op == kOpMultiply) {
|
||||
|
||||
// Override the operation for this operation since we multiply texture COORDS by the matrix rather than
|
||||
NodeInput* tex_in = (type_a == NodeValue::kTexture) ? param_a_in : param_b_in;
|
||||
NodeInput* mat_in = (type_a == NodeValue::kTexture) ? param_b_in : param_a_in;
|
||||
const QString& tex_in = (type_a == NodeValue::kTexture) ? param_a_in : param_b_in;
|
||||
const QString& mat_in = (type_a == NodeValue::kTexture) ? param_b_in : param_a_in;
|
||||
|
||||
// No-op frag shader (can we return QString() instead?)
|
||||
operation = QStringLiteral("texture(%1, ove_texcoord)").arg(tex_in->id());
|
||||
operation = QStringLiteral("texture(%1, ove_texcoord)").arg(tex_in);
|
||||
|
||||
vert = QStringLiteral("uniform mat4 %1;\n"
|
||||
"\n"
|
||||
@@ -59,7 +59,7 @@ ShaderCode MathNodeBase::GetShaderCodeInternal(const QString &shader_id, NodeInp
|
||||
"void main() {\n"
|
||||
" gl_Position = %1 * a_position;\n"
|
||||
" ove_texcoord = a_texcoord;\n"
|
||||
"}\n").arg(mat_in->id());
|
||||
"}\n").arg(mat_in);
|
||||
|
||||
} else {
|
||||
switch (op) {
|
||||
@@ -89,8 +89,8 @@ ShaderCode MathNodeBase::GetShaderCodeInternal(const QString &shader_id, NodeInp
|
||||
break;
|
||||
}
|
||||
|
||||
operation = operation.arg(GetShaderVariableCall(param_a_in->id(), type_a),
|
||||
GetShaderVariableCall(param_b_in->id(), type_b));
|
||||
operation = operation.arg(GetShaderVariableCall(param_a_in, type_a),
|
||||
GetShaderVariableCall(param_b_in, type_b));
|
||||
}
|
||||
|
||||
frag = QStringLiteral("uniform %1 %3;\n"
|
||||
@@ -104,8 +104,8 @@ ShaderCode MathNodeBase::GetShaderCodeInternal(const QString &shader_id, NodeInp
|
||||
" fragColor = %5;\n"
|
||||
"}\n").arg(GetShaderUniformType(type_a),
|
||||
GetShaderUniformType(type_b),
|
||||
param_a_in->id(),
|
||||
param_b_in->id(),
|
||||
param_a_in,
|
||||
param_b_in,
|
||||
operation);
|
||||
|
||||
return ShaderCode(frag, vert);
|
||||
@@ -165,7 +165,7 @@ void MathNodeBase::PushVector(NodeValueTable *output, olive::NodeValue::Type typ
|
||||
}
|
||||
}
|
||||
|
||||
NodeValueTable MathNodeBase::ValueInternal(NodeValueDatabase &value, Operation operation, Pairing pairing, NodeInput *param_a_in, const NodeValue& val_a, NodeInput *param_b_in, const NodeValue& val_b) const
|
||||
NodeValueTable MathNodeBase::ValueInternal(NodeValueDatabase &value, Operation operation, Pairing pairing, const QString& param_a_in, const NodeValue& val_a, const QString& param_b_in, const NodeValue& val_b) const
|
||||
{
|
||||
NodeValueTable output = value.Merge();
|
||||
|
||||
@@ -342,7 +342,7 @@ NodeValueTable MathNodeBase::ValueInternal(NodeValueDatabase &value, Operation o
|
||||
{
|
||||
// Queue a sample job
|
||||
const NodeValue& number_val = val_a.type() == NodeValue::kSamples ? val_b : val_a;
|
||||
NodeInput* number_param = val_a.type() == NodeValue::kSamples ? param_b_in : param_a_in;
|
||||
const QString& number_param = val_a.type() == NodeValue::kSamples ? param_b_in : param_a_in;
|
||||
|
||||
float number = RetrieveNumber(number_val);
|
||||
|
||||
@@ -350,7 +350,7 @@ NodeValueTable MathNodeBase::ValueInternal(NodeValueDatabase &value, Operation o
|
||||
job.InsertValue(number_param, NodeValue(NodeValue::kFloat, number, this));
|
||||
|
||||
if (job.HasSamples()) {
|
||||
if (number_param->IsStatic()) {
|
||||
if (IsInputStatic(number_param)) {
|
||||
if (!NumberIsNoOp(operation, number)) {
|
||||
for (int i=0;i<job.samples()->audio_params().channel_count();i++) {
|
||||
for (int j=0;j<job.samples()->sample_count();j++) {
|
||||
@@ -375,7 +375,7 @@ NodeValueTable MathNodeBase::ValueInternal(NodeValueDatabase &value, Operation o
|
||||
return output;
|
||||
}
|
||||
|
||||
void MathNodeBase::ProcessSamplesInternal(NodeValueDatabase &values, MathNodeBase::Operation operation, NodeInput *param_a_in, NodeInput *param_b_in, const SampleBufferPtr input, SampleBufferPtr output, int index) const
|
||||
void MathNodeBase::ProcessSamplesInternal(NodeValueDatabase &values, MathNodeBase::Operation operation, const QString ¶m_a_in, const QString ¶m_b_in, const SampleBufferPtr input, SampleBufferPtr output, int index) const
|
||||
{
|
||||
// This function is only used for sample+number pairing
|
||||
NodeValue number_val = values[param_a_in].GetWithMeta(NodeValue::kNumber);
|
||||
|
||||
@@ -109,13 +109,13 @@ protected:
|
||||
|
||||
static bool NumberIsNoOp(const Operation& op, const float& number);
|
||||
|
||||
ShaderCode GetShaderCodeInternal(const QString &shader_id, NodeInput* param_a_in, NodeInput* param_b_in) const;
|
||||
ShaderCode GetShaderCodeInternal(const QString &shader_id, const QString ¶m_a_in, const QString ¶m_b_in) const;
|
||||
|
||||
void PushVector(NodeValueTable* output, NodeValue::Type type, const QVector4D& vec) const;
|
||||
|
||||
NodeValueTable ValueInternal(NodeValueDatabase &value, Operation operation, Pairing pairing, NodeInput* param_a_in, const NodeValue &val_a, NodeInput* param_b_in, const NodeValue& val_b) const;
|
||||
NodeValueTable ValueInternal(NodeValueDatabase &value, Operation operation, Pairing pairing, const QString& param_a_in, const NodeValue &val_a, const QString& param_b_in, const NodeValue& val_b) const;
|
||||
|
||||
void ProcessSamplesInternal(NodeValueDatabase &values, Operation operation, NodeInput* param_a_in, NodeInput* param_b_in, const SampleBufferPtr input, SampleBufferPtr output, int index) const;
|
||||
void ProcessSamplesInternal(NodeValueDatabase &values, Operation operation, const QString& param_a_in, const QString& param_b_in, const SampleBufferPtr input, SampleBufferPtr output, int index) const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -22,11 +22,14 @@
|
||||
|
||||
namespace olive {
|
||||
|
||||
const QString MergeNode::kBaseIn = QStringLiteral("base_in");
|
||||
const QString MergeNode::kBlendIn = QStringLiteral("blend_in");
|
||||
|
||||
MergeNode::MergeNode()
|
||||
{
|
||||
base_in_ = new NodeInput(this, QStringLiteral("base_in"), NodeValue::kTexture);
|
||||
AddInput(kBaseIn, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
|
||||
|
||||
blend_in_ = new NodeInput(this, QStringLiteral("blend_in"), NodeValue::kTexture);
|
||||
AddInput(kBlendIn, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable));
|
||||
}
|
||||
|
||||
Node *MergeNode::copy() const
|
||||
@@ -56,8 +59,9 @@ QString MergeNode::Description() const
|
||||
|
||||
void MergeNode::Retranslate()
|
||||
{
|
||||
base_in_->set_name(tr("Base"));
|
||||
blend_in_->set_name(tr("Blend"));
|
||||
SetInputName(kBaseIn, tr("Base"));
|
||||
|
||||
SetInputName(kBlendIn, tr("Blend"));
|
||||
}
|
||||
|
||||
ShaderCode MergeNode::GetShaderCode(const QString &shader_id) const
|
||||
@@ -67,24 +71,26 @@ ShaderCode MergeNode::GetShaderCode(const QString &shader_id) const
|
||||
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/alphaover.frag"));
|
||||
}
|
||||
|
||||
NodeValueTable MergeNode::Value(NodeValueDatabase &value) const
|
||||
NodeValueTable MergeNode::Value(const QString &output, NodeValueDatabase &value) const
|
||||
{
|
||||
Q_UNUSED(output)
|
||||
|
||||
ShaderJob job;
|
||||
job.InsertValue(base_in_, value);
|
||||
job.InsertValue(blend_in_, value);
|
||||
job.InsertValue(this, kBaseIn, value);
|
||||
job.InsertValue(this, kBlendIn, value);
|
||||
|
||||
NodeValueTable table = value.Merge();
|
||||
|
||||
TexturePtr base_tex = job.GetValue(base_in_).data().value<TexturePtr>();
|
||||
TexturePtr blend_tex = job.GetValue(blend_in_).data().value<TexturePtr>();
|
||||
TexturePtr base_tex = job.GetValue(kBaseIn).data().value<TexturePtr>();
|
||||
TexturePtr blend_tex = job.GetValue(kBlendIn).data().value<TexturePtr>();
|
||||
|
||||
if (base_tex || blend_tex) {
|
||||
if (!base_tex || (blend_tex && blend_tex->channel_count() < VideoParams::kRGBAChannelCount)) {
|
||||
// We only have a blend texture or the blend texture is RGB only, no need to alpha over
|
||||
table.Push(job.GetValue(blend_in_));
|
||||
table.Push(job.GetValue(kBlendIn));
|
||||
} else if (!blend_tex) {
|
||||
// We only have a base texture, no need to alpha over
|
||||
table.Push(job.GetValue(base_in_));
|
||||
table.Push(job.GetValue(kBaseIn));
|
||||
} else {
|
||||
// We have both textures, push the job
|
||||
table.Push(NodeValue::kShaderJob, QVariant::fromValue(job), this);
|
||||
@@ -94,16 +100,6 @@ NodeValueTable MergeNode::Value(NodeValueDatabase &value) const
|
||||
return table;
|
||||
}
|
||||
|
||||
NodeInput *MergeNode::base_in() const
|
||||
{
|
||||
return base_in_;
|
||||
}
|
||||
|
||||
NodeInput *MergeNode::blend_in() const
|
||||
{
|
||||
return blend_in_;
|
||||
}
|
||||
|
||||
void MergeNode::Hash(QCryptographicHash &hash, const rational &time) const
|
||||
{
|
||||
// We do some hash optimization here. If only one of the inputs is connected, this node
|
||||
@@ -116,16 +112,16 @@ void MergeNode::Hash(QCryptographicHash &hash, const rational &time) const
|
||||
bool base_changed_hash = false;
|
||||
bool blend_changed_hash = false;
|
||||
|
||||
if (base_in_->IsConnected()) {
|
||||
base_in_->GetConnectedNode()->Hash(hash, time);
|
||||
if (IsInputConnected(kBaseIn)) {
|
||||
GetConnectedNode(kBaseIn)->Hash(hash, time);
|
||||
|
||||
QByteArray post_base_hash = hash.result();
|
||||
base_changed_hash = (post_base_hash != current_result);
|
||||
current_result = post_base_hash;
|
||||
}
|
||||
|
||||
if (blend_in_->IsConnected()) {
|
||||
blend_in_->GetConnectedNode()->Hash(hash, time);
|
||||
if(IsInputConnected(kBlendIn)) {
|
||||
GetConnectedNode(kBlendIn)->Hash(hash, time);
|
||||
|
||||
blend_changed_hash = (hash.result() != current_result);
|
||||
}
|
||||
|
||||
@@ -41,10 +41,10 @@ public:
|
||||
virtual void Retranslate() override;
|
||||
|
||||
virtual ShaderCode GetShaderCode(const QString &shader_id) const override;
|
||||
virtual NodeValueTable Value(NodeValueDatabase &value) const override;
|
||||
virtual NodeValueTable Value(const QString& output, NodeValueDatabase &value) const override;
|
||||
|
||||
NodeInput* base_in() const;
|
||||
NodeInput* blend_in() const;
|
||||
static const QString kBaseIn;
|
||||
static const QString kBlendIn;
|
||||
|
||||
virtual void Hash(QCryptographicHash &hash, const rational &time) const override;
|
||||
|
||||
|
||||
@@ -22,13 +22,14 @@
|
||||
|
||||
namespace olive {
|
||||
|
||||
const QString TrigonometryNode::kMethodIn = QStringLiteral("method_in");
|
||||
const QString TrigonometryNode::kXIn = QStringLiteral("x_in");
|
||||
|
||||
TrigonometryNode::TrigonometryNode()
|
||||
{
|
||||
method_in_ = new NodeInput(this, QStringLiteral("method_in"), NodeValue::kCombo);
|
||||
method_in_->SetConnectable(false);
|
||||
method_in_->SetKeyframable(false);
|
||||
AddInput(kMethodIn, NodeValue::kCombo, InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable));
|
||||
|
||||
x_in_ = new NodeInput(this, QStringLiteral("x_in"), NodeValue::kFloat, 0.0);
|
||||
AddInput(kXIn, NodeValue::kFloat, 0.0);
|
||||
}
|
||||
|
||||
olive::Node *olive::TrigonometryNode::copy() const
|
||||
@@ -70,18 +71,20 @@ void TrigonometryNode::Retranslate()
|
||||
tr("Hyperbolic Cosine"),
|
||||
tr("Hyperbolic Tangent")};
|
||||
|
||||
method_in_->set_combobox_strings(strings);
|
||||
SetComboBoxStrings(kMethodIn, strings);
|
||||
|
||||
method_in_->set_name(tr("Method"));
|
||||
SetInputName(kMethodIn, tr("Method"));
|
||||
}
|
||||
|
||||
NodeValueTable TrigonometryNode::Value(NodeValueDatabase &value) const
|
||||
NodeValueTable TrigonometryNode::Value(const QString &output, NodeValueDatabase &value) const
|
||||
{
|
||||
float x = value[x_in_].Take(NodeValue::kFloat).toFloat();
|
||||
Q_UNUSED(output)
|
||||
|
||||
float x = value[kXIn].Take(NodeValue::kFloat).toFloat();
|
||||
|
||||
NodeValueTable table = value.Merge();
|
||||
|
||||
switch (static_cast<Operation>(method_in_->GetStandardValue().toInt())) {
|
||||
switch (static_cast<Operation>(GetStandardValue(kMethodIn).toInt())) {
|
||||
case kOpSine:
|
||||
x = qSin(x);
|
||||
break;
|
||||
|
||||
@@ -40,7 +40,10 @@ public:
|
||||
|
||||
virtual void Retranslate() override;
|
||||
|
||||
virtual NodeValueTable Value(NodeValueDatabase &value) const override;
|
||||
virtual NodeValueTable Value(const QString& output, NodeValueDatabase &value) const override;
|
||||
|
||||
static const QString kMethodIn;
|
||||
static const QString kXIn;
|
||||
|
||||
private:
|
||||
enum Operation {
|
||||
@@ -55,10 +58,6 @@ private:
|
||||
kOpHypTangent
|
||||
};
|
||||
|
||||
NodeInput* method_in_;
|
||||
|
||||
NodeInput* x_in_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user