From 0e8e06c48d2a8f5ed6177fcff26b06dd89246275 Mon Sep 17 00:00:00 2001 From: kevin Date: Mon, 25 Nov 2024 10:02:33 -0500 Subject: [PATCH] cwFlowProc.cpp : poly_voice_ctl now accepts 'record' as input type rather than 'midi'. --- cwFlowProc.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 4 deletions(-) diff --git a/cwFlowProc.cpp b/cwFlowProc.cpp index 50e8dbb..f4fb7f7 100644 --- a/cwFlowProc.cpp +++ b/cwFlowProc.cpp @@ -522,6 +522,7 @@ namespace cw goto errLabel; } + // BUG BUG BUG: why register "out" here when it is apparently registered again below? if((rc = var_register( proc, kAnyChIdx, kOutPId, "out", kBaseSfxId)) != kOkRC ) { goto errLabel; @@ -4104,7 +4105,6 @@ namespace cw unsigned msg_idx; // current count of msg's in msgA[] mbuf_t* mbuf; // cached mbuf for this output variable - } voice_t; typedef struct @@ -4117,16 +4117,17 @@ namespace cw // sizeof of each voice msgA[] (same as voice_t.msgN) unsigned voiceMsgN; + unsigned midi_fld_idx; } inst_t; rc_t _create( proc_t* proc, inst_t* p ) { rc_t rc = kOkRC; - mbuf_t* mbuf = nullptr; + rbuf_t* rbuf = nullptr; if((rc = var_register_and_get(proc,kAnyChIdx, - kInPId, "in", kBaseSfxId, mbuf, + kInPId, "in", kBaseSfxId, rbuf, kVoiceCntPId, "voice_cnt", kBaseSfxId, p->voiceN)) != kOkRC ) { goto errLabel; @@ -4142,6 +4143,12 @@ namespace cw p->voiceMsgN = kVoiceMsgN; p->voiceA = mem::allocZ(p->voiceN); + if((p->midi_fld_idx = recd_type_field_index( rbuf->type, "midi")) == kInvalidIdx ) + { + rc = cwLogError(kInvalidArgRC,"The 'in' record does not have a 'midi' field."); + goto errLabel; + } + for(unsigned i=0; ivoiceN; ++i) { // create one output MIDI variable per voice @@ -4285,7 +4292,7 @@ namespace cw return rc; } - rc_t _exec( proc_t* proc, inst_t* p ) + rc_t _exec0( proc_t* proc, inst_t* p ) { rc_t rc = kOkRC; mbuf_t* mbuf = nullptr; @@ -4334,6 +4341,64 @@ namespace cw return rc; } + + rc_t _exec( proc_t* proc, inst_t* p ) + { + rc_t rc = kOkRC; + rbuf_t* rbuf = nullptr; + + // update the voice array + for(unsigned i=0; ivoiceN; ++i) + { + if( p->voiceA[i].activeFl ) + p->voiceA[i].age += 1; + + p->voiceA[i].msg_idx = 0; + p->voiceA[i].mbuf->msgN = 0; + p->voiceA[i].mbuf->msgA = nullptr; + } + + // get the input MIDI buffer + if((rc = var_get(proc,kInPId,kAnyChIdx,rbuf)) != kOkRC ) + goto errLabel; + + // process the incoming MIDI messages + for(unsigned i=0; irecdN; ++i) + { + //const midi::ch_msg_t* m = mbuf->msgA + i; + const recd_t* r = rbuf->recdA + i; + const midi::ch_msg_t* m = nullptr; + + if((rc = recd_get(rbuf->type,r,p->midi_fld_idx,m)) != kOkRC ) + { + rc = cwLogError(rc,"Record 'midi' field read failed."); + goto errLabel; + } + + switch( m->status ) + { + case midi::kNoteOnMdId: + if( m->d1 == 0 ) + rc = _on_note_off(proc,p,m); + else + rc = _on_note_on(proc,p,m); + break; + + case midi::kNoteOffMdId: + rc = _on_note_off(proc,p,m); + break; + + default: + rc = _send_to_all_voices(proc,p,m); + break; + } + } + + + errLabel: + return rc; + } + rc_t _report( proc_t* proc, inst_t* p ) { return kOkRC; }