From e545c0681855280a6bb1aadf8b0da8292eb0dab8 Mon Sep 17 00:00:00 2001 From: kevin Date: Fri, 20 Dec 2024 14:19:39 -0500 Subject: [PATCH] cwFlowTypes.h/cpp : Remove value_t related functions and structures to cwFlowValue.h/cpp. Added proc_t.presetL. preset_value_t is now a unoin of preset_val_t and net_preset_val_t and proc_var_val_t Added var_desc_has_recd_format(),proc_preset_find(),global_var(),global_var_alloc() Added Added var_register_and_set() variations for the 'record' type. Added var_set() for 'record' type. --- cwFlowTypes.cpp | 1379 +++++++++-------------------------------------- cwFlowTypes.h | 269 +++------ 2 files changed, 349 insertions(+), 1299 deletions(-) diff --git a/cwFlowTypes.cpp b/cwFlowTypes.cpp index 84fe1ea..6109632 100644 --- a/cwFlowTypes.cpp +++ b/cwFlowTypes.cpp @@ -16,6 +16,7 @@ #include "cwMidiDecls.h" #include "cwFlowDecl.h" #include "cwFlow.h" +#include "cwFlowValue.h" #include "cwFlowTypes.h" @@ -36,685 +37,6 @@ namespace cw }; - idLabelPair_t _typeLabelFlagsA[] = { - - { kBoolTFl, "bool" }, - { kUIntTFl, "uint" }, - { kIntTFl, "int", }, - { kFloatTFl, "float"}, - { kDoubleTFl,"double"}, - - { kBoolMtxTFl, "bool_mtx" }, - { kUIntMtxTFl, "uint_mtx" }, - { kIntMtxTFl, "int_mtx" }, - { kFloatMtxTFl, "float_mtx" }, - { kDoubleMtxTFl,"double_mtx" }, - - { kABufTFl, "audio" }, - { kFBufTFl, "spectrum" }, - { kMBufTFl, "midi" }, - { kStringTFl, "string" }, - { kTimeTFl, "time" }, - { kCfgTFl, "cfg" }, - - // alias types to map to cwDspTypes.h - { kFloatTFl, "srate"}, - { kFloatTFl, "sample"}, - { kFloatTFl, "coeff"}, - { kDoubleTFl, "ftime" }, - - { kNumericTFl, "numeric" }, - { kAllTFl, "all" }, - - { kRuntimeTFl, "runtime" }, - - { kInvalidTFl, "" } - }; - - const char* _typeFlagToLabel( unsigned flag ) - { - return idToLabel(_typeLabelFlagsA,flag,kInvalidTFl); - } - - - void _value_release( value_t* v ) - { - if( v == nullptr ) - return; - - switch( v->tflag & kTypeMask ) - { - case kInvalidTFl: - break; - - case kBoolTFl: - case kUIntTFl: - case kIntTFl: - case kFloatTFl: - case kDoubleTFl: - break; - - case kABufTFl: - abuf_destroy( v->u.abuf ); - break; - - case kFBufTFl: - fbuf_destroy( v->u.fbuf ); - break; - - case kMBufTFl: - mbuf_destroy( v->u.mbuf ); - break; - - case kBoolMtxTFl: - case kUIntMtxTFl: - case kIntMtxTFl: - case kFloatMtxTFl: - case kDoubleMtxTFl: - assert(0); // not implemeneted - break; - - case kStringTFl: - mem::release( v->u.s ); - break; - - case kTimeTFl: - assert(0); - break; - - case kCfgTFl: - break; - - default: - assert(0); - break; - } - - v->tflag = kInvalidTFl; - } - - void _value_duplicate( value_t& dst, const value_t& src ) - { - switch( src.tflag & kTypeMask ) - { - case kInvalidTFl: - break; - - case kBoolTFl: - case kUIntTFl: - case kIntTFl: - case kFloatTFl: - case kDoubleTFl: - dst = src; - break; - - case kABufTFl: - - dst.u.abuf = src.u.abuf == nullptr ? nullptr : abuf_duplicate(dst.u.abuf,src.u.abuf); - dst.tflag = src.tflag; - break; - - case kFBufTFl: - dst.u.fbuf = src.u.fbuf == nullptr ? nullptr : fbuf_duplicate(dst.u.fbuf,src.u.fbuf); - dst.tflag = src.tflag; - break; - - case kMBufTFl: - dst.u.mbuf = src.u.mbuf == nullptr ? nullptr : mbuf_duplicate(src.u.mbuf); - dst.tflag = src.tflag; - break; - - case kBoolMtxTFl: - case kUIntMtxTFl: - case kIntMtxTFl: - case kFloatMtxTFl: - case kDoubleMtxTFl: - assert(0); // not implemeneted - break; - - case kStringTFl: - dst.u.s = mem::duplStr( dst.u.s ); - dst.tflag = src.tflag; - break; - - case kTimeTFl: - assert(0); - break; - - case kCfgTFl: - dst = src; - break; - - default: - assert(0); - break; - } - - } - - void _value_print( const value_t* v, bool info_fl=true ) - { - if( v == nullptr ) - return; - - switch( v->tflag & kTypeMask ) - { - case kInvalidTFl: - cwLogPrint(""); - break; - - case kBoolTFl: - - cwLogPrint("%s%s ", info_fl ? "b:" : "", v->u.b ? "true" : "false" ); - break; - - case kUIntTFl: - cwLogPrint("%s%i ", info_fl ? "u:" : "", v->u.u ); - break; - - case kIntTFl: - cwLogPrint("%s%i ", info_fl ? "i:" : "", v->u.i ); - break; - - case kFloatTFl: - cwLogPrint("%s%f ", info_fl ? "f:" : "", v->u.f ); - break; - - case kDoubleTFl: - cwLogPrint("%s%f ", info_fl ? "d:" : "", v->u.d ); - break; - - case kABufTFl: - if( info_fl ) - { - if( v->u.abuf == nullptr ) - cwLogPrint("abuf: "); - else - cwLogPrint("abuf: chN:%i frameN:%i srate:%8.1f ", v->u.abuf->chN, v->u.abuf->frameN, v->u.abuf->srate ); - } - else - { - bool null_fl = v->u.abuf==nullptr || v->u.abuf->buf == nullptr; - cwLogPrint("("); - for(unsigned i=0; iu.abuf->chN; ++i) - cwLogPrint("%f ",null_fl ? 0.0 : vop::rms(v->u.abuf->buf + i*v->u.abuf->frameN, v->u.abuf->frameN)); - cwLogPrint(") "); - } - break; - - case kFBufTFl: - if( info_fl ) - { - if( v->u.fbuf == nullptr ) - cwLogPrint("fbuf: "); - else - { - cwLogPrint("fbuf: chN:%i srate:%8.1f ", v->u.fbuf->chN, v->u.fbuf->srate ); - for(unsigned i=0; iu.fbuf->chN; ++i) - cwLogPrint("(binN:%i hopSmpN:%i) ", v->u.fbuf->binN_V[i], v->u.fbuf->hopSmpN_V[i] ); - } - } - else - { - - bool null_fl = v->u.fbuf==nullptr || v->u.fbuf->magV == nullptr; - cwLogPrint("("); - for(unsigned i=0; iu.fbuf->chN; ++i) - cwLogPrint("%f ",null_fl ? 0.0 : vop::mean(v->u.fbuf->magV[i], v->u.fbuf->binN_V[i])); - cwLogPrint(") "); - - } - break; - - case kMBufTFl: - if( info_fl ) - { - if( v->u.mbuf == nullptr ) - cwLogPrint("mbuf: "); - else - { - cwLogPrint("mbuf: cnt: %i", v->u.mbuf->msgN ); - } - } - else - { - //bool null_fl = v->u.mbuf==nullptr || v->u.mbuf->msgA == nullptr; - for(unsigned i=0; iu.mbuf->msgN; ++i) - cwLogPrint("(0x%x 0x%x 0x%x) ",v->u.mbuf->msgA[i].status + v->u.mbuf->msgA[i].ch,v->u.mbuf->msgA[i].d0,v->u.mbuf->msgA[i].d1); - } - break; - - case kBoolMtxTFl: - case kUIntMtxTFl: - case kIntMtxTFl: - case kFloatMtxTFl: - case kDoubleMtxTFl: - assert(0); // not implemeneted - break; - - case kStringTFl: - cwLogPrint("s:%s ", v->u.s); - break; - - case kTimeTFl: - assert(0); - break; - - case kCfgTFl: - cwLogPrint("c:"); - if( v->u.cfg != nullptr ) - v->u.cfg->print(); - break; - - default: - assert(0); - break; - } - - } - - - rc_t _val_get( const value_t* val, bool& valRef ) - { - rc_t rc = kOkRC; - switch( val->tflag & kTypeMask ) - { - case kBoolTFl: valRef = val->u.b; break; - case kUIntTFl: valRef = val->u.u!=0; break; - case kIntTFl: valRef = val->u.i!=0; break; - case kFloatTFl: valRef = val->u.f!=0; break; - case kDoubleTFl: valRef = val->u.d!=0; break; - default: - rc = cwLogError(kTypeMismatchRC,"The type %s (0x%x) could not be converted to a bool.",_typeFlagToLabel(val->tflag),val->tflag); - } - return rc; - } - - rc_t _val_set( value_t* val, bool v ) - { - rc_t rc = kOkRC; - - switch( val->tflag & kTypeMask ) - { - case kBoolTFl: val->u.b=v; break; - case kUIntTFl: val->u.u=v; break; - case kIntTFl: val->u.i=v; break; - case kFloatTFl: val->u.f=v; break; - case kDoubleTFl: val->u.d=v; break; - case kInvalidTFl: - val->u.b = v; - val->tflag = kBoolTFl; - break; - - default: - rc = cwLogError(kTypeMismatchRC,"A bool could not be converted to a %s (0x%x).",_typeFlagToLabel(val->tflag),val->tflag); - } - - return rc; - } - - rc_t _val_get( const value_t* val, uint_t& valRef ) - { - rc_t rc = kOkRC; - switch( val->tflag & kTypeMask ) - { - case kBoolTFl: valRef = val->u.b ? 1 : 0; break; - case kUIntTFl: valRef = val->u.u; break; - case kIntTFl: valRef = val->u.i; break; - case kFloatTFl: valRef = (uint_t)val->u.f; break; - case kDoubleTFl: valRef = (uint_t)val->u.d; break; - default: - rc = cwLogError(kTypeMismatchRC,"The type %s (0x%x) could not be converted to a uint.",_typeFlagToLabel(val->tflag),val->tflag); - } - return rc; - } - - rc_t _val_set( value_t* val, uint_t v ) - { - rc_t rc = kOkRC; - - switch( val->tflag & kTypeMask ) - { - case kBoolTFl: val->u.b=v!=0; break; - case kUIntTFl: val->u.u=v; break; - case kIntTFl: val->u.i=v; break; - case kFloatTFl: val->u.f=v; break; - case kDoubleTFl: val->u.d=v; break; - case kInvalidTFl: - val->u.u = v; - val->tflag = kUIntTFl; - break; - - default: - rc = cwLogError(kTypeMismatchRC,"A uint could not be converted to a %s (0x%x).",_typeFlagToLabel(val->tflag),val->tflag); - } - - return rc; - } - - rc_t _val_get( const value_t* val, int_t& valRef ) - { - rc_t rc = kOkRC; - switch( val->tflag & kTypeMask ) - { - case kBoolTFl: valRef = val->u.b ? 1 : 0; break; - case kUIntTFl: valRef = (int_t)val->u.u; break; - case kIntTFl: valRef = val->u.i; break; - case kFloatTFl: valRef = (int_t)val->u.f; break; - case kDoubleTFl: valRef = (int_t)val->u.d; break; - default: - rc = cwLogError(kTypeMismatchRC,"The type %s (0x%x) could not be converted to an int.",_typeFlagToLabel(val->tflag),val->tflag); - - } - return rc; - } - - rc_t _val_set( value_t* val, int_t v ) - { - rc_t rc = kOkRC; - - switch( val->tflag & kTypeMask ) - { - case kBoolTFl: val->u.b=v!=0; break; - case kUIntTFl: val->u.u=v; break; - case kIntTFl: val->u.i=v; break; - case kFloatTFl: val->u.f=v; break; - case kDoubleTFl: val->u.d=v; break; - case kInvalidTFl: - val->u.i = v; - val->tflag = kIntTFl; - break; - - default: - rc = cwLogError(kTypeMismatchRC,"An int could not be converted to a %s (0x%x).",_typeFlagToLabel(val->tflag),val->tflag); - } - - return rc; - } - - - rc_t _val_get( const value_t* val, float& valRef ) - { - rc_t rc = kOkRC; - switch( val->tflag & kTypeMask ) - { - case kBoolTFl: valRef = val->u.b ? 1 : 0; break; - case kUIntTFl: valRef = (float)val->u.u; break; - case kIntTFl: valRef = (float)val->u.i; break; - case kFloatTFl: valRef = (float)val->u.f; break; - case kDoubleTFl: valRef = (float)val->u.d; break; - default: - rc = cwLogError(kTypeMismatchRC,"The type %s (0x%x) could not be converted to a float.",_typeFlagToLabel(val->tflag),val->tflag); - } - return rc; - } - - rc_t _val_set( value_t* val, float v ) - { - rc_t rc = kOkRC; - - switch( val->tflag & kTypeMask ) - { - case kBoolTFl: val->u.b=v!=0; break; - case kUIntTFl: val->u.u=(unsigned)v; break; - case kIntTFl: val->u.i=(int)v; break; - case kFloatTFl: val->u.f=v; break; - case kDoubleTFl: val->u.d=v; break; - case kInvalidTFl: - val->u.f = v; - val->tflag = kFloatTFl; - break; - - default: - rc = cwLogError(kTypeMismatchRC,"A float could not be converted to a %s (0x%x).",_typeFlagToLabel(val->tflag),val->tflag); - } - - return rc; - } - - rc_t _val_get( const value_t* val, double& valRef ) - { - rc_t rc = kOkRC; - switch( val->tflag & kTypeMask ) - { - case kBoolTFl: valRef = val->u.b ? 1 : 0; break; - case kUIntTFl: valRef = (double)val->u.u; break; - case kIntTFl: valRef = (double)val->u.i; break; - case kFloatTFl: valRef = (double)val->u.f; break; - case kDoubleTFl: valRef = val->u.d; break; - default: - rc = cwLogError(kTypeMismatchRC,"The type %s (0x%x) could not be converted to a double.",_typeFlagToLabel(val->tflag),val->tflag); - } - return rc; - } - - rc_t _val_set( value_t* val, double v ) - { - rc_t rc = kOkRC; - - switch( val->tflag & kTypeMask ) - { - case kBoolTFl: val->u.b=v!=0; break; - case kUIntTFl: val->u.u=(unsigned)v; break; - case kIntTFl: val->u.i=(int)v; break; - case kFloatTFl: val->u.f=(float)v; break; - case kDoubleTFl: val->u.d=v; break; - case kInvalidTFl: - val->u.d = v; - val->tflag = kDoubleTFl; - break; - - default: - rc = cwLogError(kTypeMismatchRC,"A double could not be converted to a %s (0x%x).",_typeFlagToLabel(val->tflag),val->tflag); - } - - return rc; - } - - rc_t _val_get( const value_t* val, const char*& valRef ) - { - rc_t rc = kOkRC; - if( cwIsFlag(val->tflag & kTypeMask, kStringTFl) ) - valRef = val->u.s; - else - { - rc = cwLogError(kTypeMismatchRC,"The type %s (0x%x) could not be converted to a string.",_typeFlagToLabel(val->tflag),val->tflag); - valRef = nullptr; - } - - return rc; - } - - rc_t _val_set( value_t* val, const char* v ) - { - rc_t rc = kOkRC; - - switch( val->tflag & kTypeMask ) - { - case kStringTFl: - val->u.s=mem::duplStr(v); break; - - case kInvalidTFl: - val->u.s = mem::duplStr(v); - val->tflag = kStringTFl; - break; - default: - rc = cwLogError(kTypeMismatchRC,"A string could not be converted to a %s (0x%x).",_typeFlagToLabel(val->tflag),val->tflag); - } - - return rc; - } - - rc_t _val_get( value_t* val, abuf_t*& valRef ) - { - rc_t rc = kOkRC; - if( cwIsFlag(val->tflag & kTypeMask, kABufTFl) ) - valRef = val->u.abuf; - else - { - rc = cwLogError(kTypeMismatchRC,"The type %s (0x%x) could not be converted to an abuf.",_typeFlagToLabel(val->tflag),val->tflag); - valRef = nullptr; - } - return rc; - } - - rc_t _val_get( value_t* val, const abuf_t*& valRef ) - { - abuf_t* non_const_val; - rc_t rc = kOkRC; - if((rc = _val_get(val,non_const_val)) == kOkRC ) - valRef = non_const_val; - return rc; - } - - rc_t _val_set( value_t* val, abuf_t* v ) - { - rc_t rc = kOkRC; - - switch( val->tflag & kTypeMask ) - { - case kABufTFl: - val->u.abuf=v; - break; - - case kInvalidTFl: - val->u.abuf=v; - val->tflag = kABufTFl; - break; - - default: - rc = cwLogError(kTypeMismatchRC,"A audio signal could not be converted to a %s (0x%x).",_typeFlagToLabel(val->tflag),val->tflag); - } - - return rc; - } - - rc_t _val_get( value_t* val, fbuf_t*& valRef ) - { - rc_t rc = kOkRC; - if( cwIsFlag(val->tflag & kTypeMask, kFBufTFl) ) - valRef = val->u.fbuf; - else - { - valRef = nullptr; - rc = cwLogError(kTypeMismatchRC,"The type %s (0x%x) could not be converted to an fbuf.",_typeFlagToLabel(val->tflag),val->tflag); - } - return rc; - } - - rc_t _val_get( value_t* val, const fbuf_t*& valRef ) - { - fbuf_t* non_const_val; - rc_t rc = kOkRC; - if((rc = _val_get(val,non_const_val)) == kOkRC ) - valRef = non_const_val; - return rc; - } - - rc_t _val_set( value_t* val, fbuf_t* v ) - { - rc_t rc = kOkRC; - - switch( val->tflag & kTypeMask ) - { - case kFBufTFl: - val->u.fbuf=v; - break; - - case kInvalidTFl: - val->u.fbuf=v; - val->tflag = kFBufTFl; - break; - - default: - rc = cwLogError(kTypeMismatchRC,"A spectrum signal could not be converted to a %s (0x%x).",_typeFlagToLabel(val->tflag),val->tflag); - } - - return rc; - } - - rc_t _val_get( value_t* val, mbuf_t*& valRef ) - { - rc_t rc = kOkRC; - if( cwIsFlag(val->tflag & kTypeMask, kMBufTFl) ) - valRef = val->u.mbuf; - else - { - valRef = nullptr; - rc = cwLogError(kTypeMismatchRC,"The type %s (0x%x) could not be converted to an mbuf.",_typeFlagToLabel(val->tflag),val->tflag); - } - return rc; - } - - rc_t _val_set( value_t* val, mbuf_t* v ) - { - rc_t rc = kOkRC; - - switch( val->tflag & kTypeMask ) - { - case kMBufTFl: - val->u.mbuf=v; - break; - - case kInvalidTFl: - val->u.mbuf=v; - val->tflag = kMBufTFl; - break; - - default: - rc = cwLogError(kTypeMismatchRC,"A MIDI signal could not be converted to a %s (0x%x).",_typeFlagToLabel(val->tflag),val->tflag); - } - - return rc; - } - - - rc_t _val_get( value_t* val, const mbuf_t*& valRef ) - { - mbuf_t* non_const_val; - rc_t rc = kOkRC; - if((rc = _val_get(val,non_const_val)) == kOkRC ) - valRef = non_const_val; - return rc; - } - - rc_t _val_get( value_t* val, const object_t*& valRef ) - { - rc_t rc = kOkRC; - - if( cwIsFlag(val->tflag & kTypeMask, kCfgTFl) ) - valRef = val->u.cfg; - else - { - valRef = nullptr; - rc = cwLogError(kTypeMismatchRC,"The type %s (0x%x) could not be converted to a cfg.",_typeFlagToLabel(val->tflag),val->tflag); - - } - return rc; - } - - rc_t _val_set( value_t* val, const object_t* v ) - { - rc_t rc = kOkRC; - - switch( val->tflag & kTypeMask ) - { - case kCfgTFl: - val->u.cfg=v; - break; - - case kInvalidTFl: - val->u.cfg=v; - val->tflag = kCfgTFl; - break; - - default: - rc = cwLogError(kTypeMismatchRC,"A cfg. could not be converted to a %s (0x%x).",_typeFlagToLabel(val->tflag),val->tflag); - } - - return rc; - } - template< typename T > rc_t _val_get_driver( const variable_t* var, T& valRef ) { @@ -724,7 +46,7 @@ namespace cw if( var->value == nullptr ) return cwLogError(kInvalidStateRC,"No value has been assigned to the variable: %s:%i.%s:%i ch:%i.",cwStringNullGuard(var->proc->label),var->proc->label_sfx_id,cwStringNullGuard(var->label),var->label_sfx_id,var->chIdx); - return _val_get(var->value,valRef); + return value_get(var->value,valRef); } @@ -789,9 +111,9 @@ namespace cw cwLogPrint(" %12s:%3i vid:%3i ch:%3i : %s : ", var->label, var->label_sfx_id, var->vid, var->chIdx, conn_label ); if( var->value == nullptr ) - _value_print( &var->local_value[0] ); + value_print( &var->local_value[0] ); else - _value_print( var->value ); + value_print( var->value ); if( var->src_var != nullptr ) cwLogPrint(" src:%s:%i.%s:%i",var->src_var->proc->label,var->src_var->proc->label_sfx_id,var->src_var->label,var->src_var->label_sfx_id); @@ -855,9 +177,8 @@ namespace cw value_t* original_value = var->value; unsigned original_value_idx = var->local_value_idx; - // release the previous value in the next slot - _value_release(&var->local_value[next_local_value_idx]); + value_release(&var->local_value[next_local_value_idx]); // if the value type of this variable has not been established if( value_type_flag == kInvalidTFl ) @@ -885,7 +206,7 @@ namespace cw var->local_value[ next_local_value_idx ].tflag = value_type_flag; // set the new local value in var->local_value[next_local_value_idx] - if((rc = _val_set(var->local_value + next_local_value_idx, val )) != kOkRC ) + if((rc = value_set(var->local_value + next_local_value_idx, val )) != kOkRC ) { rc = cwLogError(rc,"Value set failed on '%s:%i %s:%i",var->proc->label,var->proc->label_sfx_id,var->label,var->label_sfx_id); goto errLabel; @@ -910,6 +231,9 @@ namespace cw if( rc == kOkRC ) { + if( var->ui_var != nullptr && var->ui_var->user_id != kInvalidId ) + var_send_to_ui(var); + // send the value to connected downstream proc's rc = _var_broadcast_new_value( var ); } @@ -983,7 +307,21 @@ namespace cw return rc; } + + rc_t _var_register_and_set( proc_t* proc, const char* var_label, unsigned sfx_id, unsigned vid, unsigned chIdx, rbuf_t* rbuf ) + { + rc_t rc; + variable_t* var = nullptr; + if((rc = var_register_and_set( proc, var_label, sfx_id, vid, chIdx, var)) != kOkRC ) + return rc; + + if( var != nullptr ) + _var_set_driver( var, kRBufTFl, rbuf ); + + return rc; + } + rc_t _var_register_and_set( proc_t* proc, const char* var_label, unsigned sfx_id, unsigned vid, unsigned chIdx, fbuf_t* fbuf ) { rc_t rc; @@ -1180,296 +518,50 @@ namespace cw cwLogPrint(" %10s 0x%08x %s %s %s %s\n", cwStringNullGuard(vd->label), vd->type, srcFlStr, srcOptFlStr, plyMltFlStr, cwStringNullGuard(vd->docText) ); } } - - } -} -void cw::flow::value_duplicate( value_t& dst, const value_t& src ) -{ - _value_duplicate(dst,src); -} - -void cw::flow::value_print( const value_t* value, bool info_fl) -{ - _value_print(value,info_fl); -} - - -cw::flow::abuf_t* cw::flow::abuf_create( srate_t srate, unsigned chN, unsigned frameN ) -{ - if( chN*frameN == 0 ) - { - cwLogError(kInvalidArgRC,"The %s audio signal parameter cannot be zero.", chN==0 ? "channel count" : "frame count"); - return nullptr; - } - - abuf_t* a = mem::allocZ(); - a->srate = srate; - a->chN = chN; - a->frameN = frameN; - a->bufAllocSmpN = chN*frameN; - - - a->buf = mem::allocZ(a->bufAllocSmpN); - - return a; -} - -void cw::flow::abuf_destroy( abuf_t*& abuf ) -{ - if( abuf == nullptr ) - return; - - mem::release(abuf->buf); - mem::release(abuf); -} - -cw::flow::abuf_t* cw::flow::abuf_duplicate( abuf_t* dst, const abuf_t* src ) -{ - abuf_t* abuf = nullptr; - - if( dst != nullptr && dst->bufAllocSmpN < src->bufAllocSmpN ) - mem::release(dst->buf); - - if( dst == nullptr || dst->buf == nullptr ) - abuf = abuf_create( src->srate, src->chN, src->frameN ); - else - abuf = dst; - - if( abuf != nullptr ) - vop::copy(abuf->buf,src->buf,src->chN*src->frameN); - - return abuf; -} - - -cw::rc_t cw::flow::abuf_set_channel( abuf_t* abuf, unsigned chIdx, const sample_t* v, unsigned vN ) -{ - rc_t rc = kOkRC; - - if( vN > abuf->frameN ) - rc = cwLogError(kInvalidArgRC,"Cannot copy source vector of length %i into an abuf of length %i.", vN, abuf->frameN); - else - if( chIdx > abuf->chN ) - rc = cwLogError(kInvalidArgRC,"The abuf destination channel %i is out of range.", chIdx); - else - vop::copy( abuf->buf + (chIdx*abuf->frameN), v, vN); - - return rc; -} - -const cw::flow::sample_t* cw::flow::abuf_get_channel( abuf_t* abuf, unsigned chIdx ) -{ - assert( abuf->buf != nullptr ); - return abuf->buf + (chIdx*abuf->frameN); -} - - -cw::flow::fbuf_t* cw::flow::fbuf_create( srate_t srate, unsigned chN, const unsigned* maxBinN_V, const unsigned* binN_V, const unsigned* hopSmpN_V, const fd_sample_t** magV, const fd_sample_t** phsV, const fd_sample_t** hzV ) -{ - for(unsigned i=0; i maxBinN_V[i] ) + void _network_preset_print( const network_preset_t* net_preset ) { - cwLogError(kInvalidArgRC,"A channel bin count (%i) execeeds the max bin count (%i).",binN_V[i],maxBinN_V[i]); - return nullptr;; - } - - fbuf_t* f = mem::allocZ(); + switch( net_preset->tid ) + { + case kPresetVListTId: + { + const preset_value_t* net_val = net_preset->u.vlist.value_head; + for(; net_val!=nullptr; net_val=net_val->link) + { + switch( net_val->tid ) + { + case kPolyPresetValueTId: + _network_preset_print( net_val->u.npv.net_preset ); + break; + + case kDirectPresetValueTId: + cwLogPrint(" %s:%i %s:%i ch:%i ",cwStringNullGuard(net_val->u.pvv.proc->label),net_val->u.pvv.proc->label_sfx_id,cwStringNullGuard(net_val->u.pvv.var->label),net_val->u.pvv.var->label_sfx_id,net_val->u.pvv.var->chIdx); + value_print( &net_val->u.pvv.value ); + cwLogPrint("\n"); + break; + + default: + cwLogError(kInvalidIdRC,"The preset value type id %i is unknown.",net_val->tid); + goto errLabel; + } + } + } + break; + + case kPresetDualTId: + cwLogPrint(" %s %s %f",net_preset->u.dual.pri->label,net_preset->u.dual.sec->label,net_preset->u.dual.coeff); + break; + } - bool proxy_fl = magV != nullptr || phsV != nullptr || hzV != nullptr; - - // Calculate the total count of bins for each data vector. - unsigned maxTotalBinN = proxy_fl ? 0 : vop::sum(maxBinN_V, chN); - - // calc the total size of memory required for all internal data structures - f->memByteN - = sizeof(unsigned) * chN*kFbufVectN // maxBinN_V[],binN_V[],hopSmpN_V[] - + sizeof(fd_sample_t*) * chN*kFbufVectN // magV[],phsV[],hzV[] (pointer to bin buffers) - + sizeof(bool) * chN*1 // readyFlV[] - + sizeof(fd_sample_t) * maxTotalBinN*kFbufVectN; // bin buffer memory - - // allocate mory - f->mem = mem::allocZ(f->memByteN); - - unsigned* base_maxBinV = (unsigned*)f->mem; - fd_sample_t** base_bufV = (fd_sample_t**)(base_maxBinV + kFbufVectN * chN); - bool* base_boolV = (bool*)(base_bufV + kFbufVectN * chN); - fd_sample_t* base_buf = (fd_sample_t*)(base_boolV + chN); - - - f->srate = srate; - f->chN = chN; - f->maxBinN_V = base_maxBinV; - f->binN_V = f->maxBinN_V + chN; - f->hopSmpN_V = f->binN_V + chN; - f->magV = base_bufV; - f->phsV = f->magV + chN; - f->hzV = f->phsV + chN; - f->readyFlV = base_boolV; - - vop::copy( f->binN_V, binN_V, chN ); - vop::copy( f->maxBinN_V, maxBinN_V, chN ); - vop::copy( f->hopSmpN_V, hopSmpN_V, chN ); - - if( proxy_fl ) - { - for(unsigned chIdx=0; chIdxmagV[ chIdx ] = (fd_sample_t*)magV[chIdx]; - f->phsV[ chIdx ] = (fd_sample_t*)phsV[chIdx]; - f->hzV[ chIdx ] = (fd_sample_t*)hzV[chIdx]; - } - } - else - { - fd_sample_t* m = base_buf; - for(unsigned chIdx=0; chIdxmagV[chIdx] = m + 0 * f->binN_V[chIdx]; - f->phsV[chIdx] = m + 1 * f->binN_V[chIdx]; - f->hzV[ chIdx] = m + 2 * f->binN_V[chIdx]; - m += f->maxBinN_V[chIdx]; - assert( m <= base_buf + kFbufVectN * maxTotalBinN ); - } - } - - return f; -} - -/* -cw::flow::fbuf_t* cw::flow::fbuf_create( srate_t srate, unsigned chN, const unsigned* maxBinN_V, const unsigned* binN_V, const unsigned* hopSmpN_V, const fd_sample_t** magV, const fd_sample_t** phsV, const fd_sample_t** hzV ) -{ - for(unsigned i=0; i maxBinN_V[i] ) - { - cwLogError(kInvalidArgRC,"A channel bin count (%i) execeeds the max bin count (%i).",binN_V[i],maxBinN_V[i]); - return nullptr;; - } - - fbuf_t* f = mem::allocZ(); - - f->srate = srate; - f->chN = chN; - f->maxBinN_V = mem::allocZ(chN); - f->binN_V = mem::allocZ(chN); - f->hopSmpN_V = mem::allocZ(chN); - f->magV = mem::allocZ(chN); - f->phsV = mem::allocZ(chN); - f->hzV = mem::allocZ(chN); - f->readyFlV = mem::allocZ(chN); - - vop::copy( f->binN_V, binN_V, chN ); - vop::copy( f->maxBinN_V, maxBinN_V, chN ); - vop::copy( f->hopSmpN_V, hopSmpN_V, chN ); - - if( magV != nullptr || phsV != nullptr || hzV != nullptr ) - { - for(unsigned chIdx=0; chIdxmagV[ chIdx ] = (fd_sample_t*)magV[chIdx]; - f->phsV[ chIdx ] = (fd_sample_t*)phsV[chIdx]; - f->hzV[ chIdx ] = (fd_sample_t*)hzV[chIdx]; - } - } - else - { - unsigned maxTotalBinsN = vop::sum( maxBinN_V, chN ); - - fd_sample_t* buf = mem::allocZ( kFbufVectN * maxTotalBinsN ); - fd_sample_t* m = buf; - for(unsigned chIdx=0; chIdxmagV[chIdx] = m + 0 * f->binN_V[chIdx]; - f->phsV[chIdx] = m + 1 * f->binN_V[chIdx]; - f->hzV[ chIdx] = m + 2 * f->binN_V[chIdx]; - m += f->maxBinN_V[chIdx]; - assert( m <= buf + kFbufVectN * maxTotalBinsN ); + errLabel: + return; } - f->buf = buf; - - } - - return f; -} -*/ - -cw::flow::fbuf_t* cw::flow::fbuf_create( srate_t srate, unsigned chN, unsigned maxBinN, unsigned binN, unsigned hopSmpN, const fd_sample_t** magV, const fd_sample_t** phsV, const fd_sample_t** hzV ) -{ - unsigned maxBinN_V[ chN ]; - unsigned binN_V[ chN ]; - unsigned hopSmpN_V[ chN ]; - - vop::fill( maxBinN_V, chN, maxBinN ); - vop::fill( binN_V, chN, binN ); - vop::fill( hopSmpN_V, chN, binN ); - return fbuf_create( srate, chN, maxBinN_V, binN_V, hopSmpN_V, magV, phsV, hzV ); -} - -void cw::flow::fbuf_destroy( fbuf_t*& fbuf ) -{ - if( fbuf == nullptr ) - return; - - mem::release( fbuf->mem); - mem::release( fbuf); -} - -cw::flow::fbuf_t* cw::flow::fbuf_duplicate( fbuf_t* dst, const fbuf_t* src ) -{ - fbuf_t* fbuf = nullptr; - - if( dst != nullptr && dst->memByteN < src->memByteN ) - fbuf_destroy(dst); - - if( dst == nullptr ) - fbuf = fbuf_create( src->srate, src->chN, src->maxBinN_V, src->binN_V, src->hopSmpN_V ); - else - fbuf = dst; - - for(unsigned i=0; ichN; ++i) - { - fbuf->maxBinN_V[i] = src->maxBinN_V[i]; - fbuf->binN_V[i] = src->binN_V[i]; - fbuf->hopSmpN_V[i] = src->hopSmpN_V[i]; - - vop::copy( fbuf->magV[i], src->magV[i], fbuf->binN_V[i] ); - vop::copy( fbuf->phsV[i], src->phsV[i], fbuf->binN_V[i] ); - vop::copy( fbuf->hzV[i], src->hzV[i], fbuf->binN_V[i] ); - } - return fbuf; -} - - -cw::flow::mbuf_t* cw::flow::mbuf_create( const midi::ch_msg_t* msgA, unsigned msgN ) -{ - mbuf_t* m = mem::allocZ(); - m->msgA = msgA; - m->msgN = msgN; - return m; -} - -void cw::flow::mbuf_destroy( mbuf_t*& buf ) -{ - mem::release(buf); -} - -cw::flow::mbuf_t* cw::flow::mbuf_duplicate( const mbuf_t* src ) -{ - return mbuf_create(src->msgA,src->msgN); -} - -unsigned cw::flow::value_type_label_to_flag( const char* s ) -{ - unsigned flags = labelToId(_typeLabelFlagsA,s,kInvalidTFl); - if( flags == kInvalidTFl ) - cwLogError(kInvalidArgRC,"Invalid type flag: '%s'",cwStringNullGuard(s)); - return flags; -} + + } // flow +} // cw -const char* cw::flow::value_type_flag_to_label( unsigned flag ) -{ return _typeFlagToLabel(flag); } cw::flow::var_desc_t* cw::flow::var_desc_create( const char* label, const object_t* cfg ) { @@ -1483,6 +575,9 @@ void cw::flow::var_desc_destroy( var_desc_t* var_desc ) { if( var_desc != nullptr ) { + if( var_desc_has_recd_format(var_desc) ) + recd_format_destroy(var_desc->fmt.recd_fmt); + mem::release(var_desc->proxyProcLabel); mem::release(var_desc->proxyVarLabel); mem::release(var_desc); @@ -1526,6 +621,7 @@ void cw::flow::class_desc_destroy( class_desc_t* class_desc) mem::release(pr0); pr0 = pr1; } + class_desc->presetL = nullptr; if( class_desc->ui != nullptr ) { @@ -1570,6 +666,11 @@ cw::rc_t cw::flow::var_desc_find( class_desc_t* cd, const char* label, var_desc_ return kOkRC; } +bool cw::flow::var_desc_has_recd_format( var_desc_t* vd ) +{ + return vd!=nullptr && vd->type & kRBufTFl && vd->fmt_cfg != nullptr && vd->fmt.recd_fmt != nullptr; +} + const cw::flow::class_preset_t* cw::flow::class_preset_find( const class_desc_t* cd, const char* preset_label ) { const class_preset_t* pr; @@ -1590,6 +691,21 @@ void cw::flow::class_dict_print( flow_t* p ) } +cw::flow::external_device_t* cw::flow::external_device_find( flow_t* p, const char* device_label, unsigned typeId, unsigned inOrOutFl, const char* midiPortLabel ) +{ + for(unsigned i=0; ideviceN; ++i) + if( (device_label==nullptr || cw::textIsEqual(p->deviceA[i].devLabel,device_label)) + && p->deviceA[i].typeId==typeId + && cwIsFlag(p->deviceA[i].flags,inOrOutFl) + && (midiPortLabel==nullptr || cw::textIsEqual(p->deviceA[i].portLabel,midiPortLabel)) ) + return p->deviceA + i; + + cwLogError(kInvalidArgRC,"The %s device named '%s' could not be found.", cwIsFlag(inOrOutFl,kInFl) ? "in" : "out", device_label ); + + return nullptr; +} + + void cw::flow::network_print( const network_t& net ) { // for each proc in the network @@ -1602,7 +718,8 @@ void cw::flow::network_print( const network_t& net ) if( proc->internal_net != nullptr ) { cwLogPrint("------- Begin Nested Network: %s -------\n",cwStringNullGuard(proc->label)); - network_print(*(proc->internal_net)); + for(const network_t* n = proc->internal_net; n!=nullptr; n=n->poly_link) + network_print(*n); cwLogPrint("------- End Nested Network: %s -------\n",cwStringNullGuard(proc->label)); } @@ -1614,75 +731,14 @@ void cw::flow::network_print( const network_t& net ) for(unsigned i=0; ilabel); - switch( net_preset->tid ) - { - case kPresetVListTId: - { - const preset_value_t* net_val = net_preset->u.vlist.value_head; - for(; net_val!=nullptr; net_val=net_val->link) - { - cwLogPrint(" %s:%i %s:%i ",cwStringNullGuard(net_val->proc->label),net_val->proc->label_sfx_id,cwStringNullGuard(net_val->var->label),net_val->var->label_sfx_id); - _value_print( &net_val->value ); - cwLogPrint("\n"); - } - } - break; - - case kPresetDualTId: - cwLogPrint(" %s %s %f",net_preset->u.dual.pri->label,net_preset->u.dual.sec->label,net_preset->u.dual.coeff); - break; - } + cwLogPrint("%i %s\n",i,cwStringNullGuard(net_preset->label)); + + _network_preset_print(net_preset); } cwLogPrint("\n"); } } -void* cw::flow::network_global_var( proc_t* proc, const char* var_label ) -{ - net_global_var_t* gv; - - assert( proc->net != nullptr ); - - for(gv=proc->net->globalVarL; gv!=nullptr; gv=gv->link ) - if( textIsEqual(proc->class_desc->label,gv->class_label) && textIsEqual(gv->var_label,var_label) ) - return gv->blob; - - return nullptr; -} - -cw::rc_t cw::flow::network_global_var_alloc( proc_t* proc, const char* var_label, const void* blob, unsigned blobByteN ) -{ - rc_t rc = kOkRC; - net_global_var_t* gv; - void* v; - - unsigned allocWordN = 0; - - if((v = network_global_var(proc,var_label)) != nullptr ) - { - rc = cwLogError(kInvalidArgRC,"The global variable '%s:%s' already exists.",cwStringNullGuard(proc->class_desc->label),cwStringNullGuard(var_label)); - goto errLabel; - } - - gv = mem::allocZ(); - - allocWordN = std::max(blobByteN/sizeof(unsigned),1ul); - - gv->class_label = proc->class_desc->label; - gv->var_label = mem::duplStr(var_label); - gv->blob = mem::allocZ(allocWordN); - gv->blobByteN = blobByteN; - memcpy(gv->blob,blob,blobByteN); - - gv->link = proc->net->globalVarL; - proc->net->globalVarL = gv; - -errLabel: - return rc; -} - - const cw::flow::network_preset_t* cw::flow::network_preset_from_label( const network_t& net, const char* preset_label ) { for(unsigned i=0; ipresetL; + class_preset_t* pr1 = nullptr; + while( pr0 != nullptr ) + { + pr1 = pr0->link; + mem::release(pr0); + pr0 = pr1; + } + proc->presetL = nullptr; proc->varL = nullptr; @@ -1792,10 +859,10 @@ cw::rc_t cw::flow::proc_validate( proc_t* proc ) if( !is_connected_to_source(var) && !(var->varDesc->type & var->value->tflag) ) { rc = cwLogError(kInvalidStateRC, "The value type flag '%s' (0x%x) of '%s:%i-%s:%i' is not found in the variable class type flags: '%s' (0x%x)", - _typeFlagToLabel(var->value->tflag),var->value->tflag, + value_type_flag_to_label(var->value->tflag),var->value->tflag, var->proc->label,var->proc->label_sfx_id, var->label,var->label_sfx_id, - _typeFlagToLabel(var->varDesc->type),var->varDesc->type); + value_type_flag_to_label(var->varDesc->type),var->varDesc->type); continue; } @@ -1835,20 +902,62 @@ cw::rc_t cw::flow::proc_find( network_t& net, const char* proc_label, unsigned s return cwLogError(kInvalidArgRC,"The proc '%s:%i' was not found.", proc_label, sfx_id ); } -cw::flow::external_device_t* cw::flow::external_device_find( flow_t* p, const char* device_label, unsigned typeId, unsigned inOrOutFl, const char* midiPortLabel ) +const cw::flow::class_preset_t* cw::flow::proc_preset_find( const proc_t* proc, const char* preset_label ) { - for(unsigned i=0; ideviceN; ++i) - if( (device_label==nullptr || cw::textIsEqual(p->deviceA[i].devLabel,device_label)) - && p->deviceA[i].typeId==typeId - && cwIsFlag(p->deviceA[i].flags,inOrOutFl) - && (midiPortLabel==nullptr || cw::textIsEqual(p->deviceA[i].portLabel,midiPortLabel)) ) - return p->deviceA + i; - - cwLogError(kInvalidArgRC,"The %s device named '%s' could not be found.", cwIsFlag(inOrOutFl,kInFl) ? "in" : "out", device_label ); + const class_preset_t* pr; + for(pr=proc->presetL; pr!=nullptr; pr=pr->link) + if( textCompare(pr->label,preset_label) == 0 ) + return pr; return nullptr; } + +void* cw::flow::global_var( proc_t* proc, const char* var_label ) +{ + global_var_t* gv; + + assert( proc->net != nullptr ); + + for(gv=proc->ctx->globalVarL; gv!=nullptr; gv=gv->link ) + if( textIsEqual(proc->class_desc->label,gv->class_label) && textIsEqual(gv->var_label,var_label) ) + return gv->blob; + + return nullptr; +} + +cw::rc_t cw::flow::global_var_alloc( proc_t* proc, const char* var_label, const void* blob, unsigned blobByteN ) +{ + rc_t rc = kOkRC; + global_var_t* gv; + void* v; + + unsigned allocWordN = 0; + + if((v = global_var(proc,var_label)) != nullptr ) + { + rc = cwLogError(kInvalidArgRC,"The global variable '%s:%s' already exists.",cwStringNullGuard(proc->class_desc->label),cwStringNullGuard(var_label)); + goto errLabel; + } + + gv = mem::allocZ(); + + allocWordN = std::max(blobByteN/sizeof(unsigned),1ul); + + gv->class_label = proc->class_desc->label; + gv->var_label = mem::duplStr(var_label); + gv->blob = mem::allocZ(allocWordN); + gv->blobByteN = blobByteN; + memcpy(gv->blob,blob,blobByteN); + + gv->link = proc->ctx->globalVarL; + proc->ctx->globalVarL = gv; + +errLabel: + return rc; +} + + void cw::flow::proc_print( proc_t* proc ) { cwLogPrint("%s:%i\n", proc->label,proc->label_sfx_id); @@ -1885,8 +994,6 @@ char* cw::flow::proc_expand_filename( const proc_t* proc, const char* fname ) return fn1; } - - cw::rc_t cw::flow::var_create( proc_t* proc, const char* var_label, unsigned sfx_id, unsigned id, unsigned chIdx, const object_t* value_cfg, unsigned altTypeFl, variable_t*& varRef ) { rc_t rc = kOkRC; @@ -1901,7 +1008,7 @@ void cw::flow::var_destroy( variable_t* var ) if( var != nullptr ) { for(unsigned i=0; ilocal_value+i); + value_release(var->local_value+i); if( var->localVarDesc != nullptr ) mem::release(var->localVarDesc); @@ -1995,7 +1102,7 @@ cw::rc_t cw::flow::var_channelize( proc_t* proc, const char* var_label, unsigne { // Set the value of the new variable to the value of the 'any' channel - _value_duplicate( var->local_value[ var->local_value_idx], base_var->local_value[ base_var->local_value_idx ] ); + value_duplicate( var->local_value[ var->local_value_idx], base_var->local_value[ base_var->local_value_idx ] ); // If the 'any' channel value was set to point to it's local value then do same with this value if( base_var->local_value + base_var->local_value_idx == base_var->value ) @@ -2347,6 +1454,9 @@ bool cw::flow::is_connected_to_source( const variable_t* var ) bool cw::flow::is_a_source_var( const variable_t* var ) { return var->dst_head != nullptr; } +bool cw::flow::var_has_recd_format( const variable_t* var ) +{ return var!=nullptr && var_desc_has_recd_format(var->varDesc); } + void cw::flow::var_connect( variable_t* src_var, variable_t* in_var ) { @@ -2526,6 +1636,93 @@ cw::rc_t cw::flow::var_register_and_set( proc_t* proc, const char* var_label, un return var_register_and_set(proc,var_label,sfx_id,vid,chIdx,srate, chN, maxBinN_V, binN_V, hopSmpN_V, magV, phsV, hzV); } +cw::rc_t cw::flow::var_register_and_set( proc_t* proc, const char* var_label, unsigned sfx_id, unsigned vid, unsigned chIdx, const recd_type_t* recd_type, recd_t* recdA, unsigned recdN ) +{ + rc_t rc = kOkRC; + + rbuf_t* rbuf; + if((rbuf = rbuf_create(recd_type,recdA,recdN)) == nullptr ) + return cwLogError(kOpFailRC,"rbuf create failed on proc:'%s:%i' variable:'%s:%i'.", proc->label, proc->label_sfx_id, var_label, sfx_id); + + if((rc = _var_register_and_set( proc, var_label, sfx_id, vid, chIdx, rbuf )) != kOkRC ) + rbuf_destroy(rbuf); + + return rc; +} + + + +cw::rc_t cw::flow::var_alloc_register_and_set( proc_t* proc, const char* var_label, unsigned sfx_id, unsigned vid, unsigned chIdx, const recd_type_t* base, recd_array_t*& recd_array_ref, unsigned recdN ) +{ + rc_t rc = kOkRC; + recd_array_t* recd_array = nullptr; + recd_array_ref = nullptr; + + if((rc = var_alloc_record_array(proc,var_label,sfx_id,chIdx,base,recd_array,recdN)) != kOkRC ) + goto errLabel; + + if((rc = var_register_and_set(proc, var_label, sfx_id, vid, chIdx, recd_array->type, recd_array->recdA, recd_array->allocRecdN )) != kOkRC ) + goto errLabel; + + recd_array_ref = recd_array; + +errLabel: + if( rc != kOkRC ) + { + rc = cwLogError(rc,"Record array create failed on the variable '%s:%i ch:%i.",cwStringNullGuard(var_label),sfx_id,chIdx); + if( recd_array != nullptr ) + recd_array_destroy(recd_array); + } + return rc; + +} + +cw::rc_t cw::flow::var_alloc_record_array( proc_t* proc, const char* var_label, unsigned sfx_id, unsigned chIdx, const recd_type_t* base, recd_array_t*& recd_array_ref, unsigned recdN ) +{ + rc_t rc = kOkRC; + variable_t* var = nullptr; + + recd_array_ref = nullptr; + + // find the record variable + if((rc = var_find( proc, var_label, sfx_id, chIdx, var )) != kOkRC ) + { + rc = cwLogError(rc,"The record variable '%s:%i' could was not found.",cwStringNullGuard(var_label),sfx_id); + goto errLabel; + } + + // verify that the variable has a record format + if( !var_has_recd_format(var) ) + { + rc = cwLogError(kInvalidArgRC,"The variable does not have a valid record format."); + goto errLabel; + } + else + { + recd_fmt_t* recd_fmt = var->varDesc->fmt.recd_fmt; + unsigned alloc_cnt = recdN==0 ? recd_fmt->alloc_cnt : recdN; + + // verify that a non-zero length was given to the count of records in the array + if( alloc_cnt == 0 ) + { + rc = cwLogError(kInvalidArgRC,"A non-zero record array length has not been assigned to the the varaible '%s'.",cwStringNullGuard(var_label)); + goto errLabel; + } + + // create the recd_array + if((rc = recd_array_create( recd_array_ref, recd_fmt->recd_type, base, alloc_cnt )) != kOkRC ) + { + goto errLabel; + } + } + +errLabel: + + if( rc != kOkRC ) + rc = cwLogError(rc,"Record array alloc, based on the variable '%s:%i ch:%i, failed.",cwStringNullGuard(var_label),sfx_id,chIdx); + + return rc; +} cw::rc_t cw::flow::var_get( const variable_t* var, bool& valRef ) { return _val_get_driver(var,valRef); } @@ -2563,80 +1760,22 @@ cw::rc_t cw::flow::var_get( const variable_t* var, const mbuf_t*& valRef ) cw::rc_t cw::flow::var_get( variable_t* var, mbuf_t*& valRef ) { return _val_get_driver(var,valRef); } +cw::rc_t cw::flow::var_get( const variable_t* var, const rbuf_t*& valRef ) +{ return _val_get_driver(var,valRef); } + +cw::rc_t cw::flow::var_get( variable_t* var, rbuf_t*& valRef ) +{ return _val_get_driver(var,valRef); } + cw::rc_t cw::flow::var_get( const variable_t* var, const object_t*& valRef ) { return _val_get_driver(var,valRef); } -cw::rc_t cw::flow::cfg_to_value( const object_t* cfg, value_t& value_ref ) -{ - rc_t rc = kOkRC; - - switch( cfg->type->id ) - { - case kCharTId: - case kUInt8TId: - case kUInt16TId: - case kUInt32TId: - value_ref.tflag = kUIntTFl; - if((rc = cfg->value(value_ref.u.u)) != kOkRC ) - rc = cwLogError(rc,"Conversion to uint failed."); - break; - - case kInt8TId: - case kInt16TId: - case kInt32TId: - value_ref.tflag = kIntTFl; - if((rc = cfg->value(value_ref.u.i)) != kOkRC ) - rc = cwLogError(rc,"Conversion to int failed."); - break; - - case kInt64TId: - case kUInt64TId: - rc = cwLogError(kInvalidArgRC,"The flow system does not currently implement 64bit integers."); - goto errLabel; - break; - - case kFloatTId: - value_ref.tflag = kFloatTFl; - if((rc = cfg->value(value_ref.u.f)) != kOkRC ) - rc = cwLogError(rc,"Conversion to float failed."); - break; - - case kDoubleTId: - value_ref.tflag = kDoubleTFl; - if((rc = cfg->value(value_ref.u.d)) != kOkRC ) - rc = cwLogError(rc,"Conversion to double failed."); - break; - - case kBoolTId: - value_ref.tflag = kBoolTFl; - if((rc = cfg->value(value_ref.u.b)) != kOkRC ) - rc = cwLogError(rc,"Conversion to bool failed."); - break; - - case kStringTId: - case kCStringTId: - value_ref.tflag = kStringTFl; - if((rc = cfg->value(value_ref.u.s)) != kOkRC ) - rc = cwLogError(rc,"Conversion to string failed."); - break; - - default: - value_ref.tflag = kCfgTFl; - value_ref.u.cfg = cfg; - - } -errLabel: - - return rc; -} - cw::rc_t cw::flow::var_set_from_cfg( variable_t* var, const object_t* cfg_value ) { rc_t rc = kOkRC; value_t v; - if((rc = cfg_to_value(cfg_value, v)) != kOkRC ) + if((rc = value_from_cfg(cfg_value, v)) != kOkRC ) goto errLabel; if((rc = var_set(var,&v)) != kOkRC ) @@ -2644,7 +1783,7 @@ cw::rc_t cw::flow::var_set_from_cfg( variable_t* var, const object_t* cfg_value errLabel: if( rc != kOkRC ) - rc = cwLogError(kSyntaxErrorRC,"The %s:%i.%s:%i could not extract a type:%s from a configuration value.",var->proc->label,var->proc->label_sfx_id,var->label,var->label_sfx_id,_typeFlagToLabel(var->varDesc->type & kTypeMask)); + rc = cwLogError(kSyntaxErrorRC,"The %s:%i.%s:%i could not extract a type:%s from a configuration value.",var->proc->label,var->proc->label_sfx_id,var->label,var->label_sfx_id,value_type_flag_to_label(var->varDesc->type & kTypeMask)); return rc; @@ -2666,6 +1805,7 @@ cw::rc_t cw::flow::var_set( variable_t* var, const value_t* val ) case kABufTFl: rc = _var_set_driver(var,val->tflag,val->u.abuf); break; case kFBufTFl: rc = _var_set_driver(var,val->tflag,val->u.fbuf); break; case kMBufTFl: rc = _var_set_driver(var,val->tflag,val->u.mbuf); break; + case kRBufTFl: rc = _var_set_driver(var,val->tflag,val->u.rbuf); break; default: rc = cwLogError(kNotImplementedRC,"The var_set() from value_t has not been implemented for the type 0x%x.",val->tflag); } @@ -2683,6 +1823,7 @@ cw::rc_t cw::flow::var_set( variable_t* var, const char* val ) { return _var cw::rc_t cw::flow::var_set( variable_t* var, abuf_t* val ) { return _var_set_driver(var,kABufTFl,val); } cw::rc_t cw::flow::var_set( variable_t* var, fbuf_t* val ) { return _var_set_driver(var,kFBufTFl,val); } cw::rc_t cw::flow::var_set( variable_t* var, mbuf_t* val ) { return _var_set_driver(var,kMBufTFl,val); } +cw::rc_t cw::flow::var_set( variable_t* var, rbuf_t* val ) { return _var_set_driver(var,kRBufTFl,val); } cw::rc_t cw::flow::var_set( variable_t* var, const object_t* val ) { return _var_set_driver(var,kCfgTFl,val); } cw::rc_t cw::flow::var_set( proc_t* proc, unsigned vid, unsigned chIdx, const value_t* val ) @@ -2795,6 +1936,16 @@ cw::rc_t cw::flow::var_set( proc_t* proc, unsigned vid, unsigned chIdx, mbuf_t* return rc; } +cw::rc_t cw::flow::var_set( proc_t* proc, unsigned vid, unsigned chIdx, rbuf_t* val ) +{ + rc_t rc = kOkRC; + variable_t* var = nullptr; + + if((rc = var_find(proc, vid, chIdx, var )) == kOkRC ) + rc = _var_set_driver(var,kRBufTFl,val); + + return rc; +} cw::rc_t cw::flow::var_set( proc_t* proc, unsigned vid, unsigned chIdx, const object_t* val ) { diff --git a/cwFlowTypes.h b/cwFlowTypes.h index e6581f3..2295cc8 100644 --- a/cwFlowTypes.h +++ b/cwFlowTypes.h @@ -5,128 +5,6 @@ namespace cw namespace flow { - typedef dsp::coeff_t coeff_t; - typedef dsp::sample_t sample_t; - typedef dsp::fd_sample_t fd_sample_t; - typedef dsp::srate_t srate_t; - typedef dsp::ftime_t ftime_t; - typedef unsigned uint_t; - typedef int int_t; - - - typedef unsigned vid_t; - - enum { - kBaseSfxId = 0, - kFbufVectN = 3, // count of signal vectors in fbuf (mag,phs,hz) - kAnyChIdx = kInvalidIdx, - kLocalValueN = 2, - kDefaultFramesPerCycle=64, - kDefaultSampleRate=48000 - }; - - typedef struct abuf_str - { - srate_t srate; // Signal sample rate - unsigned chN; // Count of channels - unsigned frameN; // Count of sample frames per channel - unsigned bufAllocSmpN; // Size of allocated buf[] in samples. - sample_t* buf; // buf[ chN ][ frameN ] - } abuf_t; - - - typedef struct fbuf_str - { - unsigned memByteN; // Count of bytes in mem[]. - void* mem; // mem[ memByteN ] All dynamically allocated memory used by this fbuf. - - srate_t srate; // signal sample rate - unsigned flags; // See kXXXFbufFl - unsigned chN; // count of channels - unsigned* maxBinN_V; // maxBinN_V[chN] max value that binN_V[i] is allowed to take - unsigned* binN_V; // binN_V[ chN ] count of sample frames per channel - unsigned* hopSmpN_V; // hopSmpN_V[ chN ] hop sample count - fd_sample_t** magV; // magV[ chN ][ binN ] - fd_sample_t** phsV; // phsV[ chN ][ binN ] - fd_sample_t** hzV; // hzV[ chN ][ binN ] - bool* readyFlV; // readyFlV[chN] true if this channel is ready to be processed (used to sync. fbuf rate to abuf rate) - } fbuf_t; - - typedef struct mbuf_str - { - const midi::ch_msg_t* msgA; - unsigned msgN; - } mbuf_t; - - enum - { - kInvalidTFl = 0x00000000, - kBoolTFl = 0x00000001, - kUIntTFl = 0x00000002, - kIntTFl = 0x00000004, - kFloatTFl = 0x00000008, - kDoubleTFl = 0x00000010, - - kBoolMtxTFl = 0x00000020, - kUIntMtxTFl = 0x00000040, - kIntMtxTFl = 0x00000080, - kFloatMtxTFl = 0x00000100, - kDoubleMtxTFl= 0x00000200, - - kABufTFl = 0x00000400, - kFBufTFl = 0x00000800, - kMBufTFl = 0x00001000, - kStringTFl = 0x00002000, - kTimeTFl = 0x00004000, - kCfgTFl = 0x00008000, - - kTypeMask = 0x0000ffff, - - kRuntimeTFl = 0x80000000, - - kNumericTFl = kBoolTFl | kUIntTFl | kIntTFl | kFloatTFl | kDoubleTFl, - kMtxTFl = kBoolMtxTFl | kUIntMtxTFl | kIntMtxTFl | kFloatMtxTFl | kDoubleMtxTFl, - kAllTFl = kTypeMask - }; - - typedef struct mtx_str - { - union { - struct mtx::mtx_str< unsigned >* u; - struct mtx::mtx_str< int >* i; - struct mtx::mtx_str< float >* f; - struct mtx::mtx_str< double >* d; - } u; - } mtx_t; - - typedef struct value_str - { - unsigned tflag; - - union { - bool b; - uint_t u; - int_t i; - float f; - double d; - - mtx_t* mtx; - abuf_t* abuf; - fbuf_t* fbuf; - mbuf_t* mbuf; - - char* s; - - const object_t* cfg; - void* p; - - } u; - - struct value_str* link; - - } value_t; - - struct proc_str; struct variable_str; @@ -153,15 +31,21 @@ namespace cw member_func_t exec; member_func_t report; } class_members_t; - + typedef struct var_desc_str { const object_t* cfg; // The cfg object that describes this variable from 'flow_class'. const object_t* val_cfg; // An object containing the default value for this variable. + const object_t* fmt_cfg; // An object containg the format (e.g. record fields) information const char* label; // Name of this var. unsigned type; // Value type id (e.g. kBoolTFl, kIntTFl, ...) unsigned flags; // Attributes for this var. (e.g. kSrcVarFl ) const char* docText; // User help string for this var. + + union + { + recd_fmt_t* recd_fmt; // the 'recd_type.base' is never set in 'recd_type' because it is only valid once the var is instantiated + } fmt; char* proxyProcLabel; char* proxyVarLabel; @@ -216,7 +100,7 @@ namespace cw unsigned local_value_idx; // local_value[] is double buffered to allow the cur value of the buf[] to be held while the next value is validated (see _var_set_template()) struct variable_str* src_var; // pointer to this input variables source link (or null if it uses the local_value) value_t* value; // pointer to the value associated with this variable - + struct variable_str* var_link; // instance.varL list link struct variable_str* ch_link; // list of channels that share this variable (rooted on 'any' channel - in order by channel number) @@ -242,6 +126,7 @@ namespace cw unsigned label_sfx_id; // label suffix id (set to kBaseSfxId (0) unless poly is non-null) const object_t* proc_cfg; // instance configuration + class_preset_t* presetL; // instance presets void* userPtr; // instance state @@ -252,18 +137,45 @@ namespace cw unsigned varMapN; // varMapN = varMapIdN * varMapChN variable_t** varMapA; // varMapA[ varMapN ] = allows fast lookup from ('vid','chIdx) to variable + // For 'poly' proc's 'internal_net' is a list linked by network_t.poly_link. struct network_str* internal_net; } proc_t; - - // preset_value_t holds a preset value and the proc/var to which it will be applied. - typedef struct preset_value_str + struct network_preset_str; + typedef struct proc_var_value_str { proc_t* proc; // proc target for this preset value variable_t* var; // var target for this preset value value_t value; // Preset value. unsigned pairTblIdx; // Index into the preset pair table for this preset value + } proc_var_value_t; + + typedef struct net_preset_value_str + { + struct proc_str* net_preset_proc; // net_preset_proc->internal_net has the preset list which net_preset is part of. + struct network_str* net_preset_net; // poly net this preset will be applied to + const network_preset_str* net_preset; // network_preset_t of presets + } poly_preset_value_t; + + typedef enum { + kDirectPresetValueTId, + kPolyPresetValueTId, + } preset_val_tid_t; + + + + // preset_value_t holds a preset value and the proc/var to which it will be applied. + typedef struct preset_value_str + { + preset_val_tid_t tid; + + union + { + proc_var_value_t pvv; // Direct proc/var/value tuples. + poly_preset_value_t npv; // Refers to a network_preset_t and a list of preset_values. + } u; + struct preset_value_str* link; } preset_value_t; @@ -273,8 +185,6 @@ namespace cw preset_value_t* value_tail; // Last preset value in the list. } preset_value_list_t; - struct network_preset_str; - typedef struct dual_preset_str { const struct network_preset_str* pri; @@ -308,16 +218,15 @@ namespace cw const value_t* value; // } network_preset_pair_t; - typedef struct net_global_var_str + typedef struct global_var_str { const char* class_label; char* var_label; void* blob; unsigned blobByteN; - struct net_global_var_str* link; - - } net_global_var_t; + struct global_var_str* link; + } global_var_t; typedef struct network_str { @@ -334,8 +243,6 @@ namespace cw network_preset_pair_t* preset_pairA; unsigned preset_pairN; - net_global_var_t* globalVarL; - struct network_str* poly_link; unsigned poly_idx; @@ -390,51 +297,13 @@ namespace cw variable_t ui_var_stub; variable_t* ui_var_tail; + global_var_t* globalVarL; + } flow_t; - //------------------------------------------------------------------------------------------------------------------------ - // - // Value Only - // - - inline void set_null( value_t& v, unsigned tflag ) { v.tflag=tflag; v.u.p=nullptr; } - inline bool is_numeric( const value_t* v ) { return cwIsFlag(v->tflag,kNumericTFl); } - inline bool is_matrix( const value_t* v ) { return cwIsFlag(v->tflag,kMtxTFl); } - - // if all of the src flags are set in the dst flags then the two types are convertable. - inline bool can_convert( unsigned src_tflag, unsigned dst_tflag ) { return (src_tflag&dst_tflag)==src_tflag; } + - abuf_t* abuf_create( srate_t srate, unsigned chN, unsigned frameN ); - void abuf_destroy( abuf_t*& buf ); - - // If 'dst' is null then a new abuf is allocated, filled with the contents of 'src'. - // If 'dst' is non-null and there is enough space for the contents of 'src' then only a copy is executed. - // If there is not enough space then dst is reallocated. - abuf_t* abuf_duplicate( abuf_t* dst, const abuf_t* src ); - rc_t abuf_set_channel( abuf_t* buf, unsigned chIdx, const sample_t* v, unsigned vN ); - const sample_t* abuf_get_channel( abuf_t* buf, unsigned chIdx ); - - fbuf_t* fbuf_create( srate_t srate, unsigned chN, const unsigned* maxBinN_V, const unsigned* binN_V, const unsigned* hopSmpN_V, const fd_sample_t** magV=nullptr, const fd_sample_t** phsV=nullptr, const fd_sample_t** hzV=nullptr ); - fbuf_t* fbuf_create( srate_t srate, unsigned chN, unsigned maxBinN, unsigned binN, unsigned hopSmpN, const fd_sample_t** magV=nullptr, const fd_sample_t** phsV=nullptr, const fd_sample_t** hzV=nullptr ); - void fbuf_destroy( fbuf_t*& buf ); - - // Memory allocation will only occur if dst is null, or the size of dst's internal buffer are too small. - fbuf_t* fbuf_duplicate( fbuf_t* dst, const fbuf_t* src ); - - mbuf_t* mbuf_create( const midi::ch_msg_t* msgA=nullptr, unsigned msgN=0 ); - void mbuf_destroy( mbuf_t*& buf ); - mbuf_t* mbuf_duplicate( const mbuf_t* src ); - - inline bool value_is_abuf( const value_t* v ) { return v->tflag & kABufTFl; } - inline bool value_is_fbuf( const value_t* v ) { return v->tflag & kFBufTFl; } - - unsigned value_type_label_to_flag( const char* type_desc ); - const char* value_type_flag_to_label( unsigned flag ); - - void value_duplicate( value_t& dst, const value_t& src ); - - void value_print( const value_t* value, bool info_fl=false); //------------------------------------------------------------------------------------------------------------------------ // @@ -455,9 +324,19 @@ namespace cw const var_desc_t* var_desc_find( const class_desc_t* cd, const char* var_label ); rc_t var_desc_find( class_desc_t* cd, const char* var_label, var_desc_t*& vdRef ); + bool var_desc_has_recd_format( var_desc_t* vd ); + const class_preset_t* class_preset_find( const class_desc_t* cd, const char* preset_label ); - void class_dict_print( flow_t* p ); + //------------------------------------------------------------------------------------------------------------------------ + // + // Flow + // + + void class_dict_print( flow_t* p ); + + external_device_t* external_device_find( flow_t* p, const char* device_label, unsigned typeId, unsigned inOrOutFl, const char* midiPortLabel=nullptr ); + //------------------------------------------------------------------------------------------------------------------------ @@ -465,12 +344,6 @@ namespace cw // Network // - // Access a blob stored via network_global_var() - void* network_global_var( proc_t* proc, const char* var_label ); - - // Copy a named blob into the network global variable space. - rc_t network_global_var_alloc( proc_t* proc, const char* var_label, const void* blob, unsigned blobByteN ); - void network_print(const network_t& net ); @@ -481,6 +354,8 @@ namespace cw rc_t proc_mult_sfx_id_array( const network_t& net, const char* proc_label, unsigned* idA, unsigned idAllocN, unsigned& idN_ref ); unsigned network_poly_count( const network_t& net ); + + inline bool network_is_part_of_poly( const network_t& net ) { return net.poly_idx > 0 || net.poly_link!=nullptr; } //------------------------------------------------------------------------------------------------------------------------ @@ -494,8 +369,14 @@ namespace cw proc_t* proc_find( network_t& net, const char* proc_label, unsigned sfx_id ); rc_t proc_find( network_t& net, const char* proc_label, unsigned sfx_id, proc_t*& procPtrRef ); - external_device_t* external_device_find( flow_t* p, const char* device_label, unsigned typeId, unsigned inOrOutFl, const char* midiPortLabel=nullptr ); + const class_preset_t* proc_preset_find( const proc_t* cd, const char* preset_label ); + // Access a blob stored via global_var() + void* global_var( proc_t* proc, const char* var_label ); + + // Copy a named blob into the network global variable space. + rc_t global_var_alloc( proc_t* proc, const char* var_label, const void* blob, unsigned blobByteN ); + void proc_print( proc_t* proc ); // Count of all var instances on this proc. This is a count of the length of proc->varL. @@ -546,6 +427,9 @@ namespace cw // Return true if this var is acting as a source for another var. bool is_a_source_var( const variable_t* var ); + // Returns true if var->varDesc->fmt.recd_fmt is valid. + bool var_has_recd_format( const variable_t* var ); + // Connect in_var to src_var. void var_connect( variable_t* src_var, variable_t* in_var ); @@ -641,7 +525,19 @@ namespace cw rc_t var_register_and_set( proc_t* proc, const char* var_label, unsigned sfx_id, unsigned vid, unsigned chIdx, midi::ch_msg_t* midiA, unsigned midiN ); rc_t var_register_and_set( proc_t* proc, const char* var_label, unsigned sfx_id, unsigned vid, unsigned chIdx, srate_t srate, unsigned chN, const unsigned* maxBinN_V, const unsigned* binN_V, const unsigned* hopSmpN_V, const fd_sample_t** magV=nullptr, const fd_sample_t** phsV=nullptr, const fd_sample_t** hzV=nullptr ); rc_t var_register_and_set( proc_t* proc, const char* var_label, unsigned sfx_id, unsigned vid, unsigned chIdx, srate_t srate, unsigned chN, unsigned maxBinN, unsigned binN, unsigned hopSmpN, const fd_sample_t** magV=nullptr, const fd_sample_t** phsV=nullptr, const fd_sample_t** hzV=nullptr ); + rc_t var_register_and_set( proc_t* proc, const char* var_label, unsigned sfx_id, unsigned vid, unsigned chIdx, const recd_type_t* recd_type, recd_t* recdA, unsigned recdN ); + // Alloc a recd_array, using an internal call to var_alloc_recd_array(), and assign all records to the specified variable. + // The caller is responsible for destroying (recd_array_destroy()) the returned recd_array. + rc_t var_alloc_register_and_set( proc_t* proc, const char* var_label, unsigned sfx_id, unsigned vid, unsigned chIdx, const recd_type_t* baseh, recd_array_t*& recd_arrray_ref, unsigned recdN=0 ); + + + // Alloc the recd_array_t based on the recd_type defined by the variable. Set recdN to a non-zero value to override the 'alloc_cnt' + // which may have been set in the variables user provided cfg. + // The caller is responsible for destroying (recd_array_destroy()) the returned recd_array. + rc_t var_alloc_record_array( proc_t* proc, const char* var_label, unsigned sfx_id, unsigned chIdx, const recd_type_t* base, recd_array_t*& recd_array_ref, unsigned recdN=0 ); + + inline rc_t _var_register_and_set(cw::flow::proc_t*, unsigned int ) { return kOkRC; } template< typename T0, typename T1, typename T2, typename... ARGS > @@ -685,7 +581,6 @@ namespace cw rc_t var_channel_count( proc_t* proc, const char* label, unsigned sfx_idx, unsigned& chCntRef ); rc_t var_channel_count( const variable_t* var, unsigned& chCntRef ); - rc_t cfg_to_value( const object_t* cfg, value_t& value_ref ); // @@ -704,6 +599,8 @@ namespace cw rc_t var_get( variable_t* var, fbuf_t*& valRef ); rc_t var_get( const variable_t* var, const mbuf_t*& valRef ); rc_t var_get( variable_t* var, mbuf_t*& valRef ); + rc_t var_get( const variable_t* var, const rbuf_t*& valRef ); + rc_t var_get( variable_t* var, rbuf_t*& valRef ); rc_t var_get( const variable_t* var, const object_t*& valRef ); template< typename T> @@ -742,6 +639,7 @@ namespace cw rc_t var_set( variable_t* var, abuf_t* val ); rc_t var_set( variable_t* var, fbuf_t* val ); rc_t var_set( variable_t* var, mbuf_t* val ); + rc_t var_set( variable_t* var, rbuf_t* val ); rc_t var_set( variable_t* var, const object_t* val ); rc_t var_set( proc_t* proc, unsigned vid, unsigned chIdx, const value_t* val ); @@ -754,6 +652,7 @@ namespace cw rc_t var_set( proc_t* proc, unsigned vid, unsigned chIdx, abuf_t* val ); rc_t var_set( proc_t* proc, unsigned vid, unsigned chIdx, fbuf_t* val ); rc_t var_set( proc_t* proc, unsigned vid, unsigned chIdx, mbuf_t* val ); + rc_t var_set( proc_t* proc, unsigned vid, unsigned chIdx, rbuf_t* val ); rc_t var_set( proc_t* proc, unsigned vid, unsigned chIdx, const object_t* val );