#!/usr/bin/perl -dw
#
# Test driver for the abcCode() routine.
#

$V = 9;
push @INC, '.', 'sh', "$ENV{HOME}/sh";

require "abcCode.pm";

for $l (<>) {
	$l =~ s/\s+$//;
	if (!$l) {
		next if !@music;
		$K = 'C'   if !$K;
		$M = 'C'   if !$M;
		$L = '1/8' if !$L;
		$code = &abcCode($K,$L,$M,@music);
		print "\n";
		print "X: $X\n";
		print "T: $T\n";
		print "M: $M L: $L K: $K Code=$code\n";
		@music = ();
		$X = $T = $M = $L = $K = '';
		$intune = $inhdrs = 0;
		next;
	}
	if ($l =~ m"^X:\s*(\d+)") {
		$X = $1;
		$inhdrs = 1;
	} elsif ($l =~ m"^K:\s*([A-G])") {
		$K = $1;
		$inhdrs = 0;
		$intune = 1;
	} elsif ($l =~ m"^L:\s*([\d+/\d+]+)") {
		$L = $1;
	} elsif ($l =~ m"^M:\s*([\dC/|]+)") {
		$M = $1;
	} elsif ($l =~ m"^T:\s*(.+)") {
		$T = $1 if !$T;
		$inhdrs = 1;
	} elsif ($l =~ m"^[A-Z]:") {
		# Ignore other headers.
	} elsif ($intune) {
		push @music, $l;
	}
}
