Running Timidity as a service

View: New views
4 Messages — Rating Filter:   Alert me  

Running Timidity as a service

by Jonathan Gazeley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,

I'm running Fedora. I am able to use timidity with my midi editor using -iA

However I want timidity to run as a service upon boot, so I made an
init.d script:

> #!/bin/bash
> #
> # chkconfig: 35 56 56
> # description: Start Folding At Home execution
>
> check_running() {
>     COUNT=`ps -ef|grep timidity|grep -v grep|wc -l`
>     if [ $COUNT = 1 ]
>     then
>         RUN=1
>     else
>         RUN=0
>     fi
> }
>
> case "$1" in
>     start)
>         check_running
>             if [ $RUN = 1 ]
>             then
>                 echo "Timidity seems to be running already"
>                 exit
>             else
>                 /usr/bin/timidity -iA 2>&1 &
>                 exit
>             fi
>         ;;
>
>     stop)
>         check_running
>             if [ $RUN = 1 ]
>             then
>                 killall timidity
>                 exit
>             else
>                 echo "Timidity does not seem to be running"
>                 exit
>             fi
>         ;;
>
>     status)
>         check_running
>             if [ $RUN = 1 ]
>             then
>                 echo "Timidity is running"
>                 exit
>             else
>                 echo "Timidity does not seem to be running"
>                 exit
>             fi
>         ;;
> esac

However, this script gives an error:

[jonathan@poseidon ~]$ sudo service timidity start
[jonathan@poseidon ~]$ file mcoputils.cc: line 499 (static std::string
Arts::MCOPUtils::mcopDirectory()): assertion failed: (home != 0)
HOME environment variable not set?
jack_client_new: deprecated
Cannot connect to server socket err = No such file or directory
Cannot connect to server socket
jack server is not running or cannot be started
no message buffer overruns
Couldn't open output device


I tested that I can successfully run timidity using sudo:

[jonathan@poseidon ~]$ sudo timidity -iA
TiMidity starting in ALSA server mode
Opening sequencer port: 128:0 128:1 128:2 128:3

Does anyone have any ideas what might be up?

Cheers,
Jonathan


------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Timidity-talk mailing list
Timidity-talk@...
https://lists.sourceforge.net/lists/listinfo/timidity-talk

Parent Message unknown Re: Running Timidity as a service

by wg2002a :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Date: Tue, 13 Jan 2009 19:29:48 +0000
> From: Jonathan Gazeley
> <jonathan.gazeley@...>
> Subject: [timidity-talk] Running Timidity as a service

. . .

> [jonathan@poseidon ~]$ sudo service timidity start
> [jonathan@poseidon ~]$ file mcoputils.cc: line 499 (static
> std::string
> Arts::MCOPUtils::mcopDirectory()): assertion failed: (home
> != 0)
> HOME environment variable not set?
> jack_client_new: deprecated
> Cannot connect to server socket err = No such file or
> directory
> Cannot connect to server socket
> jack server is not running or cannot be started
> no message buffer overruns
> Couldn't open output device
>
>
> I tested that I can successfully run timidity using sudo:
>
> [jonathan@poseidon ~]$ sudo timidity -iA
> TiMidity starting in ALSA server mode
> Opening sequencer port: 128:0 128:1 128:2 128:3
>
> Does anyone have any ideas what might be up?
>
> Cheers,
> Jonathan

I use Debian, not Fedora, so there might be some config differences.

I don't know about the HOME environment thing right off the bat.  If someone knows, please answer.  Else, someone may have to look into Timidity source code to figure out.

As for server socket error, and "jack server is not running or cannot be started", I think it is one and the same.  The problem is the new "jackd" version, the message "jack_client_new: deprecated" points to the real cause.

Timidity code still uses jack_client_new() as a mean to connect to jackd.  However, with the new jackd, and libjack0 both are at version 0.116.1-2 in Debian Sid (unstable), the call to jack_client_new() doesn't seem to work.

I tried the following code in jack_a.c

static int detect(void)
{
        jack_client_t *client;
        jack_status_t status;
        /* ---OLD--- client = jack_client_new(TIMIDITY_JACK_CLIENT_NAME); */
        /* open a connection to the JACK server */
        client = jack_client_open (TIMIDITY_JACK_CLIENT_NAME, JackNullOption, &status);
        if (! client) {
                ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
                        "jack_client_open() failed, status = 0x%2.0x\n", status);
                return 0;
        }

        jack_client_close(client);
        return 1; /* found */
}


and equivalent code in

   static int open_jack(void)

function of the same file.  It seems jackd deliberately breaks that old jack_client_new() API call.  Otherwise, they could have easily use similar code as shown above to implement jack_client_new(), which is simple enough to keep old apps working without changes.  Either that or they don't care for backward compatibility in this case, and force everyone to use new code.

Jimmy




     

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Timidity-talk mailing list
Timidity-talk@...
https://lists.sourceforge.net/lists/listinfo/timidity-talk

Re: Running Timidity as a service

by Jonathan Gazeley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Jimmy,

Thanks for your response. What I don't understand is why timidity is
trying to use jack at all. I want it to use alsa, and so when I run
timidity from the command line by hand I use the -iA switches, and it
all works fine. So I don't know why it is trying to use jack as a
backend when I run it as a service.

I guess if it can't easily be fixed, I will just have to write something
that starts timidity when I start my midi program.

Cheers,
Jonathan


jimmy wrote:

> I use Debian, not Fedora, so there might be some config differences.
> I don't know about the HOME environment thing right off the bat.  If someone knows, please answer.  Else, someone may have to look into Timidity source code to figure out.
>
> As for server socket error, and "jack server is not running or cannot be started", I think it is one and the same.  The problem is the new "jackd" version, the message "jack_client_new: deprecated" points to the real cause.
>
> Timidity code still uses jack_client_new() as a mean to connect to jackd.  However, with the new jackd, and libjack0 both are at version 0.116.1-2 in Debian Sid (unstable), the call to jack_client_new() doesn't seem to work.
>
> I tried the following code in jack_a.c
>
> static int detect(void)
> {
> jack_client_t *client;
>         jack_status_t status;
> /* ---OLD--- client = jack_client_new(TIMIDITY_JACK_CLIENT_NAME); */
> /* open a connection to the JACK server */
> client = jack_client_open (TIMIDITY_JACK_CLIENT_NAME, JackNullOption, &status);
> if (! client) {
> ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
> "jack_client_open() failed, status = 0x%2.0x\n", status);
> return 0;
> }
>
> jack_client_close(client);
> return 1; /* found */
> }
>
>
> and equivalent code in
>
>    static int open_jack(void)
>
> function of the same file.  It seems jackd deliberately breaks that old jack_client_new() API call.  Otherwise, they could have easily use similar code as shown above to implement jack_client_new(), which is simple enough to keep old apps working without changes.  Either that or they don't care for backward compatibility in this case, and force everyone to use new code.
>
> Jimmy
>  

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Timidity-talk mailing list
Timidity-talk@...
https://lists.sourceforge.net/lists/listinfo/timidity-talk

Re: Running Timidity as a service

by wataru.em :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi.

Did you try compiling from source code?

I've compiled timidity from source code, 2.13.2,
from the official(?) site.

I've tested on Vine Linux 4.2.

--
./configure --enable-audio="oss,alsa" --enable-alsaseq
make clean all
--

and placed the binary to /usr/local/bin.

This binary worked with your init.d script, with
slight modification.

1) added HOME=/root for safety.
  o HOME environment seems to be referred from
    timidity/timidity.c.
2) optimized options for timidity
  o to use ALSA pcm device directly with 16-bit sample,
    linear encoding. (-Os1l option.)
  o optimization of buffering. (-B2,8 option.)
  o "-iA -B2,8 -Os1l -s 44100 -p 512" was good for me.
3) kick /usr/local/bin/timidity instead of /usr/bin/timidity.
  o Vine's timidity binary does not compiled with
    alsaseq.

Kicking init.d script showed "128:0, 128:1, 128:2, and
128:3" are avaiable.

"aplaymidi -p 128:0 midi/foo.midi" worked fine.

BTW,

>[jonathan@poseidon ~]$ sudo service timidity start
>[jonathan@poseidon ~]$ file mcoputils.cc: line 499 (static std::string
>Arts::MCOPUtils::mcopDirectory()): assertion failed: (home != 0)
>HOME environment variable not set?
>jack_client_new: deprecated

Your timidity binary on Fedora seems trying to
connect to JACK audio interface.

Add -Os1l to connect to ALSA pcm device.

--
wataru.em


------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Timidity-talk mailing list
Timidity-talk@...
https://lists.sourceforge.net/lists/listinfo/timidity-talk