# 2003-08-03 Version 1.1 Uses stylesheets
# 2014-02-05 Added things particular to my implementation of Songbook at
# http://defaria.com/songbook
-
use strict;
use warnings;
use CGI::Carp qw (fatalsToBrowser);
use File::Basename;
-my ($chopro, $output, $i);
+my ($chopro, $i);
my $documentRoot = "/web";
my $debug = param ('debug');
my $infile = param ('chordpro');
unless (-f $infile) {
- $infile = '/opt/songbook/Songs/' . $infile;
+ $infile = '/opt/songbook/Andrew/' . $infile;
unless (-f $infile) {
$infile = '/web/xmas/' . param ('chordpro');
sub debug ($) {
my ($msg) = @_;
-
+
return unless $debug;
-
+
print "<font color=red><b>Debug:</b></font> $msg<br>";
-
+
return;
} # debug
-sub warning ($) {\r
+sub warning ($) {
my ($msg) = @_;
debug "warning";
print "<font color=orange><b>Warning</b></font> $msg<br>";
- return;
+ return;
} # warning
sub error {
my ($msg) = @_;
-
+
print "<html><head><title>Web Chord: Error</title></head>" .
"<body><h1>Error</h1><p>\n$msg\n</p>" .
"</body></html>";
-
+
exit;
} # error
+sub getTitle ($) {
+ my ($song) = @_;
+
+ return fileparse ($song, qr/\.pro/);
+} # getTitle
+
sub musicFileExists ($) {
my ($song) = @_;
debug "ENTER musicFileExists ($song)";
-
- my $title = fileparse ($song, qr/\.pro/);
- my $musicfile = "/opt/songbook/Media/$title.mp3";
-
- if (-r $musicfile) {
- debug "Exists!";
-
- return $title;
- } else {
- debug "Could not find $musicfile";
-
- return undef;
- } # if
+
+ my $title = getTitle ($song);
+ my $musicfile = "/opt/media/$title.mp3";
+
+ return -r $musicfile;
} # musicFileExists
sub updateMusicpath ($$) {
my ($chopro, $song) = @_;
- my $title = musicFileExists $song;
-
# If there's no corresponding music file then do nothing
- return unless $title;
-
+ return unless musicFileExists $song;
+
# If the .pro file already has musicpath then do nothing
- if ($chopro =~ /\{musicpath:.*\}/) {
- debug "$song already has musicpath";
- } # if
-
return if $chopro =~ /\{musicpath:.*\}/;
# Otherwise append the musicpath
my $songfile;
-
+
open $songfile, '>>', $song
or undef $songfile;
-
+
unless (defined $songfile) {
my $msg = "Unable to open $song for append - $!<br>";
$msg .= "<br>Please notify <a href=\"mailto:adefaria\@gmail.com?subject=Please chmod 666 $song\">Andrew DeFaria</a> so this can be corrected.<br>";
$msg .= "<br>Thanks";
warning $msg;
-
+
return;
} # unless
my $songbase = '/sdcard';
-
+ my $title = getTitle $song;
+
print $songfile "{musicpath:$songbase/SongBook/Media/$title.mp3}\n";
-
+
close $songfile;
- return;
+ return;
} # updateMusicPath
# Outputs the HTML code of the chordpro file in the first parameter
$chopro =~ s/\>/\>/g; # replace > with >
$chopro =~ s/\&/\&/g; # replace & with &
- my $title;
-
- if(($chopro =~ /^{title:(.*)}/mi) || ($chopro =~ /^{t:(.*)}/mi)) {
+ my $title = "ChordPro Song";
+ my $artist = "Unknown";
+
+ if (($chopro =~ /^{title:(.*)}/mi) || ($chopro =~ /^{t:(.*)}/mi)) {
$title = $1;
- } else {
- $title = "ChordPro song";
- }
- print <<END;
+ } # if
+
+ if (($chopro =~ /^{subtitle:(.*)}/mi) || ($chopro =~ /^{st:(.*)}/mi)) {
+ $artist = $1;
+ } # if
+
+ print <<"END";
<html>
<head>
<title>$title</title>
-<style type="text/css">
-body {
- background-image: url('/songbook/background.jpg');
- padding-left: 100px;
-}
-h1 {
- text-align: center;
- font-family: Arial, Helvetica;
- font-size: 28pt;
- line-height: 10%;
-}
-h2 {
- text-align: center;
- font-family: Arial, Helvetica;
- font-size: 22pt;
- line-height: 50%;
-}
-.lyrics, .lyrics_chorus {
- font-size: 22pt;
-}
-.lyrics_tab, .lyrics_chorus_tab {
- font-family: "Courier New", Courier;
- font-size: 18pt;
-}
-.lyrics_chorus, .lyrics_chorus_tab, .chords_chorus, .chords_chorus_tab {
- font-weight: bold;
-}
-.chords, .chords_chorus, .chords_tab, .chords_chorus_tab {
- font-size: 18pt;
- color: blue;
- padding-right: 4pt;
-}
-.comment, .comment_italic {
- color: #999;
- font-size: 18pt;
-}
-.comment_box {
- background-color: #ffbbaa;
- text-align: center;
-}
-.comment_italic {
- font-style: italic;
-}
-.comment_box {
- border: solid;
-}
-</style>
+<link rel="stylesheet" type="text/css" href="songbook.css">
+<link rel="stylesheet" type="text/css" href="question.mark.css">
+<script src="songbook.js"></script>
+<script src="question.mark.js"></script>
</head>
+
<body>
END
- $title = musicFileExists $song;
-
+ $title = getTitle $song;
+
if ($title) {
updateMusicpath $chopro, $song;
} # if
-
+
+ my $titleLink = "<a href=\"/songbook/pro/$title.pro\">$title</a>";
print << "END";
-<table border="0" width="100%">
+<table id="heading">
<tbody>
<tr>
<td align="left"><a href="/songbook"><img src="/Icons/Home.png" alt="Home"></a></td>
-END
-
- if ($title) {
- print <<"END";
-<td align="right">
-<audio controls autoplay>
- <source src="http://defaria.com/Media/$title.mp3" type='audio/mp3'>
- <p>Your user agent does not support the HTML5 Audio element.</p>
-</audio>
-</td>
-END
- } # if
-print <<"END";
+ <td><div id="title">$titleLink</div>
+ <div id="artist"><a href="/songbook/displayartist.php?artist=$artist">$artist</a></div></td>
+ <td align="right" width="300px">
+ <audio id="song" controls autoplay style="padding:0; margin:0">
+ <source src="https://defaria.com/Media/$title.mp3" style="padding:0; margin:0" type='audio/mp3'>
+ Your user agent does not support the HTML5 Audio element.
+ </audio><br>
+ <p align="center" <font size=-1><b>Mark A:</b></font>
+ <font size=-1 color=#666><span id="a"><i>not set</i></span></font>
+ <font size=-1><b>Mark B:</b></font>
+ <font size=-1 color=#666><span id="b">not set</span></font></p>
+ </td>
</tr>
</tbody>
</table>
+<div id="song">
END
my $mode = 0; # mode defines which class to use
$_ = $1;
chomp;
- if(/^#(.*)/) { # a line starting with # is a comment
- print "<!--$1-->\n"; # insert as HTML comment
- } elsif(/{(.*)}/) { # this is a command
+ if (/^#(.*)/) { # a line starting with # is a comment
+ print "<!--$1-->\n"; # insert as HTML comment
+ } elsif (/{(.*)}/) { # this is a command
$_ = $1;
- if(/^title:/i || /^t:/i) { # title
- print "<H1>$'</H1>\n";
- } elsif(/^subtitle:/i || /^st:/i) { # subtitle
- print "<H2>$'</H2>\n";
- } elsif(/^start_of_chorus/i || /^soc/i) { # start_of_chorus
+ if (/^start_of_chorus/i || /^soc/i) { # start_of_chorus
$mode |= 1;
- } elsif(/^end_of_chorus/i || /^eoc/i) { # end_of_chorus
+ } elsif (/^end_of_chorus/i || /^eoc/i) { # end_of_chorus
$mode &= ~1;
- } elsif(/^comment:/i || /^c:/i) { # comment
+ } elsif (/^comment:/i || /^c:/i) { # comment
print "<span class=\"comment\">($')</span>\n";
- } elsif(/^comment_italic:/i || /^ci:/i) { # comment_italic
+ } elsif (/^comment_italic:/i || /^ci:/i) { # comment_italic
print "<span class=\"comment_italic\">($')</span>\n";
- } elsif(/^comment_box:/i || /^cb:/i) { # comment_box
+ } elsif (/^comment_box:/i || /^cb:/i) { # comment_box
print "<P class=\"comment_box\">$'</P>\n";
- } elsif(/^start_of_tab/i || /^sot/i) { # start_of_tab
+ } elsif (/^start_of_tab/i || /^sot/i) { # start_of_tab
$mode |= 2;
- } elsif(/^end_of_tab/i || /^eot/i) { # end_of_tab
+ } elsif (/^end_of_tab/i || /^eot/i) { # end_of_tab
$mode &= ~2;
} else {
print "<!--Unsupported command: $_-->\n";
}
push(@lyrics,$_); # rest of line (after last chord) into @lyrics
- if($lyrics[0] eq "") { # line began with a chord
+ if ($lyrics[0] eq "") { # line began with a chord
shift(@chords); # remove first item
shift(@lyrics); # (they are both empty)
}
- if(@lyrics==0) { # empty line?
+ if (@lyrics==0) { # empty line?
print "<BR>\n";
- } elsif(@lyrics==1 && $chords[0] eq "") { # line without chords
- print "<DIV class=\"$lClasses[$mode]\">$lyrics[0]</DIV>\n";
+ } elsif (@lyrics==1 && $chords[0] eq "") { # line without chords
+ print "<div class=\"$lClasses[$mode]\">$lyrics[0]</div>\n";
} else {
- print "<TABLE cellpadding=0 cellspacing=0>";
- print "<TR>\n";
- my($i);
- for($i = 0; $i < @chords; $i++) {
- print "<TD class=\"$cClasses[$mode]\">$chords[$i]</TD>";
+ print "<table cellpadding=0 cellspacing=0>";
+ print "<tr>\n";
+ for(my $i = 0; $i < @chords; $i++) {
+ print "<td class=\"$cClasses[$mode]\">$chords[$i]</td>";
}
- print "</TR>\n<TR>\n";
+ print "</tr>\n<tr>\n";
for($i = 0; $i < @lyrics; $i++) {
- print "<TD class=\"$lClasses[$mode]\">$lyrics[$i]</TD>";
+ print "<td class=\"$lClasses[$mode]\">$lyrics[$i]</td>";
}
- print "</TR></TABLE>\n";
+ print "</tr></table>\n";
} # if
} # if
} # while
+
+ print "</div>";
} # chordpro2html
## Main
print header;
unless ($infile) {
- error "No chordpro parameter";
+ error "No chordpro parameter";
} # unless
open my $file, '<', $infile
print end_html();
-exit;
-
-
+exit;
\ No newline at end of file