cwFlowTypes.h/cpp : Remove value_t related functions and structures to cwFlowValue.h/cpp.

Added proc_t.presetL.
preset_value_t is now a unoin of preset_val_t and net_preset_val_t and proc_var_val_t
Added var_desc_has_recd_format(),proc_preset_find(),global_var(),global_var_alloc()
Added Added var_register_and_set() variations for the 'record' type.
Added var_set() for 'record' type.
This commit is contained in:
kevin 2024-12-20 14:19:39 -05:00
parent fefbe68309
commit e545c06818
2 changed files with 349 additions and 1299 deletions

File diff suppressed because it is too large Load Diff

View File

@ -5,128 +5,6 @@ namespace cw
namespace flow
{
typedef dsp::coeff_t coeff_t;
typedef dsp::sample_t sample_t;
typedef dsp::fd_sample_t fd_sample_t;
typedef dsp::srate_t srate_t;
typedef dsp::ftime_t ftime_t;
typedef unsigned uint_t;
typedef int int_t;
typedef unsigned vid_t;
enum {
kBaseSfxId = 0,
kFbufVectN = 3, // count of signal vectors in fbuf (mag,phs,hz)
kAnyChIdx = kInvalidIdx,
kLocalValueN = 2,
kDefaultFramesPerCycle=64,
kDefaultSampleRate=48000
};
typedef struct abuf_str
{
srate_t srate; // Signal sample rate
unsigned chN; // Count of channels
unsigned frameN; // Count of sample frames per channel
unsigned bufAllocSmpN; // Size of allocated buf[] in samples.
sample_t* buf; // buf[ chN ][ frameN ]
} abuf_t;
typedef struct fbuf_str
{
unsigned memByteN; // Count of bytes in mem[].
void* mem; // mem[ memByteN ] All dynamically allocated memory used by this fbuf.
srate_t srate; // signal sample rate
unsigned flags; // See kXXXFbufFl
unsigned chN; // count of channels
unsigned* maxBinN_V; // maxBinN_V[chN] max value that binN_V[i] is allowed to take
unsigned* binN_V; // binN_V[ chN ] count of sample frames per channel
unsigned* hopSmpN_V; // hopSmpN_V[ chN ] hop sample count
fd_sample_t** magV; // magV[ chN ][ binN ]
fd_sample_t** phsV; // phsV[ chN ][ binN ]
fd_sample_t** hzV; // hzV[ chN ][ binN ]
bool* readyFlV; // readyFlV[chN] true if this channel is ready to be processed (used to sync. fbuf rate to abuf rate)
} fbuf_t;
typedef struct mbuf_str
{
const midi::ch_msg_t* msgA;
unsigned msgN;
} mbuf_t;
enum
{
kInvalidTFl = 0x00000000,
kBoolTFl = 0x00000001,
kUIntTFl = 0x00000002,
kIntTFl = 0x00000004,
kFloatTFl = 0x00000008,
kDoubleTFl = 0x00000010,
kBoolMtxTFl = 0x00000020,
kUIntMtxTFl = 0x00000040,
kIntMtxTFl = 0x00000080,
kFloatMtxTFl = 0x00000100,
kDoubleMtxTFl= 0x00000200,
kABufTFl = 0x00000400,
kFBufTFl = 0x00000800,
kMBufTFl = 0x00001000,
kStringTFl = 0x00002000,
kTimeTFl = 0x00004000,
kCfgTFl = 0x00008000,
kTypeMask = 0x0000ffff,
kRuntimeTFl = 0x80000000,
kNumericTFl = kBoolTFl | kUIntTFl | kIntTFl | kFloatTFl | kDoubleTFl,
kMtxTFl = kBoolMtxTFl | kUIntMtxTFl | kIntMtxTFl | kFloatMtxTFl | kDoubleMtxTFl,
kAllTFl = kTypeMask
};
typedef struct mtx_str
{
union {
struct mtx::mtx_str< unsigned >* u;
struct mtx::mtx_str< int >* i;
struct mtx::mtx_str< float >* f;
struct mtx::mtx_str< double >* d;
} u;
} mtx_t;
typedef struct value_str
{
unsigned tflag;
union {
bool b;
uint_t u;
int_t i;
float f;
double d;
mtx_t* mtx;
abuf_t* abuf;
fbuf_t* fbuf;
mbuf_t* mbuf;
char* s;
const object_t* cfg;
void* p;
} u;
struct value_str* link;
} value_t;
struct proc_str;
struct variable_str;
@ -153,15 +31,21 @@ namespace cw
member_func_t exec;
member_func_t report;
} class_members_t;
typedef struct var_desc_str
{
const object_t* cfg; // The cfg object that describes this variable from 'flow_class'.
const object_t* val_cfg; // An object containing the default value for this variable.
const object_t* fmt_cfg; // An object containg the format (e.g. record fields) information
const char* label; // Name of this var.
unsigned type; // Value type id (e.g. kBoolTFl, kIntTFl, ...)
unsigned flags; // Attributes for this var. (e.g. kSrcVarFl )
const char* docText; // User help string for this var.
union
{
recd_fmt_t* recd_fmt; // the 'recd_type.base' is never set in 'recd_type' because it is only valid once the var is instantiated
} fmt;
char* proxyProcLabel;
char* proxyVarLabel;
@ -216,7 +100,7 @@ namespace cw
unsigned local_value_idx; // local_value[] is double buffered to allow the cur value of the buf[] to be held while the next value is validated (see _var_set_template())
struct variable_str* src_var; // pointer to this input variables source link (or null if it uses the local_value)
value_t* value; // pointer to the value associated with this variable
struct variable_str* var_link; // instance.varL list link
struct variable_str* ch_link; // list of channels that share this variable (rooted on 'any' channel - in order by channel number)
@ -242,6 +126,7 @@ namespace cw
unsigned label_sfx_id; // label suffix id (set to kBaseSfxId (0) unless poly is non-null)
const object_t* proc_cfg; // instance configuration
class_preset_t* presetL; // instance presets
void* userPtr; // instance state
@ -252,18 +137,45 @@ namespace cw
unsigned varMapN; // varMapN = varMapIdN * varMapChN
variable_t** varMapA; // varMapA[ varMapN ] = allows fast lookup from ('vid','chIdx) to variable
// For 'poly' proc's 'internal_net' is a list linked by network_t.poly_link.
struct network_str* internal_net;
} proc_t;
// preset_value_t holds a preset value and the proc/var to which it will be applied.
typedef struct preset_value_str
struct network_preset_str;
typedef struct proc_var_value_str
{
proc_t* proc; // proc target for this preset value
variable_t* var; // var target for this preset value
value_t value; // Preset value.
unsigned pairTblIdx; // Index into the preset pair table for this preset value
} proc_var_value_t;
typedef struct net_preset_value_str
{
struct proc_str* net_preset_proc; // net_preset_proc->internal_net has the preset list which net_preset is part of.
struct network_str* net_preset_net; // poly net this preset will be applied to
const network_preset_str* net_preset; // network_preset_t of presets
} poly_preset_value_t;
typedef enum {
kDirectPresetValueTId,
kPolyPresetValueTId,
} preset_val_tid_t;
// preset_value_t holds a preset value and the proc/var to which it will be applied.
typedef struct preset_value_str
{
preset_val_tid_t tid;
union
{
proc_var_value_t pvv; // Direct proc/var/value tuples.
poly_preset_value_t npv; // Refers to a network_preset_t and a list of preset_values.
} u;
struct preset_value_str* link;
} preset_value_t;
@ -273,8 +185,6 @@ namespace cw
preset_value_t* value_tail; // Last preset value in the list.
} preset_value_list_t;
struct network_preset_str;
typedef struct dual_preset_str
{
const struct network_preset_str* pri;
@ -308,16 +218,15 @@ namespace cw
const value_t* value; //
} network_preset_pair_t;
typedef struct net_global_var_str
typedef struct global_var_str
{
const char* class_label;
char* var_label;
void* blob;
unsigned blobByteN;
struct net_global_var_str* link;
} net_global_var_t;
struct global_var_str* link;
} global_var_t;
typedef struct network_str
{
@ -334,8 +243,6 @@ namespace cw
network_preset_pair_t* preset_pairA;
unsigned preset_pairN;
net_global_var_t* globalVarL;
struct network_str* poly_link;
unsigned poly_idx;
@ -390,51 +297,13 @@ namespace cw
variable_t ui_var_stub;
variable_t* ui_var_tail;
global_var_t* globalVarL;
} flow_t;
//------------------------------------------------------------------------------------------------------------------------
//
// Value Only
//
inline void set_null( value_t& v, unsigned tflag ) { v.tflag=tflag; v.u.p=nullptr; }
inline bool is_numeric( const value_t* v ) { return cwIsFlag(v->tflag,kNumericTFl); }
inline bool is_matrix( const value_t* v ) { return cwIsFlag(v->tflag,kMtxTFl); }
// if all of the src flags are set in the dst flags then the two types are convertable.
inline bool can_convert( unsigned src_tflag, unsigned dst_tflag ) { return (src_tflag&dst_tflag)==src_tflag; }
abuf_t* abuf_create( srate_t srate, unsigned chN, unsigned frameN );
void abuf_destroy( abuf_t*& buf );
// If 'dst' is null then a new abuf is allocated, filled with the contents of 'src'.
// If 'dst' is non-null and there is enough space for the contents of 'src' then only a copy is executed.
// If there is not enough space then dst is reallocated.
abuf_t* abuf_duplicate( abuf_t* dst, const abuf_t* src );
rc_t abuf_set_channel( abuf_t* buf, unsigned chIdx, const sample_t* v, unsigned vN );
const sample_t* abuf_get_channel( abuf_t* buf, unsigned chIdx );
fbuf_t* fbuf_create( srate_t srate, unsigned chN, const unsigned* maxBinN_V, const unsigned* binN_V, const unsigned* hopSmpN_V, const fd_sample_t** magV=nullptr, const fd_sample_t** phsV=nullptr, const fd_sample_t** hzV=nullptr );
fbuf_t* fbuf_create( srate_t srate, unsigned chN, unsigned maxBinN, unsigned binN, unsigned hopSmpN, const fd_sample_t** magV=nullptr, const fd_sample_t** phsV=nullptr, const fd_sample_t** hzV=nullptr );
void fbuf_destroy( fbuf_t*& buf );
// Memory allocation will only occur if dst is null, or the size of dst's internal buffer are too small.
fbuf_t* fbuf_duplicate( fbuf_t* dst, const fbuf_t* src );
mbuf_t* mbuf_create( const midi::ch_msg_t* msgA=nullptr, unsigned msgN=0 );
void mbuf_destroy( mbuf_t*& buf );
mbuf_t* mbuf_duplicate( const mbuf_t* src );
inline bool value_is_abuf( const value_t* v ) { return v->tflag & kABufTFl; }
inline bool value_is_fbuf( const value_t* v ) { return v->tflag & kFBufTFl; }
unsigned value_type_label_to_flag( const char* type_desc );
const char* value_type_flag_to_label( unsigned flag );
void value_duplicate( value_t& dst, const value_t& src );
void value_print( const value_t* value, bool info_fl=false);
//------------------------------------------------------------------------------------------------------------------------
//
@ -455,9 +324,19 @@ namespace cw
const var_desc_t* var_desc_find( const class_desc_t* cd, const char* var_label );
rc_t var_desc_find( class_desc_t* cd, const char* var_label, var_desc_t*& vdRef );
bool var_desc_has_recd_format( var_desc_t* vd );
const class_preset_t* class_preset_find( const class_desc_t* cd, const char* preset_label );
void class_dict_print( flow_t* p );
//------------------------------------------------------------------------------------------------------------------------
//
// Flow
//
void class_dict_print( flow_t* p );
external_device_t* external_device_find( flow_t* p, const char* device_label, unsigned typeId, unsigned inOrOutFl, const char* midiPortLabel=nullptr );
//------------------------------------------------------------------------------------------------------------------------
@ -465,12 +344,6 @@ namespace cw
// Network
//
// Access a blob stored via network_global_var()
void* network_global_var( proc_t* proc, const char* var_label );
// Copy a named blob into the network global variable space.
rc_t network_global_var_alloc( proc_t* proc, const char* var_label, const void* blob, unsigned blobByteN );
void network_print(const network_t& net );
@ -481,6 +354,8 @@ namespace cw
rc_t proc_mult_sfx_id_array( const network_t& net, const char* proc_label, unsigned* idA, unsigned idAllocN, unsigned& idN_ref );
unsigned network_poly_count( const network_t& net );
inline bool network_is_part_of_poly( const network_t& net ) { return net.poly_idx > 0 || net.poly_link!=nullptr; }
//------------------------------------------------------------------------------------------------------------------------
@ -494,8 +369,14 @@ namespace cw
proc_t* proc_find( network_t& net, const char* proc_label, unsigned sfx_id );
rc_t proc_find( network_t& net, const char* proc_label, unsigned sfx_id, proc_t*& procPtrRef );
external_device_t* external_device_find( flow_t* p, const char* device_label, unsigned typeId, unsigned inOrOutFl, const char* midiPortLabel=nullptr );
const class_preset_t* proc_preset_find( const proc_t* cd, const char* preset_label );
// Access a blob stored via global_var()
void* global_var( proc_t* proc, const char* var_label );
// Copy a named blob into the network global variable space.
rc_t global_var_alloc( proc_t* proc, const char* var_label, const void* blob, unsigned blobByteN );
void proc_print( proc_t* proc );
// Count of all var instances on this proc. This is a count of the length of proc->varL.
@ -546,6 +427,9 @@ namespace cw
// Return true if this var is acting as a source for another var.
bool is_a_source_var( const variable_t* var );
// Returns true if var->varDesc->fmt.recd_fmt is valid.
bool var_has_recd_format( const variable_t* var );
// Connect in_var to src_var.
void var_connect( variable_t* src_var, variable_t* in_var );
@ -641,7 +525,19 @@ namespace cw
rc_t var_register_and_set( proc_t* proc, const char* var_label, unsigned sfx_id, unsigned vid, unsigned chIdx, midi::ch_msg_t* midiA, unsigned midiN );
rc_t var_register_and_set( proc_t* proc, const char* var_label, unsigned sfx_id, unsigned vid, unsigned chIdx, srate_t srate, unsigned chN, const unsigned* maxBinN_V, const unsigned* binN_V, const unsigned* hopSmpN_V, const fd_sample_t** magV=nullptr, const fd_sample_t** phsV=nullptr, const fd_sample_t** hzV=nullptr );
rc_t var_register_and_set( proc_t* proc, const char* var_label, unsigned sfx_id, unsigned vid, unsigned chIdx, srate_t srate, unsigned chN, unsigned maxBinN, unsigned binN, unsigned hopSmpN, const fd_sample_t** magV=nullptr, const fd_sample_t** phsV=nullptr, const fd_sample_t** hzV=nullptr );
rc_t var_register_and_set( proc_t* proc, const char* var_label, unsigned sfx_id, unsigned vid, unsigned chIdx, const recd_type_t* recd_type, recd_t* recdA, unsigned recdN );
// Alloc a recd_array, using an internal call to var_alloc_recd_array(), and assign all records to the specified variable.
// The caller is responsible for destroying (recd_array_destroy()) the returned recd_array.
rc_t var_alloc_register_and_set( proc_t* proc, const char* var_label, unsigned sfx_id, unsigned vid, unsigned chIdx, const recd_type_t* baseh, recd_array_t*& recd_arrray_ref, unsigned recdN=0 );
// Alloc the recd_array_t based on the recd_type defined by the variable. Set recdN to a non-zero value to override the 'alloc_cnt'
// which may have been set in the variables user provided cfg.
// The caller is responsible for destroying (recd_array_destroy()) the returned recd_array.
rc_t var_alloc_record_array( proc_t* proc, const char* var_label, unsigned sfx_id, unsigned chIdx, const recd_type_t* base, recd_array_t*& recd_array_ref, unsigned recdN=0 );
inline rc_t _var_register_and_set(cw::flow::proc_t*, unsigned int ) { return kOkRC; }
template< typename T0, typename T1, typename T2, typename... ARGS >
@ -685,7 +581,6 @@ namespace cw
rc_t var_channel_count( proc_t* proc, const char* label, unsigned sfx_idx, unsigned& chCntRef );
rc_t var_channel_count( const variable_t* var, unsigned& chCntRef );
rc_t cfg_to_value( const object_t* cfg, value_t& value_ref );
//
@ -704,6 +599,8 @@ namespace cw
rc_t var_get( variable_t* var, fbuf_t*& valRef );
rc_t var_get( const variable_t* var, const mbuf_t*& valRef );
rc_t var_get( variable_t* var, mbuf_t*& valRef );
rc_t var_get( const variable_t* var, const rbuf_t*& valRef );
rc_t var_get( variable_t* var, rbuf_t*& valRef );
rc_t var_get( const variable_t* var, const object_t*& valRef );
template< typename T>
@ -742,6 +639,7 @@ namespace cw
rc_t var_set( variable_t* var, abuf_t* val );
rc_t var_set( variable_t* var, fbuf_t* val );
rc_t var_set( variable_t* var, mbuf_t* val );
rc_t var_set( variable_t* var, rbuf_t* val );
rc_t var_set( variable_t* var, const object_t* val );
rc_t var_set( proc_t* proc, unsigned vid, unsigned chIdx, const value_t* val );
@ -754,6 +652,7 @@ namespace cw
rc_t var_set( proc_t* proc, unsigned vid, unsigned chIdx, abuf_t* val );
rc_t var_set( proc_t* proc, unsigned vid, unsigned chIdx, fbuf_t* val );
rc_t var_set( proc_t* proc, unsigned vid, unsigned chIdx, mbuf_t* val );
rc_t var_set( proc_t* proc, unsigned vid, unsigned chIdx, rbuf_t* val );
rc_t var_set( proc_t* proc, unsigned vid, unsigned chIdx, const object_t* val );