Skip to content

Commit

Permalink
More structure. Forward declare. Add ng test for tweens.
Browse files Browse the repository at this point in the history
  • Loading branch information
linuscu committed Sep 25, 2024
1 parent 7ff4444 commit 2727ba1
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/audio/include/audio/PortAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>& GetWriteBuffer();
bool CanWrite();
Expand Down
58 changes: 57 additions & 1 deletion packages/nodegraph/tests/common/NodeGraphDataTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TestOp : public NodeGraphOp2 {



TEST(NodeGraphData, Setup) {
TEST(NodeGraphData, Sampler) {

NodeGraph<TestOp> node0;
NodeGraph<TestOp> node1;
Expand All @@ -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<NodeGraphInput>& inputs, std::vector<NodeGraphOutput>& 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<TestOp> node0;
NodeGraph<TestOp> 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<float>(i > 24 ? 24 : i);
*input1++ = static_cast<float>(i > 24 ? 24 : i);
}
}

node1.ProcessSubGraph(32);

return 0;
}

2 changes: 1 addition & 1 deletion packages/nodegraph/tests/common/NodeGraphSchemaTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ TEST(NodeGraph, GraphGroups) {
return 0;
}

TEST(NodeGraph, SchemaBasic) {
TEST(NodeGraph, SchemaAllNodes) {

NodeGraphSchema ng;

Expand Down
22 changes: 5 additions & 17 deletions packages/rendering/include/rendering/ui/UIVisitors.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
#include "rendering/ui/UIContainer.h"
#include "rendering/ui/UIWindow.h"

#include "nodegraph/NodeGraphSchema.h"

#include <unordered_set>
#include <deque>

namespace l::nodegraph {
class NodeGraphSchema;
}

namespace l::ui {

class UIUpdate : public UIVisitor {
Expand Down Expand Up @@ -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<int8_t>(inputChannel), *outputNode, static_cast<int8_t>(outputChannel));
}
return inputNode->ClearInput(static_cast<int8_t>(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;
Expand Down
18 changes: 18 additions & 0 deletions packages/rendering/source/common/ui/UIVisitors.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "rendering/ui/UIVisitors.h"
#include "hid/KeyboardPiano.h"
#include "nodegraph/NodeGraphSchema.h"


namespace l::ui {

Expand Down Expand Up @@ -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<int8_t>(inputChannel), *outputNode, static_cast<int8_t>(outputChannel));
}
return inputNode->ClearInput(static_cast<int8_t>(inputChannel));
}

}

0 comments on commit 2727ba1

Please sign in to comment.