Skip to content

Commit

Permalink
Various MIDI/Fluidsynth fixes and improvements
Browse files Browse the repository at this point in the history
- Use pulseaudio instead of alsa as the default driver on linux (Fix #1147)
- Add 'default-GM.sf2' to linux soundfont path detection, looks like this changed since the detection was originally added
- Stop all notes when pausing/stopping fluidsynth, hopefully this fixes some notes getting stuck playing when switching between MIDI entries
  • Loading branch information
sirjuddington committed Dec 31, 2024
1 parent 1d1d746 commit bf00e9f
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/Audio/MIDIPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,18 @@ class FluidSynthMIDIPlayer : public MIDIPlayer
fs_initialised_ = false;
file_ = "";

// Set fluidsynth driver to alsa in linux (no idea why it defaults to jack)
// Set fluidsynth driver to pulseaudio in linux (no idea why it defaults to jack)
if (app::platform() == app::Platform::Linux && fs_driver.value.empty())
fs_driver = "alsa";
fs_driver = "pulseaudio";

// Init soundfont path
if (fs_soundfont_path.value.empty())
{
if (app::platform() == app::Platform::Linux)
fs_soundfont_path = "/usr/share/sounds/sf2/FluidR3_GM.sf2:/usr/share/sounds/sf2/FluidR3_GS.sf2";
fs_soundfont_path =
"/usr/share/sounds/sf2/FluidR3_GM.sf2"
":/usr/share/sounds/sf2/FluidR3_GS.sf2"
":/usr/share/sounds/sf2/default-GM.sf2";
else
log::warning(1, "No FluidSynth soundfont set, MIDI playback will not work");
}
Expand Down Expand Up @@ -249,17 +252,19 @@ class FluidSynthMIDIPlayer : public MIDIPlayer

elapsed_ms_ += timer_.getElapsedTime().asMilliseconds();

return fluid_player_stop(fs_player_) == FLUID_OK;
auto ok = fluid_player_stop(fs_player_) == FLUID_OK;
fluid_synth_all_notes_off(fs_synth_, -1);

return ok;
}

// -------------------------------------------------------------------------
// Stops playback of the currently loaded MIDI stream
// -------------------------------------------------------------------------
bool stop() override
{
if (isPlaying())
fluid_player_stop(fs_player_);

fluid_player_stop(fs_player_);
fluid_synth_all_notes_off(fs_synth_, -1);
fluid_player_seek(fs_player_, 0);
elapsed_ms_ = 0;

Expand Down

0 comments on commit bf00e9f

Please sign in to comment.