#!/usr/bin/perl -w # script to process repeat level granularity into event list for vamp # Stan Swanson 2 May 2004 %keyword = ( fiddle => 111, piano => 1, clarinet => 72, guitar => 25, bass => 44, sax => 66, flute => 74, banjo => 106, instrument => 0, melody => -1, chords => -2, dynamics => -3 ); %volume = ( fff => 120, ff => 104, f => 88, mf => 72, mp => 56, p => 40, pp => 24, ppp => 8 ); print "input file: "; $infile = ; open INFILE, $infile or die "cannot find $infile $!"; $mode = $notes = $voice = 0; # keywords melody, chords, dynamics not seen yet $ref_file = ; # get reference file for tune while (1) { $line = ; # prime the while loop last unless ($line); print $line; chomp $line; @tokens = split /\s+/, $line; $_ = $tokens[0]; next unless ($_); next if (/^#/); # blank lines and comments # 045.03 combine syntax # melody/chords chunk [rep] ... # dynamics vol [rep] ... # name/{instrument n} (accent/phrase)chunk [rep]... if (exists $keyword{$tokens[0]} ) # look for "reserved" word { $i = $keyword{$tokens[0]}; shift @tokens; $rep = 1; if ($i<0) { $mode = -$i; $notes = 1; } else { $notes = 0; warn "mode not defined\n" unless $mode; if ($i == 0) { $i = $tokens[0]+0; shift @tokens; } push @band, $i; $voice++; foreach (@music) { $item = sprintf("%-20s %2d",$_,$voice); # print $item, "\n"; push @events, $item; $rep++; } $rep = 1; # reinitialize for instrument accents... } } # found keyword if ($notes) { if ($mode<3) { @music = (); foreach (@tokens) { if (/\D/) { $item = sprintf(" %3d %-20s ",$rep,$_); # print $item, "\n"; push @music, $item; $rep++; } else { $rep += $_ - 1; } } } else { # translate "dynamics" info into _vel_ events foreach (@tokens) { if (/\D/) { $vol = $volume{$_}; $item = sprintf(" %3d _volume_ %3d",$rep,$vol); # print $item, "\n"; push @events, $item; $rep++; } else { $rep += $_ - 1; } } } } else # look for instrument accent and phrasing chunks { if ($mode == 1 or $mode ==2 ) # look for new instrument { foreach (@tokens) { if (/\D/) { $item = sprintf(" %3d %-20s %3d",$rep,$_,$voice); # print $item, "\n"; push @events, $item; $rep++; } else { $rep += $_ - 1; } } } else { print "mode $mode should not get here\n"; } } } # while ($line) print "==============\n\n@","$ref_file\n\n"; print "instrum "; foreach (@band) { print $_, " "; } print "\n"; print "events\n"; @events = sort @events; foreach (@events) { print "$_ \n"; } print "/events\n"; print "output file: "; $output = ; if ($output) { open OUT, "> $output" or die "could not open $output"; print "opened $output\n"; print OUT "@","$ref_file\n\n"; print OUT "instrum "; foreach (@band) { print OUT $_, " "; } print OUT "\n"; print OUT "\nevents\n", " -1 potatoes \n"; @events = sort @events; foreach (@events) { print OUT "$_ \n"; } print OUT "/events\n"; }