#!/home/jj/bin/perl BEGIN {@INC = ("/home/jj/lib/perl5", @INC); } use CGI qw(:all); use chord; $music_files="/~jj/musica"; $index_file="$music_files/indice_autores.html#"; sub refau{ my $p = shift; my $a; my $r=""; for (split(/\s*;\s*/, $p)){ $a = $_; s/\s*\(.*?\)\s*//g; $r .= a({href => $index_file . $_ }, $a) . "; "; } chop $r; chop $r; $r } for (@ARGV){ open(STDIN, "< $_") or die "can't find '$_' :-(((" ; $dir = `dirname $_`; chop $dir; $name = `basename $_ .lyr`; chop $name; open(STDOUT, "> $dir/html/$name.html") or die "can't create '$dir/html/$name.html' :-(((" ; $st=0; $n =0; my %chords=(); %hea = (n => 0 , t => 1); while(){ if($st==0){ # cabecalho if (/\s*(\w+)\s*:\s*(.*?)\s*$/){ $hea{lc($1)}=$2; if(lc($1) eq "chorddef" || lc($1) eq "chordef"){ my $r=$2; if($r =~ m{([^ ]+)\s+([^ ]+)} ) {learn_chords($1 => $2)}} } if (/^ *$/) {$st= $hea{t}; $agrad= "$hea{from}" . (($hea{date} ne "") ? "($hea{date})": ""); if (defined $hea{jeito}) { $agrad .= " (jeito de $hea{jeito})";} if (defined $hea{comm}) { $agrad .= br . "\n($hea{comm})";} $tti = join("/", @hea{'title','singer','author','music','lyrics'}); if (defined $hea{singer}) { $ti = refau($hea{singer})." : $hea{title}";} elsif (defined $hea{author}) { $ti = refau($hea{author})." : $hea{title}";} elsif (defined $hea{music}) { $ti = refau($hea{music})." : $hea{title}";} else { $ti = $hea{title};} $subti =""; if (defined $hea{author}) { $subti .="Letra e música: ". refau($hea{author}).br;} if (defined $hea{music}) { $subti .="Música: ". refau($hea{music}). br;} if (defined $hea{lyrics}) { $subti .="Letra: ".refau($hea{lyrics}).br;} if (defined $hea{in}) { $subti .=" In: $hea{in}". br;} if (defined $hea{type}) { $subti .=" ($hea{type})". br;} if ($hea{title} =~ /^\s*=/) { $midi = a({href => "$music_files/abc/$name.mid"}, 'Midi'). br;} else {$midi = "";} print start_html(-title => $tti, -meta => {'keywords' => 'music,música'}),"\n", hr, h2(a({name => $hea{"n"}},$ti)), strong($subti), $midi, i( font({size=> -2}, $agrad)), hr; begincite() if ($hea{t} == 1 || $hea{t} == 7) ; beginpre() if $hea{t} == 4 ; } } elsif($st==1 || $st == 7){ # corpo geral chop; if (/^title:\s*(.*)/i) { endcite(); %hea= ("title" => $1, "n" => ++$n ); $st=0;} elsif(/^htmlnot[ae]\s*:\s*(.*)/i){ endcite(); print hr, h4("Nota: $1"), "\n"; $st=3;} elsif(/^(not[ae]):\s*(.*)/i){ endcite(); print hr, h4($_), "\n"; $st=2;} elsif($st==7 && /\[/) { s/\[(.*?)\]/$chords{$1}++; sup(b("$1"))/ge; print $_ , br , "\n";} elsif($st==1 && /^([^ ].*?) +(.*)$/) { @x=split(' ',$2); $i=0; for(@x){$chords{$_}++} ($letra = $1) =~ s/_/sup(b($x[$i++]))/ge; print "$letra". br . "\n";} elsif(/^/i){ open(ABC, "> $dir/abc/$name.abc") or die ("cant open $name.abc\n"); $st=5;} else { print "\n$_",br;} } elsif($st==2){ chop; if (/^title:\s*(.*)/i) { endcite(); %hea= ("title" => $1, "n" => ++$n ); $st=0;} else { print "\n$_",br;} } elsif($st==3){ chop; if (/^title:\s*(.*)/i) { endcite(); %hea= ("title" => $1, "n" => ++$n ); $st=0;} else { print "\n$_";} } elsif($st==4){ chop; if (/^title:\s*(.*)/i) { endpre(); %hea= ("title" => $1, "n" => ++$n ); $st=0;} elsif(/^htmlnot[ae]\s*:\s*(.*)/i){ endpre(); print hr, h4("Nota: $1"), "\n"; $st=3;} elsif(/^(not[ae]):\s*(.*)/i){ endpre(); print hr, h4($_), "\n"; $st=2;} else { print "\n$_";} } elsif($st==5){ chop; if (/^<\/abc>/i) { close ABC; system ("abc2gif $dir/abc/$name.abc >/dev/null"); system ("abc2midi ../abc/$name.abc > /dev/null ; mv 1.mid $dir/abc/$name.mid "); $st=1; # print a({href => "$dir/abc/$name.mid"}, Midi),br; print img({ src => "$music_files/abc/$name.abc.gif"}),br ;} else { print ABC "$_\n";} } } endcite2(); if(%chords){my $chrs = htmlchords({dir=>"$dir/html"},keys(%chords)); $chrs=~ s!$dir/html/!!g ; print hr, $chrs } endhtml(); close STDOUT; } sub begincite{ print "
\n"; } sub endcite { print "
\n" ;} sub endcite2 { print "\n" if $st==1 || $st==7 ;} sub beginpre{ print "
\n"; }
sub endpre{ print "
\n" ; } sub endhtml{ print "\n" if $st == 4 ; print end_html ; }