Skip to content

MIDI playback on Linux

Federico Bruni edited this page Aug 4, 2020 · 18 revisions

Frescobaldi MIDI playback requires:

  • The PortMidi library. Package name depends on Linux distribution: it's called portmidi in Fedora and libportmidi0 in Debian/Ubuntu. If you installed Frescobaldi from a repository, you have it installed already.
  • A MIDI synthesizer. The most used software synthesizers in Linux are TiMidity and FluidSynth. We recommend the latter, as it's actively developed and can be managed via a GUI frontend called Qsynth.

Use your package manager to install FluidSynth, Qsynth and some soundfonts to use. In Fedora you can use the following command:

sudo dnf install fluidsynth qsynth fluid-soundfont-gm

There are two ways to start fluidsynth:

  • manually by launching Qsynth.
  • automatically via a systemd service.

Qsynth, FluidSynth GUI

Qsynth is the best option if you often need adjusting the MIDI playback settings.

Remember to start it up! Alternatively, you can add it to the list of startup applications with a simple command: cp /usr/share/applications/qsynth.desktop ~/.config/autostart.

Click on Setup to edit the basic settings:

  • MIDI tab: the MIDI Client Name ID option should have a fixed name (such as qsynth) instead of pid (always changing), so you won't have to choose the right port/name in Frescobaldi preferences each time.
  • Audio tab: select the proper audio driver (Pulseaudio, Alsa or Jack). Most users should choose Pulseaudio.
  • Soundfonts tab: click on Open to add a Soundfont file, if it's not listed already.

In case of problems, check the logs by clicking on the Messages button.

systemd FluidSynth service

The systemd service is a perfect choice if you don't need to adjust the MIDI settings often.

Create the service file in your home directory, in this exact location: ~/.config/systemd/user/fluidsynth.service. The file should contain these lines:

[Unit]
Description=FluidSynth launched in server mode
After=sound.target

[Service]
ExecStart=/usr/bin/fluidsynth -a pulseaudio -m alsa_seq -i -l -s -p FluidSynth /usr/share/soundfonts/default.sf2

[Install]
WantedBy=default.target

fluidsynth will be started in server mode, using pulseaudio as audio driver and a port named FluidSynth. You may have to adapt above command to your system, especially the path to the soundfonts.

Let systemd find the new unit file and start the service:

systemctl --user daemon-reload
systemctl --user start fluidsynth.service

If it works correctly, you can enable the service to let it start at login:

systemctl --user enable fluidsynth.service

You can then stop or disable it at any time with the following commands:

systemctl --user stop fluidsynth.service
systemctl --user disable fluidsynth.service

The logs can be viewed with:

systemctl --user status fluidsynth

Troubleshooting and common errors

In case of problems, check the fluidsynth logs.

Permission denied

A common error is denied permission to access the soundcard:

ALSA lib seq_hw.c:466:(snd_seq_hw_open) open /dev/snd/seq failed: Permission denied

Check the permissions required to access that device:

$ ls -l /dev/snd/seq
crw-rw----+ 1 root audio 116, 1 28 apr 21.57 /dev/snd/seq

This device can be accessed by root user and any user who is part of the audio group. If the command groups does not return the audio group, add your user to it:

sudo usermod -a -G audio $USER

and reload the settings with:

newgrp audio

Error writing to PulseAudio connection

When you see the following error in the log:

fluidsynth: error: Error writing to PulseAudio connection.

you can work around it by changing the audio driver to alsa, so the fluidsynth command in the service file will be:

ExecStart=/usr/bin/fluidsynth -a alsa -m alsa_seq -i -l -s -p FluidSynth /usr/share/soundfonts/default.sf2

It might be a bug in the Alsa to Pulseaudio backend (alsa-plugins package in Fedora).