#!/usr/bin/perl -w

# used as ~/git/musik/bin/extrmidiinstr.pl /Net/git/lilypond/scm/midi.scm
# to get the instrument names printed out

use strict;

while (<>) {
    last if (m/^\(set! instrument-names-alist/);
    last if (m/^\(define-public instrument-names-alist/);
}

my @instr;
while (<>) {
    last if (m/;; \(channel 10 drum-kits /);

    if (m/\("(.+)"\s*\.\s*,\(- (\d+) 1\)\)/) {
	my $num = $2 - 1;
	$instr[$num] = $1;
    }
}

my $ix;
for ($ix = 0; $ix < @instr; $ix++) {
    #if (($ix % 4) == 0) { print "\n"; }
    my $name = $instr[$ix];
    if (!defined($name)) {
	$name = "undefined";
    }
    #print " \"$name\",";
    printf "%3d  %s\n", $ix, $name;
}
#print "\n";
