diff --git a/cwFlow.cpp b/cwFlow.cpp index 912d275..0d60507 100644 --- a/cwFlow.cpp +++ b/cwFlow.cpp @@ -41,6 +41,7 @@ namespace cw { "audio_delay", &audio_delay::members }, { "dc_filter", &dc_filter::members }, { "balance", &balance::members }, + { "audio_meter", &audio_meter::members }, { nullptr, nullptr } }; @@ -759,19 +760,23 @@ namespace cw } } - // complete the instantiation - + // Complete the instantiation + + // Call the custom instance create() function. if((rc = class_desc->members->create( inst )) != kOkRC ) { rc = cwLogError(kInvalidArgRC,"Instantiation failed on instance '%s'.", inst->label ); goto errLabel; } - + + // Create the instance->varMap[] lookup array if((rc =_create_instance_var_map( inst )) != kOkRC ) goto errLabel; - + + // _complete_input_connections(inst); - + + // call the 'value()' function to inform the instance of the current value of all of it's variables. if((rc = _call_value_func_on_all_variables( inst )) != kOkRC ) goto errLabel; @@ -873,13 +878,15 @@ namespace cw return rc; } - template< typename T > - rc_t _set_variable_value( flow_t* p, const char* inst_label, const char* var_label, unsigned chIdx, T value ) + rc_t _get_variable( flow_t* p, const char* inst_label, const char* var_label, unsigned chIdx, instance_t*& instPtrRef, variable_t*& varPtrRef ) { rc_t rc = kOkRC; instance_t* inst = nullptr; variable_t* var = nullptr; + varPtrRef = nullptr; + instPtrRef = nullptr; + // locate the proc instance if((inst = instance_find(p,inst_label)) == nullptr ) { @@ -894,6 +901,24 @@ namespace cw goto errLabel; } + instPtrRef = inst; + varPtrRef = var; + + errLabel: + return rc; + } + + template< typename T > + rc_t _set_variable_value( flow_t* p, const char* inst_label, const char* var_label, unsigned chIdx, T value ) + { + rc_t rc = kOkRC; + instance_t* inst = nullptr; + variable_t* var = nullptr; + + // get the variable + if((rc = _get_variable(p,inst_label,var_label,chIdx,inst,var)) != kOkRC ) + goto errLabel; + // set the variable value if((rc = var_set( inst, var->vid, chIdx, value )) != kOkRC ) { @@ -905,6 +930,28 @@ namespace cw return rc; } + template< typename T > + rc_t _get_variable_value( flow_t* p, const char* inst_label, const char* var_label, unsigned chIdx, T& valueRef ) + { + rc_t rc = kOkRC; + instance_t* inst = nullptr; + variable_t* var = nullptr; + + // get the variable + if((rc = _get_variable(p,inst_label,var_label,chIdx,inst,var)) != kOkRC ) + goto errLabel; + + // get the variable value + if((rc = var_get( inst, var->vid, chIdx, valueRef )) != kOkRC ) + { + rc = cwLogError(kOpFailRC,"The variable get failed on instance:'%s' variable:'%s'.",cwStringNullGuard(inst_label),cwStringNullGuard(var_label)); + goto errLabel; + } + + errLabel: + return rc; + } + } @@ -1128,6 +1175,22 @@ cw::rc_t cw::flow::set_variable_value( handle_t h, const char* inst_label, const cw::rc_t cw::flow::set_variable_value( handle_t h, const char* inst_label, const char* var_label, unsigned chIdx, double value ) { return _set_variable_value( _handleToPtr(h), inst_label, var_label, chIdx, value ); } +cw::rc_t cw::flow::get_variable_value( handle_t h, const char* inst_label, const char* var_label, unsigned chIdx, bool& valueRef ) +{ return _get_variable_value( _handleToPtr(h), inst_label, var_label, chIdx, valueRef ); } + +cw::rc_t cw::flow::get_variable_value( handle_t h, const char* inst_label, const char* var_label, unsigned chIdx, int& valueRef ) +{ return _get_variable_value( _handleToPtr(h), inst_label, var_label, chIdx, valueRef ); } + +cw::rc_t cw::flow::get_variable_value( handle_t h, const char* inst_label, const char* var_label, unsigned chIdx, unsigned& valueRef ) +{ return _get_variable_value( _handleToPtr(h), inst_label, var_label, chIdx, valueRef ); } + +cw::rc_t cw::flow::get_variable_value( handle_t h, const char* inst_label, const char* var_label, unsigned chIdx, float& valueRef ) +{ return _get_variable_value( _handleToPtr(h), inst_label, var_label, chIdx, valueRef ); } + +cw::rc_t cw::flow::get_variable_value( handle_t h, const char* inst_label, const char* var_label, unsigned chIdx, double& valueRef ) +{ return _get_variable_value( _handleToPtr(h), inst_label, var_label, chIdx, valueRef ); } + + void cw::flow::print_class_list( handle_t h ) { diff --git a/cwFlow.h b/cwFlow.h index 13f23bf..8e6dc29 100644 --- a/cwFlow.h +++ b/cwFlow.h @@ -73,6 +73,12 @@ namespace cw rc_t set_variable_value( handle_t h, const char* inst_label, const char* var_label, unsigned chIdx, float value ); rc_t set_variable_value( handle_t h, const char* inst_label, const char* var_label, unsigned chIdx, double value ); + rc_t get_variable_value( handle_t h, const char* inst_label, const char* var_label, unsigned chIdx, bool& valueRef ); + rc_t get_variable_value( handle_t h, const char* inst_label, const char* var_label, unsigned chIdx, int& valueRef ); + rc_t get_variable_value( handle_t h, const char* inst_label, const char* var_label, unsigned chIdx, unsigned& valueRef ); + rc_t get_variable_value( handle_t h, const char* inst_label, const char* var_label, unsigned chIdx, float& valueRef ); + rc_t get_variable_value( handle_t h, const char* inst_label, const char* var_label, unsigned chIdx, double& valueRef ); + void print_class_list( handle_t h ); void print_network( handle_t h ); diff --git a/cwFlowCross.cpp b/cwFlowCross.cpp index da8db33..e11bfa5 100644 --- a/cwFlowCross.cpp +++ b/cwFlowCross.cpp @@ -271,6 +271,25 @@ namespace cw return rc; } + template< typename T > + rc_t _get_variable_value( handle_t h, destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, T& valueRef ) + { + rc_t rc = kOkRC; + flow_cross_t* p = _handleToPtr(h); + unsigned flow_idx = destId == kAllDestId ? 0 : _get_flow_index(p, destId ); + unsigned flow_cnt = destId == kAllDestId ? p->netN : flow_idx + 1; + + for(; flow_idx < flow_cnt; ++flow_idx ) + if((rc = get_variable_value( p->netA[ flow_idx ].flowH, inst_label, var_label, chIdx, valueRef )) != kOkRC ) + { + cwLogError(rc,"Get variable value failed on cross-network index: %i.",flow_idx); + goto errLabel; + } + + errLabel: + return rc; + } + } } @@ -421,6 +440,22 @@ cw::rc_t cw::flow_cross::set_variable_value( handle_t h, destId_t destId, const cw::rc_t cw::flow_cross::set_variable_value( handle_t h, destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, double value ) { return _set_variable_value(h,destId,inst_label,var_label,chIdx,value); } + +cw::rc_t cw::flow_cross::get_variable_value( handle_t h, destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, bool& valueRef ) +{ return _get_variable_value(h,destId,inst_label,var_label,chIdx,valueRef); } + +cw::rc_t cw::flow_cross::get_variable_value( handle_t h, destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, int& valueRef ) +{ return _get_variable_value(h,destId,inst_label,var_label,chIdx,valueRef); } + +cw::rc_t cw::flow_cross::get_variable_value( handle_t h, destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, unsigned& valueRef ) +{ return _get_variable_value(h,destId,inst_label,var_label,chIdx,valueRef); } + +cw::rc_t cw::flow_cross::get_variable_value( handle_t h, destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, float& valueRef ) +{ return _get_variable_value(h,destId,inst_label,var_label,chIdx,valueRef); } + +cw::rc_t cw::flow_cross::get_variable_value( handle_t h, destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, double& valueRef ) +{ return _get_variable_value(h,destId,inst_label,var_label,chIdx,valueRef); } + cw::rc_t cw::flow_cross::begin_cross_fade( handle_t h, unsigned crossFadeMs ) { rc_t rc = kOkRC; @@ -471,3 +506,16 @@ void cw::flow_cross::print_network( handle_t h, destId_t destId ) } +void cw::flow_cross::report( handle_t h ) +{ + flow_cross_t* p = _handleToPtr(h); + unsigned cur_flow_idx = _get_flow_index( p, kCurDestId ); + unsigned next_flow_idx = _get_flow_index( p, kNextDestId ); + + for(unsigned i=0; inetN; ++i) + { + const char* label = i==cur_flow_idx ? "Current" : (i==next_flow_idx ? "Next" : ""); + printf("%s %f : ",label,p->netA[i].fadeGain ); + } + printf("\n"); +} diff --git a/cwFlowCross.h b/cwFlowCross.h index 616d421..dc501bc 100644 --- a/cwFlowCross.h +++ b/cwFlowCross.h @@ -36,10 +36,17 @@ namespace cw rc_t set_variable_value( handle_t h, destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, float value ); rc_t set_variable_value( handle_t h, destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, double value ); + rc_t get_variable_value( handle_t h, destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, bool& valueRef ); + rc_t get_variable_value( handle_t h, destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, int& valueRef ); + rc_t get_variable_value( handle_t h, destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, unsigned& valueRef ); + rc_t get_variable_value( handle_t h, destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, float& valueRef ); + rc_t get_variable_value( handle_t h, destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, double& valueRef ); + rc_t begin_cross_fade( handle_t h, unsigned crossFadeMs ); void print( handle_t h ); void print_network( handle_t h, flow_cross::destId_t destId ); + void report( handle_t h ); } } diff --git a/cwIoFlow.cpp b/cwIoFlow.cpp index 1ddc590..878e09b 100644 --- a/cwIoFlow.cpp +++ b/cwIoFlow.cpp @@ -437,8 +437,28 @@ cw::rc_t cw::io_flow::set_variable_value( handle_t h, flow_cross::destId_t destI cw::rc_t cw::io_flow::begin_cross_fade( handle_t h, unsigned crossFadeMs ) { return flow_cross::begin_cross_fade( _handleToPtr(h)->crossFlowH, crossFadeMs ); } + +cw::rc_t cw::io_flow::get_variable_value( handle_t h, flow_cross::destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, bool& valueRef ) +{ return flow_cross::get_variable_value( _handleToPtr(h)->crossFlowH, destId, inst_label, var_label, chIdx, valueRef ); } + +cw::rc_t cw::io_flow::get_variable_value( handle_t h, flow_cross::destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, int& valueRef ) +{ return flow_cross::get_variable_value( _handleToPtr(h)->crossFlowH, destId, inst_label, var_label, chIdx, valueRef ); } + +cw::rc_t cw::io_flow::get_variable_value( handle_t h, flow_cross::destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, unsigned& valueRef ) +{ return flow_cross::get_variable_value( _handleToPtr(h)->crossFlowH, destId, inst_label, var_label, chIdx, valueRef ); } + +cw::rc_t cw::io_flow::get_variable_value( handle_t h, flow_cross::destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, float& valueRef ) +{ return flow_cross::get_variable_value( _handleToPtr(h)->crossFlowH, destId, inst_label, var_label, chIdx, valueRef ); } + +cw::rc_t cw::io_flow::get_variable_value( handle_t h, flow_cross::destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, double& valueRef ) +{ return flow_cross::get_variable_value( _handleToPtr(h)->crossFlowH, destId, inst_label, var_label, chIdx, valueRef ); } + + void cw::io_flow::print( handle_t h ) { return flow_cross::print( _handleToPtr(h)->crossFlowH ); } void cw::io_flow::print_network( handle_t h, flow_cross::destId_t destId ) { return flow_cross::print_network( _handleToPtr(h)->crossFlowH, destId ); } + +void cw::io_flow::report( handle_t h ) +{ flow_cross::report( _handleToPtr(h)->crossFlowH ); } diff --git a/cwIoFlow.h b/cwIoFlow.h index 4a7fd8d..a5266bf 100644 --- a/cwIoFlow.h +++ b/cwIoFlow.h @@ -26,12 +26,19 @@ namespace cw rc_t set_variable_value( handle_t h, flow_cross::destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, unsigned value ); rc_t set_variable_value( handle_t h, flow_cross::destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, float value ); rc_t set_variable_value( handle_t h, flow_cross::destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, double value ); - + rc_t begin_cross_fade( handle_t h, unsigned crossFadeMs ); + + rc_t get_variable_value( handle_t h, flow_cross::destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, bool& valueRef ); + rc_t get_variable_value( handle_t h, flow_cross::destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, int& valueRef ); + rc_t get_variable_value( handle_t h, flow_cross::destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, unsigned& valueRef ); + rc_t get_variable_value( handle_t h, flow_cross::destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, float& valueRef ); + rc_t get_variable_value( handle_t h, flow_cross::destId_t destId, const char* inst_label, const char* var_label, unsigned chIdx, double& valueRef ); void print( handle_t h ); void print_network( handle_t h, flow_cross::destId_t destId ); + void report( handle_t h ); } }