Timidity++

来自 Arch Linux 中文维基

TiMidity++ 是用于在不使用硬件合成器的情况下播放 MIDI 文件的软件合成器。它可以实时将 MIDI 翻译给声卡,或是将成果存储到文件中,比如存储到 PCM.wav 文件格式。

安装[编辑 | 编辑源代码]

安装 timidity++ 包。

你还应当安装 音色库Gravis UltraSound(GUS) 补丁文件来获得产生音频的能力。参见 MIDI#音色库列表

如果你使用 pipewire, 由于 Timidity++ 有时依赖 ALSA 工作,你需要安装 pipewire-alsa

配置[编辑 | 编辑源代码]

To configure your preferred SoundFont, add the following lines to timidity.cfg(5) based on your choice.

For FreePats:

/etc/timidity/timidity.cfg
soundfont /usr/share/soundfonts/freepats-general-midi.sf2

For Fluid:

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

守护进程[编辑 | 编辑源代码]

If you intended to use TiMidity++ as an ALSA sequencer client, you should add yourself to the audio user group first. As with most group changes, you will typically need to restart your user session (e.g. log out and log in again), so that the new group is visible in the output of the groups command.

Start/enable the timidity.service user unit. Note that starting the service may fail if you have changed your audio group membership but not yet restarted your session.

If you are using PulseAudio, that may also cause the service to fail. You may want to add the following command as an autostart 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

用例[编辑 | 编辑源代码]

播放文件[编辑 | 编辑源代码]

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

独立模式[编辑 | 编辑源代码]

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

$ timidity example.mid

Add option -in for a text-based interface. There are many other options to TiMidity++. See timidity(1) or use -h to get help.

守护进程模式[编辑 | 编辑源代码]

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.

$ 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, patchageAUR or kaconnect. As a result when you play around with the keys on the vkeybd TiMidity++ plays the appropriate notes.

连接到虚拟 MIDI 设备[编辑 | 编辑源代码]

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 your system to load the module at boot.

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).

小技巧[编辑 | 编辑源代码]

转换文件[编辑 | 编辑源代码]

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

如何使 DOSBox 使用 TIMIdity++[编辑 | 编辑源代码]

注意: The following method is tested in version DOSBox 0.72

First of all, you need to write a configuration 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.

疑难解惑[编辑 | 编辑源代码]

TiMidity++ 并不能播放 MIDI 文件[编辑 | 编辑源代码]

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

$ timidity example.mid

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 have installed some samples and your SoundFile is added to /etc/timidity/timidity.cfg. See Configuration for more details.

守护进程模式下,播放声音速度过快[编辑 | 编辑源代码]

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.

参见[编辑 | 编辑源代码]