Porting Timidity ++


gruso

thunderbox
Joined
Feb 28, 2008
Messages
7,461
Age
47
Location
Sydney, Australia
Website
pandorapress.net
I'm working on a full port of Timidity++ (not to be confused with sebt3's installer which enables music in certain games). The main motivation for this port is to use Timidity as an ALSA device, to handle MIDI output from something like Seq24.

I have a PND already, which is behaving strangely, but was never expected to 'just run' anyway. Its behaviour is a bit of a tangent at this point so I'll throw it into a spoiler.

http://bunnitude.com/gruso/timidity.pnd

It is showing up twice on the desktop. Running each one produces different output:

Code:
sudo /usr/pandora/scripts/pnd_run.sh -m -p /media/GP2X8GB/pandora/desktop//timidity.pnd -e scripts/icon.png.sh -b timidity
not mounted on loop yet, doing so
LoopMountedon: 
/dev/loop2
Filetype is Squashfs
Mounting PND (mount -t squashfs) :
/dev/loop2 on /mnt/pnd/timidity type squashfs (ro)
Filesystem is vfat
Mounting the Union FS using /media/GP2X8GB/pandora/appdata/timidity as Write directory:
mount -t aufs -o exec,noplink,dirs=/media/GP2X8GB/pandora/appdata/timidity=rw+nolwh:/mnt/pnd/timidity=rr none /mnt/utmp/timidity
none on /mnt/utmp/timidity type aufs (rw,si=62711277,noplink)
none on /mnt/utmp/timidity type aufs (rw,si=62711277,noplink)
[------------------------------]{ App start }[---------------------------------]
./icon.png: line 1: ‰PNG
: not found
./icon.png: line 2: : not found
./icon.png: line 3: 
IHDR00Wù‡ÙIDATxÚÕ™kL–eÇ9ÊQ9: not found
./icon.png: line 4: syntax error: "(" unexpected
[-------------------------------]{ App end }[----------------------------------]
cleanup done

Code:
sudo /usr/pandora/scripts/pnd_run.sh -m -p /media/GP2X8GB/pandora/desktop//timidity.pnd -e scripts/timidity.sh -b timidity
not mounted on loop yet, doing so
LoopMountedon: 
/dev/loop3
Filetype is Squashfs
Mounting PND (mount -t squashfs) :
/dev/loop3 on /mnt/pnd/timidity type squashfs (ro)
Filesystem is vfat
Mounting the Union FS using /media/GP2X8GB/pandora/appdata/timidity as Write directory:
mount -t aufs -o exec,noplink,dirs=/media/GP2X8GB/pandora/appdata/timidity=rw+nolwh:/mnt/pnd/timidity=rr none /mnt/utmp/timidity
none on /mnt/utmp/timidity type aufs (rw,si=62711577,noplink)
none on /mnt/utmp/timidity type aufs (rw,si=62711577,noplink)
[------------------------------]{ App start }[---------------------------------]
TiMidity++ version 2.13.0 -- MIDI to WAVE converter and player
Copyright (C) 1999-2004 Masanao Izumo <iz@onicos.co.jp>
Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

[-------------------------------]{ App end }[----------------------------------]
cleanup done

To give it a test I threw the binary itself onto SD and attempted to play a midi file:
Code:
# ./timidity song.mid

It asked for /mnt/utmp/timidity/share/timidity/timidity.cfg. Naturally without a PND mounted this wasn't there, but after mounting the PND (which I presumed would make the cfg accessible via that path) and running the standalone binary again it gave the same error.

Obviously the PND needs to be an installer but I'm not sure where to go from here.
 
Last edited by a moderator:
I think i could help for the 2 icon displayed on desktop.
I think is a bug of genpxml script, for some strange motive it generate a series of scripts under the dir /mnt/utmp/name_of_app/scripts and also append it to pxml.xml file.
For example:
sudo /usr/pandora/scripts/pnd_run.sh -m -p /media/GP2X8GB/pandora/desktop//timidity.pnd -e scripts/icon.png.sh -b timidity
So delete the others *.sh exept your timidity.sh under the scripts dir.
Next edit your PXML.xml file so to eliminate all the parts relative to the others scripts.
Next rebuild the PND.

Forgot to mention that is apply to sebt3 Yactfeau toolchain (IIRC Gruso seems to compile with this ).
 
Gruso said:
It is showing up twice on the desktop. Running each one produces different output:

Code:
sudo /usr/pandora/scripts/pnd_run.sh -m -p /media/GP2X8GB/pandora/desktop//timidity.pnd -e scripts/icon.png.sh -b timidity

When genpxml cant find any .desktop file to generate the content of the PXML file, it create launchers scripts and an application entry for any executable files found in the PND directory.
I'm guessing that your icon have the execution bit set thuss had its PXML entry generated.
I think this could/should be dropped ;)


Gruso said:
It asked for /mnt/utmp/timidity/share/timidity/timidity.cfg
imho your binary should use /etc/timidity/timidity.cfg instead (so it will use that data my installer deploy, but that will requiere you to rebuild timidity with an other pndconfigure option).

Else, you could copy /etc/timidity/timidity.cfg to /mnt/utmp/timidity/share/timidity/timidity.cfg using a scripts/pre_script.sh ;)
 
Last edited by a moderator:
Dual icon problem solved and PXML cleaned up. chmod -x icon.png, heh :)

On to /scripts/pre_script.sh, naturally I just grabbed timidity.sh to scoop out the bulk of it and drop my own line in. This is what it looks like:

Code:
#!/bin/sh
export PATH="/mnt/utmp/timidity/bin:${PATH:-"/usr/bin:/bin:/usr/local/bin"}"
export LD_LIBRARY_PATH=":${LD_LIBRARY_PATH:-"/usr/lib:/lib"}"
export HOME="/mnt/utmp/timidity" XDG_CONFIG_HOME="/mnt/utmp/timidity"

cp /etc/timidity/timidity.cfg /mnt/utmp/timidity/share/timidity/

Error in timidity.out:

Code:
Cannot create regular file '/mnt/utmp/timidity/share/timidity/timidity.cfg': Operation not permitted

I've tried a few different approaches to this but I'm not getting it right.
 
Gruso said:
On to /scripts/pre_script.sh, naturally I just grabbed timidity.sh to scoop out the bulk of it and drop my own line in. This is what it looks like:
Imho, it should look like :
Code:
#!/bin/sh

APP=timidity
if [ -z "$APPDATADIR" ];then
        printf "WARNING Guessing APPDATADIR="
        PND=$(sudo losetup -a |grep $APP|sed 's/.*(//;s/)//')
        if [[ "x$PND" = "x" ]];then
                {
                        mount|awk '/mmc/{print $3;exit}';
                        echo /
                }|while read dir;do
                        if [ -d $dir/pandora/appdata/$APP ];then
                                APPDATADIR=$dir/pandora/appdata/$APP
                        fi
                done
                echo "$APPDATADIR (wild guess)"
        else
                APPDATADIR=$(echo $PND|sed 's/pandora.*/pandora\/appdata\/'"$APP/")
        fi

fi
if [ -d "$APPDATADIR" ];then
        mkdir -p $APPDATADIR/share/timidity
        cp /etc/timidity/timidity.cfg $APPDATADIR/share/timidity
else
        echo "ERROR: APPDATADIR not found !"
fi
 
Last edited by a moderator:
Why didn't I think of that.

You have sorted me out once again, thank you. :) I am currently listening to a very cheesy rendition of Walk The Line by Johnny Cash. Job's not finished yet - all I've done here is mount the PND, then run the executable from elsewhere. Now I've got a few avenues to look at (ALSA device, usable MIDI file player, etc etc), will report back.

[edit] Trying to load it as an ALSA device, ugh. Command should be:

Code:
./timidity -iA -Os
Output is:
Code:
Interface `A' is not compiled in.
Recompile with:
Code:
pndconfigure --enable-alsa --enable-sound=alsa
No luck yet. 2.40am is bedtime.
 
Lots of false starts in spoiler, optional reading for fans of schadenfreude.

Trying something else. From configure help:

Code:
Optional Features:

--enable-audio=mode_list Enable audio (Specify comma separated mode list):
                              default:   Automatically select audio device.
                              oss:       OSS /dev/dsp
                              sun:       SunOS /dev/audio
                              hpux:      HPUX /dev/audio
                              irix:      IRIX audio library
                              mme:       OSF/1 MME
                              sb_dsp:    BSD/OS 2.0 /dev/sb_dsp
                              w32:       Windows MMS
                              darwin:    Darwin CoreAudio
                              alsa:      ALSA pcm device
                              alib:      HPUX network audio (Alib)
                              nas:       NAS - Network Audio System
                              arts:      aRts
                              esd:       EsounD - Enlightened Sound Daemon
                              portaudio: PortAudio
                              jack:      JACK
                              vorbis:    Ogg Vorbis
                              gogo:      MP3 GOGO (Only Windows is suppor

I'm adding --enable-audio=mode_alsa but not sure if my syntax is right.

Configure output:

Code:
checking enable_audio=oss... no
checking enable_audio=sun... no
checking enable_audio=hpux... no
checking enable_audio=irix... no
checking enable_audio=mme... no
checking enable_audio=sb_dsp... no
checking enable_audio=w32... no
checking enable_audio=darwin... no
checking enable_audio=alsa... no
checking enable_audio=alib... no
checking enable_audio=nas... no
checking enable_audio=arts... no
checking enable_audio=esd... no
checking enable_audio=portaudio... no
checking enable_audio=jack... no
checking enable_audio=vorbis... no
checking enable_audio=gogo... no

[edit] ah, syntax changed to --enable-audio=mode_list,alsa

Output:
Code:
checking enable_audio=oss... no
checking enable_audio=sun... no
checking enable_audio=hpux... no
checking enable_audio=irix... no
checking enable_audio=mme... no
checking enable_audio=sb_dsp... no
checking enable_audio=w32... no
checking enable_audio=darwin... no
checking enable_audio=alsa... yes, configuring alsa
checking for ALSA CFLAGS... 
checking for ALSA LDFLAGS...  -lasound -lm -ldl -lpthread
checking for libasound headers version >= 0.1.1... found.
checking for snd_ctl_open in -lasound... yes
checking for snd_seq_port_info_set_timestamping... yes
checking enable_audio=alib... no
checking enable_audio=nas... no
checking enable_audio=arts... no
checking enable_audio=esd... no
checking enable_audio=portaudio... no
checking enable_audio=jack... no
checking enable_audio=vorbis... no
checking enable_audio=gogo... no
An improvement. "Interface `A' is not compiled in" error is now gone, now it is "Couldn't open output device."

[edit] ok, apparently correct syntax is supposed to be --enable-audio=alsa but now I'm back to "Interface `A' is not compiled in." Argh.

Stumped now.
 
Gruso said:
but now I'm back to "Interface `A' is not compiled in." Argh.
I'm not that deep into timidity++, but what does it say if you just call "timidity -h"?
Can you see the ALSA-Interface listed?

This is from my Debian Squeeze desktop-machine:

Code:
Available interfaces (-i, --interface option):
  -in          ncurses interface
  -ie          Emacs interface (invoked from `M-x timidity')
  -ia          XAW interface
  -id          dumb interface
  -ir          remote interface
  -iA          ALSA sequencer interface
Supported dynamic load interfaces (/usr/lib/timidity):

Interface options (append to -i? option):
  `v'          more verbose (cumulative)
  `q'          quieter (cumulative)
  `t'          trace playing
  `l'          loop playing (some interface ignore this option)
  `r'          randomize file list arguments before playing
  `s'          sorting file list arguments before playing
  `D'          daemonize TiMidity++ in background (for alsaseq only)
 
Last edited by a moderator:
Code:
Available interfaces (-i, --interface option):
  -id          dumb interface
It looks like I feel. I didn't even think to look there, thanks for that. Shines a bit of light on what's happening (or, what is not).

[edit] Ok, couple of beers and an hour watching TV and then everything started to work. Correct build options:
Code:
# pndconfigure --enable-audio=alsa --enable-interface=alsaseq
Successfully ran
Code:
./timidity -iA -Os
...on the Pandora, and it's showing up as a MIDI device in Seq24. Shyeah! (It did ask for snd_seq initially, which I was able to load with Seq24. Will have to include it with Timidity too). Time to pack some of this joy into a working PND.

Question:-

Getting back to my crossroads from the first post, there are numerous ways to use Timidity and I don't think one PND will cover them all unless it is turned into a full installer. (I'll tell you now I'm not going near such scripts, I was mindblown enough by the chasm between what I thought was a sufficient pre_script.sh and what sebt3 posted.)

I'm planning to release the first beta as an ALSA daemon loader only. If there's interest in using this as a MIDI file player, perhaps a separate PND with GUI.

Thoughts?

------------------------

TiMidity Daemon Loader

It will prompt for password if snd-seq is not loaded (per session). Run PND, enter password, fire up Seq24 and make some noise. It is quite stuttery with moderate MIDI traffic.
 
Gruso said:
...on the Pandora, and it's showing up as a MIDI device in Seq24. Shyeah! (It did ask for snd_seq initially, which I was able to load with Seq24. Will have to include it with Timidity too). Time to pack some of this joy into a working PND.
Great stuff! Will definately try that out soon!

I'm planning to release the first beta as an ALSA daemon loader only. If there's interest in using this as a MIDI file player, perhaps a separate PND with GUI.
Thoughts?
Maybe it could be handy for that to use the "multiple-application-feature" of the PXML/PNDs?

So there could be only one PND, but different ways to invoke timidity. I'm using this eg. in my Links2-PND.
 
Last edited by a moderator:
Oh yes, good idea.

[edit] Can anyone provide some insight on peelie's issue here?

hi was trying to use my own sequence. also when firing up daemon got a strange message about malicious program and mouse? not been able to repeat it.
-------

rm: cannot remove `/tmp/cpuspeed': No such file or directory
not mounted on loop yet, doing so
LoopMountedon:
/dev/loop3
Filetype is Squashfs
sudo mount -t squashfs /dev/loop3
mounting union!
Filesystem is vfat
[------------------------------]{ App start }[---------------------------------]
WARNING Guessing APPDATADIR=
(gksudo:5396): Gdk-CRITICAL **: gdk_draw_pixbuf: assertion `GDK_IS_DRAWABLE (drawable)' failed
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
Requested buffer size 32768, fragment size 8192
ALSA pcm 'default' set buffer size 32768, period size 8192 bytes

I thought it might be a HF4 issue, but he tried it on a fresh HF5 SD install and reports the same error.
 
Gruso said:
Oh yes, good idea.

[edit] Can anyone provide some insight on peelie's issue here?



got it sorted - did not realise you had to higlight sequence to get it to output sound!
hope next version of seq24 will iron out stutter issues - then all i need is to mod my korg monotron to have midi input and away we go :)
 
Last edited by a moderator:
I'm wondering if buffer settings will improve performance. I'll experiment with some of these:

Code:
-k  msec
              Specify audio queue time limit to reduce voices.  If the remain-
              ing  audio buffer is less than msec milliseconds, TiMidity tries
              to kill some voices.  This feature makes  it  possible  to  play
              complicated MIDI files on slow CPUs.  Setting msec to zero tells
              TiMidity to never remove any voices.

 -B fragments[,buffer-bits]
              For the Linux/FreeBSD/OSS/ALSA/Windows sound driver, selects the
              number of buffer fragments in interactive mode.  Increasing  the
              number  of  fragments  may reduce choppiness when many processes
              are running.  It will make TiMidity seem to  respond  sluggishly
              to  fast forward, rewind, and volume controls, and it will throw
              the status display off sync.  Specify a fragments number of 0 to
              use the maximum number of fragments available.

-q m/n Specify audio buffer in seconds.  m: maximum size of buffer,  n:
              percentage  filled  at the beginning (default is 5.0/100%) (size
              of 100% equals the whole device buffer size)

On the GUI front, I've tried compiling in some options (listed below) but nothing seems to work. Even doing a native build on my desktop (xubuntu 10.04) I only got xaw to work, and it was crashy.

Code:
--enable-interface[=interface_list]
	ncurses: Ncurses interface. timidity's -in option will invoke this interface.
	slang: slang interface. timidity's -is option will invoke this interface.
	motif: Motif interface. timidity's -im option will invoke this interface.
	tcltk: Tcl/Tk interface. timidity's -ik option will invoke this interface.
	emacs: Emacs front-end. Type M-x timidity to invoke.
	vt100: The full-screen interface using VT100 terminal control codes. timidity's -iT option will invoke this interface.
	xaw: X Athena Widgets interface. timidity's -ia option will invoke this interface.
	xskin: X skin interface. timidity's -ii option will invoke this interface.
	gtk: GTK+ interface. timidity's -ig option will invoke this interface.
	w32gui: Build as Windows GUI binary.
 
Which version of Timidity++ are you using ?
From the first post it looks like version 2.13.0.
The latest released version is 2.13.2 from October 2004.
But there's also the CVS version from September 2010, which contains a lot of fixes since 2004.
 
You're absolutely right - I hit the download link for 2.13.0 instead of 2.13.2. I can't access CVS though (connection refused). Could be a Sourceforge issue, I'll try again later.
 
Back
Top