0

How do you use Timidity on Ubuntu 18.04?

Timidity is available in the default repo via sudo apt install timidity, which includes a service daemon. However, this daemon appears to be broken out of the box, as Timidity produces no sound and service timidity status shows several errors interacting with pulseaudio:

● timidity.service - LSB: start and stop timidity
   Loaded: loaded (/etc/init.d/timidity; generated)
   Active: active (exited) since Sun 2020-05-10 14:27:02 EDT; 1s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 2407 ExecStop=/etc/init.d/timidity stop (code=exited, status=0/SUCCESS)
  Process: 2416 ExecStart=/etc/init.d/timidity start (code=exited, status=0/SUCCESS)

May 10 14:27:02 caius systemd[1]: Starting LSB: start and stop timidity...
May 10 14:27:02 caius timidity[2416]:  * Starting TiMidity++ ALSA midi emulation...
May 10 14:27:02 caius timidity[2416]:    ...done.
May 10 14:27:02 caius systemd[1]: Started LSB: start and stop timidity.
May 10 14:27:02 caius pulseaudio[2448]: [autospawn] core-util.c: Home directory not accessible: Permission denied
May 10 14:27:02 caius pulseaudio[2448]: [autospawn] lock-autospawn.c: Cannot access autospawn lock.
May 10 14:27:02 caius pulseaudio[2448]: [pulseaudio] main.c: Failed to acquire autospawn lock

How do you fix this?

Cerin
  • 6,943

2 Answers2

3

Just trying this in 20.04, and it seems the timidity package no longer includes a service file. I tried some of kyodake's answer and it worked nicely, but you don't need any sudo!

This might also work to solve the original poster's problem, as it seems that whichever user is trying to run timidity does not have access to whichever home directory timidity wants to put a file into (perhaps the package has set up a service user without a home directory). This method makes the current user the user that starts the service, and whose home directory is used.

Firstly, add a new file ~/.config/systemd/user/timidity.service and edit it to include kyodake's contents:

[Unit]
Description=TiMidity++ Daemon
After=sound.target

[Service] ExecStart=/usr/bin/timidity -iA -Os

[Install] WantedBy=default.target

Now you can simply start the server like this:

systemctl --user start timidity

and ensure that it starts up at user login like this:

systemctl --user enable timidity

no sudo required.

To minimally fix your actual problem (and if you want timidity to start on boot and be present for all users); check if you have a /etc/systemd/system/timidity.service file. If you do, check for a line beginning User=; this will tell you which user is trying to start the service. Let's say it says User=timidityuser.

Now you want to find out if timidityuser has a home directory, so:

grep ^timidityuser: /etc/passwd

The last-but-one field returned will be the home directory. You can check that this directory exists and has the correct owner and permissions, or you can create a new one like this:

sudo usermod -md /home/timidityuser timidityuser

Hope that helps!

Tim Band
  • 131
1

Try this:

First you should add yourself to the audio group.

sudo gpasswd -a <user> audio

Second install Freepats, the Freepats project provides a set of instrument samples.

sudo apt update
sudo apt install freepats

Third to use Freepats with TiMidity:

sudo nano /etc/timidity++/timidity.cfg

Add the following lines to timidity.cfg:

soundfont /usr/share/soundfonts/freepats-general-midi.sf2

If you are using PulseAudio, that may not work.

To start TiMidity in daemon mode once, you can use the following command:

timidity -iA

To do so, write a timidity.service file in ~/.config/systemd/user/ like that one :

sudo nano /etc/systemd/user/timidity.service

Add the following lines to timidity.service

[Unit]
Description=TiMidity++ Daemon
After=sound.target

[Service]
ExecStart=/usr/bin/timidity -iA -Os

[Install]
WantedBy=default.target

Then enable the service with:

sudo systemctl --user enable timidity.service

Source: 1

kyodake
  • 18,075
  • I do not recommend adding yourself to the audio group. This breaks PulseAudio in Mint 19.3.

    A user in the audio group has exclusive access to the pulseaudio server. Other users can not access it while this user uses it. Therefore user should not be in the audio group.

    Also, if timidity.service is created within ~/.config/systemd/user/, sudo should not be used to enable the user service.

    – Sea Monkey Jun 27 '20 at 01:10