2 # Ardour session resampler, version 0.1
3 # (c)Sampo Savolainen 2005-2007
5 # Licensed under the GPL
7 # Copies the session to another directory and changes it's sampling rate in all respects.
8 # The frames in .ardour and .automation files are converted according to the conversion ration.
9 # The peakfiles and dead_sounds aren't copied. Only "identified" files are copied, instant.xml's
10 # or .bak's aren't copied either.
14 use XML
::Parser
::PerlSAX
;
15 use XML
::Handler
::XMLWriter
;
20 use ARDOUR
::SessionSRHandler
;
21 # Let's hope this is never needed
22 #use ARDOUR::AutomationSRConverter;
25 if ( ! -f
"/usr/bin/sndfile-resample" &&
26 ! -f
"/usr/local/bin/sndfile-resample") {
27 print "You don't have sndfile-resample installed. This script will not work without it, please install it and try again\n";
31 my ($sourceDirectory, $destDirectory, $sourceSR, $destSR) = @ARGV;
36 print "usage: ardour_sr.pl [ardour session directory] [destination directory] [original samplerate] [new samplerate]\n";
40 if ( ! -d
$sourceDirectory) {
41 print $sourceDirectory.": directory does not exist!\n";
45 if ( -d
$destDirectory) {
46 print $destDirectory.": directory exists!\n";
50 print "Checking source and destination directories\n";
60 # Read the names of all audio files in /sounds/
61 if ( -d
$sourceDirectory."/sounds/") {
64 opendir(SOUNDS
,$sourceDirectory."/sounds/") || die ($sourceDirectory.": not a valid session, no sounds/ directory");
65 while ( my $file=readdir(SOUNDS
) ) {
66 if ( -f
$sourceDirectory."/sounds/".$file ) {
72 my $dirname = $sourceDirectory."/interchange/".basename
($sourceDirectory)."/audiofiles/";
73 opendir(SOUNDS
,$dirname) || die ($sourceDirectory.": not a valid session, no sounds/ directory");
74 while ( my $file=readdir(SOUNDS
) ) {
75 if ( -f
$dirname.$file ) {
83 # Read the names of all audio files in /dead_sounds/
84 opendir(DEAD_SOUNDS
,$sourceDirectory."/dead_sounds/") || die ($sourceDirectory.": not a valid session, no dead_sounds/ directory");
85 while ( my $file=readdir(DEAD_SOUNDS
) ) {
86 if ( -f
$sourceDirectory."/dead_sounds/".$file ) {
87 push(@dead_sounds,$file);
92 # Read the names of all .ardour files in /
93 opendir(DOT_ARDOUR
,$sourceDirectory) || die ($sourceDirectory.": could not open!");
94 while ( my $file=readdir(DOT_ARDOUR
) ) {
95 if ( -f
$sourceDirectory."/".$file &&
96 index($file,".ardour") eq (length($file)-7)) {
97 push(@dot_ardour,$file);
102 # Read the names of all automation files in /automation/
103 opendir(AUTOMATION
,$sourceDirectory."/automation/") || die ($sourceDirectory."/automation: could not open!");
104 while ( my $file=readdir(AUTOMATION
) ) {
105 if ( -f
$sourceDirectory."/automation/".$file &&
106 index($file,".automation") eq (length($file)-11)) {
107 push(@automation,$file);
113 if ( ! -d
$sourceDirectory."/peaks" ) {
114 print $sourceDirectory.": not a valid session, no peaks/ directory\n";
118 ##########################################
119 # Checks are done, let's go!
121 print "Converting session\n";
122 mkdir $destDirectory;
125 # Run all .ardour files through the SAX parser and write the results in the destination
128 foreach my $xml (@dot_ardour) {
129 print "Doing samplerate conversion to ".$xml."...";
130 open(OUTFILE
,">".$destDirectory."/".$xml);
131 my $output = new IO
::Handle
;
132 $output->fdopen(fileno(OUTFILE
),"w");
134 my $handler = ARDOUR
::SessionSRHandler
->new($sourceSR,$destSR,$output);
136 my $parser = XML
::Parser
::PerlSAX
->new( Handler
=> $handler );
138 $parser->parse(Source
=> { SystemId
=> $sourceDirectory."/".$xml });
145 # This code is needed for 0.99.x sessions, thus the code is still here.
147 #mkdir $destDirectory."/automation";
149 #foreach my $file (@automation) {
150 # print "Converting automation file ".$file."...";
151 # open(INFILE,$sourceDirectory."/automation/".$file) || die "could not open source automation file $file!";
152 # open(OUTFILE,">".$destDirectory."/automation/".$file) || die "could not open destination automation file $file!";
153 # my $input=new IO::Handle;
154 # my $output=new IO::Handle;
156 # $input->fdopen(fileno(INFILE),"r");
157 # $output->fdopen(fileno(OUTFILE),"w");
159 # my $converter = ARDOUR::AutomationSRConverter->new($input,$output,$sourceSR,$destSR);
160 # $converter->convert;
170 if ($version_099x eq 1) {
171 mkdir $destDirectory."/sounds";
172 foreach my $sound (@sounds) {
173 my @params=("-to", $destSR,
175 $sourceDirectory."/sounds/".$sound,
176 $destDirectory."/sounds/".$sound);
177 system("sndfile-resample",@params);
180 my $srcSndDir = $sourceDirectory."/interchange/".basename
($sourceDirectory)."/audiofiles/";
182 my $dstSndDir = $destDirectory."/interchange/";
185 $dstSndDir .= basename
($sourceDirectory)."/";
188 $dstSndDir .= "audiofiles/";
191 foreach my $sound (@sounds) {
192 my @params=("-to", $destSR,
194 $srcSndDir."/".$sound,
195 $dstSndDir."/".$sound);
196 system("sndfile-resample",@params);
200 mkdir $destDirectory."/dead_sounds";
201 mkdir $destDirectory."/peaks";