#!/usr/bin/perl # tab2lily.pl -- program to convert from guitar tab notation to a lilypad script for output... use strict; use warnings; use Text::Wrap; our $VERSION = '0.01a'; my @notes = ( ["?", "e'", "b", "g", "d", "a,", "e," ], ["?", "f'", "c'", "gis", "dis", "ais,","f," ], ["?", "fis'", "cis'","a", "e", "b,", "fis,"], ["?", "g'", "d'", "ais", "f", "c", "g," ], ["?", "gis'", "dis'","b", "fis", "cis", "gis,"], ["?", "a'", "e'", "c'", "g", "d", "a," ], ["?", "ais'", "f'", "cis'","gis", "dis", "ais,"], ["?", "b'", "fis'","d'", "a", "e", "b," ], ["?", "c''", "g'", "dis'","ais", "f", "c" ], ["?", "cis''","gis'","e'", "b", "fis", "cis" ], ["?", "d''", "a'", "f'", "c'", "g", "d" ], ["?", "dis''","ais'","fis'","cis'","gis", "dis" ], ["?", "e''", "b'", "g'", "d'", "a", "e" ], ); my @strings; my $max = 0; my $count = 0; my @tabs = ('','','','','',''); my @ctabs = ('','','','','',''); my @frets; my @notelist; my @octive; my $time = 8; my @commands; while (<>) { if (/=/) { /([^=]*)=(.*)/; push(@commands,"$1 = \"$2\""); } elsif (/^-/) { chop; push(@strings,$_); if ($max < length $_) { $max = length $_; } } } for (@strings) { while (length $_ < $max) { $_ .= '-'; } $tabs[$count++ % 6] .= $_; } for (0..length $tabs[0]) { my $copy = 0; foreach my $n (0..5) { if (substr($tabs[$n],$_,1) ne '-') { $copy = 1; last; } } if ($copy) { my $list = ''; foreach my $m (0..5) { $list .= substr($tabs[$m],$_,1); } push(@frets,$list); } } for (@frets) { my $col; my $row; if (/\d.*\d/) { my $chord ='<'; while (/(\d)/g) { $col = $-[0] + 1; $row = $1; $chord .= $notes[$row][$col] . "\\$col "; } chop($chord); $chord .= "> $time "; push(@notelist,$chord); } elsif (/(\d)/) { $col = $-[0] + 1; $row = $1; push(@notelist, $notes[$row][$col] . "$time\\$col"); } } $Text::Wrap::columns = 72; @octive = octivehigher(@notelist); print "\\version \"2.10.33\"\n"; print "\\header{\n"; for (@commands) { print " $_\n"; } print "}\n\n"; print "keyboard = \\new Staff {\n"; print " {\n"; print wrap(' ', ' ', @octive); print " \\bar \"|.\"\n }\n"; print "}\n"; print "guitar = \\new TabStaff {\n"; print wrap(' ', ' ', @notelist); print " \\bar \"|.\"\n}\n"; print "{\n"; print " <<\n"; print " \\keyboard\n"; print " \\guitar\n"; print " >>\n"; print "}\n"; sub octivehigher { my @notes = @_; my @newnotes; for (@notes) { if (/^\\s\d//; s/\ $time "; } elsif (/,/) { s/,//; } elsif (/''\'/) { s/''\'/''''/; } elsif (/''/) { s/''/''\'/; } elsif (/\'/) { s/\'/''/; } else { if (/\d/) { s/(\d)/\'$1/; } else { $_ .= "'"; } } push(@newnotes,$_); } return @newnotes; }