3 #(define-markup-command
(vspace layout props amount
) (number?
)
4 "This produces a invisible object taking vertical space."
5 (let
((amount
(* amount
3.0)))
7 (ly
:make-stencil
"" (cons -
1 1) (cons
0 amount
))
8 (ly
:make-stencil
"" (cons -
1 1) (cons amount amount
)))))
10 #(define-markup-command
(when-property layout props symbol markp
) (symbol? markup?
)
11 (if
(chain-assoc-get symbol props
)
12 (interpret-markup layout props markp
)
13 (ly
:make-stencil
'() '(1 . -
1) '(1 . -
1))))
15 #(define-markup-command
(custom-copyright layout props
) ()
16 (let
* ((maintainer
(chain-assoc-get
'header
:maintainer props
))
17 (this-year
(+
1900 (tm
:year
(gmtime
(current-time
)))))
18 (year
(string-
>number
(or
(chain-assoc-get
'header
:copyrightYear props
)
19 (number-
>string this-year
)))))
20 (interpret-markup layout props
22 (if
(= year this-year
)
23 (format
#f "~a" this-year
)
24 (format
#f "~a-~a" year this-year
))
27 #(define-markup-list-command
(paragraphe paper props text
) (markup-list?
)
28 (let
((indentation
(markup
#:pad-to-box
(cons
0 3) (cons
0 0) #:null
)))
29 (interpret-markup-list paper props
30 (make-override-lines-markup-list
'(baseline-skip
. 0)
31 (make-justified-lines-markup-list
(cons indentation text
))))))
33 #(define-markup-list-command
(columns paper props text
) (markup-list?
)
34 (interpret-markup-list paper props
35 (make-override-lines-markup-list
'(baseline-skip
. 1)
36 (make-column-lines-markup-list text
))))
38 #(define-markup-command
(boxed-justify layout props text
) (markup-list?
)
39 (interpret-markup layout props
40 (make-override-markup
'(box-padding
. 1)
43 (make-justified-lines-markup-list text
))))))
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 %% vertical space skip
49 #(define-markup-command
(vspace layout props amount
) (number?
)
50 "This produces a invisible object taking vertical space."
51 (let
((amount
(* amount
3.0)))
53 (ly
:make-stencil
"" (cons -
1 1) (cons
0 amount
))
54 (ly
:make-stencil
"" (cons -
1 1) (cons amount amount
)))))
56 #(define-markup-command
(when-property layout props symbol markp
) (symbol? markup?
)
57 (if
(chain-assoc-get symbol props
)
58 (interpret-markup layout props markp
)
59 (ly
:make-stencil
'() '(1 . -
1) '(1 . -
1))))
61 #(define-markup-command
(line-width-ratio layout props width-ratio arg
) (number? markup?
)
62 (interpret-markup layout props
63 (markup
#:override
(cons
'line-width
(* width-ratio
(chain-assoc-get
'line-width props
)))
66 %%% Guile does not deal with accented letters
67 #(use-modules
(ice-
9 regex
))
68 %%;; actually defined below, in a closure
69 #(define-public string-upper-case
#f)
70 #(define accented-char-upper-case?
#f)
71 #(define accented-char-lower-case?
#f)
73 %%;; an accented character is seen as two characters by guile
74 #(let
((lower-case-accented-string
"éèêëáà âäÃìîïóòôöúùûüçœæ")
75 (upper-case-accented-string
"ÉÈÊË�ÀÂÄ�ÌÎ�ÓÒÔÖÚÙÛÜÇŒÆ"))
76 (define
(group-by-
2 chars result
)
77 (if
(or
(null? chars
) (null?
(cdr chars
)))
79 (group-by-
2 (cddr chars
)
80 (cons
(string
(car chars
) (cadr chars
))
82 (let
((lower-case-accented-chars
83 (group-by-
2 (string-
>list lower-case-accented-string
) (list
)))
84 (upper-case-accented-chars
85 (group-by-
2 (string-
>list upper-case-accented-string
) (list
))))
86 (set
! string-upper-case
88 (define
(replace-chars str froms tos
)
91 (replace-chars
(regexp-substitute
/global
#f (car froms
) str
95 (string-upcase
(replace-chars str
96 lower-case-accented-chars
97 upper-case-accented-chars
))))
98 (set
! accented-char-upper-case?
100 (member
(string char
1 char
2) upper-case-accented-chars string
=?
)))
101 (set
! accented-char-lower-case?
102 (lambda
(char
1 char
2)
103 (member
(string char
1 char
2) lower-case-accented-chars string
=?
)))))
105 #(define-markup-command
(smallCaps layout props text
) (markup?
)
106 "Turn @code{text}, which should be a string, to small caps.
108 \\markup \\small-caps \"Text between double quotes\"
110 (define
(string-list-
>markup strings lower
)
111 (let
((final-string
(string-upper-case
112 (apply string-append
(reverse strings
)))))
114 (markup
#:fontsize -
2 final-string
)
116 (define
(make-small-caps rest-chars currents current-is-lower prev-result
)
117 (if
(null? rest-chars
)
118 (make-concat-markup
(reverse
! (cons
(string-list-
>markup
119 currents current-is-lower
)
121 (let
* ((ch
1 (car rest-chars
))
122 (ch
2 (and
(not
(null?
(cdr rest-chars
))) (cadr rest-chars
)))
123 (this-char-string
(string ch
1))
124 (is-lower
(char-lower-case? ch
1))
125 (next-rest-chars
(cdr rest-chars
)))
126 (cond
((and ch
2 (accented-char-lower-case? ch
1 ch
2))
127 (set
! this-char-string
(string ch
1 ch
2))
129 (set
! next-rest-chars
(cddr rest-chars
)))
130 ((and ch
2 (accented-char-upper-case? ch
1 ch
2))
131 (set
! this-char-string
(string ch
1 ch
2))
133 (set
! next-rest-chars
(cddr rest-chars
))))
134 (if
(or
(and current-is-lower is-lower
)
135 (and
(not current-is-lower
) (not is-lower
)))
136 (make-small-caps next-rest-chars
137 (cons this-char-string currents
)
140 (make-small-caps next-rest-chars
141 (list this-char-string
)
145 (cons
(string-list-
>markup
146 currents current-is-lower
)
148 (interpret-markup layout props
150 (make-small-caps
(string-
>list text
) (list
) #f (list
))
153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157 bookTitleMarkup
= \markup \when-property
#'header
:title
\column {
159 \fill-line
{ \fontsize #8 \italic \fromproperty #'header
:composer
}
161 \fill-line
{ \fontsize #8 \italic \fromproperty #'header
:poet
}
163 \fill-line
{ \fontsize #10 \fromproperty #'header
:title
}
165 \fill-line
{ \postscript #"-20 0 moveto 40 0 rlineto stroke" }
167 \fill-line
{ \fontsize #5 \fromproperty #'header
:date
}
170 \when-property
#'header
:arrangement
\column {
172 \fill-line
{ \fontsize #3 \fromproperty #'header
:arrangement
}
176 scoreTitleMarkup
= \markup \null
179 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180 %%% Table of contents
182 #(define-markup-command
(paper-prop layout props name default
)
184 "Get the value of a \\paper property, or defaults to some value"
185 (let
((val
(ly
:output-def-lookup layout name
)))
186 (interpret-markup layout props
(if
(markup? val
)
190 tocTitleMarkup
= \markup \column {
192 \fontsize #6 \fill-line
{ \paper-prop
#'tocTitle
"TABLE OF CONTENTS" }
195 tocPieceMarkup
= \markup \fill-line
{
196 \line-width-ratio
#0.7 \fill-line
{
197 \line { \fromproperty #'toc
:text
}
198 \fromproperty #'toc
:page
201 tocSectionMarkup
= \markup \italic \column {
202 \fill-line
{ \fromproperty #'toc
:text
}
204 tocChapterMarkup
= \markup \large \italic \column {
206 \fontsize #2 \fill-line
{ \fromproperty #'toc
:text
}
211 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
212 %%% Markup commands for page headers
214 #(define-public add-odd-page-header-text
#f)
215 #(define-public add-even-page-header-text
#f)
216 #(define header-markup-aux
#f)
217 #(let
((odd-label-header-table
(list
))
218 (odd-page-header-table
(list
))
219 (even-label-header-table
(list
))
220 (even-page-header-table
(list
)))
221 (set
! header-markup-aux
222 (lambda
(layout props odd
)
223 (define
(page-text page-number table
)
226 (let
* ((elment
(car table
))
229 (display-
1st
(caddr elment
)))
230 (cond
((and
(= page-number p
) (not display-
1st
)) #f)
231 ((>= page-number p
) text
)
232 (else
(page-text page-number
(cdr table
)))))))
234 `
(delay-stencil-evaluation
235 ,(delay
(ly
:stencil-expr
237 (if
(or
(and odd
(null? odd-page-header-table
))
238 (and
(not odd
) (null? even-page-header-table
)))
239 (let
((page-header-table
(list
)))
240 (for-each
(lambda
(label-header
)
241 (let
* ((label
(car label-header
))
242 (text-disp
(cdr label-header
))
243 (table
(ly
:output-def-lookup layout
'label-page-table
))
244 (label-page
(and
(list? table
) (assoc label table
)))
245 (page-number
(and label-page
(cdr label-page
)))
246 (prev-value
(and page-number
(assoc page-number page-header-table
))))
248 (set
! page-header-table
(cons
(cons page-number text-disp
)
250 (set
! page-header-table
251 (assoc-set
! page-header-table
253 (list
(car text-disp
) (caddr prev-value
)))))))
254 (reverse
(if odd odd-label-header-table even-label-header-table
)))
256 (set
! odd-page-header-table page-header-table
)
257 (set
! even-page-header-table page-header-table
))))
258 (interpret-markup layout props
259 (let
* ((page-number
(chain-assoc-get
'page
:page-number props -
1))
260 (text
(page-text page-number
(if odd odd-page-header-table even-page-header-table
)))
261 (text-markup
(markup
#:italic
(or text
"")))
262 (page-number-markup
(number-
>string page-number
)))
263 (cond
((or
(= 1 page-number
) (not text
)) (markup
#:null
))
264 (odd
(markup
#:fill-line
(#:null text-markup page-number-markup
)))
265 (else
(markup
#:fill-line
(page-number-markup text-markup
#:null
))))))))))
267 (ly
:stencil-extent
(interpret-markup layout props
"XXX") Y
))))
268 (set
! add-odd-page-header-text
269 (lambda
(parser text display-
1st
)
270 (let
((label
(gensym
"header")))
271 (set
! odd-label-header-table
272 (cons
(list label text display-
1st
)
273 odd-label-header-table
))
274 (collect-music-for-book parser
277 'page-label label
)))))
278 (set
! add-even-page-header-text
279 (lambda
(parser text display-
1st
)
280 (let
((label
(gensym
"header")))
281 (set
! even-label-header-table
282 (cons
(list label text display-
1st
)
283 even-label-header-table
))
284 (collect-music-for-book parser
287 'page-label label
))))))
289 #(define-markup-command
(odd-header layout props
) ()
290 (header-markup-aux layout props
#t
))
292 #(define-markup-command
(even-header layout props
) ()
293 (header-markup-aux layout props
#f))
296 evenHeaderMarkup
= \markup \even-header
297 oddHeaderMarkup
= \markup \odd-header
300 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
301 %%% Utilities for adding (no-)page breaks, toplevel markups
303 #(define
(add-page-break parser
)
304 (collect-music-for-book parser
307 'line-break-permission
'force
308 'page-break-permission
'force
)))
310 #(define
(add-no-page-break parser
)
311 (collect-music-for-book parser
314 'page-break-permission
'forbid
)))
316 #(define
(add-toplevel-markup parser text
)
317 (collect-scores-for-book parser
(list text
)))
319 #(define
(add-toc-item parser markup-symbol text
)
320 (collect-music-for-book parser
321 (add-toc-item
! markup-symbol text
)))
323 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
324 %%% Rehearsal numbers
326 #(define-public rehearsal-number
#f)
327 #(define-public increase-rehearsal-major-number
#f)
328 #(let
((major-number
0)
330 (set
! increase-rehearsal-major-number
332 (set
! major-number
(1+ major-number
))
333 (set
! minor-number
0)))
334 (set
! rehearsal-number
336 (set
! minor-number
(1+ minor-number
))
337 (format
#f "~a-~a" major-number minor-number
))))
339 #(define-public
(add-rehearsal-number parser
)
340 (collect-scores-for-book parser
341 (list
(markup
#:huge
#:bold
(rehearsal-number
)))))
343 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
347 #(use-modules
(srfi srfi-
39))
348 #(define
*book-title
* (make-parameter
""))
349 #(define
*use-rehearsal-numbers
* (make-parameter
#f))
351 useRehearsalNumbers
=
352 #(define-music-function
(parser location use-numbers
) (boolean?
)
353 (*use-rehearsal-numbers
* use-numbers
)
354 (make-music
'Music
'void
#t
))
357 #(define-music-function
(parser location title
) (string?
)
359 (make-music
'Music
'void
#t
))
362 #(define-music-function
(parser location title
) (string?
)
363 (increase-rehearsal-major-number
)
364 (add-page-break parser
)
365 (add-toc-item parser
'tocChapterMarkup title
)
366 (add-even-page-header-text parser
(string-upper-case
(*book-title
*)) #f)
367 (add-odd-page-header-text parser
(string-upper-case title
) #f)
368 (add-toplevel-markup parser
(markup
#:chapter-title
(string-upper-case title
)))
369 (add-no-page-break parser
)
370 (make-music
'Music
'void
#t
))
373 #(define-music-function
(parser location title
) (string?
)
374 (add-toc-item parser
'tocSectionMarkup title
)
375 (add-toplevel-markup parser
(markup
#:section-title
(string-upper-case title
)))
376 (add-no-page-break parser
)
377 (make-music
'Music
'void
#t
))
380 #(define-music-function
(parser location title
) (markup?
)
381 (add-toc-item parser
'tocPieceMarkup title
)
382 (add-no-page-break parser
)
383 (if
(*use-rehearsal-numbers
*)
384 (add-toplevel-markup parser
(markup
#:rehearsal-number
(rehearsal-number
))))
385 (add-no-page-break parser
)
386 (make-music
'Music
'void
#t
))
389 #(define-music-function
(parser location title
) (markup?
)
390 (add-toc-item parser
'tocPieceMarkup title
)
391 (if
(*use-rehearsal-numbers
*)
392 (add-toplevel-markup parser
393 (markup
#:piece-title-with-number
(rehearsal-number
) (string-upper-case title
)))
394 (add-toplevel-markup parser
(markup
#:piece-title
(string-upper-case title
))))
395 (add-no-page-break parser
)
396 (make-music
'Music
'void
#t
))
398 #(define-markup-command
(chapter-title layout props title
) (markup?
)
399 (interpret-markup layout props
400 (markup
#:column
(#:vspace
3
401 #:pad-markup
3 #:fill-line
(#:fontsize
5 title
)))))
403 #(define-markup-command
(section-title layout props title
) (markup?
)
404 (interpret-markup layout props
405 (markup
#:column
(#:vspace
1
406 #:fill-line
(#:fontsize
3 title
)
409 #(define-markup-command
(piece-title layout props title
) (markup?
)
410 (interpret-markup layout props
411 (markup
#:fill-line
(#:override
'(line-width
. 80) title
))))
413 #(define-markup-command
(rehearsal-number layout props number
) (markup?
)
414 (interpret-markup layout props
415 (markup
#:huge
#:bold number
)))
417 #(define-markup-command
(piece-title-with-number layout props number title
)
419 (interpret-markup layout props
420 (markup
#:rehearsal-number number