@ -42,7 +42,8 @@ private:
/// Instance cache
/// Instance cache
struct CacheEntry
struct CacheEntry
{
{
CacheEntry ( const Params & p ) : mParams { p } , mClient { mParams } { }
CacheEntry ( const Params & p , FluidContext c )
: mParams { p } , mClient { mParams , c } { }
Params mParams ;
Params mParams ;
Client mClient ;
Client mClient ;
@ -151,11 +152,11 @@ public:
return lookup = = mCache . end ( ) ? WeakCacheEntryPointer ( ) : lookup - > second ;
return lookup = = mCache . end ( ) ? WeakCacheEntryPointer ( ) : lookup - > second ;
}
}
static WeakCacheEntryPointer add ( World * world , index id , const Params & params )
static WeakCacheEntryPointer add ( World * world , index id , const Params & params , FluidContext context )
{
{
if ( isNull ( get ( id ) ) )
if ( isNull ( get ( id ) ) )
{
{
auto result = mCache . emplace ( id , std : : make_shared < CacheEntry > ( params )) ;
auto result = mCache . emplace ( id , std : : make_shared < CacheEntry > ( params , context )) ;
addToRTCache { } ( world , * ( result . first ) ) ;
addToRTCache { } ( world , * ( result . first ) ) ;
@ -199,8 +200,10 @@ private:
struct NRTCommand
struct NRTCommand
{
{
NRTCommand ( World * , sc_msg_iter * args , void * replyAddr ,
NRTCommand ( World * world , sc_msg_iter * args , void * replyAddr ,
bool consumeID = true )
bool consumeID = true )
: mSCAlloc { world , Wrapper : : getInterfaceTable ( ) } ,
mAlloc { foonathan : : memory : : make_allocator_reference ( mSCAlloc ) }
{
{
auto count = args - > count ;
auto count = args - > count ;
auto pos = args - > rdpos ;
auto pos = args - > rdpos ;
@ -221,9 +224,11 @@ private:
if ( mReplyAddress ) deleteReplyAddress ( mReplyAddress ) ;
if ( mReplyAddress ) deleteReplyAddress ( mReplyAddress ) ;
}
}
NRTCommand ( ) { }
// NRTCommand() {}
explicit NRTCommand ( index id ) : mID { id } { }
explicit NRTCommand ( World * world , index id )
: mSCAlloc { world , Wrapper : : getInterfaceTable ( ) } ,
mAlloc { foonathan : : memory : : make_allocator_reference ( mSCAlloc ) } , mID { id } { }
bool stage2 ( World * ) { return true ; } // nrt
bool stage2 ( World * ) { return true ; } // nrt
bool stage3 ( World * ) { return true ; } // rt
bool stage3 ( World * ) { return true ; } // rt
@ -248,7 +253,15 @@ private:
static_cast < int > ( packet . size ( ) ) ) ;
static_cast < int > ( packet . size ( ) ) ) ;
}
}
}
}
Allocator & allocator ( )
{
return mAlloc ;
}
// protected:
// protected:
SCRawAllocator mSCAlloc ;
Allocator mAlloc ;
index mID ;
index mID ;
void * mReplyAddress { nullptr } ;
void * mReplyAddress { nullptr } ;
} ;
} ;
@ -257,16 +270,18 @@ private:
{
{
CommandNew ( World * world , sc_msg_iter * args , void * replyAddr )
CommandNew ( World * world , sc_msg_iter * args , void * replyAddr )
: NRTCommand { world , args , replyAddr , ! IsNamedShared_v < Client > } ,
: NRTCommand { world , args , replyAddr , ! IsNamedShared_v < Client > } ,
mParams { Client : : getParameterDescriptors ( ) }
mParams { Client : : getParameterDescriptors ( ) , NRTCommand : : allocator ( ) }
{
{
mParams . template setParameterValuesRT < ParamsFromOSC > ( nullptr , world ,
mParams . template setParameterValuesRT < ParamsFromOSC > ( nullptr , world ,
* args );
* args , NRTCommand : : allocator ( ) );
}
}
CommandNew ( index id , World * , FloatControlsIter & args , Unit * x )
CommandNew ( index id , World * world , FloatControlsIter & args , Unit * x )
: NRTCommand { id } , mParams { Client : : getParameterDescriptors ( ) }
: NRTCommand { world , id } , mParams { Client : : getParameterDescriptors ( ) ,
NRTCommand : : allocator ( ) }
{
{
mParams . template setParameterValuesRT < ParamsFromSynth > ( nullptr , x , args ) ;
mParams . template setParameterValuesRT < ParamsFromSynth > (
nullptr , x , args , NRTCommand : : allocator ( ) ) ;
}
}
static const char * name ( )
static const char * name ( )
@ -281,7 +296,7 @@ private:
if ( ! constraintsRes . ok ( ) ) Wrapper : : printResult ( w , constraintsRes ) ;
if ( ! constraintsRes . ok ( ) ) Wrapper : : printResult ( w , constraintsRes ) ;
mResult = ( ! isNull ( add ( w , NRTCommand : : mID , mParams )) ) ;
mResult = ( ! isNull ( add ( w , NRTCommand : : mID , mParams , FluidContext ( ) )) ) ;
// Sigh. The cache entry above has both the client instance and main
// Sigh. The cache entry above has both the client instance and main
// params instance.
// params instance.
@ -343,21 +358,23 @@ private:
{
{
CommandProcess ( World * world , sc_msg_iter * args , void * replyAddr )
CommandProcess ( World * world , sc_msg_iter * args , void * replyAddr )
: NRTCommand { world , args , replyAddr } ,
: NRTCommand { world , args , replyAddr } ,
mParams { Client : : getParameterDescriptors ( ) }
mParams { Client : : getParameterDescriptors ( ) ,NRTCommand : : allocator ( ) }
{
{
auto & ar = * args ;
auto & ar = * args ;
if ( auto ptr = get ( NRTCommand : : mID ) . lock ( ) )
if ( auto ptr = get ( NRTCommand : : mID ) . lock ( ) )
{
{
ptr - > mDone . store ( false , std : : memory_order_release ) ;
ptr - > mDone . store ( false , std : : memory_order_release ) ;
mParams . template setParameterValuesRT < ParamsFromOSC > ( nullptr , world ,
mParams . template setParameterValuesRT < ParamsFromOSC > ( nullptr , world ,
ar );
ar , NRTCommand : : allocator ( ) );
mSynchronous = static_cast < bool > ( ar . geti ( ) ) ;
mSynchronous = static_cast < bool > ( ar . geti ( ) ) ;
} // if this fails, we'll hear about it in stage2 anyway
} // if this fails, we'll hear about it in stage2 anyway
}
}
explicit CommandProcess ( index id , bool synchronous , Params * params )
explicit CommandProcess ( World * world , index id , bool synchronous ,
: NRTCommand { id } ,
Params * params )
mSynchronous ( synchronous ) , mParams { Client : : getParameterDescriptors ( ) }
: NRTCommand { world , id } ,
mSynchronous ( synchronous ) , mParams { Client : : getParameterDescriptors ( ) ,
NRTCommand : : allocator ( ) }
{
{
if ( params )
if ( params )
{
{
@ -473,7 +490,8 @@ private:
/// Not registered as a PlugInCmd. Triggered by worker thread callback
/// Not registered as a PlugInCmd. Triggered by worker thread callback
struct CommandAsyncComplete : public NRTCommand
struct CommandAsyncComplete : public NRTCommand
{
{
CommandAsyncComplete ( World * , index id , void * replyAddress )
CommandAsyncComplete ( World * world , index id , void * replyAddress )
: NRTCommand ( world , id )
{
{
NRTCommand : : mID = id ;
NRTCommand : : mID = id ;
NRTCommand : : mReplyAddress = replyAddress ;
NRTCommand : : mReplyAddress = replyAddress ;
@ -612,7 +630,9 @@ private:
struct CommandProcessNew : public NRTCommand
struct CommandProcessNew : public NRTCommand
{
{
CommandProcessNew ( World * world , sc_msg_iter * args , void * replyAddr )
CommandProcessNew ( World * world , sc_msg_iter * args , void * replyAddr )
: mNew { world , args , replyAddr } , mProcess { mNew . mID , false , nullptr }
: NRTCommand { world , args , replyAddr , false } ,
mNew { world , args , replyAddr } ,
mProcess { world , mNew . mID , false , nullptr }
{
{
mProcess . mSynchronous = args - > geti ( ) ;
mProcess . mSynchronous = args - > geti ( ) ;
mProcess . mReplyAddress = mNew . mReplyAddress ;
mProcess . mReplyAddress = mNew . mReplyAddress ;
@ -695,8 +715,8 @@ private:
auto & ar = * args ;
auto & ar = * args ;
if ( auto ptr = get ( NRTCommand : : mID ) . lock ( ) )
if ( auto ptr = get ( NRTCommand : : mID ) . lock ( ) )
{
{
ptr - > mParams . template setParameterValuesRT < ParamsFromOSC > ( nullptr ,
ptr - > mParams . template setParameterValuesRT < ParamsFromOSC > (
world , ar ) ;
nullptr , world , ar , NRTCommand : : allocator ( ) ) ;
Result result = validateParameters ( ptr - > mParams ) ;
Result result = validateParameters ( ptr - > mParams ) ;
ptr - > mClient . setParams ( ptr - > mParams ) ;
ptr - > mClient . setParams ( ptr - > mParams ) ;
}
}
@ -726,7 +746,8 @@ private:
if ( auto ptr = get ( NRTCommand : : mID ) . lock ( ) )
if ( auto ptr = get ( NRTCommand : : mID ) . lock ( ) )
{
{
ptr - > mParams . template setParameterValues < ParamsFromOSC > ( true , world , mArgs ) ;
ptr - > mParams . template setParameterValues < ParamsFromOSC > (
true , world , mArgs , FluidDefaultAllocator ( ) ) ;
Result result = validateParameters ( ptr - > mParams ) ;
Result result = validateParameters ( ptr - > mParams ) ;
ptr - > mClient . setParams ( ptr - > mParams ) ;
ptr - > mClient . setParams ( ptr - > mParams ) ;
}
}
@ -810,7 +831,6 @@ private:
template < typename Command >
template < typename Command >
static void defineNRTCommand ( )
static void defineNRTCommand ( )
{
{
auto ft = getInterfaceTable ( ) ;
auto commandRunner = [ ] ( World * world , void * , struct sc_msg_iter * args ,
auto commandRunner = [ ] ( World * world , void * , struct sc_msg_iter * args ,
void * replyAddr ) {
void * replyAddr ) {
auto ft = getInterfaceTable ( ) ;
auto ft = getInterfaceTable ( ) ;
@ -918,7 +938,9 @@ private:
NRTTriggerUnit ( )
NRTTriggerUnit ( )
: mControlsIterator { mInBuf + ControlOffset ( ) , ControlSize ( ) } ,
: mControlsIterator { mInBuf + ControlOffset ( ) , ControlSize ( ) } ,
mParams { Client : : getParameterDescriptors ( ) }
mSCAlloc ( mWorld , Wrapper : : getInterfaceTable ( ) ) ,
mAlloc { foonathan : : memory : : make_allocator_reference ( mSCAlloc ) } ,
mParams { Client : : getParameterDescriptors ( ) , mAlloc }
{
{
mID = static_cast < index > ( mInBuf [ 0 ] [ 0 ] ) ;
mID = static_cast < index > ( mInBuf [ 0 ] [ 0 ] ) ;
if ( mID = = - 1 ) mID = count ( ) ;
if ( mID = = - 1 ) mID = count ( ) ;
@ -936,7 +958,7 @@ private:
~ NRTTriggerUnit ( )
~ NRTTriggerUnit ( )
{
{
set_calc_function < NRTTriggerUnit , & NRTTriggerUnit : : clear > ( ) ;
set_calc_function < NRTTriggerUnit , & NRTTriggerUnit : : clear > ( ) ;
auto cmd = NonRealTime : : rtalloc < CommandFree > ( mWorld , m ID) ;
auto cmd = NonRealTime : : rtalloc < CommandFree > ( mWorld , m World, m ID) ;
if ( runAsyncCommand ( mWorld , cmd , nullptr , 0 , nullptr ) ! = 0 )
if ( runAsyncCommand ( mWorld , cmd , nullptr , 0 , nullptr ) ! = 0 )
{
{
std : : cout < < " ERROR: Async command failed in ~NRTTriggerUnit() "
std : : cout < < " ERROR: Async command failed in ~NRTTriggerUnit() "
@ -963,12 +985,12 @@ private:
if ( trigger )
if ( trigger )
{
{
mControlsIterator . reset ( 1 + mInBuf ) ; // add one for ID
mControlsIterator . reset ( 1 + mInBuf ) ; // add one for ID
Wrapper : : setParams ( this , mParams , mControlsIterator , true , false ) ;
Wrapper : : setParams ( this , mParams , mControlsIterator , mAlloc , true , false ) ;
bool blocking = mInBuf [ mNumInputs - 1 ] [ 0 ] > 0 ;
bool blocking = mInBuf [ mNumInputs - 1 ] [ 0 ] > 0 ;
CommandProcess * cmd =
CommandProcess * cmd =
rtalloc < CommandProcess > ( mWorld , m ID, blocking , & mParams ) ;
rtalloc < CommandProcess > ( mWorld , m World, m ID, blocking , & mParams ) ;
if ( runAsyncCommand ( mWorld , cmd , nullptr , 0 , nullptr ) ! = 0 )
if ( runAsyncCommand ( mWorld , cmd , nullptr , 0 , nullptr ) ! = 0 )
{
{
std : : cout < < " ERROR: Async command failed in NRTTriggerUnit::next() "
std : : cout < < " ERROR: Async command failed in NRTTriggerUnit::next() "
@ -1000,6 +1022,8 @@ private:
index mID ;
index mID ;
index mRunCount { 0 } ;
index mRunCount { 0 } ;
WeakCacheEntryPointer mInst ;
WeakCacheEntryPointer mInst ;
SCRawAllocator mSCAlloc ;
Allocator mAlloc ;
Params mParams ;
Params mParams ;
bool mInit { false } ;
bool mInit { false } ;
} ;
} ;