1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 1998--2012 Jan Nieuwenhuizen <janneke@gnu.org>
4 ;;;; Han-Wen Nienhuys <hanwen@xs4all.nl>
6 ;;;; LilyPond is free software: you can redistribute it and/or modify
7 ;;;; it under the terms of the GNU General Public License as published by
8 ;;;; the Free Software Foundation, either version 3 of the License, or
9 ;;;; (at your option) any later version.
11 ;;;; LilyPond is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;;; GNU General Public License for more details.
16 ;;;; You should have received a copy of the GNU General Public License
17 ;;;; along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
23 (define-public (grob::has-interface grob iface)
24 (memq iface (ly:grob-interfaces grob)))
26 (define-public (grob::is-live? grob)
27 (pair? (ly:grob-basic-properties grob)))
29 (define-public (grob::x-parent-width grob)
30 (ly:grob-property (ly:grob-parent grob X) 'X-extent))
32 (define-public (make-stencil-boxer thickness padding callback)
33 "Return function that adds a box around the grob passed as argument."
35 (box-stencil (callback grob) thickness padding)))
37 (define-public (make-stencil-circler thickness padding callback)
38 "Return function that adds a circle around the grob passed as argument."
40 (circle-stencil (callback grob) thickness padding)))
42 (define-public (print-circled-text-callback grob)
43 (grob-interpret-markup grob (make-circle-markup
44 (ly:grob-property grob 'text))))
46 (define-public (event-cause grob)
47 (let ((cause (ly:grob-property grob 'cause)))
50 ((ly:stream-event? cause) cause)
51 ((ly:grob? cause) (event-cause cause))
54 (define-public (grob-interpret-markup grob text)
55 (let* ((layout (ly:grob-layout grob))
56 (defs (ly:output-def-lookup layout 'text-font-defaults))
57 (props (ly:grob-alist-chain grob defs)))
59 (ly:text-interface::interpret-markup layout props text)))
61 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
64 ;; even though kievan noteheads do not have stems, their
65 ;; invisible stems help with beam placement
66 ;; this assures that invisible stems for kievan notes are aligned
67 ;; to the center of kievan noteheads. that is thus where the beams'
68 ;; x extrema will fall
69 (define-public (stem::kievan-offset-callback grob)
70 (let* ((note-heads (ly:grob-object grob 'note-heads))
71 (note-heads-grobs (if (not (null? note-heads))
72 (ly:grob-array->list note-heads)
74 (first-note-head (if (not (null? note-heads-grobs))
75 (car note-heads-grobs)
77 (note-head-w (if (not (null? first-note-head))
78 (ly:grob-extent first-note-head first-note-head X)
80 (interval-center note-head-w)))
83 ;; sets position of beams for Kievan notation
84 (define-public (beam::get-kievan-positions grob)
85 (let* ((stems (ly:grob-object grob 'stems))
86 (stems-grobs (if (not (null? stems))
87 (ly:grob-array->list stems)
89 (first-stem (if (not (null? stems-grobs))
92 (note-heads (if (not (null? first-stem))
93 (ly:grob-object first-stem 'note-heads)
95 (note-heads-grobs (if (not (null? note-heads))
96 (ly:grob-array->list note-heads)
98 (first-note-head (if (not (null? note-heads-grobs))
99 (car note-heads-grobs)
101 (next-stem (if (not (null? stems))
104 (next-note-heads (if (not (null? next-stem))
105 (ly:grob-object next-stem 'note-heads)
107 (next-note-heads-grobs (if (not (null? next-note-heads))
108 (ly:grob-array->list next-note-heads)
110 (next-note-head (if (not (null? next-note-heads-grobs))
111 (car next-note-heads-grobs)
113 (left-pos (ly:grob-property first-note-head 'Y-offset))
114 (right-pos (ly:grob-property next-note-head 'Y-offset))
115 (direction (ly:grob-property grob 'direction))
116 (first-nh-height (ly:grob::stencil-height first-note-head))
117 (next-nh-height (ly:grob::stencil-height next-note-head))
118 (left-height (if (= direction DOWN)
119 (+ (car first-nh-height) 0.75)
120 (- (cdr first-nh-height) 0.75)))
121 (right-height (if (= direction DOWN)
122 (+ (car next-nh-height) 0.75)
123 (- (cdr next-nh-height) 0.75))))
124 (cons (+ left-pos left-height) (+ right-pos right-height))))
126 (define-public (beam::get-kievan-quantized-positions grob)
127 (let* ((pos (ly:grob-property grob 'positions))
128 (stems (ly:grob-object grob 'stems))
129 (stems-grobs (if (not (null? stems))
130 (ly:grob-array->list stems)
134 (ly:grob-set-property! g 'stem-begin-position 0)
135 (ly:grob-set-property! g 'length 0))
139 ;; calculates each slope of a broken beam individually
140 (define-public (beam::place-broken-parts-individually grob)
141 (ly:beam::quanting grob '(+inf.0 . -inf.0) #f))
143 ;; calculates the slope of a beam as a single unit,
144 ;; even if it is broken. this assures that the beam
145 ;; will pick up where it left off after a line break
146 (define-public (beam::align-with-broken-parts grob)
147 (ly:beam::quanting grob '(+inf.0 . -inf.0) #t))
149 ;; uses the broken beam style from edition peters combines the
150 ;; values of place-broken-parts-individually and align-with-broken-parts above,
151 ;; favoring place-broken-parts-individually when the beam naturally has a steeper
152 ;; incline and align-with-broken-parts when the beam is flat
153 (define-public (beam::slope-like-broken-parts grob)
155 (/ (- (cdr y) (car y)) (- (cdr x) (car x))))
156 (let* ((quant1 (ly:beam::quanting grob '(+inf.0 . -inf.0) #t))
157 (original (ly:grob-original grob))
158 (siblings (if (ly:grob? original)
159 (ly:spanner-broken-into original)
163 (let* ((quant2 (ly:beam::quanting grob '(+inf.0 . -inf.0) #f))
164 (x-span (ly:grob-property grob 'X-positions))
165 (slope1 (slope quant1 x-span))
166 (slope2 (slope quant2 x-span))
167 (quant2 (if (not (= (sign slope1) (sign slope2)))
170 (factor (/ (atan (abs slope1)) PI-OVER-TWO))
173 (+ (* (x quant1) (- 1 factor))
174 (* (x quant2) factor)))
176 (ly:beam::quanting grob base #f)))))
178 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
181 (define-public (script-or-side-position-cross-staff g)
183 (ly:script-interface::calc-cross-staff g)
184 (ly:side-position-interface::calc-cross-staff g)))
187 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
190 (define-public (stem::calc-duration-log grob)
192 (ly:event-property (event-cause grob) 'duration)))
194 (define (stem-stub::do-calculations grob)
195 (and (ly:grob-property (ly:grob-parent grob X) 'cross-staff)
196 (not (ly:grob-property (ly:grob-parent grob X) 'transparent))))
198 (define-public (stem-stub::pure-height grob beg end)
199 (if (stem-stub::do-calculations grob)
203 (define-public (stem-stub::width grob)
204 (if (stem-stub::do-calculations grob)
205 (grob::x-parent-width grob)
208 (define-public (stem-stub::extra-spacing-height grob)
209 (if (stem-stub::do-calculations grob)
210 (let* ((dad (ly:grob-parent grob X))
211 (refp (ly:grob-common-refpoint grob dad Y))
212 (stem_ph (ly:grob-pure-height dad refp 0 1000000))
213 (my_ph (ly:grob-pure-height grob refp 0 1000000))
214 ;; only account for distance if stem is on different staff than stub
215 (dist (if (grob::has-interface refp 'hara-kiri-group-spanner-interface)
217 (- (car my_ph) (car stem_ph)))))
218 (if (interval-empty? (interval-intersection stem_ph my_ph)) #f (coord-translate stem_ph dist)))
221 (define-public (note-head::calc-kievan-duration-log grob)
224 (ly:event-property (event-cause grob) 'duration))))
226 (define-public (note-head::calc-duration-log grob)
229 (ly:event-property (event-cause grob) 'duration))))
231 (define-public (dots::calc-dot-count grob)
232 (ly:duration-dot-count
233 (ly:event-property (event-cause grob) 'duration)))
235 (define-public (dots::calc-staff-position grob)
236 (let* ((head (ly:grob-parent grob Y))
237 (log (ly:grob-property head 'duration-log)))
240 ((or (not (grob::has-interface head 'rest-interface))
241 (not (integer? log))) 0)
249 ;; Kept separate from note-head::calc-glyph-name to allow use by
250 ;; markup commands \note and \note-by-number
251 (define-public (select-head-glyph style log)
252 "Select a note head glyph string based on note head style @var{style}
253 and duration-log @var{log}."
255 ;; "default" style is directly handled in note-head.cc as a
256 ;; special case (HW says, mainly for performance reasons).
257 ;; Therefore, style "default" does not appear in this case
259 ((xcircle) "2xcircle")
260 ((harmonic) "0harmonic")
261 ((harmonic-black) "2harmonic")
262 ((harmonic-mixed) (if (<= log 1) "0harmonic"
265 ;; Oops, I actually would not call this "baroque", but, for
266 ;; backwards compatibility to 1.4, this is supposed to take
267 ;; brevis, longa and maxima from the neo-mensural font and all
268 ;; other note heads from the default font. -- jr
270 (string-append (number->string log) "neomensural")
271 (number->string log)))
273 ;; Like default, but brevis is drawn with double vertical lines
275 (string-append (number->string log) "double")
276 (number->string log)))
278 (string-append (number->string log) (symbol->string style)))
281 (string-append (number->string log) "mensural")
282 (string-append (number->string log) (symbol->string style))))
285 (string-append (number->string log) "blackmensural")
286 (string-append (number->string log) (symbol->string style))))
289 (string-append (number->string log) "semimensural")
290 (string-append (number->string log) "petrucci")))
292 (string-append (number->string log) (symbol->string style)))
294 (string-append (number->string log) "kievan"))
296 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
297 (symbol->string style)
298 (string-append (number->string (max 0 log))
299 (symbol->string style))))))
301 (define-public (note-head::calc-glyph-name grob)
302 (let* ((style (ly:grob-property grob 'style))
303 (log (if (string-match "kievan*" (symbol->string style))
304 (min 3 (ly:grob-property grob 'duration-log))
305 (min 2 (ly:grob-property grob 'duration-log)))))
306 (select-head-glyph style log)))
308 (define-public (note-head::brew-ez-stencil grob)
309 (let* ((log (ly:grob-property grob 'duration-log))
310 (pitch (ly:event-property (event-cause grob) 'pitch))
311 (pitch-index (ly:pitch-notename pitch))
312 (note-names (ly:grob-property grob 'note-names))
313 (pitch-string (if (and (vector? note-names)
314 (> (vector-length note-names) pitch-index))
315 (vector-ref note-names pitch-index)
318 (+ (modulo (+ pitch-index 2) 7)
319 (char->integer #\A))))))
320 (staff-space (ly:staff-symbol-staff-space grob))
321 (line-thickness (ly:staff-symbol-line-thickness grob))
322 (stem (ly:grob-object grob 'stem))
323 (stem-thickness (* (if (ly:grob? stem)
324 (ly:grob-property stem 'thickness)
327 (radius (/ (+ staff-space line-thickness) 2))
328 (letter (markup #:center-align #:vcenter pitch-string))
329 (filled-circle (markup #:draw-circle radius 0 #t)))
331 (ly:stencil-translate-axis
332 (grob-interpret-markup
337 (make-with-color-markup white letter))
341 (make-with-color-markup white (make-draw-circle-markup
342 (- radius stem-thickness) 0 #t)))
346 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
349 (define-public (make-rhythmic-location bar-num num den)
351 bar-num (ly:make-moment num den)))
353 (define-public (rhythmic-location? a)
356 (ly:moment? (cdr a))))
358 (define-public (make-graceless-rhythmic-location loc)
359 (make-rhythmic-location
361 (ly:moment-main-numerator (rhythmic-location-measure-position loc))
362 (ly:moment-main-denominator (rhythmic-location-measure-position loc))))
364 (define-public rhythmic-location-measure-position cdr)
365 (define-public rhythmic-location-bar-number car)
367 (define-public (rhythmic-location<? a b)
369 ((< (car a) (car b)) #t)
370 ((> (car a) (car b)) #f)
372 (ly:moment<? (cdr a) (cdr b)))))
374 (define-public (rhythmic-location<=? a b)
375 (not (rhythmic-location<? b a)))
376 (define-public (rhythmic-location>=? a b)
377 (not (rhythmic-location<? a b)))
378 (define-public (rhythmic-location>? a b)
379 (rhythmic-location<? b a))
381 (define-public (rhythmic-location=? a b)
382 (and (rhythmic-location<=? a b)
383 (rhythmic-location<=? b a)))
385 (define-public (rhythmic-location->file-string a)
386 (ly:format "~a.~a.~a"
388 (ly:moment-main-numerator (cdr a))
389 (ly:moment-main-denominator (cdr a))))
391 (define-public (rhythmic-location->string a)
392 (ly:format "bar ~a ~a"
394 (ly:moment->string (cdr a))))
396 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
399 (define-public all-visible #(#t #t #t))
400 (define-public begin-of-line-invisible #(#t #t #f))
401 (define-public center-invisible #(#t #f #t))
402 (define-public end-of-line-invisible #(#f #t #t))
403 (define-public begin-of-line-visible #(#f #f #t))
404 (define-public center-visible #(#f #t #f))
405 (define-public end-of-line-visible #(#t #f #f))
406 (define-public all-invisible #(#f #f #f))
407 (define-public (inherit-x-parent-visibility grob)
408 (let ((parent (ly:grob-parent grob X)))
409 (ly:grob-property parent 'break-visibility all-invisible)))
410 (define-public (inherit-y-parent-visibility grob)
411 (let ((parent (ly:grob-parent grob X)))
412 (ly:grob-property parent 'break-visibility)))
415 (define-public spanbar-begin-of-line-invisible #(#t #f #f))
418 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
419 ;; neighbor-interface routines
422 (define-public (shift-right-at-line-begin g)
423 "Shift an item to the right, but only at the start of the line."
424 (if (and (ly:item? g)
425 (equal? (ly:item-break-dir g) RIGHT))
426 (ly:grob-translate-axis! g 3.5 X)))
428 (define-public (pure-from-neighbor-interface::extra-spacing-height-at-beginning-of-line grob)
429 (if (= 1 (ly:item-break-dir grob))
430 (pure-from-neighbor-interface::extra-spacing-height grob)
433 (define-public (pure-from-neighbor-interface::extra-spacing-height grob)
434 (let* ((height (ly:grob-pure-height grob grob 0 10000000))
435 (from-neighbors (interval-union
437 (ly:axis-group-interface::pure-height
441 (coord-operation - from-neighbors height)))
443 (define-public (pure-from-neighbor-interface::account-for-span-bar grob)
444 (let* ((esh (pure-from-neighbor-interface::extra-spacing-height grob))
445 (hsb (ly:grob-property grob 'has-span-bar))
446 (ii (interval-intersection esh (cons -1.01 1.01))))
448 (cons (car (if (and (car hsb)
449 (ly:grob-property grob 'allow-span-bar))
451 (cdr (if (cdr hsb) esh ii)))
454 (define-public (pure-from-neighbor-interface::extra-spacing-height-including-staff grob)
455 (let ((esh (pure-from-neighbor-interface::extra-spacing-height grob))
456 (to-staff (coord-operation -
459 (ly:staff-symbol-staff-radius grob))
460 (ly:grob::stencil-height grob))))
461 (interval-union esh to-staff)))
464 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
467 (define-public (tuplet-number::calc-direction grob)
468 (ly:tuplet-bracket::calc-direction (ly:grob-object grob 'bracket)))
470 (define-public (tuplet-number::calc-denominator-text grob)
471 (number->string (ly:event-property (event-cause grob) 'denominator)))
473 (define-public (tuplet-number::calc-fraction-text grob)
474 (let ((ev (event-cause grob)))
477 (ly:event-property ev 'denominator)
478 (ly:event-property ev 'numerator))))
480 ;; a formatter function, which is simply a wrapper around an existing
481 ;; tuplet formatter function. It takes the value returned by the given
482 ;; function and appends a note of given length.
483 (define-public ((tuplet-number::append-note-wrapper function note) grob)
484 (let ((txt (if function (function grob) #f)))
487 (markup txt #:fontsize -5 #:note note UP)
488 (markup #:fontsize -5 #:note note UP))))
490 ;; Print a tuplet denominator with a different number than the one derived from
491 ;; the actual tuplet fraction
492 (define-public ((tuplet-number::non-default-tuplet-denominator-text denominator)
494 (number->string (if denominator
496 (ly:event-property (event-cause grob) 'denominator))))
498 ;; Print a tuplet fraction with different numbers than the ones derived from
499 ;; the actual tuplet fraction
500 (define-public ((tuplet-number::non-default-tuplet-fraction-text
501 denominator numerator) grob)
502 (let* ((ev (event-cause grob))
503 (den (if denominator denominator (ly:event-property ev 'denominator)))
504 (num (if numerator numerator (ly:event-property ev 'numerator))))
506 (format #f "~a:~a" den num)))
508 ;; Print a tuplet fraction with note durations appended to the numerator and the
510 (define-public ((tuplet-number::fraction-with-notes
511 denominatornote numeratornote) grob)
512 (let* ((ev (event-cause grob))
513 (denominator (ly:event-property ev 'denominator))
514 (numerator (ly:event-property ev 'numerator)))
516 ((tuplet-number::non-default-fraction-with-notes
517 denominator denominatornote numerator numeratornote) grob)))
519 ;; Print a tuplet fraction with note durations appended to the numerator and the
521 (define-public ((tuplet-number::non-default-fraction-with-notes
522 denominator denominatornote numerator numeratornote) grob)
523 (let* ((ev (event-cause grob))
524 (den (if denominator denominator (ly:event-property ev 'denominator)))
525 (num (if numerator numerator (ly:event-property ev 'numerator))))
527 (make-concat-markup (list
528 (make-simple-markup (format #f "~a" den))
529 (markup #:fontsize -5 #:note denominatornote UP)
530 (make-simple-markup " : ")
531 (make-simple-markup (format #f "~a" num))
532 (markup #:fontsize -5 #:note numeratornote UP)))))
535 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
538 (define-public (color? x)
541 (apply eq? #t (map number? x))
542 (apply eq? #t (map (lambda (y) (<= 0 y 1)) x))))
544 (define-public (rgb-color r g b) (list r g b))
547 (define-public black '(0.0 0.0 0.0))
548 (define-public white '(1.0 1.0 1.0))
549 (define-public red '(1.0 0.0 0.0))
550 (define-public green '(0.0 1.0 0.0))
551 (define-public blue '(0.0 0.0 1.0))
552 (define-public cyan '(0.0 1.0 1.0))
553 (define-public magenta '(1.0 0.0 1.0))
554 (define-public yellow '(1.0 1.0 0.0))
556 (define-public grey '(0.5 0.5 0.5))
557 (define-public darkred '(0.5 0.0 0.0))
558 (define-public darkgreen '(0.0 0.5 0.0))
559 (define-public darkblue '(0.0 0.0 0.5))
560 (define-public darkcyan '(0.0 0.5 0.5))
561 (define-public darkmagenta '(0.5 0.0 0.5))
562 (define-public darkyellow '(0.5 0.5 0.0))
565 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
568 (define-public (key-signature-interface::alteration-positions
569 entry c0-position grob)
570 (let ((step (car entry))
573 (list (+ (cdr step) (* (car step) 7) c0-position))
574 (let* ((c-position (modulo c0-position 7))
577 ;; See (flat|sharp)-positions in define-grob-properties.scm
578 (ly:grob-property grob 'flat-positions '(3))
579 (ly:grob-property grob 'sharp-positions '(3))))
580 (p (list-ref positions
581 (if (< c-position (length positions))
583 (max-position (if (pair? p) (cdr p) p))
584 (min-position (if (pair? p) (car p) (- max-position 6)))
585 (first-position (+ (modulo (- (+ c-position step)
589 (define (prepend x l) (if (> x max-position)
591 (prepend (+ x 7) (cons x l))))
592 (prepend first-position '())))))
594 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
597 (define-public (numbered-footnotes int)
598 (markup #:tiny (number->string (+ 1 int))))
600 (define-public (symbol-footnotes int)
601 (define (helper symbols out idx n)
605 (string-append out (list-ref symbols idx))
608 (markup #:tiny (helper '("*" "†" "‡" "§" "¶")
611 (+ 1 (quotient int 5)))))
613 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
616 (define-public (accidental-interface::calc-alteration grob)
617 (ly:pitch-alteration (ly:event-property (event-cause grob) 'pitch)))
619 (define-public (accidental-interface::glyph-name grob)
620 (assoc-get (ly:grob-property grob 'alteration)
621 standard-alteration-glyph-name-alist))
623 (define-public cancellation-glyph-name-alist
624 '((0 . "accidentals.natural")))
626 (define-public standard-alteration-glyph-name-alist
628 ;; ordered for optimal performance.
629 (0 . "accidentals.natural")
630 (-1/2 . "accidentals.flat")
631 (1/2 . "accidentals.sharp")
633 (1 . "accidentals.doublesharp")
634 (-1 . "accidentals.flatflat")
636 (3/4 . "accidentals.sharp.slashslash.stemstemstem")
637 (1/4 . "accidentals.sharp.slashslash.stem")
638 (-1/4 . "accidentals.mirroredflat")
639 (-3/4 . "accidentals.mirroredflat.flat")))
641 ;; FIXME: standard vs default, alteration-FOO vs FOO-alteration
642 (define-public alteration-default-glyph-name-alist
643 standard-alteration-glyph-name-alist)
645 (define-public makam-alteration-glyph-name-alist
646 '((1 . "accidentals.doublesharp")
647 (8/9 . "accidentals.sharp.slashslashslash.stemstem")
648 (5/9 . "accidentals.sharp.slashslashslash.stem")
649 (4/9 . "accidentals.sharp")
650 (1/9 . "accidentals.sharp.slashslash.stem")
651 (0 . "accidentals.natural")
652 (-1/9 . "accidentals.mirroredflat")
653 (-4/9 . "accidentals.flat.slash")
654 (-5/9 . "accidentals.flat")
655 (-8/9 . "accidentals.flat.slashslash")
656 (-1 . "accidentals.flatflat")))
658 (define-public alteration-hufnagel-glyph-name-alist
659 '((-1/2 . "accidentals.hufnagelM1")
660 (0 . "accidentals.vaticana0")
661 (1/2 . "accidentals.mensural1")))
663 (define-public alteration-medicaea-glyph-name-alist
664 '((-1/2 . "accidentals.medicaeaM1")
665 (0 . "accidentals.vaticana0")
666 (1/2 . "accidentals.mensural1")))
668 (define-public alteration-vaticana-glyph-name-alist
669 '((-1/2 . "accidentals.vaticanaM1")
670 (0 . "accidentals.vaticana0")
671 (1/2 . "accidentals.mensural1")))
673 (define-public alteration-mensural-glyph-name-alist
674 '((-1/2 . "accidentals.mensuralM1")
675 (0 . "accidentals.vaticana0")
676 (1/2 . "accidentals.mensural1")))
678 (define-public alteration-kievan-glyph-name-alist
679 '((-1/2 . "accidentals.kievanM1")
680 (1/2 . "accidentals.kievan1")))
682 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
683 ;; * Pitch Trill Heads
686 (define-public (parentheses-item::calc-parenthesis-stencils grob)
687 (let* ((font (ly:grob-default-font grob))
688 (lp (ly:font-get-glyph font "accidentals.leftparen"))
689 (rp (ly:font-get-glyph font "accidentals.rightparen")))
693 (define-public (parentheses-item::calc-angled-bracket-stencils grob)
694 (let* ((parent (ly:grob-parent grob Y))
695 (y-extent (ly:grob-extent parent parent Y))
696 (half-thickness 0.05) ; should it be a property?
697 (width 0.5) ; should it be a property?
698 (angularity 1.5) ; makes angle brackets
699 (white-padding 0.1) ; should it be a property?
700 (lp (ly:stencil-aligned-to
701 (ly:stencil-aligned-to
702 (make-parenthesis-stencil y-extent
709 (interval-widen (ly:stencil-extent lp X) white-padding))
710 (rp (ly:stencil-aligned-to
711 (ly:stencil-aligned-to
712 (make-parenthesis-stencil y-extent
719 (interval-widen (ly:stencil-extent rp X) white-padding)))
720 (set! lp (ly:make-stencil (ly:stencil-expr lp)
722 (ly:stencil-extent lp Y)))
723 (set! rp (ly:make-stencil (ly:stencil-expr rp)
725 (ly:stencil-extent rp Y)))
726 (list (stencil-whiteout lp)
727 (stencil-whiteout rp))))
729 (define (parenthesize-elements grob . rest)
730 (let* ((refp (if (null? rest)
733 (elts (ly:grob-object grob 'elements))
734 (x-ext (ly:relative-group-extent elts refp X))
735 (stencils (ly:grob-property grob 'stencils))
738 (padding (ly:grob-property grob 'padding 0.1)))
741 (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
742 (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))))
745 (define-public (parentheses-item::print me)
746 (let* ((elts (ly:grob-object me 'elements))
747 (y-ref (ly:grob-common-refpoint-of-array me elts Y))
748 (x-ref (ly:grob-common-refpoint-of-array me elts X))
749 (stencil (parenthesize-elements me x-ref))
750 (elt-y-ext (ly:relative-group-extent elts y-ref Y))
751 (y-center (interval-center elt-y-ext)))
753 (ly:stencil-translate
756 (- (ly:grob-relative-coordinate me x-ref X))
757 (- y-center (ly:grob-relative-coordinate me y-ref Y))))))
761 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
764 (define-public (chain-grob-member-functions grob value . funcs)
767 (set! value (func grob value)))
773 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
776 (define-public (bend::print spanner)
778 (< (abs (- a b)) 0.01))
780 (let* ((delta-y (* 0.5 (ly:grob-property spanner 'delta-position)))
781 (left-span (ly:spanner-bound spanner LEFT))
782 (dots (if (and (grob::has-interface left-span 'note-head-interface)
783 (ly:grob? (ly:grob-object left-span 'dot)))
784 (ly:grob-object left-span 'dot) #f))
786 (right-span (ly:spanner-bound spanner RIGHT))
787 (thickness (* (ly:grob-property spanner 'thickness)
788 (ly:output-def-lookup (ly:grob-layout spanner)
790 (padding (ly:grob-property spanner 'padding 0.5))
791 (common (ly:grob-common-refpoint right-span
792 (ly:grob-common-refpoint spanner
795 (common-y (ly:grob-common-refpoint spanner left-span Y))
796 (minimum-length (ly:grob-property spanner 'minimum-length 0.5))
800 (interval-end (ly:grob-robust-relative-extent
805 (ly:grob-relative-coordinate dots common-y Y)
806 (ly:grob-relative-coordinate spanner common-y Y)))
808 (ly:grob-robust-relative-extent dots common X))
809 ;; TODO: use real infinity constant.
811 (right-x (max (- (interval-start
812 (ly:grob-robust-relative-extent right-span common X))
814 (+ left-x minimum-length)))
815 (self-x (ly:grob-relative-coordinate spanner common X))
816 (dx (- right-x left-x))
817 (exp (list 'path thickness
825 ,dx ,(* 0.66 delta-y)
830 (cons (- left-x self-x) (- right-x self-x))
831 (cons (min 0 delta-y)
835 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
838 (define-public (grace-spacing::calc-shortest-duration grob)
839 (let* ((cols (ly:grob-object grob 'columns))
842 (ly:moment-sub (ly:grob-property
843 (ly:grob-array-ref cols (1+ idx)) 'when)
845 (ly:grob-array-ref cols idx) 'when))))
847 (moment-min (lambda (x y)
850 (if (ly:moment<? x y)
856 (fold moment-min #f (map get-difference
857 (iota (1- (ly:grob-array-length cols)))))))
860 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
863 (define-public (fingering::calc-text grob)
864 (let* ((event (event-cause grob))
865 (digit (ly:event-property event 'digit)))
867 (number->string digit 10)))
869 (define-public (string-number::calc-text grob)
870 (let ((digit (ly:event-property (event-cause grob) 'string-number)))
872 (number->string digit 10)))
874 (define-public (stroke-finger::calc-text grob)
875 (let* ((digit (ly:event-property (event-cause grob) 'digit))
876 (text (ly:event-property (event-cause grob) 'text)))
880 (vector-ref (ly:grob-property grob 'digit-names)
881 (1- (max (min 5 digit) 1))))))
884 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
887 (define-public (hairpin::calc-grow-direction grob)
888 (if (ly:in-event-class? (event-cause grob) 'decrescendo-event)
892 (define-public (dynamic-text-spanner::before-line-breaking grob)
893 "Monitor left bound of @code{DynamicTextSpanner} for absolute dynamics.
894 If found, ensure @code{DynamicText} does not collide with spanner text by
895 changing @code{'attach-dir} and @code{'padding}. Reads the
896 @code{'right-padding} property of @code{DynamicText} to fine tune space
897 between the two text elements."
898 (let ((left-bound (ly:spanner-bound grob LEFT)))
899 (if (grob::has-interface left-bound 'dynamic-text-interface)
900 (let* ((details (ly:grob-property grob 'bound-details))
901 (left-details (ly:assoc-get 'left details))
902 (my-padding (ly:assoc-get 'padding left-details))
903 (script-padding (ly:grob-property left-bound 'right-padding 0)))
905 (and (number? my-padding)
906 (ly:grob-set-nested-property! grob
907 '(bound-details left attach-dir)
909 (ly:grob-set-nested-property! grob
910 '(bound-details left padding)
911 (+ my-padding script-padding)))))))
914 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
917 (define-public (lyric-text::print grob)
918 "Allow interpretation of tildes as lyric tieing marks."
920 (let ((text (ly:grob-property grob 'text)))
922 (grob-interpret-markup grob (if (string? text)
923 (make-tied-lyric-markup text)
926 (define-public ((grob::calc-property-by-copy prop) grob)
927 (ly:event-property (event-cause grob) prop))
930 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
933 (define-public (fret-board::calc-stencil grob)
934 (grob-interpret-markup
936 (make-fret-diagram-verbose-markup
937 (ly:grob-property grob 'dot-placement-list))))
940 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
943 (define-public (script-interface::calc-x-offset grob)
944 (ly:grob-property grob 'positioning-done)
945 (let* ((shift (ly:grob-property grob 'toward-stem-shift 0.0))
947 (ly:self-alignment-interface::centered-on-x-parent grob))
948 (note-head-grob (ly:grob-parent grob X))
949 (stem-grob (ly:grob-object note-head-grob 'stem)))
951 (+ note-head-location
952 ;; If the property 'toward-stem-shift is defined and the script
953 ;; has the same direction as the stem, move the script accordingly.
954 ;; Since scripts can also be over skips, we need to check whether
955 ;; the grob has a stem at all.
956 (if (ly:grob? stem-grob)
957 (let ((dir1 (ly:grob-property grob 'direction))
958 (dir2 (ly:grob-property stem-grob 'direction)))
959 (if (equal? dir1 dir2)
960 (let* ((common-refp (ly:grob-common-refpoint grob stem-grob X))
962 (ly:grob-relative-coordinate stem-grob common-refp X)))
963 (* shift (- stem-location note-head-location)))
968 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
971 (define-public (system-start-text::print grob)
972 (let* ((left-bound (ly:spanner-bound grob LEFT))
973 (left-mom (ly:grob-property left-bound 'when))
974 (name (if (moment<=? left-mom ZERO-MOMENT)
975 (ly:grob-property grob 'long-text)
976 (ly:grob-property grob 'text))))
978 (if (and (markup? name)
979 (!= (ly:item-break-dir left-bound) CENTER))
981 (grob-interpret-markup grob name)
982 (ly:grob-suicide! grob))))
984 (define-public (system-start-text::calc-x-offset grob)
985 (let* ((left-bound (ly:spanner-bound grob LEFT))
986 (left-mom (ly:grob-property left-bound 'when))
987 (layout (ly:grob-layout grob))
988 (indent (ly:output-def-lookup layout
989 (if (moment<=? left-mom ZERO-MOMENT)
993 (system (ly:grob-system grob))
994 (my-extent (ly:grob-extent grob system X))
995 (elements (ly:grob-object system 'elements))
996 (common (ly:grob-common-refpoint-of-array system elements X))
997 (total-ext empty-interval)
998 (align-x (ly:grob-property grob 'self-alignment-X 0))
999 (padding (min 0 (- (interval-length my-extent) indent)))
1000 (right-padding (- padding
1001 (/ (* padding (1+ align-x)) 2))))
1003 ;; compensate for the variation in delimiter extents by
1004 ;; calculating an X-offset correction based on united extents
1005 ;; of all delimiters in this system
1006 (let unite-delims ((l (ly:grob-array-length elements)))
1008 (let ((elt (ly:grob-array-ref elements (1- l))))
1010 (if (grob::has-interface elt 'system-start-delimiter-interface)
1011 (let ((dims (ly:grob-extent elt common X)))
1012 (if (interval-sane? dims)
1013 (set! total-ext (interval-union total-ext dims)))))
1014 (unite-delims (1- l)))))
1017 (ly:side-position-interface::x-aligned-side grob)
1019 (- (interval-length total-ext)))))
1021 (define-public (system-start-text::calc-y-offset grob)
1023 (define (live-elements-list me)
1024 (let ((elements (ly:grob-object me 'elements)))
1026 (filter! grob::is-live?
1027 (ly:grob-array->list elements))))
1029 (let* ((left-bound (ly:spanner-bound grob LEFT))
1030 (live-elts (live-elements-list grob))
1031 (system (ly:grob-system grob))
1032 (extent empty-interval))
1034 (if (and (pair? live-elts)
1035 (interval-sane? (ly:grob-extent grob system Y)))
1036 (let get-extent ((lst live-elts))
1038 (let ((axis-group (car lst)))
1040 (if (and (ly:spanner? axis-group)
1041 (equal? (ly:spanner-bound axis-group LEFT)
1043 (set! extent (add-point extent
1044 (ly:grob-relative-coordinate
1045 axis-group system Y))))
1046 (get-extent (cdr lst)))))
1047 ;; no live axis group(s) for this instrument name -> remove from system
1048 (ly:grob-suicide! grob))
1051 (ly:self-alignment-interface::y-aligned-on-self grob)
1052 (interval-center extent))))
1055 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1058 (define-public (ambitus::print grob)
1059 (let ((heads (ly:grob-object grob 'note-heads)))
1061 (if (and (ly:grob-array? heads)
1062 (= (ly:grob-array-length heads) 2))
1063 (let* ((common (ly:grob-common-refpoint-of-array grob heads Y))
1064 (head-down (ly:grob-array-ref heads 0))
1065 (head-up (ly:grob-array-ref heads 1))
1066 (gap (ly:grob-property grob 'gap 0.35))
1067 (point-min (+ (interval-end (ly:grob-extent head-down common Y))
1069 (point-max (- (interval-start (ly:grob-extent head-up common Y))
1072 (if (< point-min point-max)
1073 (let* ((layout (ly:grob-layout grob))
1074 (line-thick (ly:output-def-lookup layout 'line-thickness))
1075 (blot (ly:output-def-lookup layout 'blot-diameter))
1076 (grob-thick (ly:grob-property grob 'thickness 2))
1077 (width (* line-thick grob-thick))
1078 (x-ext (symmetric-interval (/ width 2)))
1079 (y-ext (cons point-min point-max))
1080 (line (ly:round-filled-box x-ext y-ext blot))
1081 (y-coord (ly:grob-relative-coordinate grob common Y)))
1083 (ly:stencil-translate-axis line (- y-coord) Y))
1086 (ly:grob-suicide! grob)
1089 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1090 ;; laissez-vibrer tie
1092 ;; needed so we can make laissez-vibrer a pure print
1094 (define-public (laissez-vibrer::print grob)
1095 (ly:tie::print grob))