#!/usr/bin/perl
#
# Programmer:    Craig Stuart Sapp <craig@ccrma.stanford.edu>
# Creation Date: Sat Mar 25 10:03:48 PST 2006
# Last Modified: Sat Mar 25 10:03:48 PST 2006
# Filename:      /project/mazurka/website/auto/tapadj/addoffset
# Syntax:        perl 5
#
# Description:
#

use strict;

my $offset = 0.0;
my $line;
my $rhy;
my $beat;
my $atime;
my $delta;

while ($line = <>) {
   if ($line =~ /^!!!offset:\s*([\d\.-]+)/) {
      $offset = $1;
      next;
   }
   if ($line =~ /^!!/) {
      print $line;
      next;
   }
   if ($line =~ /^=/) {
      print $line;
      next;
   }
   if ($line =~ /^\*/) {
      print $line;
      next;
   }

   if ($line =~ /^(\d+)\t(\d+)\t(\d+)\t(\d+)$/) {
      $rhy   = $1;
      $beat  = $2;
      $atime = $3;
      $delta = $4;

      $atime = int ($atime + $offset + 0.5);
      print "$rhy\t$beat\t$atime\t$delta\n";
      next;
   }

   print $line;

}




