From da680094bf1edc548dc3c5ed76d04df7dcf1fb0b Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Sun, 1 Dec 2019 00:01:25 +1100 Subject: [PATCH] created NodeInputArray parameter type It seems unwise to let NodeInputs take more than one value, but at times it makes sense to create a list or array of inputs. This class will create sub-parameters as an easy way to provide variable inputs while also enforcing one connection per input parameter. This is also the primary motivation for the previous commit (disambiguating when a NodeParam's parent is a Node vs some other type). --- app/node/CMakeLists.txt | 2 ++ app/node/inputarray.cpp | 51 ++++++++++++++++++++++++++++++++++++++++- app/node/inputarray.h | 14 +++++++++-- app/node/node.h | 11 +++++---- 4 files changed, 70 insertions(+), 8 deletions(-) diff --git a/app/node/CMakeLists.txt b/app/node/CMakeLists.txt index dcaa35d5a..7b642f433 100644 --- a/app/node/CMakeLists.txt +++ b/app/node/CMakeLists.txt @@ -32,6 +32,8 @@ set(OLIVE_SOURCES node/graph.cpp node/input.h node/input.cpp + node/inputarray.h + node/inputarray.cpp node/keyframe.h node/keyframe.cpp node/menu.h diff --git a/app/node/inputarray.cpp b/app/node/inputarray.cpp index 756692042..cbc830a02 100644 --- a/app/node/inputarray.cpp +++ b/app/node/inputarray.cpp @@ -1,6 +1,55 @@ #include "inputarray.h" -InputArray::InputArray() +#include "node.h" + +NodeInputArray::NodeInputArray(const QString &id) : + NodeInput(id) { } + +int NodeInputArray::GetSize() const +{ + return sub_params_.size(); +} + +void NodeInputArray::SetSize(int size) +{ + int old_size = GetSize(); + + if (size == old_size) { + return; + } + + if (size < old_size) { + // If the new size is less, delete all extraneous parameters + for (int i=size;i old_size) { + // If the new size is greater, create valid parameters for each slot + for (int i=old_size;iHasParamWithID(sub_id)); + + NodeInput* new_param = new NodeInput(sub_id); + new_param->setParent(this); + sub_params_.replace(i, new_param); + + connect(new_param, SIGNAL(ValueChanged(rational, rational)), this, SIGNAL(ValueChanged(rational, rational))); + connect(new_param, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SIGNAL(EdgeAdded(NodeEdgePtr))); + connect(new_param, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SIGNAL(EdgeRemoved(NodeEdgePtr))); + } + } +} + +NodeInput *NodeInputArray::ParamAt(int index) +{ + return sub_params_.at(index); +} diff --git a/app/node/inputarray.h b/app/node/inputarray.h index ec2bdeea1..3fd3b043d 100644 --- a/app/node/inputarray.h +++ b/app/node/inputarray.h @@ -1,11 +1,21 @@ #ifndef INPUTARRAY_H #define INPUTARRAY_H +#include "input.h" -class InputArray +class NodeInputArray : public NodeInput { public: - InputArray(); + NodeInputArray(const QString &id); + + int GetSize() const; + void SetSize(int size); + + NodeInput* ParamAt(int index); + +private: + QVector sub_params_; + }; #endif // INPUTARRAY_H diff --git a/app/node/node.h b/app/node/node.h index 85a3b88e7..d3deeeb8c 100644 --- a/app/node/node.h +++ b/app/node/node.h @@ -28,6 +28,7 @@ #include "common/rational.h" #include "node/dependency.h" #include "node/input.h" +#include "node/inputarray.h" #include "node/output.h" /** @@ -254,6 +255,11 @@ public: */ virtual QVariant Value(NodeOutput* output); + /** + * @brief Return whether a parameter with ID `id` has already been added to this Node + */ + bool HasParamWithID(const QString& id); + protected: /** * @brief Add a parameter to this node @@ -309,11 +315,6 @@ signals: void EdgeRemoved(NodeEdgePtr edge); private: - /** - * @brief Return whether a parameter with ID `id` has already been added to this Node - */ - bool HasParamWithID(const QString& id); - bool HasParamOfType(NodeParam::Type type, bool must_be_connected); QList params_;