From c55f7d34ec2b6708919e370f8ba8fdceefc3d0b7 Mon Sep 17 00:00:00 2001 From: kevin Date: Thu, 12 Sep 2024 17:18:42 -0400 Subject: [PATCH] 1. caw program parameters are now in snake_case rather than camelCase. 2. Column headers are now printed for caw 'log' output. 3. The websocket LLL_NOTICE logs may now be turned off using the 'extraLogsFl'. 4. Changed the 'Number' processor to work with the 'feedback' example. 5. README.md updates. --- README.md | 1 + cwFlow.cpp | 15 ++++++++------- cwFlowProc.cpp | 24 +++++++++++++++--------- cwFlowTypes.cpp | 16 +++++++++++++--- cwFlowTypes.h | 5 +++-- cwUi.cpp | 12 ++++++++---- cwUi.h | 7 +++++-- cwWebSock.cpp | 10 +++++++--- cwWebSock.h | 3 ++- cwWebSockSvr.cpp | 8 +++++--- cwWebSockSvr.h | 3 ++- flow/proc_dict.cfg | 4 ++-- 12 files changed, 71 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 3eb42bb..f5e924f 100644 --- a/README.md +++ b/README.md @@ -1148,6 +1148,7 @@ channel that does not exist. - DONE: All cfg to value conversion should go through `cfg_to_value()`. +- Try using adding 'time' type and 'cfg' types to a 'log:{...}' stmt. Names ------ diff --git a/cwFlow.cpp b/cwFlow.cpp index 8758b2b..51b6481 100644 --- a/cwFlow.cpp +++ b/cwFlow.cpp @@ -710,17 +710,18 @@ cw::rc_t cw::flow::create( handle_t& hRef, p->sample_rate = kDefaultSampleRate; p->maxCycleCount = kInvalidCnt; p->proj_dir = proj_dir; + p->printLogHdrFl = true; // parse the optional args if((rc = flowCfg->readv("network", 0, p->networkCfg, "non_real_time_fl", kOptFl, p->non_real_time_fl, - "framesPerCycle", kOptFl, p->framesPerCycle, + "frames_per_cycle", kOptFl, p->framesPerCycle, "sample_rate", kOptFl, p->sample_rate, - "maxCycleCount", kOptFl, maxCycleCount, - "durLimitSecs", kOptFl, durLimitSecs, + "max_cycle_count", kOptFl, maxCycleCount, + "dur_limit_secs", kOptFl, durLimitSecs, "preset", kOptFl, p->init_net_preset_label, - "printClassDictFl", kOptFl, printClassDictFl, - "printNetworkFl", kOptFl, p->printNetworkFl, + "print_class_dict_fl", kOptFl, printClassDictFl, + "print_network_fl", kOptFl, p->printNetworkFl, "multiPriPresetProbFl", kOptFl, p->multiPriPresetProbFl, "multiSecPresetProbFl", kOptFl, p->multiSecPresetProbFl, "multiPresetInterpFl", kOptFl, p->multiPresetInterpFl)) != kOkRC ) @@ -875,10 +876,10 @@ cw::rc_t cw::flow::exec_cycle( handle_t h ) cw::rc_t cw::flow::exec( handle_t h ) { rc_t rc = kOkRC; - flow_t* p = _handleToPtr(h); + //flow_t* p = _handleToPtr(h); while( rc == kOkRC ) - rc = exec_cycle(p->net); + rc = exec_cycle(h); return rc; } diff --git a/cwFlowProc.cpp b/cwFlowProc.cpp index 5d184dc..9921484 100644 --- a/cwFlowProc.cpp +++ b/cwFlowProc.cpp @@ -2220,7 +2220,7 @@ namespace cw // Register variables and get their current value if((rc = var_register_and_get( proc, kAnyChIdx, - kChCntPid, "chCnt", kBaseSfxId, chCnt, + kChCntPid, "ch_cnt", kBaseSfxId, chCnt, kSratePId, "srate", kBaseSfxId, srate)) != kOkRC ) { goto errLabel; @@ -5181,7 +5181,7 @@ namespace cw rc_t rc = kOkRC; const char* out_type_label = nullptr; unsigned out_type_fl = kInvalidTFl; - variable_t* dum = nullptr; + variable_t* first_in_var = nullptr; unsigned inVarN = var_mult_count(proc,"in"); unsigned inSfxIdA[ inVarN ]; @@ -5206,12 +5206,15 @@ namespace cw // register each of the input vars for(unsigned i=0; iinVarN; ++i) { - variable_t* dum; - if((rc = var_register(proc, "in", inSfxIdA[i], kInPId+i, kAnyChIdx, nullptr, dum )) != kOkRC ) + variable_t* foo; + if((rc = var_register(proc, "in", inSfxIdA[i], kInPId+i, kAnyChIdx, nullptr, foo )) != kOkRC ) { rc = cwLogError(rc,"Variable registration failed for the variable 'in:%i'.",inSfxIdA[i]);; goto errLabel; } + + if( i==0 ) + first_in_var = foo; } @@ -5227,14 +5230,14 @@ namespace cw if( textIsEqual(out_type_label,"") ) { // ... then get the type of the first input variable - if((rc = var_find(proc, kInPId, kAnyChIdx, dum )) != kOkRC ) + if((rc = var_find(proc, kInPId, kAnyChIdx, first_in_var )) != kOkRC ) { goto errLabel; } // if the first input variable's type has a valid type is not included in the - if( dum->value != nullptr ) - out_type_fl = (dum->value->tflag & kTypeMask) ; + if( first_in_var->value != nullptr ) + out_type_fl = (first_in_var->value->tflag & kTypeMask) ; } else { @@ -5248,7 +5251,7 @@ namespace cw } // Create the output variable - if((rc = var_create( proc, "out", kBaseSfxId, kOutPId, kAnyChIdx, nullptr, out_type_fl, dum )) != kOkRC ) + if((rc = var_create( proc, "out", kBaseSfxId, kOutPId, kAnyChIdx, nullptr, out_type_fl, first_in_var )) != kOkRC ) { goto errLabel; } @@ -5267,7 +5270,6 @@ namespace cw { if( var->vid == kTriggerPId ) { - if( proc->ctx->isInRuntimeFl ) p->store_vid = kOutPId; } else @@ -5279,7 +5281,11 @@ namespace cw p->store_vid = var->vid; } else + { + // This call to set the a variable is safe because + // we are in init-time not runtime and therefore single threaded var_set( proc, kOutPId, kAnyChIdx, var->value ); + } } } diff --git a/cwFlowTypes.cpp b/cwFlowTypes.cpp index a0e2b61..ce40ba6 100644 --- a/cwFlowTypes.cpp +++ b/cwFlowTypes.cpp @@ -291,7 +291,7 @@ namespace cw break; case kStringTFl: - cwLogPrint("%s ", v->u.s); + cwLogPrint("s:%s ", v->u.s); break; case kTimeTFl: @@ -299,6 +299,7 @@ namespace cw break; case kCfgTFl: + cwLogPrint("c:"); if( v->u.cfg != nullptr ) v->u.cfg->print(); break; @@ -2009,8 +2010,17 @@ cw::rc_t cw::flow::var_call_custom_value_func( variable_t* var ) goto errLabel; if( var->flags & kLogVarFl ) - { - cwLogPrint("cycle: %8i ",var->proc->ctx->cycleIndex); + { + + if( var->proc->ctx->printLogHdrFl ) + { + cwLogPrint("%s","exe cycle: process: id: variable: id vid ch : : : type:value : destination\n"); + cwLogPrint("%s","---------- ----------- ----- --------------- -- --- ----- ------------: -------------\n"); + //: 0 : a: 0: out: 0 vid: 2 ch: -1 : : : : + var->proc->ctx->printLogHdrFl = false; + } + + cwLogPrint("%8i ",var->proc->ctx->cycleIndex); cwLogPrint("%10s:%5i", var->proc->label,var->proc->label_sfx_id); if( var->chIdx == kAnyChIdx ) diff --git a/cwFlowTypes.h b/cwFlowTypes.h index 6d261ae..b5c316f 100644 --- a/cwFlowTypes.h +++ b/cwFlowTypes.h @@ -345,7 +345,6 @@ namespace cw const object_t* networkCfg; // 'network' cfg from flowCfg bool printNetworkFl; - bool non_real_time_fl; // set if this is a non-real-time program unsigned framesPerCycle; // sample frames per cycle (64) srate_t sample_rate; // default sample rate (48000.0) @@ -354,7 +353,9 @@ namespace cw bool isInRuntimeFl; // Set when compile-time is complete - unsigned cycleIndex; // Incremented with each processing cycle + unsigned cycleIndex; // Incremented with each processing cycle + + bool printLogHdrFl; bool multiPriPresetProbFl; // If set then probability is used to choose presets on multi-preset application bool multiSecPresetProbFl; // diff --git a/cwUi.cpp b/cwUi.cpp index 455d118..a81c02a 100644 --- a/cwUi.cpp +++ b/cwUi.cpp @@ -2337,6 +2337,7 @@ cw::rc_t cw::ui::ws::parseArgs( const object_t& o, args_t& args, const char* ob "idleMsgPeriodMs", args.idleMsgPeriodMs, "queueBlkCnt", args.queueBlkCnt, "queueBlkByteCnt", args.queueBlkByteCnt, + "extraLogsFl", args.extraLogsFl, "uiCfgFn", uiCfgFn )) != kOkRC ) { rc = cwLogError(rc,"'ui' cfg. parse failed."); @@ -2401,7 +2402,8 @@ cw::rc_t cw::ui::ws::create( handle_t& h, args.xmtBufByteN, args.fmtBufByteN, args.queueBlkCnt, - args.queueBlkByteCnt); + args.queueBlkByteCnt, + args.extraLogsFl); } @@ -2420,7 +2422,8 @@ cw::rc_t cw::ui::ws::create( handle_t& h, unsigned xmtBufByteN, unsigned fmtBufByteN, unsigned queueBlkCnt, - unsigned queueBlkByteCnt ) + unsigned queueBlkByteCnt, + bool extraLogsFl) { rc_t rc = kOkRC; @@ -2440,7 +2443,7 @@ cw::rc_t cw::ui::ws::create( handle_t& h, void* wsCbA = wsCbFunc==nullptr ? p : cbArg; // create the websocket - if((rc = websock::create(p->wsH, wsCbF, wsCbA, physRootDir, dfltPageFn, port, protocolA, protocolN, queueBlkCnt, queueBlkByteCnt )) != kOkRC ) + if((rc = websock::create(p->wsH, wsCbF, wsCbA, physRootDir, dfltPageFn, port, protocolA, protocolN, queueBlkCnt, queueBlkByteCnt, extraLogsFl )) != kOkRC ) { cwLogError(rc,"UI Websock create failed."); goto errLabel; @@ -2630,7 +2633,8 @@ cw::rc_t cw::ui::srv::create( handle_t& h, unsigned xmtBufByteN, unsigned fmtBufByteN, unsigned queueBlkCnt, - unsigned queueBlkByteCnt ) + unsigned queueBlkByteCnt, + bool extraLogsFl ) { rc_t rc = kOkRC; if((rc = destroy(h)) != kOkRC ) diff --git a/cwUi.h b/cwUi.h index 30bdc49..58ef92d 100644 --- a/cwUi.h +++ b/cwUi.h @@ -195,6 +195,7 @@ namespace cw unsigned idleMsgPeriodMs; // min period without messages before an idle message is generated unsigned queueBlkCnt; unsigned queueBlkByteCnt; + bool extraLogsFl; // Report the websock LLL_NOTICE logs } args_t; rc_t parseArgs( const object_t& o, args_t& args, const char* object_label="ui" ); @@ -224,7 +225,8 @@ namespace cw unsigned xmtBufByteN = 1024, unsigned fmtBufByteN = 4096, unsigned queueBlkCnt = 4, - unsigned queueBlkByteCnt = 4096 ); + unsigned queueBlkByteCnt = 4096, + bool extraLogsFl = false ); rc_t destroy( handle_t& h ); @@ -275,7 +277,8 @@ namespace cw unsigned xmtBufByteN = 1024, unsigned fmtBufByteN = 4096, unsigned queueBlkCnt = 4, - unsigned queueBlkByteCnt = 4096 ); + unsigned queueBlkByteCnt = 4096, + bool extraLogsFl = false ); rc_t destroy( handle_t& h ); diff --git a/cwWebSock.cpp b/cwWebSock.cpp index cb6eac7..3371b55 100644 --- a/cwWebSock.cpp +++ b/cwWebSock.cpp @@ -596,7 +596,8 @@ cw::rc_t cw::websock::create( const protocol_t* protocolArgA, unsigned protocolN, unsigned queueBlkCnt, - unsigned queueBlkByteCnt ) + unsigned queueBlkByteCnt, + bool extraLogsFl ) { rc_t rc; struct lws_context_creation_info info; @@ -606,8 +607,11 @@ cw::rc_t cw::websock::create( return rc; websock_t* p = mem::allocZ(); - - int logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE; + + int logs = LLL_USER | LLL_ERR | LLL_WARN; + if( extraLogsFl ) + logs |= LLL_NOTICE; + lws_set_log_level(logs, nullptr); p->_event_loop_ops_custom = {}; diff --git a/cwWebSock.h b/cwWebSock.h index b7884ed..f4e528e 100644 --- a/cwWebSock.h +++ b/cwWebSock.h @@ -47,7 +47,8 @@ namespace cw const protocol_t* protocolA, unsigned protocolN, unsigned queueBlkCnt, - unsigned queueBlkByteCnt ); + unsigned queueBlkByteCnt, + bool extraLogsFl); rc_t destroy( handle_t& h ); diff --git a/cwWebSockSvr.cpp b/cwWebSockSvr.cpp index 3267d43..e3d1528 100644 --- a/cwWebSockSvr.cpp +++ b/cwWebSockSvr.cpp @@ -59,7 +59,8 @@ cw::rc_t cw::websockSrv::create( unsigned protocolN, unsigned timeOutMs, unsigned queueBlkCnt, - unsigned queueBlkByteCnt ) + unsigned queueBlkByteCnt, + bool extraLogsFl ) { rc_t rc; if((rc = destroy(h)) != kOkRC ) @@ -67,7 +68,7 @@ cw::rc_t cw::websockSrv::create( websockSrv_t* p = mem::allocZ(); - if((rc = websock::create( p->_websockH, cbFunc, cbArg, physRootDir, dfltHtmlPageFn, port, protocolA, protocolN, queueBlkCnt, queueBlkByteCnt )) != kOkRC ) + if((rc = websock::create( p->_websockH, cbFunc, cbArg, physRootDir, dfltHtmlPageFn, port, protocolA, protocolN, queueBlkCnt, queueBlkByteCnt, extraLogsFl )) != kOkRC ) goto errLabel; @@ -181,6 +182,7 @@ cw::rc_t cw::websockSrvTest( const object_t* cfg ) unsigned xmtBufByteN = 128; unsigned queueBlkCnt = 3; unsigned queueBlkByteCnt= 4096; + bool extraLogsFl = true; appCtx_t appCtx; enum @@ -203,7 +205,7 @@ cw::rc_t cw::websockSrvTest( const object_t* cfg ) unsigned protocolN = sizeof(protocolA)/sizeof(protocolA[0]); - if((rc = websockSrv::create( h, websockCb, &appCtx, physRootDir, dfltHtmlPageFn, port, protocolA, protocolN, timeOutMs, queueBlkCnt, queueBlkByteCnt )) != kOkRC ) + if((rc = websockSrv::create( h, websockCb, &appCtx, physRootDir, dfltHtmlPageFn, port, protocolA, protocolN, timeOutMs, queueBlkCnt, queueBlkByteCnt, extraLogsFl )) != kOkRC ) return rc; appCtx.wsH = websockSrv::websockHandle(h); diff --git a/cwWebSockSvr.h b/cwWebSockSvr.h index 2be27e4..120a491 100644 --- a/cwWebSockSvr.h +++ b/cwWebSockSvr.h @@ -18,7 +18,8 @@ namespace cw { unsigned protocolN, unsigned websockTimeOutMs, unsigned queueBlkCnt, - unsigned queueBlkByteCnt); + unsigned queueBlkByteCnt, + bool extraLogsFl ); rc_t destroy( handle_t& h ); diff --git a/flow/proc_dict.cfg b/flow/proc_dict.cfg index 666838b..368cfcf 100644 --- a/flow/proc_dict.cfg +++ b/flow/proc_dict.cfg @@ -142,7 +142,7 @@ sine_tone: { vars: { srate: { type:srate, value:0, doc:"Sine tone sample rate. 0=Use default system sample rate"} - chCnt: { type:uint, value:2, doc:"Output signal channel count."}, + ch_cnt: { type:uint, value:2, doc:"Output signal channel count."}, hz: { type:coeff, value:440.0, doc:"Frequency in Hertz."}, phase: { type:coeff, value:0.0, doc:"Offset phase in radians."}, dc: { type:coeff, value:0.0, doc:"DC offset applied after gain."}, @@ -154,7 +154,7 @@ a220 : { hz:220 }, a440 : { hz:440 }, a880 : { hz:880 }, - mono: { chCnt:1, gain:0.75 } + mono: { ch_cnt:1, gain:0.75 } } }