From 73c6fef292b48ff278838cfafb49c16ba16eb5ba Mon Sep 17 00:00:00 2001 From: Alex Harker Date: Tue, 19 Mar 2019 17:38:44 +0000 Subject: [PATCH] Full template on getting arguments in SC (no full specialisations) --- include/FluidSCWrapper.hpp | 169 ++++++++++++------------------------- 1 file changed, 55 insertions(+), 114 deletions(-) diff --git a/include/FluidSCWrapper.hpp b/include/FluidSCWrapper.hpp index 5b70e26..016d96b 100644 --- a/include/FluidSCWrapper.hpp +++ b/include/FluidSCWrapper.hpp @@ -21,134 +21,30 @@ class FluidSCWrapper; namespace impl { -template -struct Setter; -template -struct ArgumentGetter; -template -struct ControlGetter; -template -using msg_iter_method = T (sc_msg_iter::*)(T); - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // Iterate over kr/ir inputs via callbacks from params object struct FloatControlsIter { FloatControlsIter(float **vals, size_t N) - : mValues(vals) - , mSize(N) + : mValues(vals) + , mSize(N) {} - + float next() { return mCount >= mSize ? 0 : *mValues[mCount++]; } - + void reset(float **vals) { mValues = vals; mCount = 0; } - + size_t size() const noexcept { return mSize; } - + private: float **mValues; size_t mSize; size_t mCount{0}; }; -// General case -template -struct GetControl -{ - T operator()(World *, FloatControlsIter &controls) { return controls.next(); } -}; - -template -struct ControlGetter : public GetControl -{}; - -// Specializations -template -struct ControlGetter -{ - auto operator()(World *w, FloatControlsIter &iter) - { - typename LongT::type bufnum = iter.next(); - return typename BufferT::type(bufnum >= 0 ? new SCBufferAdaptor(bufnum, w) : nullptr); - } -}; - -template -struct ControlGetter -{ - typename FloatPairsArrayT::type operator()(World *, FloatControlsIter &iter) - { - return {iter.next(), iter.next(),iter.next(), iter.next()}; - } -}; - -template -struct ControlGetter -{ - typename FFTParamsT::type operator()(World *, FloatControlsIter &iter) - { - return {static_cast(iter.next()), static_cast(iter.next()), static_cast(iter.next())}; - } -}; - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -/// Iterate over arguments in sc_msg_iter, via callbacks from params object - -template Method> -struct GetArgument -{ - T operator()(World *w, sc_msg_iter *args) - { - T r = (args->*Method)(T{0}); - return r; - } -}; - -// General cases -template -struct ArgumentGetter : public GetArgument -{}; - -template -struct ArgumentGetter : public GetArgument -{}; - -template -struct ArgumentGetter : public GetArgument -{}; - -// Specializations -template -struct ArgumentGetter -{ - auto operator()(World *w, sc_msg_iter *args) - { - typename LongT::type bufnum = args->geti(-1); - return typename BufferT::type(bufnum >= 0 ? new SCBufferAdaptor(bufnum, w) : nullptr); - } -}; - -template -struct ArgumentGetter -{ - typename FloatPairsArrayT::type operator()(World *w, sc_msg_iter *args) - { - return {args->getf(), args->getf(),args->getf(), args->getf()}; - } -}; - -template -struct ArgumentGetter -{ - typename FFTParamsT::type operator()(World *w, sc_msg_iter *args) { return {args->geti(), args->geti(), args->geti()}; } -}; - //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Real Time Processor @@ -420,6 +316,52 @@ using FluidSCWrapperBase = FluidSCWrapperImpl, is template class FluidSCWrapper : public impl::FluidSCWrapperBase { + using FloatControlsIter = impl::FloatControlsIter; + + // Iterate over arguments in sc_msg_iter, via callbacks from params object + + template + struct GetArgument + { + auto fromArgs(World *w, FloatControlsIter& args, LongT::type) { return args.next(); } + auto fromArgs(World *w, FloatControlsIter& args, FloatT::type) { return args.next(); } + auto fromArgs(World *w, sc_msg_iter* args, LongT::type) { return args->geti(); } + auto fromArgs(World *w, sc_msg_iter* args, FloatT::type) { return args->getf(); } + + auto fromArgs(World *w, sc_msg_iter* args) { return args->geti(-1); } + auto fromArgs(World *w, FloatControlsIter& args) { return args.next(); } + + auto fromArgs(World *w, ArgType args, BufferT::type) + { + typename LongT::type bufnum = fromArgs(w, args); + return BufferT::type(bufnum >= 0 ? new SCBufferAdaptor(bufnum, w) : nullptr); + } + + template + static typename T::type makeVal(std::vector> &v, std::index_sequence) + { + return typename T::type{v[Is]...}; + } + + typename T::type operator()(World *w, ArgType args) + { + constexpr size_t argSize = Client::getParameterDescriptors().template get().fixedSize; + + std::vector> v; + + for (auto i = 0; i < argSize; i++) + v.push_back(fromArgs(w, args, ParamLiteralType())); + + return makeVal(v, std::make_index_sequence()); + } + }; + + template + using ArgumentGetter = GetArgument; + + template + using ControlGetter = GetArgument; + public: using Client = C; using ParameterSetType = typename C::ParamSetType; @@ -453,17 +395,17 @@ public: impl::FluidSCWrapperBase::setup(ft, name); } - static auto& setParams(ParameterSetType& p, bool verbose, World* world, impl::FloatControlsIter& inputs) + static auto& setParams(ParameterSetType& p, bool verbose, World* world, FloatControlsIter& inputs) { //We won't even try and set params if the arguments don't match if(inputs.size() == C::getParameterDescriptors().count()) - p.template setParameterValues(verbose, world, inputs); + p.template setParameterValues(verbose, world, inputs); return p; } static auto& setParams(ParameterSetType& p, bool verbose, World* world, sc_msg_iter *args) { - p.template setParameterValues(verbose,world, args); + p.template setParameterValues(verbose,world, args); return p; } }; @@ -476,4 +418,3 @@ void makeSCWrapper(const char *name, InterfaceTable *ft) } // namespace client } // namespace fluid -