cwFlowProc.cpp : Implement sustain pedal in piano_voice.
This commit is contained in:
parent
aa12a4b9b3
commit
56a88e22f6
@ -209,7 +209,7 @@ namespace cw
|
||||
|
||||
} inst_t;
|
||||
|
||||
rc_t _voice_thread_func( void* arg )
|
||||
rc_t _poly_thread_func( void* arg )
|
||||
{
|
||||
rc_t rc = kOkRC;
|
||||
voice_t* v = (voice_t*)arg;
|
||||
@ -325,7 +325,7 @@ namespace cw
|
||||
inst->voiceA[i].voice_idx = i;
|
||||
inst->voiceA[i].net = net;
|
||||
|
||||
inst->taskA[i].func = _voice_thread_func;
|
||||
inst->taskA[i].func = _poly_thread_func;
|
||||
inst->taskA[i].arg = inst->voiceA + i;
|
||||
|
||||
net = net->poly_link;
|
||||
@ -377,9 +377,13 @@ namespace cw
|
||||
}
|
||||
else
|
||||
{
|
||||
if((rc = exec_cycle(*proc->internal_net)) != kOkRC )
|
||||
for(network_t* net=proc->internal_net; net!=nullptr; net=net->poly_link)
|
||||
{
|
||||
rc = cwLogError(rc,"poly internal network exec failed.");
|
||||
if((rc = exec_cycle(*net)) != kOkRC )
|
||||
{
|
||||
rc = cwLogError(rc,"poly internal network exec failed.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4243,6 +4247,8 @@ namespace cw
|
||||
v->activeFl = true;
|
||||
v->pitch = m->d0;
|
||||
|
||||
//printf("v_idx:%i non\n",voice_idx);
|
||||
|
||||
rc = _update_voice_msg(proc,p,voice_idx,m);
|
||||
|
||||
return rc;
|
||||
@ -4572,11 +4578,13 @@ namespace cw
|
||||
unsigned test_pitchN; // Count of valid velocities for test_pitch
|
||||
unsigned* test_pitch_map; // test_pitch_map[ test_pitch_N ]
|
||||
|
||||
bool done_fl;
|
||||
bool done_fl;
|
||||
coeff_t gain;
|
||||
coeff_t gain_coeff;
|
||||
coeff_t kReleaseGain;
|
||||
coeff_t kGainThreshold;
|
||||
bool isSustainDownFl;
|
||||
bool heldByPedalFl;
|
||||
|
||||
} inst_t;
|
||||
|
||||
@ -4588,7 +4596,7 @@ namespace cw
|
||||
unsigned padSmpN = 1;
|
||||
|
||||
// if the global wave table bank has not yet been created
|
||||
if((p->wtbH_ptr = (wt_bank::handle_t*)network_global_var(proc, wtb_var_label )) == nullptr )
|
||||
if((p->wtbH_ptr = (wt_bank::handle_t*)global_var(proc, wtb_var_label )) == nullptr )
|
||||
{
|
||||
wt_bank::handle_t wtbH;
|
||||
|
||||
@ -4606,13 +4614,13 @@ namespace cw
|
||||
}
|
||||
|
||||
// store the wave table bank global var
|
||||
if((rc = network_global_var_alloc(proc, wtb_var_label, &wtbH, sizeof(wtbH) )) != kOkRC )
|
||||
if((rc = global_var_alloc(proc, wtb_var_label, &wtbH, sizeof(wtbH) )) != kOkRC )
|
||||
{
|
||||
rc = cwLogError(rc,"The wave table bank global variable allocation failed.");
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
if((p->wtbH_ptr = (wt_bank::handle_t*)network_global_var(proc, wtb_var_label )) == nullptr )
|
||||
if((p->wtbH_ptr = (wt_bank::handle_t*)global_var(proc, wtb_var_label )) == nullptr )
|
||||
{
|
||||
rc = cwLogError(rc,"The wave table bank global variable store failed.");
|
||||
goto errLabel;
|
||||
@ -4733,7 +4741,7 @@ namespace cw
|
||||
d0 = p->test_pitch;
|
||||
}
|
||||
|
||||
printf("%i %i\n",d0,d1);
|
||||
//printf("%s:%i %i %i\n",proc->label,proc->label_sfx_id,d0,d1);
|
||||
|
||||
// get the wave-table associated with the pitch and velocity
|
||||
if((rc = get_wave_table( *p->wtbH_ptr, p->wtb_instr_idx, d0, d1, mcs)) != kOkRC )
|
||||
@ -4751,21 +4759,40 @@ namespace cw
|
||||
|
||||
p->done_fl = false;
|
||||
p->kGainThreshold = 0.01;
|
||||
p->kReleaseGain = 0.9;
|
||||
p->kReleaseGain = 0.98;
|
||||
p->gain = 1.0;
|
||||
p->gain_coeff = 1.0;
|
||||
p->heldByPedalFl = false;
|
||||
|
||||
errLabel:
|
||||
return rc;
|
||||
}
|
||||
|
||||
void _on_note_off( inst_t* p )
|
||||
void _begin_note_release( inst_t* p )
|
||||
{
|
||||
p->gain_coeff = p->kReleaseGain;
|
||||
//printf("%i nof: %i %i\n",proc->label_sfx_id,m->d0,m->d1);
|
||||
|
||||
}
|
||||
|
||||
void _on_note_off( inst_t* p )
|
||||
{
|
||||
if( p->isSustainDownFl )
|
||||
p->heldByPedalFl = true;
|
||||
else
|
||||
_begin_note_release(p);
|
||||
|
||||
//printf("%i nof: %i %i\n",proc->label_sfx_id,m->d0,m->d1);
|
||||
}
|
||||
|
||||
void _on_sustain_pedal(proc_t* proc, inst_t* p, bool pedal_down_fl )
|
||||
{
|
||||
p->isSustainDownFl = pedal_down_fl;
|
||||
|
||||
if( !p->isSustainDownFl && p->heldByPedalFl )
|
||||
_begin_note_release(p);
|
||||
|
||||
//printf("%s:%i %s\n",proc->label,proc->label_sfx_id,pedal_down_fl ? "V" : "^");
|
||||
|
||||
}
|
||||
|
||||
rc_t _destroy( proc_t* proc, inst_t* p )
|
||||
{
|
||||
@ -4824,6 +4851,11 @@ namespace cw
|
||||
case midi::kPbendMdId:
|
||||
break;
|
||||
|
||||
case midi::kCtlMdId:
|
||||
if( midi::isSustainPedal( m->status, m->d0 ) )
|
||||
_on_sustain_pedal(proc,p, midi::isPedalDown(m->d1) );
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user