-
Notifications
You must be signed in to change notification settings - Fork 0
/
randtrack.pl
executable file
·83 lines (71 loc) · 2.26 KB
/
randtrack.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#! /usr/bin/perl
#
# Randomize ardour tracks
#
# Usage: randtrack.pl [ardour session file] [output file] [amount of randomization] [track name]...
#
# [amount of randomization] is the max offset in samples.
use strict;
use warnings;
use XML::LibXML;
sub is_integer { $_[0] =~ /^[+-]?\d+$/ }
my $session_file;
my $outfile;
my $randomization;
my $track;
my $session;
my $region;
my $value;
my $temp;
my $rand;
my $root;
my @nodelist;
my $i;
my $numargs = @ARGV;
if ( $numargs > 3 ) {
$session_file = $ARGV[0];
$outfile = $ARGV[1];
$randomization = $ARGV[2];
}
else {
die
"Usage: randtrack [ardour session file] [output file] [amount of randomization] [track name]...\n";
}
if ( defined($session_file) && defined($outfile) && defined($randomization) ) {
if ( is_integer($randomization) ) {
$session = XML::LibXML->load_xml( location => $session_file );
$root = $session->documentElement();
$value = $root->nodeName;
if ( $value ne "Session" ) { die "This is not an Ardour session"; }
$value = $root->getAttribute("version");
if ( $value ne "3001" && $value ne "3002" ) {
die "This Ardour session version is not supported";
}
for ( $i = 3 ; $i < $numargs ; $i++ ) {
$track = $ARGV[$i];
@nodelist = $root->findnodes(
"/Session/Routes/Route[\@name='$track']/Diskstream");
if (@nodelist) {
$value = $nodelist[0]->getAttribute("playlist");
@nodelist = $root->findnodes(
"/Session/Playlists/Playlist[\@name='$value']/Region");
foreach $region (@nodelist) {
$rand =
int( rand($randomization) - ( $randomization / 2 ) );
$value = $region->getAttribute("position");
$temp = $value + $rand;
if ( $temp < 0 ) { $temp = 0 }
$region->setAttribute( "position", $temp );
}
}
else {
print "Track $track not found\n";
}
}
$session->toFile($outfile);
}
}
else {
print
"Usage: randtrack [ardour session file] [output file] [amount of randomization (samples)] [track name]...\n";
}