#!/usr/bin/perl # # Programmer: Craig Stuart Sapp # Creation Date: Sun Jun 4 01:15:44 PDT 2006 # Last Modified: Sun Jun 4 01:15:44 PDT 2006 # Filename: /project/mazurka/website/info/revcond/pid52932-06/makebtime # Syntax: perl 5 # # Description: create a score where the beat-level events are given # event times. # use strict; # . /etc/profile.d/humdrum.sh my $avgfile = $ARGV[0]; my $scorefile = $ARGV[1]; my $minrhy = `minrhy $scorefile`; chomp $minrhy; my $scoredur = `scordur $scorefile`; my $avgdur = `scordur $avgfile`; if ($avgdur < $scoredur) { addbeats($avgfile, "tempa", $scoredur - $avgdur); } elsif ($avgdur > $scoredur) { subtractbeats($avgfile, "tempa", $avgdur - $scoredur); } else { `cp $avgfile tempa`; } `timebase -t $minrhy $scorefile > tempb`; `timebase -t $minrhy tempa | extract -f3 > tempc`; my $output = `assemble tempc tempb | rid -d | grep -v '\*tb[0-9]'`; `rm -f tempa tempb tempc`; print $output; exit(0); ########################################################################## ############################## ## ## addbeats -- ## sub addbeats { my ($infile, $outfile, $count) = @_; open (AFILE, $infile) or die "Cannot open $infile for reading."; my @contents = ; close AFILE; my $i; my $j; for ($i=@contents-1; $i>0; $i--) { next if $contents[$i] =~ /^=/; next if $contents[$i] =~ /^\*/; next if $contents[$i] =~ /^\s*$/; next if $contents[$i] =~ /^\!/; for ($j=0; $j<$count; $j++) { $contents[$i] .= "4\tX\t.\t.\t.\t.\t.\t.\t.\n"; } last; } open (AFILE, ">$outfile") or die "Cannot open $outfile for writing."; for ($i=0; $i<@contents; $i++) { print AFILE $contents[$i]; } close AFILE; } ############################## ## ## subtractbeats -- ## sub subtractbeats { my ($infile, $outfile, $count) = @_; open (AFILE, $infile) or die "Cannot open $infile for reading."; my @contents = ; close AFILE; my $i; my $j; my $deleted = 0; for ($i=@contents-1; $i>0; $i--) { next if $contents[$i] =~ /^=/; next if $contents[$i] =~ /^\*/; next if $contents[$i] =~ /^\s*$/; next if $contents[$i] =~ /^\!/; $contents[$i] = ""; $deleted++; if ($contents[$i-1] =~ /^=/) { $contents[$i-1] = ""; $i--; } last if $deleted == $count; } open (AFILE, ">$outfile") or die "Cannot open $outfile for writing."; for ($i=0; $i<@contents; $i++) { print AFILE $contents[$i]; } close AFILE; }