Linux play midi file

Linux play midi file

MIDI itself, which stands for «Musical Instrument Digital Interface», is just a protocol and standard for communication between musical instruments and any device that understands the language. It can be used to control an array of synthesizers, make a tin can sound like a drum, or even operate industrial equipments.

The scope of this article, however, will mainly focus on the usage of MIDI in computer systems for playback of files that contain MIDI data. These files usually come with the .mid extension, and were hugely popular in the golden days of multimedia computing to share music. In professional music composition/arrangement, it still plays a vital role.


MIDI file

Without going into the details of what the format is composed of, you just need to understand that a MIDI file eg. foobar.mid does not contain any digital audio data, hence no «PCM stream». It is a common misconception that MIDI is a sound file format, and as such you usually see people complaining that music players like Amarok cannot play the file. Here is a very newbie-friendly outline of what a MIDI/MID file contains:

In order for such a file to be useful, there needs to be an «engine» that can translate the data to music. This engine will have a «tone generator», and this is what we call a «synthesizer». So any player that can play back a MIDI file without MIDI-capable hardware (your computer’s sound device), has a synthesizer built-in or uses an external one. A typical keyboard (not the thing you are typing on) is actually made up of two components — a MIDI «controller» (the keys) and a synthesizer (tone generator/module; the thing that makes sound).

So up to this point, you should be able to understand that:

  • There needs to be a synthesizer to play a MIDI file.
  • A synthesizer can be hardware or software.
  • Most computer soundcards/chipsets do NOT have synthesizers.
  • You need a synthesizer with a proper «bank» (collection of sounds) to be able to enjoy all the glory of MIDI files.
  • If a certain instrument is not in the bank, your synthesizer will not play anything for notes using that instrument.
  • If a certain instrument in the file corresponds to a different one in the bank, your synthesizer will play a different sound (obviously).

GM Bank

General MIDI (GM) is a specification to standardise numerous MIDI-related matters, particularly that of instruments layout in a collection of sounds. A «soundbank» which is GM-compatible means that it meets the criteria of General MIDI, and as long as the MIDI file is also GM-compatible (as in nothing extraordinary is defined — such as introducing a new instrument or having one in a different location of the bank), the playback will be as intended since the bank has the correct instrument/handler for the MIDI message/event. One of the most popular soundbank formats is that of SoundFont, particularly SF2.

  • If you have a soundcard which can make use of soundfonts, you can load a .sf2 file onto it.
  • If you do not have a soundcard which can make use of soundfonts (basically no hardware synthesizer), you can use a software synthesizer and load the SF2 file. In turn, you can find some way to globally make use of this synthesizer.

List of SoundFonts

To be able to play or convert MIDI files, a SoundFont is needed. This is a list of some SoundFonts that is available in the official repository and the AUR.


«Why can I play MIDI with Windows Media Player, then?»

Well, because Windows has a default software synthesizer which acts globally. Even then, it lacks the quality which should be expected of modern computers. If there were a way to do it on Linux, you would be able to play back MIDI from any player too. Perhaps a MIDI server (which will hold a synthesizer of choice like timidity++ or fluidsynth ) that sits within the sound server, like Phonon or PulseAudio. Nevertheless, nothing of this sort has been implemented and you can only play MIDI with a player, or sound server, that has a plug-in to source a synthesizer, or has a synthesizer itself. For example audacious .

Читайте также:  Как подключить к виндовс 10 принтер hp laserjet 1010


(More details on soundcards and MIDI, possibly links to SBLive MIDI here. )

If you simply need to play a MIDI file on a MIDI-capable hardware device (e.g. a hardware synthesizer), you can use the aplaymidi command. To get the list of the available MIDI ports use the command

Then to play a MIDI file specify it along with an available port of the preferred MIDI device that you got from the output of the previous command, for example like this:

SB Audigy 1 — Emu10k1 WaveTable

First, make sure that the Synth mixer control is not muted and that Audigy Analog/Digital output Jack is set to [Off].

To check and adjust them, use alsamixer or your mixer of choice.

Next, build and install the awesfx AUR package from the AUR. Then, load a SoundFont file on the Emux WaveTable, like so:

The .SF2 file can be any SoundFont. If you have access to 2GMGSMT.SF2 on Windows, you can use that one.

You should be all set now. To play your .mid files with aplaymidi , you will have to do as follows:

Get a list of the available MIDI ports by running

Then, pick an available «Emu10k1 WaveTable» MIDI port, in this case 29:0, and specify it as such:



You can play MIDI files in deadbeef AUR player after installing and configuring freepats.cfg which is provided by freepats-general-midi . See Timidity#Freepats. You can also change the freepats.cfg file location in DeaDBeeF by going to Edit > Preferences > Plugins > WildMidi Player > Configure.

GStreamer-based players

You can play MIDI files on GNOME Videos and all other players using GStreamer as backend after having installed gst-plugins-bad and fluidsynth , and installed a soundfont ( soundfont-fluid for example). See FluidSynth for more info.

If you choose to use soundfont-fluid , the default search strategy will probably select FluidR3_GS.sf2 rather than FluidR3_GM.sf2. There can be no audio if that’s the case. To prevent this, you can use a symlink:

You can play MIDI files on VLC if you configure the location of the Sound Font file. Previously you need to install a sound sample, as well as the fluidsynth and vlc-plugin-fluidsynth-bin AUR package (without the latter, the audio codec will not appear in the preferences).

In VLC choose Tools > Preferences: you have to show all settings. Then, go to Input/Codecs > Audio codecs > FluidSynth.

And, if you installed e.g. fluidr3 as wiki says, set the location to:


audacious has a built-in MIDI synthesizer which makes it essentially the easiest way to play a MIDI file with no extra setup. You can specify the soundfont to use for playback in the settings of its MIDI output plugin (File > Preferences > Plugins > Input > AMIDI-Plug > Preferences). As such the only prerequisites you need is the player and a soundfont file.


MIDI to WAVE converter and player. See TiMidity++.


MIDI player and a daemon adding MIDI support to ALSA. See FluidSynth.


Drumstick MIDI File Player is able to play MIDI files. Install dmidiplayer AUR .


SF-Xpt’s Blog

Just another weblog

How to play midi files under Ubuntu Linux

How to play midi files under Ubuntu Linux

Playing midi under Linux is an old topic that nobody talks about nowadays. Hence all documents/blogs/how-tos on playing midi under Linux are more or less outdated. I’ve exhausted all my google searched but still having trouble to piece together the puzzles into a whole piece.

Finally with the help from John O’M, it is working for me now. Here is how I get it working.

The problem

After an exhausted search from Google, this is what I came back as the conclusion:

However, all that I got is:

Following another article and adding fluid-soundfont-gm to the installation does not solve the problem at all.

The solution

Thanks to John O’M, The puzzle is now complete. What’s missing is the package freepats , available from Ubuntu 14.04 onward.

So the total solution for play midi files under Ubuntu is:

  1. Install all required pacages by running
  2. Run timidity -iA in terminal first to check/get started. It should give something like this
Читайте также:  0х0000050 что за ошибка

If so, congratulations, your midi is working.
You can play a midi file directly from the command timidity followed by the file name. For example,

Or, if you want a GUI, you can simply type

and an old-fashioned window will pop up.

The explanation


This only works in terminal and can only play one midi file at a time.

If you want a playlist and graphical interface and controls, a proposed solution is Audacious, I.e.,

Audacious + AMidi Plug Plugin + fluid-soundfont-gm

But I don’t know how legitimate or how feasible is that, because it is from the same author that said “timidity + fluid-soundfont-gm” will work and provide “excellent sound”.

Back to timidity

In fact, although timidity is a command line tool, it can not only play files one-at-a-time, but also can play an entire directory. Timidity will also direct output to audio file (could be mp3 or ogg) with the identical sound so you can use them on any player. Good to share the MIDIs with those who don’t have proper midi player or good soundfont.

Moreover, with the timidity-interfaces-extra , it allows you to play midi files from your file browser as well. It will let you select which interface you prefer ( timidity -ia = default Gnome; timidity -ig = GTK interface; timidity -ik = TKM interface).
Make sure that you specify “Open With” to point to timidity. So, the command attached to your timidity icon should read timidity -ig (if that is your choice).


Feel free to skip this ranting section if you want.

The Ubuntu Software Synthesis HowTo is the fist hit that I visited, but that page is full of outdated info.

MIDI Tools

The above wiki says:

There are three main programs that do software synthesis: TiMidity++, Fluidsynth and ZynAddSubFX

ZynAddSubFX is easiest to use when you want to output a single instrument, as it does not require samples or soundfonts. When you want to play a MIDI stream with multiple instruments, such as a General MIDI file, FluidSynth or Timidity++ are an easier fit. FluidSynth has a nice GUI, but you will have to search for a suitable soundfont to go with it. TiMidity++ is a bit harder to install and use, but you can easily install a sample set for it from the repostories.

My first impression is,

  1. ZynAddSubFX is easiest to play a MIDI stream with a single instrument
  2. FluidSynth can handle multiple instruments but you will have to search for a suitable soundfont to go with it.
  3. TiMidity++ is a bit harder to install and use than FluidSynth

If you have such similar impression as mine, or your agree with my understanding from above wiki article, then congratulation, you have also been successfully fooled by the wiki article, because

  • ZynAddSubFX will not help your to play a MIDI file.
  • TiMidity is not hard to install at all. FluidSynth is the hardest.

The freepats samples

Still on the above wiki, at:
it says this sample set (freepats) “is incomplete at the moment and doesn’t cover the whole General MIDI standard yet”. I’m sure it is true, but I have to say it is very misleading — to me “incomplete” means work stopped half the way, but I played a pop music, which consists of 18 instrument tracks, I get this:

That’s much more than I expected. I don’t care if the “New Age”, or “Distrortion Guitar” or “Overdriven Guitar” is available or not, the more basic things like Shaker, Drum or Brass etc are more important to me. As long as they are there, missing some bells or whistles is not that a huge issue to me.

The CPU Usage

Still that wiki, it tells people how to fix TiMidity if it uses too much CPU. Well, when I play the above 15-instrument midi, my 10+ years old CPU barely shows any usage. The CPU graph is flat at the bottom, barely see any dent.



How to Play Midi Music on Linux



These days, I’ve stumbled upon my thousand-year-old midi music, which has been going through the long years from the good old Doom 1 era deep in the subdirectories of my machine. I thought I’d listen to them again . But unfortunately I wasn’t successful because none of the players knew the format. So with a little trace, but in the end I managed to play the midi music.

Читайте также:  Заправка картриджей для киосеры

In this description, we force our Linux system to play our old midi music with our favorite media player programs, such as Audacious or VLC Player, or we can even launch them from the command line.

Sound sample set (SoundFont) files

Before we can play midi music, we will need a so-called. sound sample set file (Sound Font), which stores sound samples of instruments needed to play midi music. This is because midi music is not an audio format, but rather resembles a kind of script that contains the soundtracks, the beats in them, and which instrument to play in that particular soundtrack, at what pitch, and so on. And the instruments are loaded from this sound sample set file by the music player you are using. As a result, midi files are extremely small in size, with just a few kbytes of file size, long, many-minute music can be compiled. That’s why they were so popular.

This was natural on windows systems by default to support the midi file format in all media player programs, but on Linux, unfortunately, these sound sample set files must be obtained separately by downloading a simple file or even installing the package in the distribution.

In the following chapters, we will obtain these files, as well as operate them with two player programs and from the command line.

Play Midi Music with Audacious Music Player

Install the packages containing the FluidSynth software MIDI synthesizer sound sample set files, fluid-soundfont-gm and the fluid-soundfont-gs package to APT with the package manager:

Note that the first package will not upload a normally small file, but an 142 Mb.

After installing the packages, the required sound sample set files are a / Usr / share / sounds / sf2 directory, but in other distributions they may land in another directory. The location of the files is as follows dpkg command if you do not put them in the directory above:

Then launch the Audacious music player, not the QT interface, but the regular GTK window, and then click File menu options:

Then, as shown in the picture, go to the Extensions main menu, then to the Input tab at the top, select the AMIDI-Plug (MIDI Player) plugin and click the settings button below.

This will bring up the plugin configuration window:

Here in the middle SoundFont libraries section, add the file you see in the image by right-clicking the plus button in the file browser. Or, if the file was on a different path, we would of course specify it.

Then close the panel and you’re done.

From now on, the Audacious music player will now launch our MIDI files.

Play midi music with VLC media player

To play MIDI files on the VLC media player, install Fluidsynth VLC plugin package:

Then, once the player was open, you just have to restart it and MIDI music is already in it.

This does not require any other setup, but you can do this here, for example, if you want to configure another SoundFont file (eg your own), or more, click Tools — Options in the main VLC window:

Here, click «All» in the lower left corner, then the window will switch to expanded view. Here, click the Input / Codecs group, including the Audio Codecs subgroup, and then the FluidSynth codec:

And here we can still adjust things if needed.

Play midi music from the command line

So far, we’ve used FluidSynth’s music and media player plugin and codec, now it’s Fluidsynth install a program (package) for MIDI playback from the command line:

Then the Fluidsynth command to play your MIDI files as follows:

(Here is the CTRL + C keys to pause playback.)


Now you can easily play your MIDI music with your favorite media player. In addition, there are many media players, and many of them are likely to configure the ability to open MIDI files by specifying a SoundFont file. I use these two so I set them up on my machine as well. But you can experiment with other media player programs in the light of the above.


Поделиться с друзьями