Difference between revisions of "Timidity"

From ArchWiki
Jump to: navigation, search
m (Standalone mode)
(Fluidr3: the soundfont filename seems to have changed)
 
(30 intermediate revisions by 16 users not shown)
Line 1: Line 1:
[[Category:Audio/Video]]
+
[[Category:Multimedia]]
Timidity++ is a [[Wikipedia:software synthesizer|software synthesizer]] that can play MIDI files without a hardware synthesizer. It can either render to the sound card in real time, or it can save the result to a file, such as a PCM .wav file.
+
[[ja:Timidity]]
 +
TiMidity++ is a [[Wikipedia:software synthesizer|software synthesizer]] that can play MIDI files without a hardware synthesizer. It can either render to the sound card in real time, or it can save the result to a file, such as a PCM .wav file.
  
 
== Installation ==
 
== Installation ==
[[Pacman|Install]] the {{Pkg|timidity++}} package from the [[Official repositories]].
 
  
You should also install a [[Wikipedia:Soundfont|soundfont]] to be able to produce sound. Here is a list of soundfonts:
+
[[Install]] the {{Pkg|timidity++}} package from the [[official repositories]].
* {{Pkg|timidity-freepats}} from the [[Official repositories]].
+
 
* {{AUR|fluidr3}} from the [[AUR]]
+
You should also install a [[Wikipedia:SoundFont|SoundFont]] to be able to produce sound. Here is a list of SoundFonts:
 +
 
 +
* {{Pkg|timidity-freepats}}.
 +
* {{Pkg|soundfont-fluid}}
  
 
== Configuration ==
 
== Configuration ==
=== Soundfonts ===
+
 
Configure your choosed soundfont:
+
First you should add yourself to the audio group.
 +
 
 +
# gpasswd -a <user> audio
 +
 
 +
=== SoundFonts ===
 +
 
 +
Configure your preferred SoundFont.
 +
 
 
==== Freepats ====
 
==== Freepats ====
The [http://freepats.zenvoid.org/ Freepats] project provides a set of instrument samples which are compatible with timidity++.
 
  
To use Freepats with timidity, add the following lines to {{ic|timidity.cfg}}:
+
The [http://freepats.zenvoid.org/ Freepats] project provides a set of instrument samples which are compatible with TiMidity++.
 +
 
 +
To use Freepats with TiMidity, add the following lines to {{ic|timidity.cfg}}:
  
 
{{hc|/etc/timidity++/timidity.cfg|
 
{{hc|/etc/timidity++/timidity.cfg|
Line 23: Line 34:
  
 
==== Fluidr3 ====
 
==== Fluidr3 ====
There are other soundfonts available. This will show how to install the {{AUR|fluidr3}} soundfont.
 
  
Now we have to add its path to the timidity++ configuration file. Just add this line:
+
There are other SoundFonts available. To install the {{Pkg|soundfont-fluid}} SoundFont, append its path to the TiMidity++ configuration file:
  
 
{{hc|/etc/timidity++/timidity.cfg|
 
{{hc|/etc/timidity++/timidity.cfg|
soundfont /usr/share/soundfonts/fluidr3/FluidR3GM.SF2
+
soundfont /usr/share/soundfonts/FluidR3_GM.sf2
 
}}
 
}}
  
 
=== Daemon ===
 
=== Daemon ===
Start and configure to autostart the {{ic|timidity.service}}. Read [[Daemons]] for more details.
 
  
If you are using [[PulseAudio]], that may not work. You may want to add the 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:
+
[[Start]] and [[enable]] the {{ic|timidity.service}}.
  
{{bc|$ timidity -iA}}
+
If you are using [[PulseAudio]], that may not work. You may want to add the 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
 +
 
 +
You can also use [[Systemd/User]] to write an user TiMidity++ service. To do so, write a {{ic|timidity.service}} file in {{ic|~/.config/systemd/user/}} like that one :
 +
 
 +
{{hc|/etc/systemd/user/timidity.service|<nowiki>[Unit]
 +
Description=TiMidity++ Daemon
 +
After=sound.target
 +
 
 +
[Service]
 +
ExecStart=/usr/bin/timidity -iA -Os
 +
 
 +
[Install]
 +
WantedBy=default.target</nowiki>
 +
}}
 +
 
 +
Then enable the service with:
 +
 
 +
  $ systemctl --user enable timidity.service
  
 
== Usage ==
 
== Usage ==
===Play files===
 
There are two ways to use timidity++. Either as MIDI player or as daemon adding MIDI support to [[ALSA]].
 
  
====Standalone mode====
+
=== Play files ===
You can simply use timidity++ to play MIDI files:
+
 
{{bc|$ timidity example.midi}}
+
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 {{ic|-in}} or {{ic|-ig}} for a text-based/gtk+ interface. E.g. as a Xfce/GNOME user you may want to set MIDI files to open with the custom command {{ic|timidity -ig}}. There are many other options to timidity; see {{ic|man timidity}} or use {{ic|-h}} to get help.
+
Add option {{ic|-in}} or {{ic|-ig}} for a text-based/gtk+ interface. E.g. as a Xfce/GNOME user you may want to set MIDI files to open with the custom command {{ic|timidity -ig}}. There are many other options to TiMidity++. See {{ic|man timidity}} or use {{ic|-h}} to get help.
  
 
The GTK+ interface offers such features as a playlist, track length estimates, volume control, a file load dialog box, play and pause buttons, rewind and fast forward buttons, as well as options to change the pitch of or speed up or slow down the playback of a midi file.
 
The GTK+ interface offers such features as a playlist, track length estimates, volume control, a file load dialog box, play and pause buttons, rewind and fast forward buttons, as well as options to change the pitch of or speed up or slow down the playback of a midi file.
  
====Daemon mode====
+
==== Daemon mode ====
If you are runing timidity as a [[#Daemon]] (ALSA sequencer client), it will provide MIDI output support for other programs such as rosegarden, aplaymidi, vkeybd, etc.
+
 
 +
If you are runing TiMidity++ as a [[#Daemon|daemon]] (ALSA sequencer client), it will provide MIDI output support for other programs such as rosegarden, aplaymidi, vkeybd, etc.
  
 
This will give you four output software MIDI ports (in addition of hardware MIDI ports on your system, if any):
 
This will give you four output software MIDI ports (in addition of hardware MIDI ports on your system, if any):
{{hc|$  aconnect -o|<nowiki>
+
{{hc|$  aconnect -o|2=
 
client 128: 'TiMidity' [type=user]
 
client 128: 'TiMidity' [type=user]
 
     0 'TiMidity port 0 '
 
     0 'TiMidity port 0 '
Line 60: Line 92:
 
     2 'TiMidity port 2 '
 
     2 'TiMidity port 2 '
 
     3 'TiMidity port 3 '
 
     3 'TiMidity port 3 '
</nowiki>}}
+
}}
  
 
You can now play MIDI files using aplaymidi:
 
You can now play MIDI files using aplaymidi:
  
{{bc|$ aplaymidi filename.mid --port 128:0}}
+
$ aplaymidi filename.mid --port 128:0
  
 
Another example is '''vkeybd''', a virtual MIDI keyboard for X.
 
Another example is '''vkeybd''', a virtual MIDI keyboard for X.
  
You can [[Pacman|install]] {{AUR|vkeybd}} from the [[AUR]].
+
You can [[install]] {{AUR|vkeybd}} from the [[AUR]].
  
{{bc|$ vkeybd --addr 128:0}}
+
$ vkeybd --addr 128:0
  
Option {{ic|--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.
+
Option {{ic|--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, {{AUR|aconnectgui}}{{Broken package link|{{aur-mirror|aconnectgui}}}}, {{Pkg|patchage}} or kaconnect. As a result when you play around with the keys on the vkeybd TiMidity++ plays the appropriate notes.
  
====Connect to virtual MIDI device====
+
==== 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.
+
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.
  
 
Load the {{ic|snd-virmidi}} '''kernel module''' and (optionally) configure it to be loaded at boot. Read [[Kernel modules]] for more information.
 
Load the {{ic|snd-virmidi}} '''kernel module''' and (optionally) configure it to be loaded at boot. Read [[Kernel modules]] for more information.
Line 82: Line 114:
 
Use aconnect to verify the port numbers:
 
Use aconnect to verify the port numbers:
  
{{hc|$ aconnect -o|<nowiki>
+
{{hc|$ aconnect -o|2=
 
  client 14: 'Midi Through' [type=kernel]
 
  client 14: 'Midi Through' [type=kernel]
 
     0 'Midi Through Port-0'
 
     0 'Midi Through Port-0'
Line 98: Line 130:
 
     2 'TiMidity port 2 '
 
     2 'TiMidity port 2 '
 
     3 'TiMidity port 3 '
 
     3 'TiMidity port 3 '
</nowiki>}}
+
}}
 
Now create the connection:
 
Now create the connection:
{{bc|$ aconnect 20:0 128:0}}
+
$ aconnect 20:0 128:0
  
 
You should now have a working MIDI output device on your system ({{ic|/dev/snd/midiC1D0}}).
 
You should now have a working MIDI output device on your system ({{ic|/dev/snd/midiC1D0}}).
  
==Troubleshooting==
+
== Troubleshooting ==
===timidity++ does not play MIDI files===
+
It may be that your soundfile is not set up correctly. Just run:
+
{{bc|$ timidity example.midi}}
+
  
If you find a line like this in the terminal output, your soundfile is not set up properly.
+
=== TiMidity++ does not play MIDI files ===
{{bc|
+
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 {{ic|/etc/timidity++/timidity.cfg}}. See [[#Soundfonts]] above for more details.
+
It may be that your SoundFile is not set up correctly. Just run:
 +
$ timidity example.midi
  
===Daemon mode won't start===
+
If you find a line like this in the terminal output, your SoundFile is not set up properly.
First, make sure you are in the '''audio''' group. If not, add yourself to it:
+
  
{{bc|# gpasswd audio -a yourusername}}
+
No instrument mapped to tone bank 0, program XX - \
 +
this instrument will not be heard
  
After group change, you should re-login.
+
Make sure you've installed some samples and your SoundFile is added to {{ic|/etc/timidity++/timidity.cfg}}. See [[#SoundFonts|SoundFonts]] for more details.
  
If you are using [[PulseAudio]], instead of [[Daemons|enabling]] the {{ic|timidity.service}}, start timidity++ as an user:
+
=== Daemon mode plays sound out of pace ===
  
{{bc|$ timidity -iA -OO}}
+
TiMidity++'s ALSA output module (default) may cause this issue in ALSA server mode. Try another output option, for example, '''libao''':
  
If you want to run timidity++ in background, do not use timidity++'s daemonize option, append {{ic|&}} instead.
+
$ timidity -iA -OO
  
===Daemon mode plays sound out of pace===
+
And test it using aplaymidi. If this does not work, you may want to configure [[JACK]] and set TiMidity++'s output to jack.
timidity++'s ALSA output module (default) may cause this issue in ALSA server mode. Try another output option, for example, '''libao''':
+
  
{{bc|$ 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.
 
 
== Tips and tricks ==
 
== Tips and tricks ==
===Convert files===
+
 
timidity++ can also convert MIDI files into other formats. The following command saves the resulting sound to a WAV file:
+
=== Convert files ===
{{bc|$ timidity ''input.mid'' -Ow -o ''out.wav''}}
+
 
 +
TiMidity++ can also convert MIDI files into other formats. The following command saves the resulting sound to a WAV file:
 +
$ timidity ''input.mid'' -Ow -o ''out.wav''
 
To convert to another formats, you can use [[FFmpeg]]. This will convert it to mp3:
 
To convert to another formats, you can use [[FFmpeg]]. This will convert it to mp3:
{{bc|$ timidity ''input.mid'' -Ow -o - <nowiki>|</nowiki> ffmpeg -i - -acodec libmp3lame -ab 256k ''out.mp3''}}
+
$ timidity ''input.mid'' -Ow -o - <nowiki>|</nowiki> ffmpeg -i - -acodec libmp3lame -ab 256k ''out.mp3''
 +
 
 +
=== How to make DOSBox use TiMidity++ ===
  
===How to make DOSBox use Timidity++===
+
{{Note|The following method is tested in version [[DOSBox]] 0.72}}
{{Note|The following method is tested in version DOSBox 0.72}}
+
  
First of all, you need to write a config file. Input the following in DOSBox to create a configuration file:
+
First of all, you need to write a config file. Input the following in [[DOSBox]] to create a configuration file:
{{bc|config -writeconf dosbox.conf}}
+
config -writeconf dosbox.conf
 
you can replace {{ic|dosbox.conf}} by any name that you want, add a dot in front of it if you want to hide it.
 
you can replace {{ic|dosbox.conf}} by any name 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.
+
Make sure you started TiMidity++ as [[#Daemon|daemon]] as the instructions above, use the '''aconnect''' command.
  
 
Edit this configuration file with any editor, go to the section:
 
Edit this configuration file with any editor, go to the section:
{{hc|dosbox.conf|<nowiki>
+
{{hc|dosbox.conf|2=
 
[midi]
 
[midi]
 
mpu401=intelligent
 
mpu401=intelligent
 
device=default
 
device=default
 
config=
 
config=
</nowiki>}}
+
}}
 
put the ALSA connection port into the back of ''config='', in default:
 
put the ALSA connection port into the back of ''config='', in default:
{{bc|1=config=128:0}}
+
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.
 
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.
 +
 
== See also ==
 
== See also ==
* [[USB Midi Keyboards]]
+
 
 +
* [[USB MIDI keyboards]]

Latest revision as of 11:52, 7 November 2016

TiMidity++ is a software synthesizer that can play MIDI files without a hardware synthesizer. It can either render to the sound card in real time, or it can save the result to a file, such as a PCM .wav file.

Installation

Install the timidity++ package from the official repositories.

You should also install a SoundFont to be able to produce sound. Here is a list of SoundFonts:

Configuration

First you should add yourself to the audio group.

# gpasswd -a <user> audio

SoundFonts

Configure your preferred SoundFont.

Freepats

The Freepats project provides a set of instrument samples which are compatible with TiMidity++.

To use Freepats with TiMidity, add the following lines to timidity.cfg:

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

Fluidr3

There are other SoundFonts available. To install the soundfont-fluid SoundFont, append its path to the TiMidity++ configuration file:

/etc/timidity++/timidity.cfg
soundfont /usr/share/soundfonts/FluidR3_GM.sf2

Daemon

Start and enable the timidity.service.

If you are using PulseAudio, that may not work. You may want to add the 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

You can also use Systemd/User to write an user TiMidity++ service. To do so, write a timidity.service file in ~/.config/systemd/user/ like that one :

/etc/systemd/user/timidity.service
[Unit]
Description=TiMidity++ Daemon
After=sound.target

[Service]
ExecStart=/usr/bin/timidity -iA -Os

[Install]
WantedBy=default.target

Then enable the service with:

 $ systemctl --user enable timidity.service

Usage

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-based/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 man timidity or use -h to get help.

The GTK+ interface offers such features as a playlist, track length estimates, volume control, a file load dialog box, play and pause buttons, rewind and fast forward buttons, as well as options to change the pitch of or speed up or slow down the playback of a midi file.

Daemon mode

If you are runing TiMidity++ as a daemon (ALSA sequencer client), it will provide MIDI output support for other programs such as rosegarden, aplaymidi, vkeybd, etc.

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, aconnectguiAUR[broken link: archived in aur-mirror], patchage or kaconnect. As a result when you play around with the keys on the vkeybd TiMidity++ plays the appropriate notes.

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.

Load the snd-virmidi kernel module and (optionally) configure it to be loaded at boot. Read Kernel modules for more information.

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 SoundFonts for more details.

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.

Tips and tricks

Convert files

TiMidity++ can also convert MIDI files into other formats. The following command saves the resulting sound to a WAV file:

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

To convert to another formats, you can use FFmpeg. This will convert it to mp3:

$ timidity input.mid -Ow -o - | ffmpeg -i - -acodec libmp3lame -ab 256k out.mp3

How to make DOSBox use TiMidity++

Note: The following method is tested in version DOSBox 0.72

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 any name that you want, add a dot in front of it if you want to hide it.

Make sure you started TiMidity++ as daemon as the instructions above, use the aconnect command.

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

dosbox.conf
[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.

See also