| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# gprocess |
| 4 |
# a script for 'compiling' gregorio gabc music files |
| 5 |
# v0.2 |
| 6 |
# Copyright (c) 2010 Richard Chonak <[email protected]> |
| 7 |
# Changes in v0.2: |
| 8 |
# -- change list of PDF viewers |
| 9 |
# -- invoke LuaLateX instead of lamed/dvipdfm |
| 10 |
# -- drop use of pdftk (it's not available for my system) |
| 11 |
# -- use latin1 character set instead of utf8 |
| 12 |
# -- update macro and variable names (with "gre" prefix) as needed |
| 13 |
# -- add 'redlines' |
| 14 |
# -- |
| 15 |
# |
| 16 |
# v0.1 |
| 17 |
# Copyright (C) 2008-2025 Richard Chonak <[email protected]> |
| 18 |
# |
| 19 |
|
| 20 |
# This program is free software: you can redistribute it and/or modify |
| 21 |
# it under the terms of the GNU General Public License as published by |
| 22 |
# the Free Software Foundation, either version 3 of the License, or |
| 23 |
# (at your option) any later version. |
| 24 |
# |
| 25 |
# This program is distributed in the hope that it will be useful, |
| 26 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 27 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 28 |
# GNU General Public License for more details. |
| 29 |
# |
| 30 |
# You should have received a copy of the GNU General Public License |
| 31 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 32 |
|
| 33 |
|
| 34 |
use strict; |
| 35 |
|
| 36 |
## USER-MODIFIABLE COMMAND PATHS |
| 37 |
|
| 38 |
my $TEXCOMPILER = "lualatex --shell-escape"; |
| 39 |
|
| 40 |
## END OF USER-MODIFIABLE COMMAND PATHS |
| 41 |
|
| 42 |
|
| 43 |
# print usage string if no command-line arg specified |
| 44 |
|
| 45 |
if ($#ARGV < 0) { |
| 46 |
die "usage: $0 <gabc-file-name>\n"; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
my $GABCFILE = $ARGV[0]; |
| 51 |
my $GABCNAME = $GABCFILE; |
| 52 |
$GABCNAME =~ s/.gabc//; |
| 53 |
my $SCORENAME; |
| 54 |
my $ANNOTATION; |
| 55 |
my $REFERENCE; |
| 56 |
my $OFFICEPART; |
| 57 |
my $NAMEFOUND = 0; |
| 58 |
my $KEEPSEARCHING = 1; |
| 59 |
my $INLINE = ""; |
| 60 |
|
| 61 |
|
| 62 |
my $SCOREWRAPTEX = $GABCFILE; |
| 63 |
$SCOREWRAPTEX =~ s/.gabc$/-main.tex/; |
| 64 |
|
| 65 |
#### GET THE SCORE TITLE FROM THE GABC FILE #### |
| 66 |
|
| 67 |
if ($GABCFILE =~ m#/#) { |
| 68 |
die "File spec must not contain slashes: $GABCFILE\n"; |
| 69 |
}; |
| 70 |
|
| 71 |
|
| 72 |
open (GABC,"<".$GABCFILE) or die "No such file: $GABCFILE\n"; |
| 73 |
while ($KEEPSEARCHING == 1 && ($INLINE = <GABC>)) { |
| 74 |
if ($INLINE =~ /^name/) { |
| 75 |
$SCORENAME = $INLINE; |
| 76 |
$SCORENAME =~ s/^.*:\s*//; |
| 77 |
$SCORENAME =~ s/\s*;\s*$//; |
| 78 |
}; |
| 79 |
if ($INLINE =~ /^anotation/) { |
| 80 |
$ANNOTATION = $INLINE; |
| 81 |
$ANNOTATION =~ s/^.*:\s*//; |
| 82 |
$ANNOTATION =~ s/\s*;\s*$//; |
| 83 |
}; |
| 84 |
if ($INLINE =~ /^reference/) { |
| 85 |
$REFERENCE = $INLINE; |
| 86 |
$REFERENCE =~ s/^.*:\s*//; |
| 87 |
$REFERENCE =~ s/\s*;\s*$//; |
| 88 |
}; |
| 89 |
if ($INLINE =~ /^office-part/) { |
| 90 |
$OFFICEPART = $INLINE; |
| 91 |
$OFFICEPART =~ s/^.*:\s*//; |
| 92 |
$OFFICEPART =~ s/\s*;\s*$//; |
| 93 |
}; |
| 94 |
if ($INLINE =~ /^%%/) { $KEEPSEARCHING = 0; } |
| 95 |
} |
| 96 |
|
| 97 |
close (GABC); |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
#### READ IN THE TEMPLATE #### |
| 102 |
|
| 103 |
my @TEMPLATELINES; |
| 104 |
|
| 105 |
|
| 106 |
@TEMPLATELINES = <DATA>; |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
#### MAKE SUBSTITUTIONS #### |
| 111 |
|
| 112 |
&do_subst ("XXXX-SCORENAME-XXXX", $SCORENAME); |
| 113 |
&do_subst ("XXXX-GABCFILE-XXXX", $GABCNAME); |
| 114 |
&do_subst ("XXXX-ANNOTATION-XXXX", $ANNOTATION); |
| 115 |
&do_subst ("XXXX-OFFICEPART-XXXX", $OFFICEPART); |
| 116 |
&do_subst ("XXXX-REFERENCE-XXXX", $REFERENCE); |
| 117 |
|
| 118 |
foreach (@TEMPLATELINES){ |
| 119 |
s/^.*XXXX.*$//; |
| 120 |
}; |
| 121 |
|
| 122 |
#### WRITE TEX WRAPPER FILE #### |
| 123 |
|
| 124 |
open (TEXWRAP,">".$SCOREWRAPTEX) or die "Cannot write file $SCOREWRAPTEX\n"; |
| 125 |
print TEXWRAP @TEMPLATELINES; |
| 126 |
close (TEXWRAP); |
| 127 |
|
| 128 |
#### RUN LATEX #### |
| 129 |
my $PDFFILE = $SCOREWRAPTEX; |
| 130 |
$PDFFILE =~ s/tex$/pdf/; |
| 131 |
my $AUXFILE = $SCOREWRAPTEX; |
| 132 |
$AUXFILE =~ s/tex$/aux/; |
| 133 |
my $GAUXFILE = $SCOREWRAPTEX; |
| 134 |
$GAUXFILE =~ s/tex$/gaux/; |
| 135 |
|
| 136 |
# remove product files so that we don't accidentally view results |
| 137 |
# from a prior run |
| 138 |
unlink $PDFFILE; |
| 139 |
|
| 140 |
do_cmd("$TEXCOMPILER $SCOREWRAPTEX"); |
| 141 |
# Run twice to calculate line heights. |
| 142 |
do_cmd("$TEXCOMPILER $SCOREWRAPTEX"); |
| 143 |
unlink $AUXFILE; |
| 144 |
unlink $GAUXFILE; |
| 145 |
|
| 146 |
print "\n\nOutput is in $PDFFILE .\n"; |
| 147 |
|
| 148 |
exit; |
| 149 |
|
| 150 |
sub do_subst { |
| 151 |
my $TAG = $_[0]; |
| 152 |
my $VAL = $_[1]; |
| 153 |
|
| 154 |
foreach (@TEMPLATELINES) { |
| 155 |
s/$TAG/$VAL/g; |
| 156 |
} |
| 157 |
}; |
| 158 |
|
| 159 |
sub do_cmd { |
| 160 |
my $CMD = $_[0]; |
| 161 |
#debugging print "Doing command: \n $CMD\n\n"; |
| 162 |
system ($CMD) == 0 |
| 163 |
or die "\n\nSystem command failed: $CMD : $?\n"; |
| 164 |
}; |
| 165 |
|
| 166 |
|
| 167 |
# THE LINES AFTER THIS "END" TAG ARE A TEMPLATE FOR THE TEX FILE TO BE GENERATED |
| 168 |
__END__ |
| 169 |
|
| 170 |
\documentclass[12pt, letterpaper]{article} |
| 171 |
\usepackage{fullpage} |
| 172 |
\usepackage[T1]{fontenc} |
| 173 |
\usepackage{palatino} |
| 174 |
\usepackage[autocompile,allowdeprecated=false]{gregoriotex} |
| 175 |
\pagestyle{empty} |
| 176 |
\begin{document} |
| 177 |
|
| 178 |
\begin{center}\begin{huge}\textsc{XXXX-SCORENAME-XXXX}\end{huge}\end{center} |
| 179 |
|
| 180 |
\gregorioscore{XXXX-GABCFILE-XXXX} |
| 181 |
|
| 182 |
\end{document} |
| 183 |
|