From 2e2f57f45a02b88c502cefff246def405fdb9a1d Mon Sep 17 00:00:00 2001 From: kevin Date: Sat, 13 Jan 2024 10:16:37 -0500 Subject: [PATCH] cwFlow.h/cpp : Added apply_preset( handle_t, multi_preset_selector& ) and _select_ranked_ele_by_rank_prob(). --- cwFlow.cpp | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- cwFlow.h | 2 ++ 2 files changed, 94 insertions(+), 3 deletions(-) diff --git a/cwFlow.cpp b/cwFlow.cpp index 621a042..00b1f90 100644 --- a/cwFlow.cpp +++ b/cwFlow.cpp @@ -8,6 +8,7 @@ #include "cwVectOps.h" #include "cwMtx.h" #include "cwDspTypes.h" // real_t, sample_t +#include "cwFlowDecl.h" #include "cwFlow.h" #include "cwFlowTypes.h" #include "cwFlowProc.h" @@ -922,7 +923,7 @@ namespace cw // get the variable if((rc = _get_variable(p,inst_label,var_label,chIdx,inst,var)) != kOkRC ) - goto errLabel; + goto errLabel; // set the variable value if((rc = var_set( inst, var->vid, chIdx, value )) != kOkRC ) @@ -944,7 +945,7 @@ namespace cw // get the variable if((rc = _get_variable(p,inst_label,var_label,chIdx,inst,var)) != kOkRC ) - goto errLabel; + goto errLabel; // get the variable value if((rc = var_get( inst, var->vid, chIdx, valueRef )) != kOkRC ) @@ -956,7 +957,62 @@ namespace cw errLabel: return rc; } - + + unsigned _select_ranked_ele_by_rank_prob( const preset_order_t* rankV, unsigned rankN ) + { + unsigned threshV[ rankN ]; + unsigned uniqueRankV[ rankN ]; + unsigned uniqueRankN = 0; + unsigned sel_idx = rankN - 1; // + + if( rankN == 0 ) + return kInvalidIdx; + + if( rankN == 1 ) + return 0; + + // for each possible rank value + for(unsigned i=0; i 0 ) + { + unsigned sel_preset_idx; + + if((sel_preset_idx = _select_ranked_ele_by_rank_prob( multi_preset_sel.presetA, multi_preset_sel.presetN )) == kInvalidIdx ) + { + rc = cwLogWarning("The multi-preset select function failed. Selecting preset 0."); + sel_preset_idx = 0; + } + + if( multi_preset_sel.presetA[sel_preset_idx].preset_label == nullptr ) + { + rc = cwLogError(kInvalidStateRC,"The selected multi-preset label is empty."); + goto errLabel; + } + + cwLogInfo("Multi-preset select:%s : %i from %i", cwStringNullGuard(multi_preset_sel.presetA[sel_preset_idx].preset_label), + sel_preset_idx, multi_preset_sel.presetN ); + + + rc = apply_preset( h, multi_preset_sel.presetA[sel_preset_idx].preset_label ); + } + + errLabel: + + return rc; +} + + cw::rc_t cw::flow::set_variable_value( handle_t h, const char* inst_label, const char* var_label, unsigned chIdx, bool value ) { return _set_variable_value( _handleToPtr(h), inst_label, var_label, chIdx, value ); } diff --git a/cwFlow.h b/cwFlow.h index 69e024d..4d12578 100644 --- a/cwFlow.h +++ b/cwFlow.h @@ -46,6 +46,7 @@ namespace cw } external_device_t; + void print_abuf( const struct abuf_str* abuf ); void print_external_device( const external_device_t* dev ); @@ -66,6 +67,7 @@ namespace cw rc_t exec( handle_t h ); rc_t apply_preset( handle_t h, const char* presetLabel ); + rc_t apply_preset( handle_t h, const multi_preset_selector_t& multi_preset_sel ); rc_t set_variable_value( handle_t h, const char* inst_label, const char* var_label, unsigned chIdx, bool value ); rc_t set_variable_value( handle_t h, const char* inst_label, const char* var_label, unsigned chIdx, int value );