diff --git a/app/node/factory.cpp b/app/node/factory.cpp index 0fab0b697..e70b9db63 100644 --- a/app/node/factory.cpp +++ b/app/node/factory.cpp @@ -29,7 +29,8 @@ #include "input/media/video/video.h" #include "input/media/audio/audio.h" #include "input/time/timeinput.h" -#include "math/math.h" +#include "math/math/math.h" +#include "math/trigonometry/trigonometry.h" #include "output/track/track.h" #include "output/viewer/viewer.h" #include "external.h" @@ -160,6 +161,8 @@ Node *NodeFactory::CreateInternal(const NodeFactory::InternalID &id) return new PanNode(); case kMath: return new MathNode(); + case kTrigonometry: + return new TrigonometryNode(); case kTime: return new TimeInput(); diff --git a/app/node/factory.h b/app/node/factory.h index 10077a641..3c94d23dd 100644 --- a/app/node/factory.h +++ b/app/node/factory.h @@ -43,6 +43,7 @@ public: kAudioPanning, kMath, kTime, + kTrigonometry, // Count value kInternalNodeCount diff --git a/app/node/math/CMakeLists.txt b/app/node/math/CMakeLists.txt index 9c2e5c534..1ae06847e 100644 --- a/app/node/math/CMakeLists.txt +++ b/app/node/math/CMakeLists.txt @@ -14,9 +14,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +add_subdirectory(math) +add_subdirectory(trigonometry) + set(OLIVE_SOURCES ${OLIVE_SOURCES} - node/math/math.h - node/math/math.cpp PARENT_SCOPE ) diff --git a/app/node/math/math/CMakeLists.txt b/app/node/math/math/CMakeLists.txt new file mode 100644 index 000000000..c0a2653da --- /dev/null +++ b/app/node/math/math/CMakeLists.txt @@ -0,0 +1,22 @@ +# Olive - Non-Linear Video Editor +# Copyright (C) 2019 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/math/math/math.h + node/math/math/math.cpp + PARENT_SCOPE +) diff --git a/app/node/math/math.cpp b/app/node/math/math/math.cpp similarity index 98% rename from app/node/math/math.cpp rename to app/node/math/math/math.cpp index b5d2eeb36..86769f967 100644 --- a/app/node/math/math.cpp +++ b/app/node/math/math/math.cpp @@ -63,7 +63,7 @@ QString MathNode::Category() const QString MathNode::Description() const { - return tr("Perform a mathematical operation between two."); + return tr("Perform a mathematical operation between two values."); } void MathNode::Retranslate() @@ -74,7 +74,13 @@ void MathNode::Retranslate() param_a_in_->set_name(tr("Value")); param_b_in_->set_name(tr("Value")); - QStringList operations = {tr("Add"), tr("Subtract"), tr("Multiply"), tr("Divide")}; + QStringList operations = {tr("Add"), + tr("Subtract"), + tr("Multiply"), + tr("Divide"), + QString(), + tr("Power")}; + method_in_->set_combobox_strings(operations); } diff --git a/app/node/math/math.h b/app/node/math/math/math.h similarity index 100% rename from app/node/math/math.h rename to app/node/math/math/math.h diff --git a/app/node/math/trigonometry/CMakeLists.txt b/app/node/math/trigonometry/CMakeLists.txt new file mode 100644 index 000000000..9dd5630de --- /dev/null +++ b/app/node/math/trigonometry/CMakeLists.txt @@ -0,0 +1,22 @@ +# Olive - Non-Linear Video Editor +# Copyright (C) 2019 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/math/trigonometry/trigonometry.h + node/math/trigonometry/trigonometry.cpp + PARENT_SCOPE +) diff --git a/app/node/math/trigonometry/trigonometry.cpp b/app/node/math/trigonometry/trigonometry.cpp new file mode 100644 index 000000000..00c6a693a --- /dev/null +++ b/app/node/math/trigonometry/trigonometry.cpp @@ -0,0 +1,121 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2019 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 "trigonometry.h" + +OLIVE_NAMESPACE_ENTER + +TrigonometryNode::TrigonometryNode() +{ + method_in_ = new NodeInput(QStringLiteral("method_in"), NodeParam::kCombo); + method_in_->SetConnectable(false); + method_in_->set_is_keyframable(false); + AddInput(method_in_); + + x_in_ = new NodeInput(QStringLiteral("x_in"), NodeParam::kFloat); + AddInput(x_in_); +} + +olive::Node *olive::TrigonometryNode::copy() const +{ + return new TrigonometryNode(); +} + +QString TrigonometryNode::Name() const +{ + return tr("Trigonometry"); +} + +QString TrigonometryNode::id() const +{ + return QStringLiteral("org.olivevideoeditor.Olive.trigonometry"); +} + +QString TrigonometryNode::Category() const +{ + return tr("Math"); +} + +QString TrigonometryNode::Description() const +{ + return tr("Perform a trigonometry operation on a value."); +} + +void TrigonometryNode::Retranslate() +{ + QStringList strings = {tr("Sine"), + tr("Cosine"), + tr("Tangent"), + QString(), + tr("Inverse Sine"), + tr("Inverse Cosine"), + tr("Inverse Tangent"), + QString(), + tr("Hyperbolic Sine"), + tr("Hyperbolic Cosine"), + tr("Hyperbolic Tangent")}; + + method_in_->set_combobox_strings(strings); + + method_in_->set_name(tr("Method")); +} + +NodeValueTable TrigonometryNode::Value(const NodeValueDatabase &value) const +{ + float x = value[x_in_].Take(NodeParam::kFloat).toFloat(); + + NodeValueTable table = value.Merge(); + + switch (static_cast(method_in_->get_standard_value().toInt())) { + case kOpSine: + x = qSin(x); + break; + case kOpCosine: + x = qCos(x); + break; + case kOpTangent: + x = qTan(x); + break; + case kOpArcSine: + x = qAsin(x); + break; + case kOpArcCosine: + x = qAcos(x); + break; + case kOpArcTangent: + x = qAtan(x); + break; + case kOpHypSine: + x = std::sinh(x); + break; + case kOpHypCosine: + x = std::cosh(x); + break; + case kOpHypTangent: + x = std::tanh(x); + break; + } + + table.Push(NodeParam::kFloat, x); + + return table; +} + +OLIVE_NAMESPACE_EXIT diff --git a/app/node/math/trigonometry/trigonometry.h b/app/node/math/trigonometry/trigonometry.h new file mode 100644 index 000000000..44808ee3c --- /dev/null +++ b/app/node/math/trigonometry/trigonometry.h @@ -0,0 +1,65 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2019 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 TRIGNODE_H +#define TRIGNODE_H + +#include "node/node.h" + +OLIVE_NAMESPACE_ENTER + +class TrigonometryNode : public Node +{ +public: + TrigonometryNode(); + + virtual Node* copy() const override; + + virtual QString Name() const override; + virtual QString id() const override; + virtual QString Category() const override; + virtual QString Description() const override; + + virtual void Retranslate() override; + + virtual NodeValueTable Value(const NodeValueDatabase& value) const override; + +private: + enum Operation { + kOpSine, + kOpCosine, + kOpTangent, + kOpArcSine, + kOpArcCosine, + kOpArcTangent, + kOpHypSine, + kOpHypCosine, + kOpHypTangent + }; + + NodeInput* method_in_; + + NodeInput* x_in_; + +}; + +OLIVE_NAMESPACE_EXIT + +#endif // TRIGNODE_H diff --git a/app/node/output/track/tracklist.cpp b/app/node/output/track/tracklist.cpp index 601bb7336..05f9a6e6f 100644 --- a/app/node/output/track/tracklist.cpp +++ b/app/node/output/track/tracklist.cpp @@ -21,7 +21,7 @@ #include "tracklist.h" #include "node/factory.h" -#include "node/math/math.h" +#include "node/math/math/math.h" #include "node/output/viewer/viewer.h" OLIVE_NAMESPACE_ENTER