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

@ -25,9 +25,9 @@ class FluidSCWrapper : public impl::FluidSCWrapperBase<C>
{
using FloatControlsIter = impl::FloatControlsIter;
//I would like to template these to something more scaleable, but baby steps
friend class impl::RealTime<C,FluidSCWrapper>;
friend class impl::NonRealTime<C,FluidSCWrapper>;
// I would like to template these to something more scaleable, but baby steps
friend class impl::RealTime<C, FluidSCWrapper>;
friend class impl::NonRealTime<C, FluidSCWrapper>;
static void doVersion(Unit*, sc_msg_iter*)
{
@ -38,12 +38,14 @@ class FluidSCWrapper : public impl::FluidSCWrapperBase<C>
bool mInit{false};
public:
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>
using ControlSetter = typename ClientParams<FluidSCWrapper>::template Setter<FloatControlsIter, N, T>;
using ControlSetter =
typename ClientParams<FluidSCWrapper>::template Setter<FloatControlsIter,
N, T>;
using Client = C;
using ParamSetType = typename C::ParamSetType;
@ -70,10 +72,10 @@ public:
std::string commandName("/");
commandName += getName();
commandName += "/version";
ft->fDefinePlugInCmd(commandName.c_str(),
[](World*, void*, sc_msg_iter*, void*){ doVersion(nullptr,nullptr); },
nullptr);
ft->fDefinePlugInCmd(
commandName.c_str(),
[](World*, void*, sc_msg_iter*, void*) { doVersion(nullptr, nullptr); },
nullptr);
}
static auto& setParams(Unit* x, ParamSetType& p, FloatControlsIter& inputs,
@ -84,52 +86,46 @@ public:
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>(
verbose ? reportage : nullptr, x, inputs, p, alloc);
if (constrain) p.constrainParameterValuesRT(verbose ? reportage : nullptr);
if(verbose)
if (verbose)
{
for(auto& r:*reportage)
for (auto& r : *reportage)
{
if(!r.ok()) printResult(x->mParent->mNode.mWorld, r);
if (!r.ok()) printResult(x->mParent->mNode.mWorld, r);
}
}
if(!initialized) delete reportage;
if (!initialized) delete reportage;
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())
{
case Result::Status::kWarning:
{
if (!w || w->mVerbosity > 0)
std::cout << "WARNING: " << getName() << " - " << r.message().c_str() << '\n';
break;
}
case Result::Status::kError:
{
std::cout << "ERROR: " << getName() << " - " << r.message().c_str() << '\n';
break;
}
case Result::Status::kCancelled:
{
std::cout << getName() << ": Task cancelled\n" << '\n';
break;
}
default:
{
}
case Result::Status::kWarning: {
if (!w || w->mVerbosity > 0)
std::cout << "WARNING: " << getName() << " - " << r.message().c_str()
<< '\n';
break;
}
case Result::Status::kError: {
std::cout << "ERROR: " << getName() << " - " << r.message().c_str()
<< '\n';
break;
}
case Result::Status::kCancelled: {
std::cout << getName() << ": Task cancelled\n" << '\n';
break;
}
default: {
}
}
}

@ -1,8 +1,8 @@
#pragma once
#include <Eigen/Core>
#include <data/FluidMemory.hpp>
#include <SC_PlugIn.hpp>
#include <Eigen/Core>
namespace fluid {
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 &&
client.controlChannelsOut().count > 0) &&
@ -113,16 +114,22 @@ struct RealTimeBase
}
else if (client.controlChannelsIn())
{
mControlInputBuffer.resize(unit.mSpecialIndex + 1);
mAudioInputs.emplace_back(mControlInputBuffer);
mControlInputBuffer.resize(client.controlChannelsIn(),
(unit.mSpecialIndex + 1) /
client.controlChannelsIn());
for (index i = 0; i < client.controlChannelsIn(); ++i)
{
mAudioInputs.emplace_back(mControlInputBuffer.row(i));
}
mInputMapper = &RealTimeBase::mapControlInputs;
}
else mInputMapper = &RealTimeBase::mapNoOp;
else { mInputMapper = &RealTimeBase::mapNoOp; }
index outputSize = client.controlChannelsOut().size > 0
? std::max(client.audioChannelsOut(),
client.maxControlChannelsOut())
: unit.mSpecialIndex + 1;
: (unit.mSpecialIndex + 1);
mOutputs.reserve(asUnsigned(outputSize));
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());
mControlInputBuffer[i] = unit.in0(static_cast<int>(i));
for (index j = 0; j < itemsPerChannel; ++j)
{
assert(j <= std::numeric_limits<int>::max());
mControlInputBuffer(i, j) = unit.in0(static_cast<int>(offset + j));
}
}
}
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)
{
@ -205,9 +221,9 @@ struct RealTimeBase
IsModel_t<Client>::value ? !mPrevTrig && unit.in0(0) > 0 : false;
mPrevTrig = trig;
#ifdef EIGEN_RUNTIME_NO_MALLOC
#ifdef EIGEN_RUNTIME_NO_MALLOC
Eigen::internal::set_is_malloc_allowed(false);
#endif
#endif
if (updateParams)
{
Wrapper::setParams(&unit, params, controls, alloc);
@ -218,9 +234,9 @@ struct RealTimeBase
(this->*mOutMapperPre)(unit, client);
client.process(mAudioInputs, mOutputs, mContext);
(this->*mOutMapperPost)(unit, client);
#ifdef EIGEN_RUNTIME_NO_MALLOC
Eigen::internal::set_is_malloc_allowed(true); //not really
#endif
#ifdef EIGEN_RUNTIME_NO_MALLOC
Eigen::internal::set_is_malloc_allowed(true); // not really
#endif
}
private:
@ -228,7 +244,7 @@ private:
std::vector<bool> mOutputConnections;
std::vector<HostVector> mAudioInputs;
std::vector<HostVector> mOutputs;
FluidTensor<float, 1> mControlInputBuffer;
FluidTensor<float, 2> mControlInputBuffer;
FluidTensor<float, 1> mControlOutputBuffer;
bool mPrevTrig;
IOMapFn mInputMapper;

Loading…
Cancel
Save