cwFlowProc.cpp : poly_voice_ctl now accepts 'record' as input type rather than 'midi'.
This commit is contained in:
parent
5dd9330c98
commit
0e8e06c48d
@ -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<voice_t>(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; i<p->voiceN; ++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;
|
||||
@ -4330,6 +4337,64 @@ namespace cw
|
||||
}
|
||||
|
||||
|
||||
errLabel:
|
||||
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; i<p->voiceN; ++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; i<rbuf->recdN; ++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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user