diff --git a/include/wrapper/NonRealtime.hpp b/include/wrapper/NonRealtime.hpp index 2e19d7a..20f7eac 100644 --- a/include/wrapper/NonRealtime.hpp +++ b/include/wrapper/NonRealtime.hpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include namespace fluid { namespace client { @@ -46,7 +46,7 @@ namespace impl { using WeakCacheEntryPointer = std::weak_ptr; //could use weak_type in 17 public: - using Cache = std::map; + using Cache = std::unordered_map; static Cache mCache; private: static bool isNull(WeakCacheEntryPointer const& weak) { @@ -370,20 +370,23 @@ namespace impl { struct CommandProcess: public NRTCommand { - CommandProcess(World* world, sc_msg_iter* args, void* replyAddr): NRTCommand{world, args, replyAddr} + CommandProcess(World* world, sc_msg_iter* args, void* replyAddr): NRTCommand{world, args, replyAddr},mParams{Client::getParameterDescriptors()} { auto& ar = *args; if(auto ptr = get(NRTCommand::mID).lock()) { ptr->mDone = false; - ptr->mParams.template setParameterValuesRT(nullptr, world, ar); + mParams.template setParameterValuesRT(nullptr, world, ar); mSynchronous = static_cast(ar.geti()); } //if this fails, we'll hear about it in stage2 anyway } - explicit CommandProcess(index id,bool synchronous):NRTCommand{id},mSynchronous(synchronous) - {} + explicit CommandProcess(index id,bool synchronous,Params* params):NRTCommand{id},mSynchronous(synchronous), + mParams{Client::getParameterDescriptors()} + { + if(params) mParams = *params; + } static const char* name() @@ -396,9 +399,13 @@ namespace impl { { if(auto ptr = get(NRTCommand::mID).lock()) { + auto& params = ptr->mParams; + params = mParams; auto& client = ptr->mClient; + + // if(mOSCData) // { // params.template setParameterValuesRT(nullptr, world, *mOSCData); @@ -489,13 +496,14 @@ namespace impl { bool mSynchronous; size_t mCompletionMsgSize{0}; char* mCompletionMessage{nullptr}; + Params mParams; }; struct CommandProcessNew: public NRTCommand { CommandProcessNew(World* world, sc_msg_iter* args,void* replyAddr) : mNew{world, args, replyAddr}, - mProcess{mNew.mID,false} + mProcess{mNew.mID,false,nullptr} { mProcess.mSynchronous = args->geti(); mProcess.mReplyAddress = mNew.mReplyAddress; @@ -741,19 +749,20 @@ namespace impl { } NRTTriggerUnit() - : mControlsIterator{mInBuf + ControlOffset(),ControlSize()} + : mControlsIterator{mInBuf + ControlOffset(),ControlSize()},mParams{Client::getParameterDescriptors()} { mID = static_cast(mInBuf[0][0]); if(mID == -1) mID = count(); auto cmd = NonRealTime::rtalloc(mWorld,mID,mWorld, mControlsIterator, this); runAsyncCommand(mWorld, cmd, nullptr, 0, nullptr); + mInst = get(mID); set_calc_function(); Wrapper::getInterfaceTable()->fClearUnitOutputs(this, 1); } ~NRTTriggerUnit() { - if(auto ptr = get(mID).lock()) + if(auto ptr = mInst.lock()) { auto cmd = NonRealTime::rtalloc(mWorld,mID); runAsyncCommand(mWorld, cmd, nullptr, 0, nullptr); @@ -762,32 +771,39 @@ namespace impl { void next(int) { + + index triggerInput = static_cast(mInBuf[static_cast(mNumInputs) - 2][0]); mTrigger = mTrigger || triggerInput; - if(auto ptr = get(mID).lock()) - { - bool trigger = (!mPreviousTrigger) && mTrigger; - mPreviousTrigger = mTrigger; +// if(auto ptr = mInst->lock()) +// if(auto ptr = get(mID).lock()) +// { + bool trigger = (!mPreviousTrigger) && triggerInput;//mTrigger; + mPreviousTrigger = triggerInput; mTrigger = 0; - auto& client = ptr->mClient; +// auto& client = ptr->mClient; if(trigger) { mControlsIterator.reset(1 + mInBuf); //add one for ID - auto& params = ptr->mParams; - Wrapper::setParams(this,params,mControlsIterator,true,false); +// auto& params = ptr->mParams; + Wrapper::setParams(this,mParams,mControlsIterator,true,false); bool blocking = mInBuf[mNumInputs - 1][0] > 0; - CommandProcess* cmd = rtalloc(mWorld,mID,blocking); + CommandProcess* cmd = rtalloc(mWorld,mID,blocking,&mParams); runAsyncCommand(mWorld,cmd, nullptr,0, nullptr); mRunCount++; } else { - mDone = ptr->mDone; - out0(0) = mDone ? 1 : static_cast(client.progress()); + if(auto ptr = get(mID).lock()) + { + auto& client = ptr->mClient; + mDone = ptr->mDone; + out0(0) = mDone ? 1 : static_cast(client.progress()); + } } - } +// } // else printNotFound(id); } @@ -798,6 +814,8 @@ namespace impl { impl::FloatControlsIter mControlsIterator; index mID; index mRunCount{0}; + WeakCacheEntryPointer mInst; + Params mParams; }; struct NRTModelQueryUnit: SCUnit @@ -823,7 +841,8 @@ namespace impl { : mControls{mInBuf + ControlOffset(),ControlSize()} { index id = static_cast(in0(1)); - if(auto ptr = get(id).lock()) + mInst = get(id); + if(auto ptr = mInst.lock()) { auto& client = ptr->mClient; mDelegate.init(*this,client,mControls); @@ -835,7 +854,7 @@ namespace impl { void next(int) { index id = static_cast(in0(1)); - if(auto ptr = get(id).lock()) + if(auto ptr = mInst.lock()) { auto& client = ptr->mClient; auto& params = ptr->mParams; @@ -848,6 +867,7 @@ namespace impl { Delegate mDelegate; FloatControlsIter mControls; index mID; + WeakCacheEntryPointer mInst; }; diff --git a/include/wrapper/RealTimeBase.hpp b/include/wrapper/RealTimeBase.hpp index 88bcf3a..ab4e324 100644 --- a/include/wrapper/RealTimeBase.hpp +++ b/include/wrapper/RealTimeBase.hpp @@ -129,7 +129,7 @@ namespace impl{ mPrevTrig = trig; Wrapper::setParams(&unit, params, controls); - params.constrainParameterValues(); + params.constrainParameterValuesRT(nullptr); for (index i = 0; i < client.audioChannelsIn(); ++i) {