2024-12-05 23:58:22 +01:00
|
|
|
|
/*
|
|
|
|
|
|
NodeBuilder(Test) - creation and setup of render nodes
|
|
|
|
|
|
|
|
|
|
|
|
Copyright (C)
|
|
|
|
|
|
2024, Hermann Vosseler <Ichthyostega@web.de>
|
|
|
|
|
|
|
|
|
|
|
|
**Lumiera** 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 2 of the License, or (at your
|
|
|
|
|
|
option) any later version. See the file COPYING for further details.
|
|
|
|
|
|
|
|
|
|
|
|
* *****************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
/** @file node-builder-test.cpp
|
2024-12-06 23:43:18 +01:00
|
|
|
|
** Unit test \ref NodeBuilder_test demonstrates how to build render nodes.
|
2024-12-05 23:58:22 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
|
|
|
|
|
#include "steam/engine/node-builder.hpp"
|
2024-12-22 22:31:05 +01:00
|
|
|
|
#include "steam/engine/diagnostic-buffer-provider.hpp"
|
2025-01-05 01:01:15 +01:00
|
|
|
|
#include "steam/asset/meta/time-grid.hpp"
|
2024-12-24 06:23:55 +01:00
|
|
|
|
#include "lib/test/diagnostic-output.hpp"
|
2025-01-05 01:01:15 +01:00
|
|
|
|
#include "lib/time/timequant.hpp"
|
|
|
|
|
|
#include "lib/time/timecode.hpp"
|
|
|
|
|
|
#include "lib/symbol.hpp"
|
2024-12-05 23:58:22 +01:00
|
|
|
|
|
2025-01-05 02:48:07 +01:00
|
|
|
|
#include <array>
|
2025-02-11 01:10:25 +01:00
|
|
|
|
#include <boost/lexical_cast.hpp>
|
2025-01-05 02:48:07 +01:00
|
|
|
|
|
2025-01-05 01:01:15 +01:00
|
|
|
|
using lib::Symbol;
|
2024-12-05 23:58:22 +01:00
|
|
|
|
using std::string;
|
2025-01-05 02:48:07 +01:00
|
|
|
|
using std::array;
|
2025-01-05 01:01:15 +01:00
|
|
|
|
using lib::time::Time;
|
|
|
|
|
|
using lib::time::QuTime;
|
|
|
|
|
|
using lib::time::FrameNr;
|
|
|
|
|
|
using lib::time::SmpteTC;
|
2024-12-05 23:58:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace steam {
|
|
|
|
|
|
namespace engine{
|
|
|
|
|
|
namespace test {
|
|
|
|
|
|
|
2025-01-05 01:01:15 +01:00
|
|
|
|
namespace {
|
|
|
|
|
|
Symbol SECONDS_GRID = "grid_sec";
|
|
|
|
|
|
}
|
2024-12-05 23:58:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************//**
|
2024-12-22 19:46:02 +01:00
|
|
|
|
* @test creating and configuring various kinds of Render Nodes.
|
2024-12-05 23:58:22 +01:00
|
|
|
|
*/
|
|
|
|
|
|
class NodeBuilder_test : public Test
|
|
|
|
|
|
{
|
|
|
|
|
|
virtual void
|
|
|
|
|
|
run (Arg)
|
|
|
|
|
|
{
|
2025-01-05 01:01:15 +01:00
|
|
|
|
seedRand(); // used for simple time-based „automation“
|
|
|
|
|
|
steam::asset::meta::TimeGrid::build (SECONDS_GRID, 1);
|
|
|
|
|
|
|
2024-12-22 19:46:02 +01:00
|
|
|
|
build_simpleNode();
|
|
|
|
|
|
build_Node_fixedParam();
|
|
|
|
|
|
build_Node_dynamicParam();
|
2025-02-11 01:10:25 +01:00
|
|
|
|
build_Node_adaptedParam();
|
2024-12-22 19:46:02 +01:00
|
|
|
|
build_connectedNodes();
|
|
|
|
|
|
build_ParamNode();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-12-24 06:23:55 +01:00
|
|
|
|
/** @test build a simple output-only Render Node
|
|
|
|
|
|
* @todo 12/24 ✔ define ⟶ ✔ implement
|
2024-12-22 19:46:02 +01:00
|
|
|
|
*/
|
|
|
|
|
|
void
|
|
|
|
|
|
build_simpleNode()
|
|
|
|
|
|
{
|
|
|
|
|
|
auto fun = [](uint* buff){ *buff = LIFE_AND_UNIVERSE_4EVER; };
|
|
|
|
|
|
|
|
|
|
|
|
ProcNode node{prepareNode("Test")
|
|
|
|
|
|
.preparePort()
|
|
|
|
|
|
.invoke("fun()", fun)
|
|
|
|
|
|
.completePort()
|
|
|
|
|
|
.build()};
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (watch(node).isSrc());
|
|
|
|
|
|
CHECK (watch(node).ports().size() == 1);
|
2024-12-22 22:31:05 +01:00
|
|
|
|
|
2024-12-26 21:42:32 +01:00
|
|
|
|
CHECK (LIFE_AND_UNIVERSE_4EVER == invokeRenderNode (node));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @internal Helper for Render Node invocation
|
|
|
|
|
|
* - use a DiagnosticBufferProvider to allocate a result buffer
|
|
|
|
|
|
* - assuming that the Node internally does not allocate further buffers
|
|
|
|
|
|
* - pull from Port #0 of the given node, passing the \a nomTime as argument
|
|
|
|
|
|
* - expect the buffer to hold a single `uint` value after invocation
|
|
|
|
|
|
*/
|
|
|
|
|
|
uint
|
|
|
|
|
|
invokeRenderNode (ProcNode& theNode, Time nomTime =Time::ZERO)
|
|
|
|
|
|
{
|
2024-12-22 22:31:05 +01:00
|
|
|
|
BufferProvider& provider = DiagnosticBufferProvider::build();
|
2024-12-24 06:23:55 +01:00
|
|
|
|
BuffHandle buff = provider.lockBufferFor<long> (-55);
|
|
|
|
|
|
ProcessKey key{0};
|
|
|
|
|
|
uint port{0};
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (-55 == buff.accessAs<long>());
|
|
|
|
|
|
|
|
|
|
|
|
// Trigger Node invocation...
|
2024-12-26 21:42:32 +01:00
|
|
|
|
buff = theNode.pull (port, buff, nomTime, key);
|
2024-12-22 22:31:05 +01:00
|
|
|
|
|
2024-12-26 21:42:32 +01:00
|
|
|
|
uint result = buff.accessAs<uint>();
|
|
|
|
|
|
buff.release();
|
|
|
|
|
|
return result;
|
2024-12-22 19:46:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-12-27 03:55:06 +01:00
|
|
|
|
/** @test build a Node with a fixed invocation parameter
|
|
|
|
|
|
* @todo 12/24 ✔ define ⟶ ✔ implement
|
2024-12-22 19:46:02 +01:00
|
|
|
|
*/
|
|
|
|
|
|
void
|
|
|
|
|
|
build_Node_fixedParam()
|
|
|
|
|
|
{
|
2024-12-26 21:42:32 +01:00
|
|
|
|
auto procFun = [](ushort param, uint* buff){ *buff = param; };
|
|
|
|
|
|
|
|
|
|
|
|
ProcNode node{prepareNode("Test")
|
|
|
|
|
|
.preparePort()
|
2025-01-05 02:48:07 +01:00
|
|
|
|
.invoke ("fun()", procFun)
|
2024-12-27 03:55:06 +01:00
|
|
|
|
.setParam (LIFE_AND_UNIVERSE_4EVER)
|
2024-12-26 21:42:32 +01:00
|
|
|
|
.completePort()
|
|
|
|
|
|
.build()};
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (LIFE_AND_UNIVERSE_4EVER == invokeRenderNode (node));
|
2024-12-22 19:46:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-01-05 01:01:15 +01:00
|
|
|
|
/** @test build a Node with dynamically generated parameter
|
|
|
|
|
|
* - use a processing function which takes a parameter
|
|
|
|
|
|
* - use an _automation functor,_ which just quantises
|
|
|
|
|
|
* the time into an implicitly defined grid
|
|
|
|
|
|
* - install both into a render node
|
|
|
|
|
|
* - set a random _nominal time_ for invocation
|
|
|
|
|
|
* @todo 12/24 ✔ define ⟶ ✔ implement
|
2024-12-22 19:46:02 +01:00
|
|
|
|
*/
|
|
|
|
|
|
void
|
|
|
|
|
|
build_Node_dynamicParam()
|
|
|
|
|
|
{
|
2025-01-05 01:01:15 +01:00
|
|
|
|
auto procFun = [](long param, int* buff){ *buff = int(param); };
|
|
|
|
|
|
auto autoFun = [](Time nomTime){ return FrameNr::quant (nomTime, SECONDS_GRID); };
|
|
|
|
|
|
|
|
|
|
|
|
ProcNode node{prepareNode("Test")
|
|
|
|
|
|
.preparePort()
|
2025-01-05 02:48:07 +01:00
|
|
|
|
.invoke ("fun()", procFun)
|
2025-01-05 01:01:15 +01:00
|
|
|
|
.attachAutomation (autoFun)
|
|
|
|
|
|
.completePort()
|
|
|
|
|
|
.build()};
|
|
|
|
|
|
|
|
|
|
|
|
// invoke with a random »nominal Time« <10s with ms granularity
|
|
|
|
|
|
Time theTime{rani(10'000),0};
|
|
|
|
|
|
int res = invokeRenderNode (node, theTime);
|
|
|
|
|
|
|
|
|
|
|
|
// for verification: quantise the given Time into SMPTE timecode;
|
|
|
|
|
|
QuTime qantTime (theTime, SECONDS_GRID);
|
|
|
|
|
|
CHECK (res == SmpteTC(qantTime).secs);
|
|
|
|
|
|
// Explanation: since the param-functor quantises into a 1-second grid
|
|
|
|
|
|
// and the given time is below 1 minute, the seconds field
|
|
|
|
|
|
// of SMPTE Timecode should match the parameter value
|
2024-12-22 19:46:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-02-11 01:10:25 +01:00
|
|
|
|
/** @test build a node and _adapt the parameters_ for invocation.
|
|
|
|
|
|
* - again use a processing function which takes a parameter
|
|
|
|
|
|
* - but then _decorate_ this functor, so that it takes different arguments
|
|
|
|
|
|
* - attach parameter handling to supply these adapted arguments
|
|
|
|
|
|
* @todo 2/25 ✔ define ⟶ 🔁 implement
|
|
|
|
|
|
*/
|
|
|
|
|
|
void
|
|
|
|
|
|
build_Node_adaptedParam()
|
|
|
|
|
|
{
|
|
|
|
|
|
auto procFun = [](ulong param, int* buff){ *buff = int(param); };
|
2025-02-11 17:15:32 +01:00
|
|
|
|
auto adaptor = [](string spec){ return boost::lexical_cast<int>(spec); };
|
2025-02-11 01:10:25 +01:00
|
|
|
|
|
|
|
|
|
|
ProcNode node{prepareNode("Test")
|
|
|
|
|
|
.preparePort()
|
|
|
|
|
|
.invoke ("fun()", procFun)
|
2025-02-11 17:15:32 +01:00
|
|
|
|
.adaptParam (adaptor)
|
|
|
|
|
|
.setParam ("55")
|
2025-02-11 01:10:25 +01:00
|
|
|
|
.completePort()
|
|
|
|
|
|
.build()};
|
2025-02-11 17:15:32 +01:00
|
|
|
|
SHOW_EXPR(invokeRenderNode (node));
|
2025-02-11 01:10:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-01-05 02:48:07 +01:00
|
|
|
|
/** @test build a chain with three connected Nodes
|
|
|
|
|
|
* - have two source nodes, which accept a parameter
|
|
|
|
|
|
* - but configure them differently: one gets a constant,
|
|
|
|
|
|
* while the other draws a random number
|
|
|
|
|
|
* - the third node takes two input buffers and and one output;
|
|
|
|
|
|
* it retrieves the input values, and sums them together
|
|
|
|
|
|
* - use the »simplified 1:1 wiring«, which connects consecutively
|
|
|
|
|
|
* each input slot to the next given node on the same port number;
|
|
|
|
|
|
* here we only use port#0 on all three nodes.
|
|
|
|
|
|
* @todo 12/24 ✔ define ⟶ ✔ implement
|
2024-12-22 19:46:02 +01:00
|
|
|
|
*/
|
|
|
|
|
|
void
|
|
|
|
|
|
build_connectedNodes()
|
|
|
|
|
|
{
|
2025-01-05 02:48:07 +01:00
|
|
|
|
using SrcBuffs = array<uint*, 2>;
|
2025-01-05 20:23:21 +01:00
|
|
|
|
auto sourceFun = [](uint param, uint* out) { *out = 1 + param; };
|
2025-01-05 02:48:07 +01:00
|
|
|
|
auto joinerFun = [](SrcBuffs src, uint* out){ *out = *src[0] + *src[1]; };
|
|
|
|
|
|
|
2025-01-05 20:23:21 +01:00
|
|
|
|
int peek{-1};
|
2025-01-05 02:48:07 +01:00
|
|
|
|
auto randParam = [&](TurnoutSystem&){ return peek = rani(100); };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ProcNode n1{prepareNode("Src1")
|
|
|
|
|
|
.preparePort()
|
2025-01-05 20:23:21 +01:00
|
|
|
|
.invoke ("fix-val()", sourceFun)
|
2025-01-05 02:48:07 +01:00
|
|
|
|
.setParam (LIFE_AND_UNIVERSE_4EVER)
|
|
|
|
|
|
.completePort()
|
|
|
|
|
|
.build()};
|
|
|
|
|
|
|
|
|
|
|
|
ProcNode n2{prepareNode("Src2")
|
|
|
|
|
|
.preparePort()
|
2025-01-05 20:23:21 +01:00
|
|
|
|
.invoke ("ran-val()", sourceFun)
|
2025-01-05 02:48:07 +01:00
|
|
|
|
.attachParamFun (randParam)
|
|
|
|
|
|
.completePort()
|
|
|
|
|
|
.build()};
|
|
|
|
|
|
|
|
|
|
|
|
ProcNode n3{prepareNode("Join")
|
|
|
|
|
|
.preparePort()
|
|
|
|
|
|
.invoke ("add()", joinerFun)
|
|
|
|
|
|
.connectLead(n1)
|
|
|
|
|
|
.connectLead(n2)
|
|
|
|
|
|
.completePort()
|
|
|
|
|
|
.build()};
|
|
|
|
|
|
|
2025-02-05 00:25:02 +01:00
|
|
|
|
CHECK (is_linked(n3).to(n1));
|
|
|
|
|
|
CHECK (is_linked(n3).to(n2));
|
|
|
|
|
|
|
2025-01-05 02:48:07 +01:00
|
|
|
|
uint res = invokeRenderNode(n3);
|
|
|
|
|
|
CHECK (res == peek+1 + LIFE_AND_UNIVERSE_4EVER+1 );
|
2025-01-05 20:23:21 +01:00
|
|
|
|
CHECK (peek != -1);
|
2024-12-22 19:46:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-01-05 20:23:21 +01:00
|
|
|
|
/** @test demonstrate the setup of a »Param Agent Node«
|
|
|
|
|
|
* - perform effectively the same computation as the preceding test
|
|
|
|
|
|
* - but use two new custom parameters in the Param Agent Node
|
|
|
|
|
|
* - pick them up from the nested source nodes by accessor-functors
|
|
|
|
|
|
* @todo 12/24 ✔ define ⟶ ✔ implement
|
2024-12-22 19:46:02 +01:00
|
|
|
|
*/
|
|
|
|
|
|
void
|
|
|
|
|
|
build_ParamNode()
|
|
|
|
|
|
{
|
2025-01-05 20:23:21 +01:00
|
|
|
|
// Note: using exactly the same functors as in the preceding test
|
|
|
|
|
|
using SrcBuffs = array<uint*, 2>;
|
|
|
|
|
|
auto sourceFun = [](uint param, uint* out) { *out = 1 + param; };
|
|
|
|
|
|
auto joinerFun = [](SrcBuffs src, uint* out){ *out = *src[0] + *src[1]; };
|
|
|
|
|
|
|
|
|
|
|
|
int peek{-1};
|
|
|
|
|
|
auto randParam = [&](TurnoutSystem&){ return peek = rani(100); };
|
|
|
|
|
|
|
|
|
|
|
|
// Step-1 : build a ParamSpec
|
|
|
|
|
|
auto spec = buildParamSpec()
|
|
|
|
|
|
.addValSlot (LIFE_AND_UNIVERSE_4EVER)
|
|
|
|
|
|
.addSlot (randParam)
|
|
|
|
|
|
;
|
|
|
|
|
|
auto get0 = spec.makeAccessor<0>();
|
|
|
|
|
|
auto get1 = spec.makeAccessor<1>();
|
|
|
|
|
|
|
|
|
|
|
|
// Step-2 : build delegate Node tree
|
|
|
|
|
|
ProcNode n1{prepareNode("Src1")
|
|
|
|
|
|
.preparePort()
|
|
|
|
|
|
.invoke ("fix-val()", sourceFun)
|
|
|
|
|
|
.retrieveParam (get0)
|
|
|
|
|
|
.completePort()
|
|
|
|
|
|
.build()};
|
|
|
|
|
|
|
|
|
|
|
|
ProcNode n2{prepareNode("Src2")
|
|
|
|
|
|
.preparePort()
|
|
|
|
|
|
.invoke ("ran-val()", sourceFun)
|
|
|
|
|
|
.retrieveParam (get1)
|
|
|
|
|
|
.completePort()
|
|
|
|
|
|
.build()};
|
|
|
|
|
|
|
|
|
|
|
|
ProcNode n3{prepareNode("Join")
|
|
|
|
|
|
.preparePort()
|
|
|
|
|
|
.invoke ("add()", joinerFun)
|
|
|
|
|
|
.connectLead(n1)
|
|
|
|
|
|
.connectLead(n2)
|
|
|
|
|
|
.completePort()
|
|
|
|
|
|
.build()};
|
|
|
|
|
|
|
|
|
|
|
|
// Step-3 : build Param Agent as entry point
|
|
|
|
|
|
ProcNode n4{prepareNode("Param")
|
|
|
|
|
|
.preparePort()
|
|
|
|
|
|
.computeParam(spec)
|
|
|
|
|
|
.delegateLead(n3)
|
|
|
|
|
|
.completePort()
|
|
|
|
|
|
.build()};
|
|
|
|
|
|
|
|
|
|
|
|
uint res = invokeRenderNode(n4);
|
|
|
|
|
|
CHECK (res == peek+1 + LIFE_AND_UNIVERSE_4EVER+1 );
|
|
|
|
|
|
CHECK (peek != -1);
|
2024-12-22 19:46:02 +01:00
|
|
|
|
}
|
2024-12-05 23:58:22 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
|
|
|
|
|
LAUNCHER (NodeBuilder_test, "unit node");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}}} // namespace steam::engine::test
|