summaryrefslogtreecommitdiff
path: root/Build/source/texk/gregorio/gregorio-src/contrib/gprocess
blob: 205acd7540e4cbffd41950e5ee2d14050084a2d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/perl

# gprocess
# a script for 'compiling' gregorio gabc music files
# v0.2
# Copyright (c) 2010 Richard Chonak <chonak@yahoo.com>
# Changes in v0.2:
# -- change list of PDF viewers
# -- invoke LuaLateX instead of lamed/dvipdfm
# -- drop use of pdftk (it's not available for my system)
# -- use latin1 character set instead of utf8
# -- update macro and variable names (with "gre" prefix) as needed
# -- add 'redlines'
# --
#
# v0.1
# Copyright (C) 2008-2019 Richard Chonak <chonak@yahoo.com>
#

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


use strict;

## USER-MODIFIABLE COMMAND PATHS

my $TEXCOMPILER = "lualatex --shell-escape";

## END OF USER-MODIFIABLE COMMAND PATHS


# print usage string if no command-line arg specified

if ($#ARGV < 0) {
  die "usage: $0 <gabc-file-name>\n";
}


my $GABCFILE = $ARGV[0];
my $GABCNAME = $GABCFILE;
$GABCNAME =~ s/.gabc//;
my $SCORENAME;
my $ANNOTATION;
my $REFERENCE;
my $OFFICEPART;
my $NAMEFOUND = 0;
my $KEEPSEARCHING = 1;
my $INLINE = "";


my $SCOREWRAPTEX = $GABCFILE;
$SCOREWRAPTEX =~ s/.gabc$/-main.tex/;

####  GET THE SCORE TITLE FROM THE GABC FILE ####

if ($GABCFILE =~ m#/#) {
   die "File spec must not contain slashes: $GABCFILE\n";
};


open (GABC,"<".$GABCFILE) or die "No such file: $GABCFILE\n";
while ($KEEPSEARCHING == 1 && ($INLINE = <GABC>)) {
  if ($INLINE =~ /^name/) {
    $SCORENAME = $INLINE;
    $SCORENAME =~ s/^.*:\s*//;
    $SCORENAME =~ s/\s*;\s*$//;
  };
  if ($INLINE =~ /^anotation/) {
    $ANNOTATION = $INLINE;
    $ANNOTATION =~ s/^.*:\s*//;
    $ANNOTATION =~ s/\s*;\s*$//;
  };
  if ($INLINE =~ /^reference/) {
    $REFERENCE = $INLINE;
    $REFERENCE =~ s/^.*:\s*//;
    $REFERENCE =~ s/\s*;\s*$//;
  };
  if ($INLINE =~ /^office-part/) {
    $OFFICEPART = $INLINE;
    $OFFICEPART =~ s/^.*:\s*//;
    $OFFICEPART =~ s/\s*;\s*$//;
  };
  if ($INLINE =~ /^%%/) { $KEEPSEARCHING = 0; }
}

close (GABC);



####  READ IN THE TEMPLATE  ####

my @TEMPLATELINES;


@TEMPLATELINES = <DATA>;



####  MAKE SUBSTITUTIONS ####

&do_subst ("XXXX-SCORENAME-XXXX", $SCORENAME);
&do_subst ("XXXX-GABCFILE-XXXX", $GABCNAME);
&do_subst ("XXXX-ANNOTATION-XXXX", $ANNOTATION);
&do_subst ("XXXX-OFFICEPART-XXXX", $OFFICEPART);
&do_subst ("XXXX-REFERENCE-XXXX", $REFERENCE);

foreach (@TEMPLATELINES){
  s/^.*XXXX.*$//;
};

####  WRITE TEX WRAPPER FILE ####

open (TEXWRAP,">".$SCOREWRAPTEX) or die "Cannot write file $SCOREWRAPTEX\n";
print TEXWRAP @TEMPLATELINES;
close (TEXWRAP);

#### RUN LATEX ####
my $PDFFILE = $SCOREWRAPTEX;
$PDFFILE =~ s/tex$/pdf/;
my $AUXFILE = $SCOREWRAPTEX;
$AUXFILE =~ s/tex$/aux/;
my $GAUXFILE = $SCOREWRAPTEX;
$GAUXFILE =~ s/tex$/gaux/;

# remove product files so that we don't accidentally view results
# from a prior run
unlink $PDFFILE;

do_cmd("$TEXCOMPILER $SCOREWRAPTEX");
# Run twice to calculate line heights.
do_cmd("$TEXCOMPILER $SCOREWRAPTEX");
unlink $AUXFILE;
unlink $GAUXFILE;

print "\n\nOutput is in $PDFFILE .\n";

exit;

sub do_subst {
  my $TAG = $_[0];
  my $VAL = $_[1];

  foreach (@TEMPLATELINES) {
     s/$TAG/$VAL/g;
  }
};

sub do_cmd {
	my $CMD = $_[0];
#debugging	print "Doing command: \n  $CMD\n\n";
	system ($CMD) == 0
	   or die "\n\nSystem command failed: $CMD : $?\n";
};


#  THE LINES AFTER THIS "END" TAG ARE A TEMPLATE FOR THE TEX FILE TO BE GENERATED
__END__

\documentclass[12pt, letterpaper]{article}
\usepackage{fullpage}
\usepackage[T1]{fontenc}
\usepackage{palatino}
\usepackage[autocompile,allowdeprecated=false]{gregoriotex}
\pagestyle{empty}
\begin{document}

\begin{center}\begin{huge}\textsc{XXXX-SCORENAME-XXXX}\end{huge}\end{center}

\gregorioscore{XXXX-GABCFILE-XXXX}

\end{document}