Jazz-Soft.net

We make it sound!

Home » Download » Jazz-Plugin » Software Synth in Linux

How to setup Software Synth in Linux

Unlike Windows/MacOS, Linux does not provide default software synth. But you can install one.

Tough Linux guys are not looking for easy ways! Right?

Below are the steps that work for 64-bit Ubuntu 13.10. You will need to do something similar on other systems.

Step 1: Install the software

Most likely, you have ALSA already installed on your system.

Download and install TiMidity++ or/and any other soft synth.

To make sure your software synth is installed correctly, try to play some MIDI file with it:

>> timidity some-file.mid

Step 2: Start Virtual MIDI

Chech the list of available MIDI-Out ports:

>> aconnect -lo
client 14: 'Midi Through' [type=kernel]
    0 'Midi Through Port-0'
client 20: 'XStation' [type=kernel]
    0 'XStation MIDI 1 '

The output above only shows the USB MIDI keyboard connected to the computer. If Virtual MIDI is not there, we can start it:

>> sudo modprobe snd-virmidi

Now you can see it in the list:

>> aconnect -lo
client 14: 'Midi Through' [type=kernel]
    0 'Midi Through Port-0'
client 20: 'XStation' [type=kernel]
    0 'XStation MIDI 1 '
client 24: 'Virtual Raw MIDI 2-0' [type=kernel]
    0 'VirMIDI 2-0     '
client 25: 'Virtual Raw MIDI 2-1' [type=kernel]
    0 'VirMIDI 2-1     '
client 26: 'Virtual Raw MIDI 2-2' [type=kernel]
    0 'VirMIDI 2-2     '
client 27: 'Virtual Raw MIDI 2-3' [type=kernel]
    0 'VirMIDI 2-3     '

Step 3: Start the Software Synth

Start your soft synth in a server mode:

>> timidity -iAD
Requested buffer size 32768, fragment size 8192
ALSA pcm 'default' set buffer size 32768, period size 8192 bytes
TiMidity starting in ALSA server mode
Opening sequencer port: 128:0 128:1 128:2 128:3

TiMidity++ is quite a powerful synth, and there are a lot of useful options you can add to the command line above. Please check the documentation for more details.

Step 4: Connect Soft Synth to Virtual MIDI

Connect the ports:

>> aconnect 24:0 128:0
>> aconnect -lo
client 14: 'Midi Through' [type=kernel]
    0 'Midi Through Port-0'
client 20: 'XStation' [type=kernel]
    0 'XStation MIDI 1 '
client 24: 'Virtual Raw MIDI 2-0' [type=kernel]
    0 'VirMIDI 2-0     '
	Connecting To: 128:0
client 25: 'Virtual Raw MIDI 2-1' [type=kernel]
    0 'VirMIDI 2-1     '
client 26: 'Virtual Raw MIDI 2-2' [type=kernel]
    0 'VirMIDI 2-2     '
client 27: 'Virtual Raw MIDI 2-3' [type=kernel]
    0 'VirMIDI 2-3     '
client 128: 'TiMidity' [type=user]
    0 'TiMidity port 0 '
	Connected From: 24:0
    1 'TiMidity port 1 '
    2 'TiMidity port 2 '
    3 'TiMidity port 3 '

Congratulations!

Jazz-Plugin will use the first Virtual MIDI port as the defaulf MIDI-Out.

Shell scripts

Here is the bash script I use to automate the above steps.

It starts Virtual MIDI and TiMidity++ unless they are already running, looks for the available connection ports, and connects them if they are not yet connected.

Hopefully, it will work on your system with no or few modofications...

#!/bin/bash
sudo modprobe snd-virmidi
if aconnect -lo | grep TiMidity > /dev/null; then
  echo TiMidity is already running!
else
  echo Starting TiMidity...
  timidity -iAD > /dev/null
  sleep 1
fi
IFS=$'\n'; arr=`aconnect -lo`
for str in ${arr[@]}; do
  if echo $str | grep -e '^client' > /dev/null; then
    client=`echo $str | sed 's/:.*$//' | sed 's/^.* //'`
    tmdt_curr=""; vrmd_curr=""
  elif echo $str | grep -e '^ *[0-9]* ' > /dev/null; then
    port=`echo $str | sed 's/^ *//' | sed 's/ .*$//'`
    if echo $str | grep TiMidity > /dev/null; then
      tmdt_curr="$client:$port"
      [ ! "$tmdt" ] && tmdt="$tmdt_curr"
    elif echo $str | grep VirMIDI > /dev/null; then
      vrmd_curr="$client:$port"
      [ ! "$vrmd" ] && vrmd="$vrmd_curr"
    fi
  elif echo $str | grep 'Connecting To:' > /dev/null && [ "$vrmd_curr" ]; then
    conn=`echo $str | sed 's/.*Connecting To: *//'`
    [ "$vrmd_conn" ] && vrmd_conn="$vrmd_conn "
    vrmd_conn="$vrmd_conn$vrmd_curr=$conn"
    vrmd=""
  elif echo $str | grep 'Connected From:' > /dev/null && [ "$tmdt_curr" ]; then
    conn=`echo $str | sed 's/.*Connected From: *//'`
    [ "$tmdt_conn" ] && tmdt_conn="$tmdt_conn "
    tmdt_conn="$tmdt_conn$conn=$tmdt_curr"
    tmdt=""
  fi
done
IFS=' '; arr=`echo $tmdt_conn`
for str in ${arr[@]}; do
  echo $vrmd_conn | grep $str > /dev/null && already_connected=1
done
if [ "$already_connected" ]; then
  echo Already connected!
elif [ "$vrmd" ] && [ "$tmdt" ]; then
  echo Connecting $vrmd to $tmdt...
  aconnect $vrmd $tmdt
else
  echo Cannot connect...
fi
echo
aconnect -lo

And this script will stop TiMidity++ and Virtual MIDI:

#!/bin/bash
aconnect -x
ps -aux | grep timidity | awk '{print $2,$11}' | while read pid name
do
   [ "$name" == timidity ] && kill -9 $pid
done
sudo modprobe -r snd-virmidi