Feature/add multiple out support to kr (#164)

* Tag release to correct commit

* release: delete pre-existing

* almost working class def and no difference to the wrapper

* removed the print outs and added size check of the inputs - still not sure how I get that shape of output when it should be 3 of in.asArray.size

* input shape now working

* correct input count division (was the wrong way round)

* computes the real size of the input to decline the output size

* and finally a working class. We're all set!

* troubleshooting prints all over

* new proper class for proper algo

* remove the debugging pritns

* clang-format-ed

* pre-clang-format

* clang-format-ed with the right style sheet

---------

Co-authored-by: Owen Green <gungwho@gmail.com>
nix
tremblap 2 years ago committed by GitHub
parent 0daeef1466
commit 7fbaf8fdab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -38,12 +38,14 @@ class FluidSCWrapper : public impl::FluidSCWrapperBase<C>
bool mInit{false}; bool mInit{false};
public: public:
template <size_t N, typename T> template <size_t N, typename T>
using ArgumentSetter = typename ClientParams<FluidSCWrapper>::template Setter<sc_msg_iter, N, T>; using ArgumentSetter =
typename ClientParams<FluidSCWrapper>::template Setter<sc_msg_iter, N, T>;
template <size_t N, typename T> template <size_t N, typename T>
using ControlSetter = typename ClientParams<FluidSCWrapper>::template Setter<FloatControlsIter, N, T>; using ControlSetter =
typename ClientParams<FluidSCWrapper>::template Setter<FloatControlsIter,
N, T>;
using Client = C; using Client = C;
using ParamSetType = typename C::ParamSetType; using ParamSetType = typename C::ParamSetType;
@ -70,10 +72,10 @@ public:
std::string commandName("/"); std::string commandName("/");
commandName += getName(); commandName += getName();
commandName += "/version"; commandName += "/version";
ft->fDefinePlugInCmd(commandName.c_str(), ft->fDefinePlugInCmd(
commandName.c_str(),
[](World*, void*, sc_msg_iter*, void*) { doVersion(nullptr, nullptr); }, [](World*, void*, sc_msg_iter*, void*) { doVersion(nullptr, nullptr); },
nullptr); nullptr);
} }
static auto& setParams(Unit* x, ParamSetType& p, FloatControlsIter& inputs, static auto& setParams(Unit* x, ParamSetType& p, FloatControlsIter& inputs,
@ -84,7 +86,9 @@ public:
using Reportage = decltype(static_cast<FluidSCWrapper*>(x)->mReportage); using Reportage = decltype(static_cast<FluidSCWrapper*>(x)->mReportage);
Reportage* reportage = initialized ? &(static_cast<FluidSCWrapper*>(x)->mReportage) : new Reportage(); Reportage* reportage = initialized
? &(static_cast<FluidSCWrapper*>(x)->mReportage)
: new Reportage();
p.template setParameterValuesRT<ControlSetter>( p.template setParameterValuesRT<ControlSetter>(
verbose ? reportage : nullptr, x, inputs, p, alloc); verbose ? reportage : nullptr, x, inputs, p, alloc);
@ -100,35 +104,27 @@ public:
return p; return p;
} }
// static void printResult(SharedState<C>& x, Result& r)
// {
// if (!x.get() || !x->mNodeAlive) return;
// FluidSCWrapper::printResult(x->mNode->mWorld, r);
// }
static void printResult(World* w, Result& r) static void printResult(World* w, Result& r)
{ {
switch (r.status()) switch (r.status())
{ {
case Result::Status::kWarning: case Result::Status::kWarning: {
{
if (!w || w->mVerbosity > 0) if (!w || w->mVerbosity > 0)
std::cout << "WARNING: " << getName() << " - " << r.message().c_str() << '\n'; std::cout << "WARNING: " << getName() << " - " << r.message().c_str()
<< '\n';
break; break;
} }
case Result::Status::kError: case Result::Status::kError: {
{ std::cout << "ERROR: " << getName() << " - " << r.message().c_str()
std::cout << "ERROR: " << getName() << " - " << r.message().c_str() << '\n'; << '\n';
break; break;
} }
case Result::Status::kCancelled: case Result::Status::kCancelled: {
{
std::cout << getName() << ": Task cancelled\n" << '\n'; std::cout << getName() << ": Task cancelled\n" << '\n';
break; break;
} }
default: default: {
{
} }
} }
} }

@ -1,8 +1,8 @@
#pragma once #pragma once
#include <Eigen/Core>
#include <data/FluidMemory.hpp> #include <data/FluidMemory.hpp>
#include <SC_PlugIn.hpp> #include <SC_PlugIn.hpp>
#include <Eigen/Core>
namespace fluid { namespace fluid {
namespace client { namespace client {
@ -84,7 +84,8 @@ struct RealTimeBase
} }
void init(SCUnit& unit, Client& client, FloatControlsIter& controls, Allocator& alloc) void init(SCUnit& unit, Client& client, FloatControlsIter& controls,
Allocator& alloc)
{ {
assert(!(client.audioChannelsOut() > 0 && assert(!(client.audioChannelsOut() > 0 &&
client.controlChannelsOut().count > 0) && client.controlChannelsOut().count > 0) &&
@ -113,16 +114,22 @@ struct RealTimeBase
} }
else if (client.controlChannelsIn()) else if (client.controlChannelsIn())
{ {
mControlInputBuffer.resize(unit.mSpecialIndex + 1); mControlInputBuffer.resize(client.controlChannelsIn(),
mAudioInputs.emplace_back(mControlInputBuffer); (unit.mSpecialIndex + 1) /
client.controlChannelsIn());
for (index i = 0; i < client.controlChannelsIn(); ++i)
{
mAudioInputs.emplace_back(mControlInputBuffer.row(i));
}
mInputMapper = &RealTimeBase::mapControlInputs; mInputMapper = &RealTimeBase::mapControlInputs;
} }
else mInputMapper = &RealTimeBase::mapNoOp; else { mInputMapper = &RealTimeBase::mapNoOp; }
index outputSize = client.controlChannelsOut().size > 0 index outputSize = client.controlChannelsOut().size > 0
? std::max(client.audioChannelsOut(), ? std::max(client.audioChannelsOut(),
client.maxControlChannelsOut()) client.maxControlChannelsOut())
: unit.mSpecialIndex + 1; : (unit.mSpecialIndex + 1);
mOutputs.reserve(asUnsigned(outputSize)); mOutputs.reserve(asUnsigned(outputSize));
if (client.audioChannelsOut()) if (client.audioChannelsOut())
@ -177,18 +184,27 @@ struct RealTimeBase
} }
} }
void mapControlInputs(SCUnit& unit, Client&) void mapControlInputs(SCUnit& unit, Client& client)
{ {
for (index i = 0; i < unit.mSpecialIndex + 1; ++i) assert((unit.mSpecialIndex + 1) % client.controlChannelsIn() == 0 &&
"Control channels can't be mapped");
index itemsPerChannel =
(unit.mSpecialIndex + 1) / client.controlChannelsIn();
for (index i = 0, offset = 0; i < client.controlChannelsIn();
++i, offset += itemsPerChannel)
{ {
assert(i <= std::numeric_limits<int>::max()); for (index j = 0; j < itemsPerChannel; ++j)
mControlInputBuffer[i] = unit.in0(static_cast<int>(i)); {
assert(j <= std::numeric_limits<int>::max());
mControlInputBuffer(i, j) = unit.in0(static_cast<int>(offset + j));
}
} }
} }
void mapControlOutputs(SCUnit& unit, Client&) void mapControlOutputs(SCUnit& unit, Client&)
{ {
index numOuts = std::min<index>(mControlOutputBuffer.size(),unit.mNumOutputs); index numOuts =
std::min<index>(mControlOutputBuffer.size(), unit.mNumOutputs);
for (index i = 0; i < numOuts; ++i) for (index i = 0; i < numOuts; ++i)
{ {
@ -228,7 +244,7 @@ private:
std::vector<bool> mOutputConnections; std::vector<bool> mOutputConnections;
std::vector<HostVector> mAudioInputs; std::vector<HostVector> mAudioInputs;
std::vector<HostVector> mOutputs; std::vector<HostVector> mOutputs;
FluidTensor<float, 1> mControlInputBuffer; FluidTensor<float, 2> mControlInputBuffer;
FluidTensor<float, 1> mControlOutputBuffer; FluidTensor<float, 1> mControlOutputBuffer;
bool mPrevTrig; bool mPrevTrig;
IOMapFn mInputMapper; IOMapFn mInputMapper;

Loading…
Cancel
Save