Skip to content

Commit

Permalink
Midi: opt FluidSynth into NeedsSoftReset (Fixes #3135)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyrone-sudeium committed Nov 18, 2023
1 parent 46e20b1 commit 77b52c8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/audio_decoder_midi.cpp
Expand Up @@ -402,16 +402,17 @@ void AudioDecoderMidi::meta_event(int event, const void* data, std::size_t size)

void AudioDecoderMidi::reset() {
// MIDI reset event
if (mididec->NeedsSoftReset()) {
// SoundOff every channel: necessary for synths like macOS which tend to get stuck
SendMessageToAllChannels(midimsg_all_sound_off(0));
}
SendMessageToAllChannels(midimsg_reset_all_controller(0));

// GM system on (resets most parameters)
const unsigned char gm_reset[] = { 0xF0, 0x7E, 0x7F, 0x09, 0x01, 0xF7 };
mididec->SendSysExMessage(gm_reset, sizeof(gm_reset));

// SoundOff every channel: only necessary for synths like macOS which tend to get stuck
if (mididec->NeedsSoftReset()) {
SendMessageToAllChannels(midimsg_all_sound_off(0));
}

// Set the Pitch bend range to 256
for (int channel = 0; channel < 16; channel++) {
auto midi_msg = midimsg_make(midi_event_control_change, channel, midi_set_reg_param_number_upper, 0);
Expand Down
4 changes: 4 additions & 0 deletions src/decoder_fluidsynth.cpp
Expand Up @@ -347,4 +347,8 @@ fluid_synth_t *FluidSynthDecoder::GetSynthInstance() {
}
}

bool FluidSynthDecoder::NeedsSoftReset() {
return true;
}

#endif
2 changes: 2 additions & 0 deletions src/decoder_fluidsynth.h
Expand Up @@ -69,6 +69,8 @@ class FluidSynthDecoder : public MidiDecoder {
#endif
};

bool NeedsSoftReset() override;

private:
#if defined(HAVE_FLUIDSYNTH) || defined(HAVE_FLUIDLITE)
fluid_synth_t* GetSynthInstance();
Expand Down

0 comments on commit 77b52c8

Please sign in to comment.