I'm looking for a most simple command line app (or an on-board tool on Mavericks I am not aware of) to play a midi file from the terminal. As plain as possible, something like play myfile.mid
.
Context: I'm playing around with midi in Python and I need something I can launch from a script. No GUI, no windows, just playback. It must be callable from the Python script to be accepted, but anything that works in terminal should be.
Best Answer
This turned out to be a more complicated problem than I originally expected.
QuickTime X cannot play MIDI files, although QuickTime 7 could.
As far as I can tell that means that there is no "built-in" solution to playing MIDI files on Mac OS X (for example,
afplay
does not work). Therefore I believe that any solution will involve downloading and installing some other program.Option #1: Download and install QuickTime 7 which still works fine on Mavericks, and then you can play midi files by:
however that will only autoplay if the user has enabled that preference, which I believe is off by default.
Option #2: Use FluidSynth
To install it, you have to be using either Fink, MacPorts, or (my recommendation) Homebrew. Once Homebrew is installed, type this in Terminal:
(MacPorts' command would be
sudo port install fluidsynth
and Fink's would befink install fluidsynth
.)However, downloading
fluidsynth
only gets you part-way there. Then you need a "SoundFont" file, which I had never heard of before. There is information about them hereI downloaded one from S. Christian Collins called "GeneralUser" which is free. The current version (as of 2013-11-27) is FluidSynth version 1.44. {If that direct link breaks in the future, use the previous link which will take you to the regular web page for GeneralUser.}
Once you have downloaded and unzipped that, you will have a series of files including "GeneralUser GS FluidSynth v1.44.sf2" (obviously the name may change in the future). I renamed that file and moved it to
/usr/local/share/fluidsynth/generaluser.v.1.44.sf2
.Once the SoundFont file is place and
fluidsynth
is installed, you can play a midi by using this command:n.b. There are some (seemingly harmless) error messages which get displayed when you do that. If you want to suppress them use:
instead.
Obviously I'm never going to remember all of that, so I made a
zsh
function calledplaymidi
(That should work for
bash
too I believe.)Now all I have to do is type:
and
example.mid
will play.