[LAD] forward: jack session api in perl, python, ruby, and lua

Joel Roth joelz at pobox.com
Sun Mar 18 23:40:20 UTC 2012


I am forwarding a mail and sample code from Ed Sweeney
(with permission). 

He'd appreciate any comments.

---------------------------------------------------------------------
Joel,

Programming jack is fun.

Check out the attached, it is jack's simple_session_client.c in perl.

I don't know how to test the savequit session events but support for
them is coded and the sample processing totally works.  I rewrote
metro.c metronome in perl too, works.

I have generated API libs for perl, python, ruby, and lua.  Each of
them has a reworked simple_client that works.  Ruby has a bug with the
metronome I haven't been able to find yet.

I'm sure there are lots of bugs and wrong design choices and poorly
chosen names but it is a start!

The build system is messy.  I'll put a tarball on a server and tar up
a binary installable perl module today.  If this looks like it will be
usable, I'll put it on github.


-- simple_client.pl --

#!/usr/bin/perl
use jackscript;
use strict;
use warnings;
use Cwd 'abs_path';

my $jc;

if (defined($ARGV[0])) {
    print("restarting with uuid $ARGV[0]\n");
    $jc = jackscript::JsClient->new("simpler", $ARGV[0], $jackscript::JackSessionID);
} else {
    $jc = jackscript::JsClient->new("simpler", undef, $jackscript::JackNullOption);
}


my $in = $jc->registerPort("input", $jackscript::JackPortIsInput);

my $out = $jc->registerPort("output", $jackscript::JackPortIsOutput);

$jc->activate();

my $done = undef;
until($done) {

    my $jsevent = $jc->getEvent(-1);

    if ($jsevent->getType() == $jackscript::PROCESS) {

        my $inbuffer = $in->getBuffer();

        my $outbuffer = $out->getBuffer();

        my $nframes = $outbuffer->length();

        for (my $i = 0; $i < $nframes; $i++) { #copy input to putput

          my $s = $inbuffer->getf($i);

          $outbuffer->setf($i,$s);

        }

    } elsif ($jsevent->getType() == $jackscript::SAMPLE_RATE_CHANGE) {

        my $sr = $jc->getSampleRate();
        print("sample rate change event: sample rate is now $sr\n");

    } elsif ($jsevent->getType() == $jackscript::SHUTDOWN) {

        print("jack shutdown event\n");
        $done = "done!";

    } elsif ($jsevent->getType() == $jackscript::SESSION) {

        my $dir       = $jsevent->getSessionDir();
        my $uuid      = $jsevent->getUuid();
        my $se_type   = $jsevent->getSessionEventType();
        my $setypeTxt = $se_type == $jackscript::JackSessionSave ? "save" : "quit";

        print("session notification: path $dir, uuid $uuid, type: $setypeTxt\n");

        if ($se_type == $jackscript::JackSessionSaveAndQuit) {
            $done = "done!";
        }

        my $script_path = abs_path($0);
        my $cmd = "perl $script_path $uuid"; 
        $jsevent->setCommandLine($cmd); #tell jackd how to restart us

    } else {
        die("unknown event type\n");
    }

    $jsevent->complete();
}

print("simple_client.pl ended\n");


-- 
Joel Roth




More information about the Linux-audio-dev mailing list