From 53b9d7dc0f92c290815d5b70e06cdff9bf7af12b Mon Sep 17 00:00:00 2001 From: Owen Green Date: Mon, 5 Aug 2019 15:52:40 +0100 Subject: [PATCH] Starting to add messages to SCWrapper --- include/FluidSCWrapper.hpp | 63 ++++++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/include/FluidSCWrapper.hpp b/include/FluidSCWrapper.hpp index 747e41f..4d8d5d5 100644 --- a/include/FluidSCWrapper.hpp +++ b/include/FluidSCWrapper.hpp @@ -361,28 +361,35 @@ class FluidSCWrapper : public impl::FluidSCWrapperBase { using FloatControlsIter = impl::FloatControlsIter; - // Iterate over arguments via callbacks from params object - template - struct Setter + template + struct ParamReader { - static constexpr size_t argSize = C::getParameterDescriptors().template get().fixedSize; - - auto fromArgs(World *, FloatControlsIter& args, LongT::type, int) { return args.next(); } - auto fromArgs(World *, FloatControlsIter& args, FloatT::type, int) { return args.next(); } - auto fromArgs(World *, sc_msg_iter* args, LongT::type, int defVal) { return args->geti(defVal); } - auto fromArgs(World *, sc_msg_iter* args, FloatT::type, int) { return args->getf(); } + + static auto fromArgs(World *, FloatControlsIter& args, LongT::type, int) { return args.next(); } + static auto fromArgs(World *, FloatControlsIter& args, FloatT::type, int) { return args.next(); } + static auto fromArgs(World *, sc_msg_iter* args, LongT::type, int defVal) { return args->geti(defVal); } + static auto fromArgs(World *, sc_msg_iter* args, FloatT::type, int) { return args->getf(); } - auto fromArgs(World *w, ArgType args, BufferT::type, int) + static auto fromArgs(World *w, ArgType args, BufferT::type, int) { typename LongT::type bufnum = static_cast(fromArgs(w, args, LongT::type(), -1)); return BufferT::type(bufnum >= 0 ? new SCBufferAdaptor(bufnum, w) : nullptr); } - auto fromArgs(World *w, ArgType args, InputBufferT::type, int) + static auto fromArgs(World *w, ArgType args, InputBufferT::type, int) { typename LongT::type bufnum = static_cast(fromArgs(w, args, LongT::type(), -1)); return InputBufferT::type(bufnum >= 0 ? new SCBufferAdaptor(bufnum, w) : nullptr); } + }; + + + + // Iterate over arguments via callbacks from params object + template + struct Setter + { + static constexpr size_t argSize = C::getParameterDescriptors().template get().fixedSize; typename T::type operator()(World *w, ArgType args) { @@ -390,17 +397,49 @@ class FluidSCWrapper : public impl::FluidSCWrapperBase using LiteralType = typename ParamLiteralConvertor::LiteralType; for (size_t i = 0; i < argSize; i++) - a[i] = static_cast(fromArgs(w, args, a[0], 0)); + a[i] = static_cast(ParamReader::fromArgs(w, args, a[0], 0)); return a.value(); } }; + template using ArgumentSetter = Setter; template using ControlSetter = Setter; + //Sets up a single /u_cmd + template + struct SetupMessage + { + void operator()(const T& message) + { +// class_addmethod(getClass(), (method)invokeMessage, message.name,A_GIMME, 0); + auto ft = getInterfaceTable(); + ft->fDefineUnitCmd(message.name, invokeMessage); + } + }; + + template + static void invokeMessage(FluidSCWrapper* x,sc_msg_iter* args) + { + using IndexList = typename Client::MessageSetType::template MessageDescriptorAt::IndexList; + invokeMessageImpl(x,s,ac,av,IndexList()); + } + + template + static void invokeMessageImp(FluidSCWrapper* x,sc_msg_iter* inArgs,std::index_sequence) + { + using ArgTuple = typename Client::MessageSetType::template MessageDescriptorAt::ArgumentTypes; + ArgTuple args; + (void)std::initializer_list{(std::get(args) = (ParamReader::fromArgs(x->mWorld,inArgs,std::get(args)),0))...}; + + } + + + + public: using Client = C; using ParameterSetType = typename C::ParamSetType;