From f9112c05fd6d4c2f61803b2e664773593ccceb87 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Tue, 1 Feb 2022 19:55:09 -0800 Subject: [PATCH] Implemented time offset node --- app/node/factory.cpp | 3 + app/node/factory.h | 1 + app/node/time/CMakeLists.txt | 1 + app/node/time/timeoffset/CMakeLists.txt | 22 +++++ app/node/time/timeoffset/timeoffsetnode.cpp | 91 +++++++++++++++++++++ app/node/time/timeoffset/timeoffsetnode.h | 76 +++++++++++++++++ 6 files changed, 194 insertions(+) create mode 100644 app/node/time/timeoffset/CMakeLists.txt create mode 100644 app/node/time/timeoffset/timeoffsetnode.cpp create mode 100644 app/node/time/timeoffset/timeoffsetnode.h diff --git a/app/node/factory.cpp b/app/node/factory.cpp index ed4645a60..7afcec6d9 100644 --- a/app/node/factory.cpp +++ b/app/node/factory.cpp @@ -53,6 +53,7 @@ #include "project/folder/folder.h" #include "project/footage/footage.h" #include "project/sequence/sequence.h" +#include "time/timeoffset/timeoffsetnode.h" #include "time/timeremap/timeremap.h" namespace olive { @@ -261,6 +262,8 @@ Node *NodeFactory::CreateFromFactoryIndex(const NodeFactory::InternalID &id) return new FlipDistortNode(); case kNoiseGenerator: return new NoiseGeneratorNode(); + case kTimeOffsetNode: + return new TimeOffsetNode(); case kInternalNodeCount: break; diff --git a/app/node/factory.h b/app/node/factory.h index c91895ff3..5e627841c 100644 --- a/app/node/factory.h +++ b/app/node/factory.h @@ -65,6 +65,7 @@ public: kOpacityEffect, kFlipDistort, kNoiseGenerator, + kTimeOffsetNode, // Count value kInternalNodeCount diff --git a/app/node/time/CMakeLists.txt b/app/node/time/CMakeLists.txt index bd780b985..a038672fb 100644 --- a/app/node/time/CMakeLists.txt +++ b/app/node/time/CMakeLists.txt @@ -14,6 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +add_subdirectory(timeoffset) add_subdirectory(timeremap) set(OLIVE_SOURCES diff --git a/app/node/time/timeoffset/CMakeLists.txt b/app/node/time/timeoffset/CMakeLists.txt new file mode 100644 index 000000000..b3976d54b --- /dev/null +++ b/app/node/time/timeoffset/CMakeLists.txt @@ -0,0 +1,22 @@ +# Olive - Non-Linear Video Editor +# Copyright (C) 2021 Olive Team +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +set(OLIVE_SOURCES + ${OLIVE_SOURCES} + node/time/timeoffset/timeoffsetnode.cpp + node/time/timeoffset/timeoffsetnode.h + PARENT_SCOPE +) diff --git a/app/node/time/timeoffset/timeoffsetnode.cpp b/app/node/time/timeoffset/timeoffsetnode.cpp new file mode 100644 index 000000000..d137847ee --- /dev/null +++ b/app/node/time/timeoffset/timeoffsetnode.cpp @@ -0,0 +1,91 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2021 Olive Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +***/ + +#include "timeoffsetnode.h" + +#include "widget/slider/rationalslider.h" + +namespace olive { + +const QString TimeOffsetNode::kTimeInput = QStringLiteral("time_in"); +const QString TimeOffsetNode::kInputInput = QStringLiteral("input_in"); + +#define super Node + +TimeOffsetNode::TimeOffsetNode() +{ + AddInput(kTimeInput, NodeValue::kRational, QVariant::fromValue(rational(0)), InputFlags(kInputFlagNotConnectable)); + SetInputProperty(kTimeInput, QStringLiteral("view"), RationalSlider::kTime); + SetInputProperty(kTimeInput, QStringLiteral("viewlock"), true); + IgnoreHashingFrom(kTimeInput); + + AddInput(kInputInput, NodeValue::kNone, InputFlags(kInputFlagNotKeyframable)); +} + +void TimeOffsetNode::Retranslate() +{ + SetInputName(kTimeInput, QStringLiteral("Time")); + SetInputName(kInputInput, QStringLiteral("Input")); +} + +TimeRange TimeOffsetNode::InputTimeAdjustment(const QString &input, int element, const TimeRange &input_time) const +{ + if (input == kInputInput) { + return TimeRange(GetRemappedTime(input_time.in()), GetRemappedTime(input_time.out())); + } else { + return super::InputTimeAdjustment(input, element, input_time); + } +} + +TimeRange TimeOffsetNode::OutputTimeAdjustment(const QString &input, int element, const TimeRange &input_time) const +{ + /*if (input == kInputInput) { + rational target_time = GetValueAtTime(kTimeInput, input_time.in()).value(); + + return TimeRange(target_time, target_time + input_time.length()); + } else { + return super::OutputTimeAdjustment(input, element, input_time); + }*/ + return super::OutputTimeAdjustment(input, element, input_time); +} + +void TimeOffsetNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const +{ + table->Push(value[kInputInput]); +} + +void TimeOffsetNode::Hash(QCryptographicHash &hash, const NodeGlobals &globals, const VideoParams &video_params) const +{ + // Don't hash anything of our own, just pass-through to the connected node at the remapped tmie + if (IsInputConnected(kInputInput)) { + Node *out = GetConnectedOutput(kInputInput); + + NodeGlobals new_globals = globals; + new_globals.set_time(TimeRange(GetRemappedTime(globals.time().in()), GetRemappedTime(globals.time().out()))); + Node::Hash(out, GetValueHintForInput(kInputInput), hash, new_globals, video_params); + } +} + +rational TimeOffsetNode::GetRemappedTime(const rational &input) const +{ + return input + GetValueAtTime(kTimeInput, input).value(); +} + +} diff --git a/app/node/time/timeoffset/timeoffsetnode.h b/app/node/time/timeoffset/timeoffsetnode.h new file mode 100644 index 000000000..aa712891f --- /dev/null +++ b/app/node/time/timeoffset/timeoffsetnode.h @@ -0,0 +1,76 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2021 Olive Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +***/ + +#ifndef TIMEOFFSETNODE_H +#define TIMEOFFSETNODE_H + +#include "node/node.h" + +namespace olive { + +class TimeOffsetNode : public Node +{ +public: + TimeOffsetNode(); + + NODE_DEFAULT_DESTRUCTOR(TimeOffsetNode) + NODE_COPY_FUNCTION(TimeOffsetNode) + + virtual QString Name() const override + { + return tr("Time Offset"); + } + + virtual QString id() const override + { + return QStringLiteral("org.olivevideoeditor.Olive.timeoffset"); + } + + virtual QVector Category() const override + { + return {kCategoryGeneral}; + } + + virtual QString Description() const override + { + return tr("Offset time passing through the graph."); + } + + virtual TimeRange InputTimeAdjustment(const QString& input, int element, const TimeRange& input_time) const override; + virtual TimeRange OutputTimeAdjustment(const QString& input, int element, const TimeRange& input_time) const override; + + virtual void Retranslate() override; + + virtual void Value(const NodeValueRow& value, const NodeGlobals &globals, NodeValueTable *table) const override; + + static const QString kTimeInput; + static const QString kInputInput; + +protected: + virtual void Hash(QCryptographicHash &hash, const NodeGlobals &globals, const VideoParams& video_params) const override; + +private: + rational GetRemappedTime(const rational& input) const; + +}; + +} + +#endif // TIMEOFFSETNODE_H