From badcade0b6f2ddc009e42aabe284e124730474fa Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Sat, 27 Jul 2019 02:50:22 -0700 Subject: [PATCH] added base 'block' node --- app/node/block/block.cpp | 44 ++++++++++++++++++++++++++++++++++++++++ app/node/block/block.h | 11 ++++++++-- app/node/node.cpp | 5 +++++ app/node/node.h | 17 ++++++++++++++++ 4 files changed, 75 insertions(+), 2 deletions(-) diff --git a/app/node/block/block.cpp b/app/node/block/block.cpp index 0f086d47d..de3be141d 100644 --- a/app/node/block/block.cpp +++ b/app/node/block/block.cpp @@ -22,7 +22,17 @@ Block::Block() { + previous_input_ = new NodeInput(); + AddParameter(previous_input_); + previous_output_ = new NodeOutput(); + AddParameter(previous_output_); + + next_input_ = new NodeInput(); + AddParameter(next_input_); + + next_output_ = new NodeOutput(); + AddParameter(next_output_); } QString Block::Category() @@ -30,7 +40,41 @@ QString Block::Category() return tr("Block"); } +rational Block::in() +{ + rational in_point = 0; + + Block* block = previous(); + + while (block != nullptr) { + in_point += block->length(); + + block = previous(); + } + + return in_point; +} + rational Block::out() { return in() + length(); } + +Block *Block::previous() +{ + return ValueToPtr(previous_input_->get_value(0)); +} + +Block *Block::next() +{ + return ValueToPtr(next_input_->get_value(0)); +} + +void Block::Process(const rational &time) +{ + Q_UNUSED(time) + + // Simply set both output values as a pointer to this object + previous_output_->set_value(PtrToValue(this)); + next_output_->set_value(PtrToValue(this)); +} diff --git a/app/node/block/block.h b/app/node/block/block.h index 34f90d7e5..fd35ea06e 100644 --- a/app/node/block/block.h +++ b/app/node/block/block.h @@ -36,10 +36,17 @@ public: virtual rational length() = 0; + virtual Block* previous(); + virtual Block* next(); + public slots: -// virtual void Process(const rational &time) override; - + virtual void Process(const rational &time) override; +private: + NodeInput* previous_input_; + NodeInput* next_input_; + NodeOutput* previous_output_; + NodeOutput* next_output_; }; #endif // BLOCK_H diff --git a/app/node/node.cpp b/app/node/node.cpp index 88fca5790..7c80dc0d1 100644 --- a/app/node/node.cpp +++ b/app/node/node.cpp @@ -82,3 +82,8 @@ int Node::IndexOfParameter(NodeParam *param) { return children().indexOf(param); } + +QVariant Node::PtrToValue(void *ptr) +{ + return reinterpret_cast(ptr); +} diff --git a/app/node/node.h b/app/node/node.h index 766683786..eb14ddf17 100644 --- a/app/node/node.h +++ b/app/node/node.h @@ -123,6 +123,17 @@ public: */ int IndexOfParameter(NodeParam* param); + /** + * @brief Convert a pointer to a value that can be sent between NodeParams + */ + static QVariant PtrToValue(void* ptr); + + template + /** + * @brief Convert a NodeParam value to a pointer of any kind + */ + static T* ValueToPtr(const QVariant& ptr); + public slots: /** * @brief The main processing function @@ -159,4 +170,10 @@ signals: void EdgeRemoved(NodeEdgePtr edge); }; +template +T* Node::ValueToPtr(const QVariant &ptr) +{ + return reinterpret_cast(ptr.value()); +} + #endif // NODE_H