cwFlowTypes : Added value_print() and made extra info print optional on _value_print().

The current exec. cycle index is now printed out with all 'log' lines.
This commit is contained in:
kevin 2024-05-24 16:41:42 -04:00
parent b79318a983
commit d90a3c31da
2 changed files with 119 additions and 147 deletions

View File

@ -189,7 +189,7 @@ namespace cw
} }
void _value_print( const value_t* v ) void _value_print( const value_t* v, bool info_fl=true )
{ {
if( v == nullptr ) if( v == nullptr )
return; return;
@ -199,35 +199,84 @@ namespace cw
case kInvalidTFl: case kInvalidTFl:
break; break;
case kBoolTFl: cwLogPrint("b:%s ", v->u.b ? "true" : "false" ); break; case kBoolTFl:
case kUIntTFl: cwLogPrint("u:%i ", v->u.u ); break;
case kIntTFl: cwLogPrint("i:%i ", v->u.i ); break; cwLogPrint("%s%s ", info_fl ? "b:" : "", v->u.b ? "true" : "false" );
case kFloatTFl: cwLogPrint("f:%f ", v->u.f ); break; break;
case kDoubleTFl:cwLogPrint("d:%f ", v->u.d ); 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: case kABufTFl:
if( v->u.abuf == nullptr ) if( info_fl )
cwLogPrint("abuf: <null>"); {
if( v->u.abuf == nullptr )
cwLogPrint("abuf: <null>");
else
cwLogPrint("abuf: chN:%i frameN:%i srate:%8.1f ", v->u.abuf->chN, v->u.abuf->frameN, v->u.abuf->srate );
}
else else
cwLogPrint("abuf: chN:%i frameN:%i srate:%8.1f ", v->u.abuf->chN, v->u.abuf->frameN, v->u.abuf->srate ); {
bool null_fl = v->u.abuf==nullptr || v->u.abuf->buf == nullptr;
cwLogPrint("(");
for(unsigned i=0; i<v->u.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; break;
case kFBufTFl: case kFBufTFl:
if( v->u.fbuf == nullptr ) if( info_fl )
cwLogPrint("fbuf: <null>"); {
if( v->u.fbuf == nullptr )
cwLogPrint("fbuf: <null>");
else
{
cwLogPrint("fbuf: chN:%i srate:%8.1f ", v->u.fbuf->chN, v->u.fbuf->srate );
for(unsigned i=0; i<v->u.fbuf->chN; ++i)
cwLogPrint("(binN:%i hopSmpN:%i) ", v->u.fbuf->binN_V[i], v->u.fbuf->hopSmpN_V[i] );
}
}
else else
{ {
cwLogPrint("fbuf: chN:%i srate:%8.1f ", v->u.fbuf->chN, v->u.fbuf->srate );
for(unsigned i=0; i<v->u.fbuf->chN; ++i) bool null_fl = v->u.fbuf==nullptr || v->u.fbuf->magV == nullptr;
cwLogPrint("(binN:%i hopSmpN:%i) ", v->u.fbuf->binN_V[i], v->u.fbuf->hopSmpN_V[i] ); cwLogPrint("(");
for(unsigned i=0,N=0; i<v->u.fbuf->chN; ++i)
cwLogPrint("%f ",null_fl ? 0.0 : vop::mean(v->u.fbuf->magV[i], v->u.fbuf->binN_V[i]));
cwLogPrint(") ");
} }
break; break;
case kMBufTFl: case kMBufTFl:
if( v->u.mbuf == nullptr ) if( info_fl )
cwLogPrint("mbuf: <null>"); {
if( v->u.mbuf == nullptr )
cwLogPrint("mbuf: <null>");
else
{
cwLogPrint("mbuf: cnt: %i", v->u.mbuf->msgN );
}
}
else else
{ {
cwLogPrint("mbuf: cnt: %i", v->u.mbuf->msgN ); bool null_fl = v->u.mbuf==nullptr || v->u.mbuf->msgA == nullptr;
for(unsigned i=0; i<v->u.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; break;
@ -1077,11 +1126,22 @@ namespace cw
// if value_cfg is valid set the variable value // if value_cfg is valid set the variable value
if( value_cfg != nullptr && cwIsNotFlag(vd->type,kRuntimeTFl)) if( value_cfg != nullptr && cwIsNotFlag(vd->type,kRuntimeTFl))
if((rc = var_set_from_preset( var, value_cfg )) != kOkRC ) if((rc = var_set_from_cfg( var, value_cfg )) != kOkRC )
goto errLabel; goto errLabel;
var->var_link = proc->varL; // Add the variable to the end of the chain
proc->varL = var; if( proc->varL == nullptr )
proc->varL = var;
else
{
variable_t* v = proc->varL;
while( v->var_link != nullptr )
v=v->var_link;
v->var_link = var;
}
//var->var_link = proc->varL;
//proc->varL = var;
// link the new var into the ch_link list // link the new var into the ch_link list
if((rc = _var_add_to_ch_list(proc, var )) != kOkRC ) if((rc = _var_add_to_ch_list(proc, var )) != kOkRC )
@ -1121,6 +1181,12 @@ namespace cw
} }
} }
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 ) cw::flow::abuf_t* cw::flow::abuf_create( srate_t srate, unsigned chN, unsigned frameN )
{ {
abuf_t* a = mem::allocZ<abuf_t>(); abuf_t* a = mem::allocZ<abuf_t>();
@ -1513,7 +1579,7 @@ void cw::flow::proc_destroy( proc_t* proc )
if( proc == nullptr ) if( proc == nullptr )
return; return;
if( proc->class_desc->members->destroy != nullptr && proc->userPtr != nullptr ) if( proc->class_desc->members != nullptr && proc->class_desc->members->destroy != nullptr && proc->userPtr != nullptr )
proc->class_desc->members->destroy( proc ); proc->class_desc->members->destroy( proc );
// destroy the proc instance variables // destroy the proc instance variables
@ -1753,7 +1819,7 @@ cw::rc_t cw::flow::var_channelize( proc_t* proc, const char* var_label, unsigne
var_connect( last_src_ch_var, var ); var_connect( last_src_ch_var, var );
} }
else else // the base-var is not connected, and no value was provided for the new var
{ {
// Set the value of the new variable to the value of the 'any' channel // Set the value of the new variable to the value of the 'any' channel
@ -1766,14 +1832,13 @@ cw::rc_t cw::flow::var_channelize( proc_t* proc, const char* var_label, unsigne
} }
} }
else else // the var was found - set the value
{ {
// a correctly channelized var was found - but we still may need to set the value // a correctly channelized var was found - but we still may need to set the value
if( value_cfg != nullptr ) if( value_cfg != nullptr )
{ {
//cwLogInfo("%s ch:%i",var_label,chIdx); rc = var_set_from_cfg( var, value_cfg );
rc = var_set_from_preset( var, value_cfg );
} }
else else
{ {
@ -1799,15 +1864,20 @@ cw::rc_t cw::flow::var_call_custom_value_func( variable_t* var )
if( var->flags & kLogVarFl ) if( var->flags & kLogVarFl )
{ {
cwLogPrint("cycle: %8i ",var->proc->ctx->cycleIndex);
cwLogPrint("%10s:%5i", var->proc->label,var->proc->label_sfx_id); cwLogPrint("%10s:%5i", var->proc->label,var->proc->label_sfx_id);
if( var->chIdx == kAnyChIdx ) if( var->chIdx == kAnyChIdx )
{
_var_print(var); _var_print(var);
}
else else
{ {
printf("\n"); printf("\n");
for(variable_t* ch_var = var; ch_var!=nullptr; ch_var=ch_var->ch_link) for(variable_t* ch_var = var; ch_var!=nullptr; ch_var=ch_var->ch_link)
{
_var_print(ch_var); _var_print(ch_var);
}
} }
} }
@ -2006,7 +2076,7 @@ cw::rc_t cw::flow::var_register( proc_t* proc, const char* var_label, unsigned s
{ {
// if a value was given - then update the value // if a value was given - then update the value
if( value_cfg != nullptr ) if( value_cfg != nullptr )
if((rc = var_set_from_preset( var, value_cfg )) != kOkRC ) if((rc = var_set_from_cfg( var, value_cfg )) != kOkRC )
goto errLabel; goto errLabel;
} }
else // an exact match was not found - channelize the variable else // an exact match was not found - channelize the variable
@ -2303,123 +2373,16 @@ errLabel:
} }
cw::rc_t cw::flow::var_set_from_preset( variable_t* var, const object_t* value ) cw::rc_t cw::flow::var_set_from_cfg( variable_t* var, const object_t* cfg_value )
{ {
rc_t rc = kOkRC; rc_t rc = kOkRC;
value_t v;
// if((rc = cfg_to_value(cfg_value, v)) != kOkRC )
// Determine the flow variable type of cfg. argument 'value'. goto errLabel;
//
unsigned value_flag = 0;
switch( value->type->id ) if((rc = var_set(var,&v)) != kOkRC )
{ goto errLabel;
case kCharTId:
case kUInt8TId:
case kUInt16TId:
case kUInt32TId:
value_flag = kUIntTFl;
break;
case kInt8TId:
case kInt16TId:
case kInt32TId:
value_flag = kIntTFl;
break;
case kInt64TId:
case kUInt64TId:
rc = cwLogError(kInvalidArgRC,"The flow system does not currently implement 64bit integers.");
goto errLabel;
break;
case kFloatTId:
value_flag = kFloatTFl;
break;
case kDoubleTId:
value_flag = kDoubleTFl;
break;
case kBoolTId:
value_flag = kBoolTFl;
break;
case kStringTId:
case kCStringTId:
value_flag = kStringTFl;
break;
default:
value_flag = kCfgTFl;
}
//
// Convert the cfg value to a c++ typed value and then call _var_set_driver() with the c++ value.
//
switch( value_flag )
{
case kBoolTFl:
{
bool v;
// assign the value of 'value' to to 'v' (do type conversion if necessary)
if((rc = value->value(v)) == kOkRC )
// set the value of 'var' where 'v' is the new value and 'value_flag' is the type of 'v'.
rc = _var_set_driver( var, value_flag, v );
}
break;
case kUIntTFl:
{
unsigned v;
if((rc = value->value(v)) == kOkRC )
rc = _var_set_driver( var, value_flag, v );
}
break;
case kIntTFl:
{
int v;
if((rc = value->value(v)) == kOkRC )
rc = _var_set_driver( var, value_flag, v );
}
break;
case kFloatTFl:
{
float v;
if((rc = value->value(v)) == kOkRC )
rc = _var_set_driver( var, value_flag, v );
}
break;
case kDoubleTFl:
{
double v;
if((rc = value->value(v)) == kOkRC )
rc = _var_set_driver( var, value_flag, v );
}
break;
case kStringTFl:
{
const char* v;
if((rc = value->value(v)) == kOkRC )
rc = _var_set_driver( var, value_flag, v );
}
break;
case kCfgTFl:
{
rc = _var_set_driver( var, value_flag, value );
}
break;
default:
rc = cwLogError(kOpFailRC,"The variable type 0x%x cannot yet be set via a cfg.", var->varDesc->type );
goto errLabel;
}
errLabel: errLabel:
if( rc != kOkRC ) if( rc != kOkRC )

View File

@ -252,12 +252,12 @@ namespace cw
} proc_t; } proc_t;
// preset_value_t holds a preset value and the proc/var to which it will be applied.
typedef struct preset_value_str typedef struct preset_value_str
{ {
proc_t* proc; // proc target for this preset value proc_t* proc; // proc target for this preset value
variable_t* var; // var target for this preset value variable_t* var; // var target for this preset value
value_t value; // Preset value. value_t value; // Preset value.
//unsigned chN; // Count of channels specified by this preset
unsigned pairTblIdx; // Index into the preset pair table for this preset value unsigned pairTblIdx; // Index into the preset pair table for this preset value
struct preset_value_str* link; struct preset_value_str* link;
} preset_value_t; } preset_value_t;
@ -293,6 +293,7 @@ namespace cw
} u; } u;
} network_preset_t; } network_preset_t;
// Preset-pair record used to apply dual presets.
typedef struct network_preset_pair_str typedef struct network_preset_pair_str
{ {
const proc_t* proc; // const proc_t* proc; //
@ -316,6 +317,7 @@ namespace cw
network_preset_t* presetA; network_preset_t* presetA;
unsigned presetN; unsigned presetN;
// Preset pair table used by network_apply_dual_preset()
network_preset_pair_t* preset_pairA; network_preset_pair_t* preset_pairA;
unsigned preset_pairN; unsigned preset_pairN;
@ -326,15 +328,20 @@ namespace cw
{ {
const object_t* flowCfg; // complete cfg used to create this flow const object_t* flowCfg; // complete cfg used to create this flow
bool isInRuntimeFl; // Set when compile-time is complete
unsigned framesPerCycle; // sample frames per cycle (64) unsigned framesPerCycle; // sample frames per cycle (64)
srate_t sample_rate; // default sample rate (48000.0) srate_t sample_rate; // default sample rate (48000.0)
unsigned maxCycleCount; // count of cycles to run on flow::exec() or 0 if there is no limit.
const char* init_net_preset_label;// network initialization preset label or nullptr if there is no net. init. preset
bool isInRuntimeFl; // Set when compile-time is complete
unsigned cycleIndex; // Incremented with each processing cycle
bool multiPriPresetProbFl; // If set then probability is used to choose presets on multi-preset application bool multiPriPresetProbFl; // If set then probability is used to choose presets on multi-preset application
bool multiSecPresetProbFl; // bool multiSecPresetProbFl; //
bool multiPresetInterpFl; // If set then interpolation is applied between two selectedd presets on multi-preset application bool multiPresetInterpFl; // If set then interpolation is applied between two selectedd presets on multi-preset application
unsigned cycleIndex; // Incremented with each processing cycle
unsigned maxCycleCount; // count of cycles to run on flow::exec() or 0 if there is no limit.
class_desc_t* classDescA; // class_desc_t* classDescA; //
unsigned classDescN; // unsigned classDescN; //
@ -385,6 +392,8 @@ namespace cw
unsigned value_type_label_to_flag( const char* type_desc ); unsigned value_type_label_to_flag( const char* type_desc );
const char* value_type_flag_to_label( unsigned flag ); const char* value_type_flag_to_label( unsigned flag );
void value_print( const value_t* value, bool info_fl=false);
//------------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------------
// //
// Class and Variable Description // Class and Variable Description
@ -659,7 +668,7 @@ namespace cw
// var_set() coerces the incoming value to the type of the variable (var->type) // var_set() coerces the incoming value to the type of the variable (var->type)
// //
rc_t var_set_from_preset( variable_t* var, const object_t* val ); rc_t var_set_from_cfg( variable_t* var, const object_t* cfg_value );
rc_t var_set( variable_t* var, const value_t* val ); rc_t var_set( variable_t* var, const value_t* val );
rc_t var_set( variable_t* var, bool val ); rc_t var_set( variable_t* var, bool val );