From 2727ba1f52fcdab9a46107eee8234b61ead07885 Mon Sep 17 00:00:00 2001 From: lnd3 Date: Wed, 25 Sep 2024 14:41:15 +0200 Subject: [PATCH] More structure. Forward declare. Add ng test for tweens. --- packages/audio/include/audio/PortAudio.h | 2 +- .../tests/common/NodeGraphDataTest.cpp | 58 ++++++++++++++++++- .../tests/common/NodeGraphSchemaTest.cpp | 2 +- .../include/rendering/ui/UIVisitors.h | 22 ++----- .../rendering/source/common/ui/UIVisitors.cpp | 18 ++++++ 5 files changed, 82 insertions(+), 20 deletions(-) diff --git a/packages/audio/include/audio/PortAudio.h b/packages/audio/include/audio/PortAudio.h index 6f864af9..dcba8846 100644 --- a/packages/audio/include/audio/PortAudio.h +++ b/packages/audio/include/audio/PortAudio.h @@ -73,7 +73,7 @@ namespace l::audio { AudioStream() = default; ~AudioStream() = default; - bool OpenStream(int32_t dacBufferFrames, float latency = 0.0f, BufferingMode mode = BufferingMode::DOUBLE_BUFFERING, ChannelMode channel = ChannelMode::STEREO); + bool OpenStream(int32_t dacFramesPerBufferPart, float latencyMs = 0.0f, BufferingMode mode = BufferingMode::DOUBLE_BUFFERING, ChannelMode channel = ChannelMode::STEREO); bool StartStream(); std::vector& GetWriteBuffer(); bool CanWrite(); diff --git a/packages/nodegraph/tests/common/NodeGraphDataTest.cpp b/packages/nodegraph/tests/common/NodeGraphDataTest.cpp index f89eac7d..0a115213 100644 --- a/packages/nodegraph/tests/common/NodeGraphDataTest.cpp +++ b/packages/nodegraph/tests/common/NodeGraphDataTest.cpp @@ -41,7 +41,7 @@ class TestOp : public NodeGraphOp2 { -TEST(NodeGraphData, Setup) { +TEST(NodeGraphData, Sampler) { NodeGraph node0; NodeGraph node1; @@ -66,3 +66,59 @@ TEST(NodeGraphData, Setup) { } +class TestOp2 : public NodeGraphOp2 { +public: + TestOp2(NodeGraphBase* node) : + NodeGraphOp2(node, "TestOp") + { + AddInput2(InputTypeBase::CUSTOM_INTERP_TWEEN, "In 0", 0.0f, 1, 0.0f, 1.0f); + AddInput2(InputTypeBase::CUSTOM_INTERP_TWEEN_MS, "In 1", 0.0f, 1, 0.0f, 1.0f); + AddOutput("Out 0"); + AddOutput("Out 1"); + } + + virtual ~TestOp2() = default; + virtual void Process(int32_t numSamples, std::vector& inputs, std::vector& outputs) override { + mNodeInputManager.BatchUpdate(inputs, numSamples); + auto out0 = outputs.at(0).GetIterator(numSamples, 4.0f); + auto out1 = outputs.at(1).GetIterator(numSamples, 4.0f); + + mNodeInputManager.SetDuration(0, 24.0f, 0.1); + mNodeInputManager.SetDuration(1, 0.5f, 0.1); + + for (int i = 0; i < numSamples; i++) { + float value0 = mNodeInputManager.GetValueNext(0); + float value1 = mNodeInputManager.GetValueNext(1); + *out0++ = value0; + *out1++ = value1; + + LOG(LogInfo) << "Node input(" << i << "): " << value0 << ", " << value1; + } + } +protected: +}; + +TEST(NodeGraphData, Tweening) { + + NodeGraph node0; + NodeGraph node1; + + node0.SetInput(0, 0.0f, 2); + node0.SetInput(1, 0.0f, 2); + node1.SetInput(0, node0, 0); + node1.SetInput(1, node0, 1); + + { + auto input0 = node0.GetInputOf(0).GetIterator(32); + auto input1 = node0.GetInputOf(1).GetIterator(32); + for (int i = 0; i < 32; i++) { + *input0++ = static_cast(i > 24 ? 24 : i); + *input1++ = static_cast(i > 24 ? 24 : i); + } + } + + node1.ProcessSubGraph(32); + + return 0; +} + diff --git a/packages/nodegraph/tests/common/NodeGraphSchemaTest.cpp b/packages/nodegraph/tests/common/NodeGraphSchemaTest.cpp index d1829b4d..dcfaf494 100644 --- a/packages/nodegraph/tests/common/NodeGraphSchemaTest.cpp +++ b/packages/nodegraph/tests/common/NodeGraphSchemaTest.cpp @@ -179,7 +179,7 @@ TEST(NodeGraph, GraphGroups) { return 0; } -TEST(NodeGraph, SchemaBasic) { +TEST(NodeGraph, SchemaAllNodes) { NodeGraphSchema ng; diff --git a/packages/rendering/include/rendering/ui/UIVisitors.h b/packages/rendering/include/rendering/ui/UIVisitors.h index f98697c3..2a9df045 100644 --- a/packages/rendering/include/rendering/ui/UIVisitors.h +++ b/packages/rendering/include/rendering/ui/UIVisitors.h @@ -3,11 +3,13 @@ #include "rendering/ui/UIContainer.h" #include "rendering/ui/UIWindow.h" -#include "nodegraph/NodeGraphSchema.h" - #include #include +namespace l::nodegraph { + class NodeGraphSchema; +} + namespace l::ui { class UIUpdate : public UIVisitor { @@ -108,21 +110,7 @@ namespace l::ui { virtual bool Active(UIContainer& container, const InputState& input); virtual bool Visit(UIContainer& container, const InputState& input); - bool LinkHandler(int32_t linkInputId, int32_t linkOutputId, int32_t inputChannel, int32_t outputChannel, bool connected) { - if (mNGSchema == nullptr) { - return false; - } - - auto inputNode = mNGSchema->GetNode(linkInputId); - if (inputNode == nullptr) { - return false; - } - if (connected) { - auto outputNode = mNGSchema->GetNode(linkOutputId); - return outputNode != nullptr && inputNode->SetInput(static_cast(inputChannel), *outputNode, static_cast(outputChannel)); - } - return inputNode->ClearInput(static_cast(inputChannel)); - } + bool LinkHandler(int32_t linkInputId, int32_t linkOutputId, int32_t inputChannel, int32_t outputChannel, bool connected); void SetNGSchema(l::nodegraph::NodeGraphSchema* ngSchema) { mNGSchema = ngSchema; diff --git a/packages/rendering/source/common/ui/UIVisitors.cpp b/packages/rendering/source/common/ui/UIVisitors.cpp index 1efaf270..2bc45312 100644 --- a/packages/rendering/source/common/ui/UIVisitors.cpp +++ b/packages/rendering/source/common/ui/UIVisitors.cpp @@ -1,5 +1,7 @@ #include "rendering/ui/UIVisitors.h" #include "hid/KeyboardPiano.h" +#include "nodegraph/NodeGraphSchema.h" + namespace l::ui { @@ -499,4 +501,20 @@ namespace l::ui { return false; } + bool UILinkIO::LinkHandler(int32_t linkInputId, int32_t linkOutputId, int32_t inputChannel, int32_t outputChannel, bool connected) { + if (mNGSchema == nullptr) { + return false; + } + + auto inputNode = mNGSchema->GetNode(linkInputId); + if (inputNode == nullptr) { + return false; + } + if (connected) { + auto outputNode = mNGSchema->GetNode(linkOutputId); + return outputNode != nullptr && inputNode->SetInput(static_cast(inputChannel), *outputNode, static_cast(outputChannel)); + } + return inputNode->ClearInput(static_cast(inputChannel)); + } + }