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.
12 use XML
::Parser
::PerlSAX
;
13 use XML
::Handler
::XMLWriter
;
18 use ARDOUR
::SessionSRHandler
;
19 # Let's hope this is never needed
20 #use ARDOUR::AutomationSRConverter;
23 if ( ! -f
"/usr/bin/sndfile-resample" &&
24 ! -f
"/usr/local/bin/sndfile-resample") {
25 print "You don't have sndfile-resample installed. This script will not work without it, please install it and try again\n";
29 my ($sourceDirectory, $destDirectory, $sourceSR, $destSR) = @ARGV;
34 print "usage: ardour_sr.pl [ardour session directory] [destination directory] [original samplerate] [new samplerate]\n";
38 if ( ! -d
$sourceDirectory) {
39 print $sourceDirectory.": directory does not exist!\n";
43 if ( -d
$destDirectory) {
44 print $destDirectory.": directory exists!\n";
48 print "Checking source and destination directories\n";
58 # Read the names of all audio files in /sounds/
59 if ( -d
$sourceDirectory."/sounds/") {
62 opendir(SOUNDS
,$sourceDirectory."/sounds/") || die ($sourceDirectory.": not a valid session, no sounds/ directory");
63 while ( my $file=readdir(SOUNDS
) ) {
64 if ( -f
$sourceDirectory."/sounds/".$file ) {
70 my $dirname = $sourceDirectory."/interchange/".basename
($sourceDirectory)."/audiofiles/";
71 opendir(SOUNDS
,$dirname) || die ($sourceDirectory.": not a valid session, no sounds/ directory");
72 while ( my $file=readdir(SOUNDS
) ) {
73 if ( -f
$dirname.$file ) {
81 # Read the names of all audio files in /dead_sounds/
82 opendir(DEAD_SOUNDS
,$sourceDirectory."/dead_sounds/") || die ($sourceDirectory.": not a valid session, no dead_sounds/ directory");
83 while ( my $file=readdir(DEAD_SOUNDS
) ) {
84 if ( -f
$sourceDirectory."/dead_sounds/".$file ) {
85 push(@dead_sounds,$file);
90 # Read the names of all .ardour files in /
91 opendir(DOT_ARDOUR
,$sourceDirectory) || die ($sourceDirectory.": could not open!");
92 while ( my $file=readdir(DOT_ARDOUR
) ) {
93 if ( -f
$sourceDirectory."/".$file &&
94 index($file,".ardour") eq (length($file)-7)) {
95 push(@dot_ardour,$file);
100 # Read the names of all automation files in /automation/
101 opendir(AUTOMATION
,$sourceDirectory."/automation/") || die ($sourceDirectory."/automation: could not open!");
102 while ( my $file=readdir(AUTOMATION
) ) {
103 if ( -f
$sourceDirectory."/automation/".$file &&
104 index($file,".automation") eq (length($file)-11)) {
105 push(@automation,$file);
111 if ( ! -d
$sourceDirectory."/peaks" ) {
112 print $sourceDirectory.": not a valid session, no peaks/ directory\n";
116 ##########################################
117 # Checks are done, let's go!
119 print "Converting session\n";
120 mkdir $destDirectory;
123 # Run all .ardour files through the SAX parser and write the results in the destination
126 foreach my $xml (@dot_ardour) {
127 print "Doing samplerate conversion to ".$xml."...";
128 open(OUTFILE
,">".$destDirectory."/".$xml);
129 my $output = new IO
::Handle
;
130 $output->fdopen(fileno(OUTFILE
),"w");
132 my $handler = ARDOUR
::SessionSRHandler
->new($sourceSR,$destSR,$output);
134 my $parser = XML
::Parser
::PerlSAX
->new( Handler
=> $handler );
136 $parser->parse(Source
=> { SystemId
=> $sourceDirectory."/".$xml });
143 # This code is needed for 0.99.x sessions, thus the code is still here.
145 #mkdir $destDirectory."/automation";
147 #foreach my $file (@automation) {
148 # print "Converting automation file ".$file."...";
149 # open(INFILE,$sourceDirectory."/automation/".$file) || die "could not open source automation file $file!";
150 # open(OUTFILE,">".$destDirectory."/automation/".$file) || die "could not open destination automation file $file!";
151 # my $input=new IO::Handle;
152 # my $output=new IO::Handle;
154 # $input->fdopen(fileno(INFILE),"r");
155 # $output->fdopen(fileno(OUTFILE),"w");
157 # my $converter = ARDOUR::AutomationSRConverter->new($input,$output,$sourceSR,$destSR);
158 # $converter->convert;
168 if ($version_099x eq 1) {
169 mkdir $destDirectory."/sounds";
170 foreach my $sound (@sounds) {
171 my @params=("-to", $destSR,
173 $sourceDirectory."/sounds/".$sound,
174 $destDirectory."/sounds/".$sound);
175 system("sndfile-resample",@params);
178 my $srcSndDir = $sourceDirectory."/interchange/".basename
($sourceDirectory)."/audiofiles/";
180 my $dstSndDir = $destDirectory."/interchange/";
183 $dstSndDir .= basename
($sourceDirectory)."/";
186 $dstSndDir .= "audiofiles/";
189 foreach my $sound (@sounds) {
190 my @params=("-to", $destSR,
192 $srcSndDir."/".$sound,
193 $dstSndDir."/".$sound);
194 system("sndfile-resample",@params);
198 mkdir $destDirectory."/dead_sounds";
199 mkdir $destDirectory."/peaks";