Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn off pending notes and issue a warning #1264

Merged
merged 1 commit into from
Aug 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/midi/fluid_midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,23 @@ fluid_player_handle_reset_synth(void *data, const char *name, int value)
player->reset_synth_between_songs = value;
}

static int check_for_on_notes(fluid_synth_t *synth)
{
fluid_voice_t* v[1024];
int i, res=FALSE;
fluid_synth_get_voicelist(synth, v, FLUID_N_ELEMENTS(v), -1);
for(i=0; i<FLUID_N_ELEMENTS(v) && v[i] != NULL; i++)
{
fluid_voice_t *vv = v[i];
if(vv != NULL && fluid_voice_is_on(vv))
{
res = TRUE;
FLUID_LOG(FLUID_DBG, "Voice is on! channel %d, key %d", fluid_voice_get_channel(vv), fluid_voice_get_key(vv));
}
}
return res;
}

/**
* Create a new MIDI player.
* @param synth Fluid synthesizer instance to create player for
Expand Down Expand Up @@ -2197,10 +2214,16 @@ fluid_player_callback(void *data, unsigned int msec)
/* The first time we notice we've run out of MIDI events but there are still active voices, disable all hold pedals */
if(!player->end_pedals_disabled)
{
if(check_for_on_notes(synth))
{
FLUID_LOG(FLUID_WARN, "End of the MIDI file reached, but not all notes have received a note off event! OFFing them now! Run with --verbose to spot pending voices.");
}

for(i = 0; i < synth->midi_channels; i++)
{
fluid_synth_cc(player->synth, i, SUSTAIN_SWITCH, 0);
fluid_synth_cc(player->synth, i, SOSTENUTO_SWITCH, 0);
fluid_synth_cc(player->synth, i, ALL_NOTES_OFF, 0);
}

player->end_pedals_disabled = 1;
Expand Down
Loading