@ -1,8 +1,8 @@
# pragma once
# pragma once
# include <Eigen/Core>
# include <data/FluidMemory.hpp>
# include <data/FluidMemory.hpp>
# include <SC_PlugIn.hpp>
# include <SC_PlugIn.hpp>
# include <Eigen/Core>
namespace fluid {
namespace fluid {
namespace client {
namespace client {
@ -84,7 +84,8 @@ struct RealTimeBase
}
}
void init ( SCUnit & unit , Client & client , FloatControlsIter & controls , Allocator & alloc )
void init ( SCUnit & unit , Client & client , FloatControlsIter & controls ,
Allocator & alloc )
{
{
assert ( ! ( client . audioChannelsOut ( ) > 0 & &
assert ( ! ( client . audioChannelsOut ( ) > 0 & &
client . controlChannelsOut ( ) . count > 0 ) & &
client . controlChannelsOut ( ) . count > 0 ) & &
@ -113,16 +114,22 @@ struct RealTimeBase
}
}
else if ( client . controlChannelsIn ( ) )
else if ( client . controlChannelsIn ( ) )
{
{
mControlInputBuffer . resize ( unit . mSpecialIndex + 1 ) ;
mControlInputBuffer . resize ( client . controlChannelsIn ( ) ,
mAudioInputs . emplace_back ( mControlInputBuffer ) ;
( unit . mSpecialIndex + 1 ) /
client . controlChannelsIn ( ) ) ;
for ( index i = 0 ; i < client . controlChannelsIn ( ) ; + + i )
{
mAudioInputs . emplace_back ( mControlInputBuffer . row ( i ) ) ;
}
mInputMapper = & RealTimeBase : : mapControlInputs ;
mInputMapper = & RealTimeBase : : mapControlInputs ;
}
}
else mInputMapper = & RealTimeBase : : mapNoOp ;
else { mInputMapper = & RealTimeBase : : mapNoOp ; }
index outputSize = client . controlChannelsOut ( ) . size > 0
index outputSize = client . controlChannelsOut ( ) . size > 0
? std : : max ( client . audioChannelsOut ( ) ,
? std : : max ( client . audioChannelsOut ( ) ,
client . maxControlChannelsOut ( ) )
client . maxControlChannelsOut ( ) )
: unit . mSpecialIndex + 1 ;
: ( unit . mSpecialIndex + 1 ) ;
mOutputs . reserve ( asUnsigned ( outputSize ) ) ;
mOutputs . reserve ( asUnsigned ( outputSize ) ) ;
if ( client . audioChannelsOut ( ) )
if ( client . audioChannelsOut ( ) )
@ -177,18 +184,27 @@ struct RealTimeBase
}
}
}
}
void mapControlInputs ( SCUnit & unit , Client & )
void mapControlInputs ( SCUnit & unit , Client & client )
{
{
for ( index i = 0 ; i < unit . mSpecialIndex + 1 ; + + i )
assert ( ( unit . mSpecialIndex + 1 ) % client . controlChannelsIn ( ) = = 0 & &
" Control channels can't be mapped " ) ;
index itemsPerChannel =
( unit . mSpecialIndex + 1 ) / client . controlChannelsIn ( ) ;
for ( index i = 0 , offset = 0 ; i < client . controlChannelsIn ( ) ;
+ + i , offset + = itemsPerChannel )
{
{
assert ( i < = std : : numeric_limits < int > : : max ( ) ) ;
for ( index j = 0 ; j < itemsPerChannel ; + + j )
mControlInputBuffer [ i ] = unit . in0 ( static_cast < int > ( i ) ) ;
{
assert ( j < = std : : numeric_limits < int > : : max ( ) ) ;
mControlInputBuffer ( i , j ) = unit . in0 ( static_cast < int > ( offset + j ) ) ;
}
}
}
}
}
void mapControlOutputs ( SCUnit & unit , Client & )
void mapControlOutputs ( SCUnit & unit , Client & )
{
{
index numOuts = std : : min < index > ( mControlOutputBuffer . size ( ) , unit . mNumOutputs ) ;
index numOuts =
std : : min < index > ( mControlOutputBuffer . size ( ) , unit . mNumOutputs ) ;
for ( index i = 0 ; i < numOuts ; + + i )
for ( index i = 0 ; i < numOuts ; + + i )
{
{
@ -205,9 +221,9 @@ struct RealTimeBase
IsModel_t < Client > : : value ? ! mPrevTrig & & unit . in0 ( 0 ) > 0 : false ;
IsModel_t < Client > : : value ? ! mPrevTrig & & unit . in0 ( 0 ) > 0 : false ;
mPrevTrig = trig ;
mPrevTrig = trig ;
# ifdef EIGEN_RUNTIME_NO_MALLOC
# ifdef EIGEN_RUNTIME_NO_MALLOC
Eigen : : internal : : set_is_malloc_allowed ( false ) ;
Eigen : : internal : : set_is_malloc_allowed ( false ) ;
# endif
# endif
if ( updateParams )
if ( updateParams )
{
{
Wrapper : : setParams ( & unit , params , controls , alloc ) ;
Wrapper : : setParams ( & unit , params , controls , alloc ) ;
@ -218,9 +234,9 @@ struct RealTimeBase
( this - > * mOutMapperPre ) ( unit , client ) ;
( this - > * mOutMapperPre ) ( unit , client ) ;
client . process ( mAudioInputs , mOutputs , mContext ) ;
client . process ( mAudioInputs , mOutputs , mContext ) ;
( this - > * mOutMapperPost ) ( unit , client ) ;
( this - > * mOutMapperPost ) ( unit , client ) ;
# ifdef EIGEN_RUNTIME_NO_MALLOC
# ifdef EIGEN_RUNTIME_NO_MALLOC
Eigen : : internal : : set_is_malloc_allowed ( true ) ; // not really
Eigen : : internal : : set_is_malloc_allowed ( true ) ; // not really
# endif
# endif
}
}
private :
private :
@ -228,7 +244,7 @@ private:
std : : vector < bool > mOutputConnections ;
std : : vector < bool > mOutputConnections ;
std : : vector < HostVector > mAudioInputs ;
std : : vector < HostVector > mAudioInputs ;
std : : vector < HostVector > mOutputs ;
std : : vector < HostVector > mOutputs ;
FluidTensor < float , 1 > mControlInputBuffer ;
FluidTensor < float , 2 > mControlInputBuffer ;
FluidTensor < float , 1 > mControlOutputBuffer ;
FluidTensor < float , 1 > mControlOutputBuffer ;
bool mPrevTrig ;
bool mPrevTrig ;
IOMapFn mInputMapper ;
IOMapFn mInputMapper ;