Skip to content

Commit

Permalink
Try implementing sustain stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
derselbst committed Sep 1, 2023
1 parent 310379e commit 45e7d34
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/synth/fluid_voice.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ fluid_voice_init(fluid_voice_t *voice, fluid_sample_t *sample,
voice->mod_count = 0;
voice->start_time = start_time;
voice->has_noteoff = 0;
voice->ignore_sustain = 0;
UPDATE_RVOICE0(fluid_rvoice_reset);

/*
Expand Down Expand Up @@ -612,6 +613,15 @@ fluid_voice_calculate_runtime_synthesis_parameters(fluid_voice_t *voice)
int dest_gen_index = mod->dest;
fluid_gen_t *dest_gen = &voice->gen[dest_gen_index];
dest_gen->mod += modval;

// issue blablabla: If a modulator is in use, which responds to CC64 and intended to manipulate the release envelope, this voice should not be sustained,
// to allow the modulator to achieve its desired behavior while the sustain switch is being depressed.
if((mod->src1 == SUSTAIN_SWITCH && mod->flags1 & (FLUID_MOD_CC | FLUID_MOD_SWITCH))
|| (mod->src2 == SUSTAIN_SWITCH && mod->flags2 & (FLUID_MOD_CC | FLUID_MOD_SWITCH))
&& (mod->dest == GEN_VOLENVRELEASE))
{
voice->ignore_sustain = 1;
}
/* fluid_dump_modulator(mod); */
}

Expand Down Expand Up @@ -1364,7 +1374,7 @@ fluid_voice_noteoff(fluid_voice_t *voice)
voice->status = FLUID_VOICE_HELD_BY_SOSTENUTO;
}
/* Or sustain a note under Sustain pedal */
else if(fluid_channel_sustained(channel))
else if(fluid_channel_sustained(channel) && !voice->ignore_sustain)
{
voice->status = FLUID_VOICE_SUSTAINED;
}
Expand Down
1 change: 1 addition & 0 deletions src/synth/fluid_voice.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ struct _fluid_voice_t
/* rvoice control */
fluid_rvoice_t *rvoice;
fluid_rvoice_t *overflow_rvoice; /* Used temporarily and only in overflow situations */
char ignore_sustain;
char can_access_rvoice; /* False if rvoice is being rendered in separate thread */
char can_access_overflow_rvoice; /* False if overflow_rvoice is being rendered in separate thread */
char has_noteoff; /* Flag set when noteoff has been sent */
Expand Down

0 comments on commit 45e7d34

Please sign in to comment.