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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user