diff --git a/include/FluidSCWrapper.hpp b/include/FluidSCWrapper.hpp index 371e64b..5a30904 100644 --- a/include/FluidSCWrapper.hpp +++ b/include/FluidSCWrapper.hpp @@ -16,7 +16,7 @@ namespace fluid { namespace client { -template +template class FluidSCWrapper; namespace impl { @@ -31,6 +31,7 @@ template using msg_iter_method = T (sc_msg_iter::*)(T); //////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // Iterate over kr/ir inputs via callbacks from params object struct FloatControlsIter { @@ -96,6 +97,7 @@ struct ControlGetter }; //////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Iterate over arguments in sc_msg_iter, via callbacks from params object template Method> @@ -148,12 +150,15 @@ struct ArgumentGetter }; //////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // Real Time Processor -template +template class RealTime : public SCUnit { using HostVector = FluidTensorView; + using Params = typename Client::Params; + // using Client = typename Wrapper::ClientType; public: @@ -173,11 +178,11 @@ public: std::cout << ss.str() << '\n'; ft->fSendNodeReply(&unit->mParent->mNode, -1, ss.str().c_str(), 1, l); } - + RealTime() - : mControlsIterator{mInBuf + mSpecialIndex + 1, mNumInputs - mSpecialIndex - 1} - , mParams{*Wrapper::getParamDescriptors()} - , mClient{Wrapper::setParams(mParams, mWorld->mVerbosity > 0, mWorld, mControlsIterator)} + : mControlsIterator{mInBuf + mSpecialIndex + 1,mNumInputs - mSpecialIndex - 1} + , mParams{Wrapper::Client::getParameterDescriptor()} + , mClient{Wrapper::setParams(mParams,mWorld->mVerbosity > 0, mWorld, mControlsIterator)} {} void init() @@ -185,13 +190,13 @@ public: assert(!(mClient.audioChannelsOut() > 0 && mClient.controlChannelsOut() > 0) && "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 - // set plugin to no-op, squawk, and bail; - if (mControlsIterator.size() != Wrapper::getParamDescriptors()->count()) + //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; + if(mControlsIterator.size() != Client::getParameterDescriptor().count()) { mCalcFunc = Wrapper::getInterfaceTable()->fClearUnitOutputs; 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; return; } @@ -221,9 +226,8 @@ public: void next(int n) { - mControlsIterator.reset(mInBuf + 1); // mClient.audioChannelsIn()); - Wrapper::setParams(mParams, mWorld->mVerbosity > 0, mWorld, - mControlsIterator); // forward on inputs N + audio inputs as params + mControlsIterator.reset(mInBuf + 1); //mClient.audioChannelsIn()); + Wrapper::setParams(mParams, mWorld->mVerbosity > 0, mWorld, mControlsIterator); // forward on inputs N + audio inputs as params const Unit *unit = this; for (int i = 0; i < mClient.audioChannelsIn(); ++i) { @@ -250,10 +254,14 @@ protected: }; //////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Non Real Time Processor -template + +template class NonRealTime { + using Params = typename Client::Params; + public: static void setup(InterfaceTable *ft, const char *name) { DefinePlugInCmd(name, launch, nullptr); } @@ -369,63 +377,63 @@ private: }; //////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// An impossible monstrosty -template -class NonRealTimeAndRealTime : public RealTime, public NonRealTime +template +class NonRealTimeAndRealTime : public RealTime, public NonRealTime { static void setup(InterfaceTable *ft, const char *name) { - RealTime::setup(ft, name); - NonRealTime::setup(ft, name); + RealTime::setup(ft, name); + NonRealTime::setup(ft, name); } }; //////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // Template Specialisations for NRT/RT -template +template class FluidSCWrapperImpl; -template -class FluidSCWrapperImpl - : public NonRealTime +template +class FluidSCWrapperImpl + : public NonRealTime { public: - FluidSCWrapperImpl(World *w, sc_msg_iter *args) - : NonRealTime(w, args){}; + FluidSCWrapperImpl(World* w, sc_msg_iter *args): NonRealTime(w,args){}; }; -template -class FluidSCWrapperImpl : public RealTime +template +class FluidSCWrapperImpl : public RealTime {}; //////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // Make base class(es), full of CRTP mixin goodness -template -using FluidSCWrapperBase = - FluidSCWrapperImpl, Params, isNonRealTime, isRealTime>; +template +using FluidSCWrapperBase = FluidSCWrapperImpl, isNonRealTime, isRealTime>; } // namespace impl //////////////////////////////////////////////////////////////////////////////////////////////////////////////// -/// The main wrapper -template -class FluidSCWrapper : public impl::FluidSCWrapperBase -{ +///The main wrapper +template +class FluidSCWrapper : public impl::FluidSCWrapperBase +{ public: using Client = C; - using Params = P; + using ParameterSetType = ParameterSet; FluidSCWrapper() // mParams{*getParamDescriptors()}, //impl::FluidSCWrapperBase() { - impl::FluidSCWrapperBase::init(); + impl::FluidSCWrapperBase::init(); } - FluidSCWrapper(World *w, sc_msg_iter *args) - : impl::FluidSCWrapperBase(w, args) + FluidSCWrapper(World* w, sc_msg_iter *args): impl::FluidSCWrapperBase(w,args) { - impl::FluidSCWrapperBase::init(); + impl::FluidSCWrapperBase::init(); } static const char *getName(const char *setName = nullptr) @@ -434,47 +442,38 @@ public: 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 *ft = nullptr; 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); getInterfaceTable(ft); - getParamDescriptors(&p); - impl::FluidSCWrapperBase::setup(ft, name); + impl::FluidSCWrapperBase::setup(ft, name); } - template - static auto &setParams(ParameterSet &p, bool verbose, World *world, impl::FloatControlsIter &inputs) + static auto& setParams(ParameterSetType& p, bool verbose, World* world, impl::FloatControlsIter& inputs) { - // We won't even try and set params if the arguments don't match - if (inputs.size() == getParamDescriptors()->count()) - p.template setParameterValues(verbose, world, inputs); + //We won't even try and set params if the arguments don't match + if(inputs.size() == C::getParameterDescriptor().count()) + p.template setParameterValues(verbose, world, inputs); return p; } - template - static auto &setParams(ParameterSet &p, bool verbose, World *world, sc_msg_iter *args) + static auto& setParams(ParameterSetType& p, bool verbose, World* world, sc_msg_iter *args) { - p.template setParameterValues(verbose, world, args); - return p; + p.template setParameterValues(verbose,world, args); + return p; } }; -template