cwFlowPerf.h/cpp : score_player now outputs a 'record' type.

This commit is contained in:
kevin 2024-11-25 09:58:25 -05:00
parent 5d748bdb7e
commit 5dd9330c98
2 changed files with 77 additions and 14 deletions

View File

@ -83,6 +83,11 @@ namespace cw
msg_t* msgA; // msgA[ msgN ]
midi::ch_msg_t* chMsgA; // chMsgA[ msgN ]
recd_array_t* recd_array;
unsigned midi_fld_idx;
unsigned loc_fld_idx;
unsigned meas_fld_idx;
vel_tbl_t* velTblL; // List of vel. tables.
vel_tbl_t* activeVelTbl; // Currently active vel. table or null if no vel. tbl is active.
@ -311,6 +316,43 @@ namespace cw
return rc;
}
rc_t _alloc_recd_array( proc_t* proc, const char* var_label, unsigned sfx_id, unsigned chIdx, const recd_type_t* base, recd_array_t*& recd_array_ref )
{
rc_t rc = kOkRC;
variable_t* var = nullptr;
// find the record variable
if((rc = var_find( proc, var_label, sfx_id, chIdx, var )) != kOkRC )
{
rc = cwLogError(rc,"The record variable '%s:%i' could was not found.",cwStringNullGuard(var_label),sfx_id);
goto errLabel;
}
// verify that the variable has a record format
if( !var_has_recd_format(var) )
{
rc = cwLogError(kInvalidArgRC,"The variable does not have a valid record format.");
goto errLabel;
}
else
{
recd_fmt_t* recd_fmt = var->varDesc->fmt.recd_fmt;
// create the recd_array
if((rc = recd_array_create( recd_array_ref, recd_fmt->recd_type, base, recd_fmt->alloc_cnt )) != kOkRC )
{
goto errLabel;
}
}
errLabel:
if( rc != kOkRC )
rc = cwLogError(rc,"Record array create failed on the variable '%s:%i ch:%i.",cwStringNullGuard(var_label),sfx_id,chIdx);
return rc;
}
rc_t _create( proc_t* proc, inst_t* p )
{
rc_t rc = kOkRC;
@ -360,8 +402,19 @@ namespace cw
}
}
// allocate the output recd array
if((rc = _alloc_recd_array( proc, "out", kBaseSfxId, kAnyChIdx, nullptr, p->recd_array )) != kOkRC )
{
goto errLabel;
}
// create one output MIDI buffer
rc = var_register_and_set( proc, "out", kBaseSfxId, kOutPId, kAnyChIdx, nullptr, 0 );
rc = var_register_and_set( proc, "out", kBaseSfxId, kOutPId, kAnyChIdx, p->recd_array->type, nullptr, 0 );
p->midi_fld_idx = recd_type_field_index( p->recd_array->type, "midi");
p->loc_fld_idx = recd_type_field_index( p->recd_array->type, "loc");
p->meas_fld_idx = recd_type_field_index( p->recd_array->type, "meas");
errLabel:
return rc;
@ -392,29 +445,38 @@ namespace cw
rc_t _exec( proc_t* proc, inst_t* p )
{
rc_t rc = kOkRC;
mbuf_t* mbuf = nullptr;
rbuf_t* rbuf = nullptr;
bool done_fl = false;
p->sample_idx += proc->ctx->framesPerCycle;
// get the output variable
if((rc = var_get(proc,kOutPId,kAnyChIdx,mbuf)) != kOkRC )
if((rc = var_get(proc,kOutPId,kAnyChIdx,rbuf)) != kOkRC )
rc = cwLogError(kInvalidStateRC,"The MIDI file instance '%s' does not have a valid MIDI output buffer.",proc->label);
else
{
mbuf->msgA = nullptr;
mbuf->msgN = 0;
rbuf->recdA = nullptr;
rbuf->recdN = 0;
while( p->msg_idx < p->msgN && p->sample_idx >= p->msgA[p->msg_idx].sample_idx )
{
if( mbuf->msgA == nullptr )
recd_t* r = p->recd_array->recdA + rbuf->recdN;
msg_t* m = p->msgA + p->msg_idx;
if( rbuf->recdA == nullptr )
rbuf->recdA = r;
if( rbuf->recdN >= p->recd_array->allocRecdN )
{
// Note we only set a pointer to the first msg in p->chMsgA[]
// successive messages will be consecutively after it.
mbuf->msgA = p->msgA[p->msg_idx].midi;
rc = cwLogError(kBufTooSmallRC,"The internal record buffer overflowed. (buf recd count:%i).",p->recd_array->allocRecdN);
goto errLabel;
}
mbuf->msgN += 1;
recd_set( rbuf->type, nullptr, r, p->midi_fld_idx, m->midi );
recd_set( rbuf->type, nullptr, r, p->loc_fld_idx, m->loc );
recd_set( rbuf->type, nullptr, r, p->meas_fld_idx, m->meas );
rbuf->recdN += 1;
p->msg_idx += 1;
@ -427,7 +489,7 @@ namespace cw
var_set(proc, kDoneFlPId, kAnyChIdx, true );
}
errLabel:
return rc;
}
@ -449,6 +511,7 @@ namespace cw
//
// Midi To Msg
//
/*
namespace midi_to_msg
{
enum {
@ -461,6 +524,7 @@ namespace cw
typedef struct
{
recd_array_t* recd_array;
rbuf_t* rbuf;
unsigned allocRecdN;
unsigned midiFieldIdx;
@ -477,7 +541,6 @@ namespace cw
s[sn] = 0;
recd_type_t* recd_type = nullptr;
if((rc = recd_type_create( recd_type, nullptr, s )) != kOkRC )
{
rc = cwLogError(kOpFailRC,"recd type failed on field strings:'%s'.",cwStringNullGuard(s));
@ -598,7 +661,7 @@ namespace cw
};
} // midi_to_msg
*/
//------------------------------------------------------------------------------------------------------------------
//

View File

@ -3,7 +3,7 @@ namespace cw
namespace flow
{
namespace score_player { extern class_members_t members; }
namespace midi_to_msg { extern class_members_t members; }
//namespace midi_to_msg { extern class_members_t members; }
namespace score_follower { extern class_members_t members; }
}