Enabling Note Track playback on Linux
MIDI playback on Linux with TiMidmidity++ software synthesizer
This guide has instructions for Ubuntu 16.04, though the necessary steps for other distributions will often be very similar.
Install TiMidity++ (MIDI player/synth), freepats (Sound bank) and pmidi (command line MIDI utility).
sudo apt-get install timidity freepats pmidi
First we need to disable TiMidity-daemon from starting:
For Ubuntu 16.04: Open /etc/default/timidity in a text editor with root permissions. For example (assuming that gedit text editor is installed):
sudo gedit /etc/default/timidity
Then, to launch TiMidity automatically after log-in:
- Launch "Startup Applications" (Ubuntu) or "Session and Startup" (Xubuntu)
- Create a new Application Autostart item containing the command:
| "Session and Startup" for the XFCE desktop only handles startup commands. It does not provide a means to end scripts on logout. This means that if you log out and back in again, there will be two instances of Timodity because it is started on login but not closed on logout. The simplest solution is to manually kill Timidity before logging out, which may be done at the command line with:
See below for a way to automatically stop Timidity when logging out from XFCE.
Open a terminal window and enter:
The output should look similar to:
Port Client name Port name 14:0 Midi Through Midi Through Port-0 128:0 TiMidity TiMidity port 0 128:1 TiMidity TiMidity port 1 128:2 TiMidity TiMidity port 2 128:3 TiMidity TiMidity port 3
Navigate to a folder that contains a MIDI file and enter:
pmidi -p 128:0 "name_of_midi_file.mid"
(Ctrl+C to quit)
While TiMidity is playing, launch PulseAudio Volume Control (pavucontrol) and ensure that TiMidity is playing through PulseAudio (the Playback tab should list "ALSA plug-in [timidity]:")
|There may be crackles when MIDI playback starts. This is due to a bug in TiMidity 3.13.
For more information, see: https://bugs.launchpad.net/ubuntu/+source/timidity/+bug/1587215 A fix is available here: http://martinwguy.co.uk/ubuntu/ which may be included when Ubuntu / Debian next update TiMidity++
Playing a MIDI file with Audacity
- Launch Audacity
- Import a MIDI (.MID) file
- Open Preferences and ensure that one of the TiMidity ports is selected for playback.
- Close preferences.
- Start playback.
Optional steps for better MIDI sounds
The "freepat" sound bank is a fairly small, free sound bank. Most Linux distributions also have a much larger GM (general midi) sound bank available called "Fluid3_GM". To install:
sudo apt-get install fluid-soundfont-gm
To configure TiMidity to use Fluid3_GM
sudo gedit /etc/timidity/timidity.cfg
Scroll down near the bottom of the file and change:
# source /etc/timidity/freepats.cfg
Save the changes, then log out and back in again.
|Note that "better" is subjective. For some MIDI files, the freepat sound bank may sound better than Fluid GM sound bank.|
Timidity with XFCE
The XFCE application "Session and Startup" is a convenient way to start Timidity (or other applications) automatically on logging in, but at time of writing (XFCE 4.12) it does not provide a means to stop the application or script on logout. For some applications (including Timidity), this has the downside that logging out of the XFCE session and back in again will cause a new instance of the application to be launched in addition to the original instance.
To avoid starting multiple instances of Timidity, the application may simply be killed before logging out with the command line:
A more convenient way to stop Timidity on logging out, is to add a script to override the default xfce4-session behavior. To do this we create a bash script called /usr/local/bin/xfce4-session which will run when logging into XFCE, and the script will launch the standard /usr/bin/xfce4-session application, allowing us to add additional commands before starting or after ending the XFCE session.
Assuming MousePad is the text editor (if you use a different text editor, substitute the name of your editor in place of "mousepad")
sudo mousepad /usr/local/bin/xfce4-session
Then in the editor, add the following:
#!/bin/bash ### Uncomment the next line to test that this script runs on logon. ### To uncomment, remove the '#' from the beginning of the line. #echo "Login : `date`" >> /tmp/testfile ### Additional commands to run on login may be added here ### Run the normal xfce-session /usr/bin/xfce4-session ### Uncomment the next line to test that this script runs on logout. #echo "Logout : `date`" >> /tmp/testfile ### Additional commands to run on logout may be added here: killall timidity
Finally, save the script and make it executable:
sudo chmod a+x /usr/local/bin/xfce4-session