Initial commit for linking parameters to clients

nix
Alex Harker 7 years ago
parent 6d19889ba5
commit f56bd42182

@ -16,7 +16,7 @@
namespace fluid { namespace fluid {
namespace client { namespace client {
template <typename Client, typename Params> template <typename Client>
class FluidSCWrapper; class FluidSCWrapper;
namespace impl { namespace impl {
@ -31,6 +31,7 @@ template <typename T>
using msg_iter_method = T (sc_msg_iter::*)(T); using msg_iter_method = T (sc_msg_iter::*)(T);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Iterate over kr/ir inputs via callbacks from params object // Iterate over kr/ir inputs via callbacks from params object
struct FloatControlsIter struct FloatControlsIter
{ {
@ -96,6 +97,7 @@ struct ControlGetter<N, FFTParamsT>
}; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Iterate over arguments in sc_msg_iter, via callbacks from params object /// Iterate over arguments in sc_msg_iter, via callbacks from params object
template <size_t N, typename T, msg_iter_method<T> Method> template <size_t N, typename T, msg_iter_method<T> Method>
@ -148,12 +150,15 @@ struct ArgumentGetter<N, FFTParamsT>
}; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Real Time Processor // Real Time Processor
template <typename Client, class Wrapper, class Params> template <typename Client, class Wrapper>
class RealTime : public SCUnit class RealTime : public SCUnit
{ {
using HostVector = FluidTensorView<float, 1>; using HostVector = FluidTensorView<float, 1>;
using Params = typename Client::Params;
// using Client = typename Wrapper::ClientType; // using Client = typename Wrapper::ClientType;
public: public:
@ -173,11 +178,11 @@ public:
std::cout << ss.str() << '\n'; std::cout << ss.str() << '\n';
ft->fSendNodeReply(&unit->mParent->mNode, -1, ss.str().c_str(), 1, l); ft->fSendNodeReply(&unit->mParent->mNode, -1, ss.str().c_str(), 1, l);
} }
RealTime() RealTime()
: mControlsIterator{mInBuf + mSpecialIndex + 1, mNumInputs - mSpecialIndex - 1} : mControlsIterator{mInBuf + mSpecialIndex + 1,mNumInputs - mSpecialIndex - 1}
, mParams{*Wrapper::getParamDescriptors()} , mParams{Wrapper::Client::getParameterDescriptor()}
, mClient{Wrapper::setParams(mParams, mWorld->mVerbosity > 0, mWorld, mControlsIterator)} , mClient{Wrapper::setParams(mParams,mWorld->mVerbosity > 0, mWorld, mControlsIterator)}
{} {}
void init() void init()
@ -185,13 +190,13 @@ public:
assert(!(mClient.audioChannelsOut() > 0 && mClient.controlChannelsOut() > 0) && assert(!(mClient.audioChannelsOut() > 0 && mClient.controlChannelsOut() > 0) &&
"Client can't have both audio and control outputs"); "Client can't have both audio and control outputs");
// If we don't the number of arguments we expect, the language side code is probably the wrong version //If we don't the number of arguments we expect, the language side code is probably the wrong version
// set plugin to no-op, squawk, and bail; //set plugin to no-op, squawk, and bail;
if (mControlsIterator.size() != Wrapper::getParamDescriptors()->count()) if(mControlsIterator.size() != Client::getParameterDescriptor().count())
{ {
mCalcFunc = Wrapper::getInterfaceTable()->fClearUnitOutputs; mCalcFunc = Wrapper::getInterfaceTable()->fClearUnitOutputs;
std::cout << "ERROR: " << Wrapper::getName() << " wrong number of arguments. Expected " std::cout << "ERROR: " << Wrapper::getName() << " wrong number of arguments. Expected "
<< Wrapper::getParamDescriptors()->count() << ", got " << mControlsIterator.size() << Client::getParameterDescriptor().count() << ", got " << mControlsIterator.size()
<< ". Your .sc file and binary plugin might be different versions." << std::endl; << ". Your .sc file and binary plugin might be different versions." << std::endl;
return; return;
} }
@ -221,9 +226,8 @@ public:
void next(int n) void next(int n)
{ {
mControlsIterator.reset(mInBuf + 1); // mClient.audioChannelsIn()); mControlsIterator.reset(mInBuf + 1); //mClient.audioChannelsIn());
Wrapper::setParams(mParams, mWorld->mVerbosity > 0, mWorld, Wrapper::setParams(mParams, mWorld->mVerbosity > 0, mWorld, mControlsIterator); // forward on inputs N + audio inputs as params
mControlsIterator); // forward on inputs N + audio inputs as params
const Unit *unit = this; const Unit *unit = this;
for (int i = 0; i < mClient.audioChannelsIn(); ++i) for (int i = 0; i < mClient.audioChannelsIn(); ++i)
{ {
@ -250,10 +254,14 @@ protected:
}; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Non Real Time Processor /// Non Real Time Processor
template <typename Client, typename Wrapper, typename Params>
template <typename Client, typename Wrapper>
class NonRealTime class NonRealTime
{ {
using Params = typename Client::Params;
public: public:
static void setup(InterfaceTable *ft, const char *name) { DefinePlugInCmd(name, launch, nullptr); } static void setup(InterfaceTable *ft, const char *name) { DefinePlugInCmd(name, launch, nullptr); }
@ -369,63 +377,63 @@ private:
}; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// An impossible monstrosty /// An impossible monstrosty
template <typename Client, typename Wrapper, typename Params> template <typename Client, typename Wrapper>
class NonRealTimeAndRealTime : public RealTime<Client, Wrapper, Params>, public NonRealTime<Client, Wrapper, Params> class NonRealTimeAndRealTime : public RealTime<Client, Wrapper>, public NonRealTime<Client, Wrapper>
{ {
static void setup(InterfaceTable *ft, const char *name) static void setup(InterfaceTable *ft, const char *name)
{ {
RealTime<Client, Wrapper, Params>::setup(ft, name); RealTime<Client,Wrapper>::setup(ft, name);
NonRealTime<Client, Wrapper, Params>::setup(ft, name); NonRealTime<Client,Wrapper>::setup(ft, name);
} }
}; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Template Specialisations for NRT/RT // Template Specialisations for NRT/RT
template <typename Client, typename Wrapper, typename Params, typename NRT, typename RT> template <typename Client, typename Wrapper, typename NRT, typename RT>
class FluidSCWrapperImpl; class FluidSCWrapperImpl;
template <typename Client, typename Wrapper, typename Params> template <typename Client, typename Wrapper>
class FluidSCWrapperImpl<Client, Wrapper, Params, std::true_type, std::false_type> class FluidSCWrapperImpl<Client, Wrapper, std::true_type, std::false_type>
: public NonRealTime<Client, Wrapper, Params> : public NonRealTime<Client, Wrapper>
{ {
public: public:
FluidSCWrapperImpl(World *w, sc_msg_iter *args) FluidSCWrapperImpl(World* w, sc_msg_iter *args): NonRealTime<Client, Wrapper>(w,args){};
: NonRealTime<Client, Wrapper, Params>(w, args){};
}; };
template <typename Client, typename Wrapper, typename Params> template <typename Client, typename Wrapper>
class FluidSCWrapperImpl<Client, Wrapper, Params, std::false_type, std::true_type> : public RealTime<Client, Wrapper, Params> class FluidSCWrapperImpl<Client, Wrapper, std::false_type, std::true_type> : public RealTime<Client, Wrapper>
{}; {};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Make base class(es), full of CRTP mixin goodness // Make base class(es), full of CRTP mixin goodness
template <typename Client, typename Params> template <typename Client>
using FluidSCWrapperBase = using FluidSCWrapperBase = FluidSCWrapperImpl<Client, FluidSCWrapper<Client>, isNonRealTime<Client>, isRealTime<Client>>;
FluidSCWrapperImpl<Client, FluidSCWrapper<Client, Params>, Params, isNonRealTime<Client>, isRealTime<Client>>;
} // namespace impl } // namespace impl
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// The main wrapper
template <typename C, typename P>
class FluidSCWrapper : public impl::FluidSCWrapperBase<C, P>
{
///The main wrapper
template <typename C>
class FluidSCWrapper : public impl::FluidSCWrapperBase<C>
{
public: public:
using Client = C; using Client = C;
using Params = P; using ParameterSetType = ParameterSet<typename C::Params>;
FluidSCWrapper() // mParams{*getParamDescriptors()}, //impl::FluidSCWrapperBase<Client,Params>() FluidSCWrapper() // mParams{*getParamDescriptors()}, //impl::FluidSCWrapperBase<Client,Params>()
{ {
impl::FluidSCWrapperBase<Client, Params>::init(); impl::FluidSCWrapperBase<Client>::init();
} }
FluidSCWrapper(World *w, sc_msg_iter *args) FluidSCWrapper(World* w, sc_msg_iter *args): impl::FluidSCWrapperBase<Client>(w,args)
: impl::FluidSCWrapperBase<Client, Params>(w, args)
{ {
impl::FluidSCWrapperBase<Client, Params>::init(); impl::FluidSCWrapperBase<Client>::init();
} }
static const char *getName(const char *setName = nullptr) static const char *getName(const char *setName = nullptr)
@ -434,47 +442,38 @@ public:
return (name = setName ? setName : name); return (name = setName ? setName : name);
} }
static Params *getParamDescriptors(Params *setParams = nullptr)
{
static Params *descriptors = nullptr;
return (descriptors = setParams ? setParams : descriptors);
}
static InterfaceTable *getInterfaceTable(InterfaceTable *setTable = nullptr) static InterfaceTable *getInterfaceTable(InterfaceTable *setTable = nullptr)
{ {
static InterfaceTable *ft = nullptr; static InterfaceTable *ft = nullptr;
return (ft = setTable ? setTable : ft); return (ft = setTable ? setTable : ft);
} }
static void setup(Params &p, InterfaceTable *ft, const char *name) static void setup(InterfaceTable *ft, const char *name)
{ {
getName(name); getName(name);
getInterfaceTable(ft); getInterfaceTable(ft);
getParamDescriptors(&p); impl::FluidSCWrapperBase<Client>::setup(ft, name);
impl::FluidSCWrapperBase<Client, Params>::setup(ft, name);
} }
template <typename ParameterSet> static auto& setParams(ParameterSetType& p, bool verbose, World* world, impl::FloatControlsIter& inputs)
static auto &setParams(ParameterSet &p, bool verbose, World *world, impl::FloatControlsIter &inputs)
{ {
// We won't even try and set params if the arguments don't match //We won't even try and set params if the arguments don't match
if (inputs.size() == getParamDescriptors()->count()) if(inputs.size() == C::getParameterDescriptor().count())
p.template setParameterValues<impl::ControlGetter>(verbose, world, inputs); p.template setParameterValues<impl::ControlGetter>(verbose, world, inputs);
return p; return p;
} }
template <typename ParameterSet> static auto& setParams(ParameterSetType& p, bool verbose, World* world, sc_msg_iter *args)
static auto &setParams(ParameterSet &p, bool verbose, World *world, sc_msg_iter *args)
{ {
p.template setParameterValues<impl::ArgumentGetter>(verbose, world, args); p.template setParameterValues<impl::ArgumentGetter>(verbose,world, args);
return p; return p;
} }
}; };
template <template <typename...> class Client, typename... Rest, typename Params> template <class Client>
void makeSCWrapper(const char *name, Params &params, InterfaceTable *ft) void makeSCWrapper(const char *name, InterfaceTable *ft)
{ {
FluidSCWrapper<Client<ParameterSet<Params>, Rest...>, Params>::setup(params, ft, name); FluidSCWrapper<Client>::setup(ft, name);
} }
} // namespace client } // namespace client

@ -9,5 +9,5 @@ static InterfaceTable *ft;
PluginLoad(FluidSTFTUGen) { PluginLoad(FluidSTFTUGen) {
ft = inTable; ft = inTable;
using namespace fluid::client; using namespace fluid::client;
makeSCWrapper<TransientClient, double, float>("FluidTransients", TransientParams, ft); makeSCWrapper<TransientClient<float>>("FluidTransients", ft);
} }

Loading…
Cancel
Save