Here’s how I got Mplay.jl to work under Linux (Ubuntu 20.04).
Mplay.jl writes to a “raw midi device”, and Ubuntu does not have those on by default.
To create a “virtual midi device” I do
$ sudo modprobe snd-virmidi snd_index=1
On my system they show up like this:
$ ls /dev/snd/midi*
/dev/snd/midiC3D0 /dev/snd/midiC3D1 /dev/snd/midiC3D2 /dev/snd/midiC3D3
The number “3” in “midiC3D0” is important, and depends on the number of physical soundcards on the system.
We also need a software synthesizer to turn the midi code into a sound signal. I use fluidsynth
together with the FluidR3 GM
soundfonts. On Ubuntu I get them like this (we will need alsa-utils also):
$ sudo apt install fluidsynth fluid-soundfont-gm alsa-utils
Then I can run fluidsynth
in “server mode” (it blocks the terminal):
$ fluidsynth --server --audio-driver=alsa -o audio.alsa.device=hw:0 /usr/share/sounds/sf2/FluidR3_GM.sf2
>
Here the device “hw:0” is the soundcard on the motherboard, so the sound will come out of the headphones I plugged in the jack on the front of the computer.
Now we need to connect fluidsynth
to the the virtual midi device. This is done using aconnect
from alsa-utils.
First we need an overview of our system:
$ aconnect -l
client 0: 'System' [type=kernel]
0 'Timer '
1 'Announce '
client 14: 'Midi Through' [type=kernel]
0 'Midi Through Port-0'
client 28: 'Virtual Raw MIDI 3-0' [type=kernel,card=3]
0 'VirMIDI 3-0 '
client 29: 'Virtual Raw MIDI 3-1' [type=kernel,card=3]
0 'VirMIDI 3-1 '
client 30: 'Virtual Raw MIDI 3-2' [type=kernel,card=3]
0 'VirMIDI 3-2 '
client 31: 'Virtual Raw MIDI 3-3' [type=kernel,card=3]
0 'VirMIDI 3-3 '
client 128: 'FLUID Synth (5104)' [type=user,pid=5104]
0 'Synth input port (5104:0)'
My virtual midi devices are clients 28 to 31 and fluidsynth
is client 128 (these numbers might be different on other systems).
Then I can connect the output of client 28 to the input of client 128 like this:
$ aconnect 28:0 128:0
The result should look like this:
$ aconnect -l
client 0: 'System' [type=kernel]
0 'Timer '
1 'Announce '
client 14: 'Midi Through' [type=kernel]
0 'Midi Through Port-0'
client 28: 'Virtual Raw MIDI 3-0' [type=kernel,card=3]
0 'VirMIDI 3-0 '
Connecting To: 128:0
client 29: 'Virtual Raw MIDI 3-1' [type=kernel,card=3]
0 'VirMIDI 3-1 '
client 30: 'Virtual Raw MIDI 3-2' [type=kernel,card=3]
0 'VirMIDI 3-2 '
client 31: 'Virtual Raw MIDI 3-3' [type=kernel,card=3]
0 'VirMIDI 3-3 '
client 128: 'FLUID Synth (5104)' [type=user,pid=5104]
0 'Synth input port (5104:0)'
Connected From: 28:0
Now we are ready to start Mplay.jl using the helper script in the src
directory:
Mplay.jl/src$ bash Mplay.sh --device="hw:3,0" song.midi
Here the number “3” in “hw:3,0” is the same “3” as in /dev/snd/midiC3D0
With a bit of luck, your song will now play.
If not, try reconnecting the midi device and fluidsynth
by doing
$ aconnect -x
$ aconnect 28:0 128:0
The graphical tool aconnectgui
gives a graphical version of aconnect -l
I hope this can help others.
I’ve used these 2 midi tutorials:
There a lots of free midi file son the internet, eg here: https://freemidi.org/