[ardour-dev] Fwd: [ardour-users] perl script to extract regions from ardour session.

Jesse Chappell jesse at essej.net
Mon Sep 27 16:20:01 PDT 2004

Forwarded to ardour-dev from ardour-users......

----- Forwarded Message -----

Subject: [ardour-users] perl script to extract regions from ardour session.
Date: Tue, 28 Sep 2004 00:35:38 +0100
From: andy <news4 at earthsong.free-online.co.uk>
To: ardour-users at lists.ardour.org

I've written this script which looks through the ardour config file, and
dumps all the current regions to separate .flac files, with the position
of the region as part of the file name. I'm posting it here under the 'do
what you want with it but don't blame me if it doesn't work the way you
expect' license. The command line parameters are the name of an ardour
session directory, and the name of a directory to extract the regions to.

use strict;
use XML::Twig;
use POSIX;

#use src/xtract.pm;
Extract ($ARGV[0],$ARGV[1]);
exit 0;

sub Extract {
my ($ardour_dir, $archdir)=@_;
my ($ardour_sess)=reverse (split ('/',"$ardour_dir"));
print "opening ardour session: $ardour_sess\n";
my $ardour_file="$ardour_dir/${ardour_sess}.ardour";
my $rate=48000;
my $date = strftime "%a-%d-%b-%y", localtime;
my $c=1;
while (opendir(DIR,"${archdir}/session-${date}-$c")) {
	closedir DIR;
my $outd="${archdir}/session-${date}-$c";

if (opendir(DIR,"${outd}.running")) {
	print "Removing unfinished session directory.\n";
	while (my $f=readdir (DIR)) {
		unlink "${outd}.running/$f" if ($f !~ m/^\..*/);
	closedir DIR;
	rmdir "${outd}.running";

if (! mkdir "${outd}.running") {
	print "Can't create output directory ${outd}.running\n";
	exit 0;
print "Created output directory ${outd}.running\n";
my $twig=XML::Twig->new();
my @regs=$twig->get_xpath("/Session/Playlists/Playlist/Region"); # find all the regions.
foreach my $reg (@regs) {
	my $name=$reg->att("name");
	my $pos=$reg->att("position");
	my $length=$reg->att("length");
	my $s1=$reg->att("source-1");
	my $s0=$reg->att("source-0");
	my $st=$reg->att("start");
	my $sts=$st/$rate;
	my ($s0fe)=$twig->get_xpath("/Session/Sources/Source[\@id=\"$s0\"]");
	my $s0f=$s0fe->att("name");
	my ($s1fe)=$twig->get_xpath("/Session/Sources/Source[\@id=\"$s1\"]");
	my $s1f=$s1fe->att("name");
	my $ls=$length/$rate;
	my $lsi=int($ls);
	my $ps=int($pos/$rate);
	my $pm=int ($ps /60);
	my $ph=int($pm/60);
	my $lm=int ($lsi /60);
	my $lh=int($lm/60);
	my $fname=sprintf("region-%02d:%02d:%02d.flac",$ph,$pm,$ps);
	print <<_END ;
Found region:
name:              $name
position (h:m:s):  $ph:$pm:$ps
length (h:m:s):    $lh:$lm:$lsi
source 0:          $s0f
source 1:          $s1f\n
output file:       $fname
print "Extracting region to flac file.\n";
print "${outd}.running/${fname}";
system ("bash -c \'ecasound -t:$ls -a:1  -i:resample,48000,\"$ardour_dir/sounds/$s0f\" -y:$sts -erc:1,1 -a:2  -i:resample,48000,\"$ardour_dir/sounds/$s1f\" -y:$sts -erc:1,2 -a:1,2 -f:16,2,44100 -o:stdout| flac --sign=signed --endian=little --sample-rate=44100 --channels=2 --bps=16 -o ${outd}.running/${fname} - >& /dev/null\'");
rename "${outd}.running", $outd;


remove 'n-u-l-l' to email me. html mail or attachments will go in the spam
bin unless notified with [html] or [attachment] in the subject line. 

ardour-users-ardour.org mailing list
ardour-users at lists.ardour.org

More information about the Ardour-Dev mailing list