I was trying to play a MIDI file on my laptop, with Ubuntu MATE 24.04, using fluidsynth, but nothing was playing.
I could see the following error via journalctl -r -b 0 | grep fluid:
Jan 01 12:34:56 host fluidsynth[1234]: fluidsynth: error: Failed to open the "default" audio device
Turns out, all we need is to use the pipewire audio driver setting, but this requires either; a) a user configuration for fluidsynth, or; b) for fluidsynth.service to pass the correct value to the --audio-driver argument.
User configuration
The documentation for user configuration is found here: FluidSynth configuration files · FluidSynth/fluidsynth Wiki · GitHub
All we'll need in our ~/.fluidsynth file is the following contents:
set audio.driver pipewire
And we restart the service:
user@host:~$ systemctl restart --user fluidsynth.service
And presto
A fluidsynth process was running with port 128:0 for MIDI playback.
Configure arguments for service
With a little bit of digging in /etc/systemd/user/default.target.wants/fluidsynth.service; I noticed that:
- An environment variable called
OTHER_OPTSis appended to the command when launching the fluidsynth process, and; - The environment (variables) for the service can be set on a per-user basis via the
~/.config/fluidsynthfile.
So with this in mind, I created the ~/.config/fluidsynth file with the simple contents (e.g. in Pluma or any text editor):
OTHER_OPTS=--audio-driver pipewire
And we restart the service:
user@host:~$ systemctl restart --user fluidsynth.service
Same result as above
!
Discussion
These solutions have minor differences. The first option will apply those settings whenever the user invokes the fluidsynth CLI (including by systemd). The second option will only apply those settings when the systemd service invokes the fluidsynth CLI.