MIDI controller guide
Midi controllers include a vast assortment of musical equipment including keyboards, pads, pot/fader controls and much more. It is possible to connect these devices via USB and other means to a computer in order to trigger and control sound and video for live performances, recording, and other purposes. There are two programs among many others that can play MIDI as a software synthesizer in Gentoo, these are media-sound/timidity++ and media-sound/fluidsynth. This article will only focus on timidity++.
Installation
Kernel
Kernel drivers are usually required for external MIDI controller support such as interfacing with a MIDI keyboard or drum pads. The configuration below are examples for the legacy PC game/MIDI port and through USB, for other more exotic hardware try to find if the specific hardware is in the kernel module list.
Device Drivers --->
<*> Sound Card Support --->
<*> Advanced Linux Sound Architecture --->
<M> Sequencer Support
<M> Sequencer dummy client
...
<M> HR-timer backend support
[*] Use HR-Timer as default sequencer timer
...
(For the PC MIDI/game port)
[*] Generic sound devices --->
...
(enable any special modules here)
<M> Generic MPU-401 UART Driver
...
(USB)
[*] USB sound devices --->
<M> USB Audio/MIDI driver
(enable any special modules here)
...
USE flags
Several packages are aware of the midi USE flag.
There are several USE flags in Gentoo enabling MIDI support for packages, to see a list of some packages which contain USE flags which contain the keyword midi
, the command quse from app-portage/portage-utils could be used.
user $
quse -ve midi
TiMidity++
Emerge
Install timidity++
with:
root #
emerge --ask timidity++
optionally, install the additional fluid-soundfont
with:
root #
emerge --ask fluid-soundfont
Configuration
The available patchsets can be queried using eselect
:
user $
eselect timidity list
Available TiMidity++ patchsets: [1] fluid-soundfont [2] freepats
As an example, to set the fluid-soundfont
as the default patchset for the current user:
user $
eselect timidity set 1
Starting the daemon
The timidity daemon can be run in user mode and need not be a system service:
user $
timidity -iAD -Os
Timidity can be used with the JACK audio server. It must be started by the same user than the user running JACK, as example:
user $
timidity -iA -B2,8 -Oj -EFreverb=0 -s 48000
Connecting midi ports
To begin using the midi controller, a midi input port must be connected to an output port. To see which input ports are available:
user $
aconnect -li
client 0: 'System' [type=kernel] 0 'Timer ' 1 'Announce ' client 14: 'Midi Through' [type=kernel] 0 'Midi Through Port-0' client 28: 'KOMPLETE KONTROL A49' [type=kernel,card=3] 0 'KOMPLETE KONTROL A49 MIDI 1'
the above is an example of what the output may look like. Here the midi controller is a Native Instruments Komplete Kontrol A49.
Similarly, to see which output ports are available:
user $
aconnect -lo
client 14: 'Midi Through' [type=kernel] 0 'Midi Through Port-0' client 28: 'KOMPLETE KONTROL A49' [type=kernel,card=3] 0 'KOMPLETE KONTROL A49 MIDI 1' client 128: 'TiMidity' [type=user,pid=5294] 0 'TiMidity port 0 ' 1 'TiMidity port 1 ' 2 'TiMidity port 2 ' 3 'TiMidity port 3 '
To connect directly to Timidity, use the following command:
user $
aconnect 28:0 128:0
The connection can be verified using:
user $
aconnect -l
client 0: 'System' [type=kernel] 0 'Timer ' 1 'Announce ' client 14: 'Midi Through' [type=kernel] 0 'Midi Through Port-0' client 28: 'KOMPLETE KONTROL A49' [type=kernel,card=3] 0 'KOMPLETE KONTROL A49 MIDI 1' Connecting To: 128:0 client 128: 'TiMidity' [type=user,pid=5294] 0 'TiMidity port 0 ' Connected From: 28:0 1 'TiMidity port 1 ' 2 'TiMidity port 2 ' 3 'TiMidity port 3 '
If all went well, pressing a key on the midi controller should play a sound. This sound will depend on which timidity patchset is enabled using eselect timidity
.
To remove all connections, use:
user $
aconnect -x
Software-specific configuration
Milkytracker
To use a midi controller with Milkytracker, the package media-libs/rtmidi
is required. This package is not available in the official Gentoo repository, but can be found in several community overlays. Once rtmidi
has been installed, verify that the midi port is available:
user $
aconnect -lo
... client 129: 'RtMidi Input Client' [type=user,pid=7350] 0 'RtMidi Input '
Once a midi controller has been connected to this port, Milkytracker will automatically recognize the controller.
Troubleshooting
Testing midi controller keys
If for some reason midi controller input is not producing any output, physical device failure can be ruled out using aseqdump
from media-sound/alsa-utils
. First, identify the port of the midi controller:
user $
aconnect -l
then run the following:
user $
aseqdump -p PORT
where PORT
is the port of the midi controller. Pressing any key on the controller should show up in the stdout. If no output is displayed, assuming the correct port was used, physical hardware failure may be to blame.
Pulseaudio
Unfortunately TiMidity++ has difficulties with PulseAudio.
Two possibilities to overcome the situation:
- Remove
media-sound/pulseaudio
and disable PulseAudio support if installed by removing thepulseaudio
use flag from your system configuration - Emerge
media-sound/timidity++
with Libao support by activating theao
use flag then run Timidity with-Oo
Furthermore once PulseAudio has been removed sound may be blocked when timidity is run as a system service. The solution seems to be that some soundcards require a dmix parameter in /etc/asound.conf:
defaults.pcm.dmix.rate 48000