use Parse::DSLUtils qw(:yapp); use strict; my $instruments=join("",); %initstate ABC %white [\ \t]+ %comments ##.+ %% my $c=0; my $chs=""; my $M; REC:ABC{ ### ABC header level (M:\s*(\d+).*\n) { $M=$2; print $1; } chords\[(\d+)\]\[(.*?)\]\{ { instru($1); gchord($2); REC CHORDS; } chords\[([\w\s]+)\]\[(.*?)\]\{ { sinstru($1); gchord($2); REC CHORDS; } chords\[(.*?)\]\{ { gchord($1); REC CHORDS; } chords\{ { REC CHORDS; } (.*\n) { print $1; } } REC:CHORDS{ ### { \}\n { DONE; } \. { $c++; $chs .= "z";} (:?\|\d?) { if($c < $M){ print nch("${chs}z".($M-$c)."$1\n");} else { print nch("$chs$1\n");} $c=0; $chs="" } ([^\s.|]+) { $c++; $chs .= qq{ "$1"z}; } \n { } } %% sub instru{ print "%%MIDI chordprog $_[0] % $_[1]\n"} sub gchord{ print "%%MIDI gchord $_[0]\n"} sub nch { return ($_[0] =~ s/zz(\d)?/"z".(($1||1)+1)/ger) } sub sinstru{my ($i,$j) = ($instruments =~ m!(\d+)=($_[0].*)!g); instru($i,$j) } lex(); __DATA__ 0=piano 1=bright acoustic piano 2=electric grand piano 3=honky-tonk piano 4=electric piano 1 5=electric piano 2 6=harpsichord 7=clavi 8=celesta 9=glockenspiel 10=music box 11=vibraphone 12=marimba 13=xylophone 14=tubular bells 15=dulcimer 16=drawbar organ 17=percussive organ 18=rock organ 19=organ // church organ 20=reed organ 21=accordion 22=harmonica 23=tango accordion 24=guitar (nylon) 25=guitar (steel) 26=electric guitar (jazz) 27=electric guitar (clean) 28=electric guitar (muted) 29=overdriven guitar 30=distortion guitar 31=guitar harmonics 32=acoustic bass 33=electric bass (finger) 34=electric bass (pick) 35=fretless bass 36=slap bass 1 37=slap bass 2 38=synth bass 1 39=synth bass 2 40=violin 41=viola 42=cello 43=contrabass 44=tremolo strings 45=pizzicato strings 46=orchestral harp 47=timpani 48=string ensemble 1 49=string ensemble 2 50=synthstrings 1 51=synthstrings 2 52=choir aahs 53=voice oohs 54=synth voice 55=orchestra hit 56=trumpet 57=trombone 58=tuba 59=muted trumpet 60=french horn 61=brass section 62=synthbrass 1 63=synthbrass 2 64=soprano sax 65=alto sax 66=tenor sax 67=baritone sax 68=oboe 69=english horn 70=bassoon 71=clarinet 72=piccolo 73=flute 74=recorder 75=pan flute 76=blown bottle 77=shakuhachi 78=whistle 79=ocarina 80=lead 1 (square) 81=lead 2 (sawtooth) 82=lead 3 (calliope) 83=lead 4 (chiff) 84=lead 5 (charang) 85=lead 6 (voice) 86=lead 7 (fifths) 87=lead 8 (bass + lead) 88=pad 1 (new age) 89=pad 2 (warm) 90=pad 3 (polysynth) 91=pad 4 (choir) 92=pad 5 (bowed) 93=pad 6 (metallic) 94=pad 7 (halo) 95=pad 8 (sweep) 96=fx 1 (rain) 97=fx 2 (soundtrack) 98=fx 3 (crystal) 99=fx 4 (atmosphere) 100=fx 5 (brightness) 101=fx 6 (goblins) 102=fx 7 (echoes) 103=fx 8 (sci-fi) 104=sitar 105=banjo 106=shamisen 107=koto 108=kalimba 109=bag pipe 110=fiddle 111=shanai 112=tinkle bell 113=agogo 114=steel drums 115=woodblock 116=taiko drum 117=melodic tom 118=synth drum 119=reverse cymbal 120=guitar fret noise 121=breath noise 122=seashore 123=bird tweet 124=telephone ring 125=helicopter 126=applause 127=gunshot