cwFlowTypes.h,cwFlowProc.cpp,proc_dict.cfg : Add 'parallel' param to 'poly' proc.

This commit is contained in:
kevin 2024-09-16 08:19:09 -04:00
parent e1ebbeac6c
commit 3f9458afb2
3 changed files with 46 additions and 25 deletions

View File

@ -31,6 +31,8 @@
#include "cwWaveTableBank.h" #include "cwWaveTableBank.h"
#include "cwThread.h"
#include "cwThreadMach.h"
namespace cw namespace cw
{ {
@ -214,31 +216,37 @@ namespace cw
{ {
enum enum
{ {
kParallelFlPId,
kCountPId, kCountPId,
kOrderPId,
}; };
typedef struct typedef struct
{ {
unsigned count; unsigned count;
network_t net; network_t net;
network_order_id_t orderId; bool parallel_fl;
thread_mach::handle_t threadMachH;
} inst_t; } inst_t;
bool _thread_func( void* arg )
{
return true;
}
rc_t create( proc_t* proc ) rc_t create( proc_t* proc )
{ {
rc_t rc = kOkRC; rc_t rc = kOkRC;
inst_t* inst = mem::allocZ<inst_t>(); inst_t* inst = mem::allocZ<inst_t>();
const object_t* networkCfg = nullptr; const object_t* networkCfg = nullptr;
const char* order_label = nullptr;
variable_t* proxyVarL = nullptr; variable_t* proxyVarL = nullptr;
proc->userPtr = inst; proc->userPtr = inst;
if((rc = var_register_and_get( proc, kAnyChIdx, if((rc = var_register_and_get( proc, kAnyChIdx,
kCountPId, "count", kBaseSfxId, inst->count, kParallelFlPId, "parallel_fl", kBaseSfxId, inst->parallel_fl,
kOrderPId, "order", kBaseSfxId, order_label )) != kOkRC ) kCountPId, "count", kBaseSfxId, inst->count )) != kOkRC )
goto errLabel; goto errLabel;
if( inst->count == 0 ) if( inst->count == 0 )
@ -253,19 +261,6 @@ namespace cw
goto errLabel; goto errLabel;
} }
// get the network exec. order type
if( textIsEqual(order_label,"net") )
inst->orderId = kNetFirstPolyOrderId;
else
{
if( textIsEqual(order_label,"proc") )
inst->orderId = kProcFirstPolyOrderId;
else
{
rc = cwLogError(kInvalidArgRC,"'%s' is not one of the valid order types (i.e. 'net','proc').",order_label);
goto errLabel;
}
}
if((rc = network_create(proc->ctx,networkCfg,inst->net,proxyVarL,inst->count)) != kOkRC ) if((rc = network_create(proc->ctx,networkCfg,inst->net,proxyVarL,inst->count)) != kOkRC )
{ {
@ -273,6 +268,16 @@ namespace cw
goto errLabel; goto errLabel;
} }
if( inst->parallel_fl )
{
if((rc = thread_mach::create( inst->threadMachH, _thread_func, proc->net->poly_voiceA, sizeof(poly_voice_t), inst->count )) != kOkRC )
{
rc = cwLogError(rc,"Thread machine create failed.");
goto errLabel;
}
}
// Set the internal net pointer in the base proc instance // Set the internal net pointer in the base proc instance
// so that network based utilities can scan it // so that network based utilities can scan it
@ -287,8 +292,9 @@ namespace cw
inst_t* p = (inst_t*)proc->userPtr; inst_t* p = (inst_t*)proc->userPtr;
network_destroy(p->net); network_destroy(p->net);
thread_mach::destroy(p->threadMachH);
mem::release( proc->userPtr ); mem::release( proc->userPtr );
return kOkRC; return kOkRC;
} }
@ -302,9 +308,16 @@ namespace cw
inst_t* p = (inst_t*)proc->userPtr; inst_t* p = (inst_t*)proc->userPtr;
rc_t rc = kOkRC; rc_t rc = kOkRC;
if((rc = exec_cycle(p->net)) != kOkRC ) if( p->parallel_fl )
{ {
rc = cwLogError(rc,"poly internal network exec failed.");
}
else
{
if((rc = exec_cycle(p->net)) != kOkRC )
{
rc = cwLogError(rc,"poly internal network exec failed.");
}
} }
return rc; return rc;

View File

@ -317,12 +317,20 @@ namespace cw
} net_global_var_t; } net_global_var_t;
typedef struct poly_voice_str
{
struct network_str* net; // Network containing the proc's referened by proc_idx, proc_cnt
unsigned proc_idx; // Index into network_t.proc_array[] of first proc in voice
unsigned proc_cnt; // Count of proc's in the voice
rc_t rc; // Result code from last call to exec_cycle()
} poly_voice_t;
typedef struct network_str typedef struct network_str
{ {
const object_t* procsCfg; // network proc list const object_t* procsCfg; // network proc list
const object_t* presetsCfg; // presets designed for this network const object_t* presetsCfg; // presets designed for this network
unsigned* poly_proc_idxA; // poly_proc_idxA[ poly_cnt ]. Index into proc_array[] of first proc in each network poly_voice_t* poly_voiceA; // poly_voiceA[ poly_cnt ].
unsigned poly_cnt; // count of duplicated networks in the list unsigned poly_cnt; // count of duplicated networks in the list
struct proc_str** proc_array; struct proc_str** proc_array;

View File

@ -565,8 +565,8 @@
poly: { poly: {
vars: { vars: {
count: { type:uint, doc:"Count of network duplicates." }, count: { type:uint, flags:['init'], value:1, doc:"Count of network duplicates." },
order: { type:string, value:"net", doc:"Execution order 'net'=net first 'proc'=proc first" } parallel_fl: { type:bool, flags:['init'], value:false, doc:"True to run voices concurrently." }
} }
} }