#!/usr/bin/perl -w

# Goal: extract just the series of time points contained in a TextGrid
# file (here, typically, beats) and output to a file.  What you do
# with it then is entirely your own business.
# For present purposes, we don't check that beats have any specific labels.

scalar(@ARGV) == 2 or die "Usage: extractBeatTimes.pl inTextGrid OutFile";

$infile = shift;
$outfile = shift;

open(IN, $infile) or die "bad infile";
open(OUT, ">$outfile") or die "bad outfile";

# Skip forward a bit
while($_ = <IN>) {
  next unless $_ =~ /TextTier/;
  last;
}

$_ = <IN>;$_ = <IN>;$_ = <IN>;

chomp($nPoints = <IN>);

for($i = 0; $i < $nPoints; $i++) {
  chomp($beat = <IN>);
  print OUT "$beat\n";
  $_ = <IN>;   #skip label without check
}

print "extrractBeatTimes.pl done\n";
