Difference between revisions of "Timidity"

From ArchWiki
Jump to: navigation, search
m (Alsa daemon mode)
(Soundfonts)
(32 intermediate revisions by 16 users not shown)
Line 1: Line 1:
[[Category: Audio/Video (English)]]
+
[[Category:Audio/Video]]
[[Category:HOWTOs (English)]]
+
==Introduction==
+
 
timidity++ is a MIDI to WAVE converter and player which is basically used to play MIDI files if your sound card does not support the MIDI protocol natively.
 
timidity++ is a MIDI to WAVE converter and player which is basically used to play MIDI files if your sound card does not support the MIDI protocol natively.
  
Line 26: Line 24:
  
 
===Soundfonts===
 
===Soundfonts===
There are many soundfonts available. This example will show how to isntall the fluidr3 soundfont, which is accessible via the [[AUR]].
+
There are many soundfonts available. This example will show how to install the {{AUR|fluidr3}} soundfont, which is accessible via the AUR.
 
:'''Note:''' It will be assumed that you know how to build packages from the AUR. If you have never used the AUR before, please take a look at the [[AUR_User_Guidelines|AUR User Guidelines]].
 
:'''Note:''' It will be assumed that you know how to build packages from the AUR. If you have never used the AUR before, please take a look at the [[AUR_User_Guidelines|AUR User Guidelines]].
  
As sfarkxtc, a decompressor for soundfonts, is a make dependency of fluidr3, we install it first:
+
As {{AUR|sfarkxtc}}, a decompressor for soundfonts, is a make dependency of fluidr3, we install it first. Notice that it is accessible via the AUR.
# pacman -S sfarkxtc
+
  
 
After sfarkxtc has been installed, we will be able to build fluidr3 which may take some time.
 
After sfarkxtc has been installed, we will be able to build fluidr3 which may take some time.
# wget http://aur.archlinux.org/packages/fluidr3/fluidr3/PKGBUILD
 
# wget http://aur.archlinux.org/packages/fluidr3/fluidr3/fluidr3.install
 
# wget http://aur.archlinux.org/packages/fluidr3/fluidr3/license
 
# makepkg
 
# pacman -U fluidr3-122501-6.pkg.tar.gz
 
  
If fluidr3 has been installed properly, we have to add it's path to the timidity++ configuration file. Just add this line to /etc/timidity++/timidity.cfg:
+
If fluidr3 has been installed properly, we have to add its path to the timidity++ configuration file. Just add this line to /etc/timidity++/timidity.cfg:
  soundfont /usr/share/soundfonts/fluidr3/FluidR3GM.SF2
+
  soundfont /usr/share/soundfonts/fluidr3/FluidR3_GM.SF2
  
 
Then timidity++ is ready for use.
 
Then timidity++ is ready for use.
  
 
==How to use timidity++==
 
==How to use timidity++==
 +
 +
===Convert files===
 +
timidity++ can also convert MIDI files into other formats. The following command converts a MIDI file into a WAV file:
 +
$ timidity input.mid -Ow -o out.wav
 +
 +
===Play files===
 
There are two ways to use timidity++. Either as MIDI player or as daemon adding MIDI support to [[ALSA]].
 
There are two ways to use timidity++. Either as MIDI player or as daemon adding MIDI support to [[ALSA]].
  
===Standalone mode===
+
====Standalone mode====
 
You can simply use timidity++ to play MIDI files:
 
You can simply use timidity++ to play MIDI files:
 
  $ timidity example.midi
 
  $ timidity example.midi
Line 53: Line 51:
 
Add option -in or -ig for a text mode/gtk+ interface. E.g. as a Xfce/GNOME user you may want to set MIDI files to open with the custom command `timidity -ig'. There are many other options to timidity; see manpage or use -h to get help.
 
Add option -in or -ig for a text mode/gtk+ interface. E.g. as a Xfce/GNOME user you may want to set MIDI files to open with the custom command `timidity -ig'. There are many other options to timidity; see manpage or use -h to get help.
  
===Alsa daemon mode===
+
====Daemon mode====
If you want timidity to run as ALSA daemon, just use:
+
Timidity can run as a daemon (ALSA sequencer client) providing MIDI output support for other programs such as rosegarden, aplaymidi, vkeybd, etc.
  # /etc/rc.d/timidity++ start
+
 
 +
To do this (if you are not using PulseAudio):
 +
 
 +
  # rc.d start timidity++
 +
 
 +
Add timidity++ to your daemon list in /etc/rc.conf to have permanent MIDI support:
  
If you want to have permanent MIDI support, add timidity to your daemon list in /etc/rc.conf:
 
 
  DAEMONS=(... timidity++ ...)
 
  DAEMONS=(... timidity++ ...)
  
Or if you just want to run timidity with ALSA support once, you can use the following command which will make console output viewable:
+
If you are using PulseAudio, above methods may not work, you may want to add following command as an auto start program in your desktop environment. Or if you just want to start timidity in daemon mode once, you can use the following command which will make console output viewable:
 +
 
 
  $ timidity -iA
 
  $ timidity -iA
  
Line 72: Line 75:
 
     3 'TiMidity port 3 '
 
     3 'TiMidity port 3 '
  
An example usage for this is AUR/vkeybd, a virtual MIDI keyboard for X, using yaourt[http://wiki.archlinux.org/index.php/Yaourt yaourt] we have:
+
You can now play MIDI files using aplaymidi:
 +
 
 +
$ aplaymidi filename.mid --port 128:0
 +
 
 +
Another example is vkeybd, a virtual MIDI keyboard for X.
 +
 
 +
You can install {{AUR|vkeybd}} from the [[AUR]].
  
$yaourt vkeybd
 
...
 
 
  $ vkeybd --addr 128:0
 
  $ vkeybd --addr 128:0
  
Option --addr 128:0 connects the input (readable) software MIDI port provided by vkeybd to the first output (writable) ALSA port provided by Timidity. Alternatively you can use aconnect(1), community/aconnectgui or AUR packages [http://aur.archlinux.org/packages.php?do_Details=1&ID=9668 patchage], [http://aur.archlinux.org/packages.php?ID=13818 kaconnect]. As a result when you play around with the keys on the vkeybd timidity plays the appropriate notes. See also [[USB_Midi_Keyboards|USB Midi Keyboards]].
+
Option --addr 128:0 connects the input (readable) software MIDI port provided by vkeybd to the first output (writable) ALSA port provided by Timidity. Alternatively you can use aconnect(1), community/aconnectgui or AUR packages [https://aur.archlinux.org/packages.php?do_Details=1&ID=9668 patchage], {{AUR|kaconnect}}. As a result when you play around with the keys on the vkeybd timidity plays the appropriate notes. See also [[USB_Midi_Keyboards|USB Midi Keyboards]].
 +
 
 +
===Connect to virtual MIDI device===
 +
 
 +
Once you have the timidity++ daemon running and it is working with aplaymidi, you can connect it to a virtual MIDI device that will work in programs such as rosegarden or scala.
 +
 
 +
# modprobe snd-virmidi
 +
 
 +
Use aconnect to verify the port numbers:
 +
 
 +
$ aconnect -o
 +
 
 +
client 14: 'Midi Through' [type=kernel]
 +
    0 'Midi Through Port-0'
 +
client 20: 'Virtual Raw MIDI 1-0' [type=kernel]
 +
    0 'VirMIDI 1-0    '
 +
client 21: 'Virtual Raw MIDI 1-1' [type=kernel]
 +
    0 'VirMIDI 1-1    '
 +
client 22: 'Virtual Raw MIDI 1-2' [type=kernel]
 +
    0 'VirMIDI 1-2    '
 +
client 23: 'Virtual Raw MIDI 1-3' [type=kernel]
 +
    0 'VirMIDI 1-3    '
 +
client 128: 'TiMidity' [type=user]
 +
    0 'TiMidity port 0 '
 +
    1 'TiMidity port 1 '
 +
    2 'TiMidity port 2 '
 +
    3 'TiMidity port 3 '
 +
 
 +
Now create the connection:
 +
$ aconnect 20:0 128:0
 +
 
 +
You should now have a working MIDI output device on your system (/dev/snd/midiC1D0).
 +
 
  
 
==Troubleshooting==
 
==Troubleshooting==
Line 90: Line 129:
  
 
Make sure you've installed some samples and your soundfile is added to /etc/timidity++/timidity.cfg. See [[Timidity#Setting up the sound samples|Setting up the sound samples]] above for more details.
 
Make sure you've installed some samples and your soundfile is added to /etc/timidity++/timidity.cfg. See [[Timidity#Setting up the sound samples|Setting up the sound samples]] above for more details.
 +
 +
===timidity++ daemon mode won't start===
 +
First, make sure you are in audio group. If not, add yourself to audio group:
 +
 +
# gpasswd audio -a yourusername
 +
 +
After group change, you should re-login.
 +
 +
If you are using PulseAudio, instead of
 +
 +
# rc.d start timidity++
 +
 +
Start timidity++ in your Desktop Environment:
 +
 +
$ timidity -iA -OO
 +
 +
If you want to run timidity++ in background, do not use timidity++'s daemonize option, use & instead.
 +
 +
===timidity++ daemon mode plays sound out of pace===
 +
timidity++'s ALSA output module (default) may cause this issue in ALSA server mode. Try another output option, for example, libao:
 +
 +
$ timidity -iA -OO
 +
 +
And test it using aplaymidi. If this does not work, you may want to configure [[JACK]] and set timidity++'s output to jack.
  
 
===How to make DOSBox use Timidity++===
 
===How to make DOSBox use Timidity++===

Revision as of 11:41, 24 September 2012

timidity++ is a MIDI to WAVE converter and player which is basically used to play MIDI files if your sound card does not support the MIDI protocol natively.

Installing timidity++

The first step is to install timidity++ itself. It can be installed via pacman from the extra repository:

# pacman -S timidity++

However, timidity++ will not produce any sound yet. This is because timidity++ does not include any instrument samples. To produce sound, instrument patches and/or soundfonts need to be installed and timidity++ configured so it knows where to find them. This guide shows two ways of getting sound samples: Freepats and soundfonts.

Setting up the sound samples

Freepats

The Freepats project provides a set of instrument samples which are compatible with timidity++. It can be installed from the community repository:

# pacman -S timidity-freepats

To use Freepats with timidity, add the following lines to /etc/timidity++/timidity.cfg:

dir /usr/share/timidity/freepats
source /etc/timidity++/freepats/freepats.cfg

Then timidity++ is ready for use.

Soundfonts

There are many soundfonts available. This example will show how to install the fluidr3AUR soundfont, which is accessible via the AUR.

Note: It will be assumed that you know how to build packages from the AUR. If you have never used the AUR before, please take a look at the AUR User Guidelines.

As sfarkxtcAUR, a decompressor for soundfonts, is a make dependency of fluidr3, we install it first. Notice that it is accessible via the AUR.

After sfarkxtc has been installed, we will be able to build fluidr3 which may take some time.

If fluidr3 has been installed properly, we have to add its path to the timidity++ configuration file. Just add this line to /etc/timidity++/timidity.cfg:

soundfont /usr/share/soundfonts/fluidr3/FluidR3_GM.SF2

Then timidity++ is ready for use.

How to use timidity++

Convert files

timidity++ can also convert MIDI files into other formats. The following command converts a MIDI file into a WAV file:

$ timidity input.mid -Ow -o out.wav

Play files

There are two ways to use timidity++. Either as MIDI player or as daemon adding MIDI support to ALSA.

Standalone mode

You can simply use timidity++ to play MIDI files:

$ timidity example.midi

Add option -in or -ig for a text mode/gtk+ interface. E.g. as a Xfce/GNOME user you may want to set MIDI files to open with the custom command `timidity -ig'. There are many other options to timidity; see manpage or use -h to get help.

Daemon mode

Timidity can run as a daemon (ALSA sequencer client) providing MIDI output support for other programs such as rosegarden, aplaymidi, vkeybd, etc.

To do this (if you are not using PulseAudio):

# rc.d start timidity++

Add timidity++ to your daemon list in /etc/rc.conf to have permanent MIDI support:

DAEMONS=(... timidity++ ...)

If you are using PulseAudio, above methods may not work, you may want to add following command as an auto start program in your desktop environment. Or if you just want to start timidity in daemon mode once, you can use the following command which will make console output viewable:

$ timidity -iA

This will give you four output software MIDI ports (in addition of hardware MIDI ports on your system, if any):

$  aconnect -o
client 128: 'TiMidity' [type=user]
    0 'TiMidity port 0 '
    1 'TiMidity port 1 '
    2 'TiMidity port 2 '
    3 'TiMidity port 3 '

You can now play MIDI files using aplaymidi:

$ aplaymidi filename.mid --port 128:0

Another example is vkeybd, a virtual MIDI keyboard for X.

You can install vkeybdAUR from the AUR.

$ vkeybd --addr 128:0

Option --addr 128:0 connects the input (readable) software MIDI port provided by vkeybd to the first output (writable) ALSA port provided by Timidity. Alternatively you can use aconnect(1), community/aconnectgui or AUR packages patchage, kaconnectAUR. As a result when you play around with the keys on the vkeybd timidity plays the appropriate notes. See also USB Midi Keyboards.

Connect to virtual MIDI device

Once you have the timidity++ daemon running and it is working with aplaymidi, you can connect it to a virtual MIDI device that will work in programs such as rosegarden or scala.

# modprobe snd-virmidi

Use aconnect to verify the port numbers:

$ aconnect -o
client 14: 'Midi Through' [type=kernel]
    0 'Midi Through Port-0'
client 20: 'Virtual Raw MIDI 1-0' [type=kernel]
    0 'VirMIDI 1-0     '
client 21: 'Virtual Raw MIDI 1-1' [type=kernel]
    0 'VirMIDI 1-1     '
client 22: 'Virtual Raw MIDI 1-2' [type=kernel]
    0 'VirMIDI 1-2     '
client 23: 'Virtual Raw MIDI 1-3' [type=kernel]
    0 'VirMIDI 1-3     '
client 128: 'TiMidity' [type=user]
    0 'TiMidity port 0 '
    1 'TiMidity port 1 '
    2 'TiMidity port 2 '
    3 'TiMidity port 3 '

Now create the connection:

$ aconnect 20:0 128:0

You should now have a working MIDI output device on your system (/dev/snd/midiC1D0).


Troubleshooting

timidity++ does not play MIDI files

It may be that your soundfile is not set up correctly. Just run:

$ timidity example.midi

If you find a line like this in the terminal output, your soundfile is not set up properly.

No instrument mapped to tone bank 0, program XX - \
this instrument will not be heard

Make sure you've installed some samples and your soundfile is added to /etc/timidity++/timidity.cfg. See Setting up the sound samples above for more details.

timidity++ daemon mode won't start

First, make sure you are in audio group. If not, add yourself to audio group:

# gpasswd audio -a yourusername

After group change, you should re-login.

If you are using PulseAudio, instead of

# rc.d start timidity++

Start timidity++ in your Desktop Environment:

$ timidity -iA -OO

If you want to run timidity++ in background, do not use timidity++'s daemonize option, use & instead.

timidity++ daemon mode plays sound out of pace

timidity++'s ALSA output module (default) may cause this issue in ALSA server mode. Try another output option, for example, libao:

$ timidity -iA -OO

And test it using aplaymidi. If this does not work, you may want to configure JACK and set timidity++'s output to jack.

How to make DOSBox use Timidity++

The following method is tested in version DOSBox 0.72 (don't know if this works for OLDER or NEWER!).

First of all, you need to write a config file. Input the following in DOSBox to create a configuration file:

config -writeconf dosbox.conf

you can replace dosbox.conf by anyname that you want, add a dot in front of it if you want to hide it.

Make sure you statred Timidity++ as DAEMON as the instructions above, use the aconnect command.

Edit this configuration file with any editor, go to the section:

[midi]
mpu401=intelligent
device=default
config=

put the ALSA connection port into the back of config=, in default:

config=128:0

Restart DOSBox within a terminal so you can see its debug messages, by no accident you should see a successful initiation on port 128:0.