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 (non-event-cause grob)
55 (let ((cause (ly:grob-property grob 'cause)))
58 ((ly:stream-event? cause) (non-event-cause cause))
59 ((ly:grob? cause) cause)
62 (define-public (grob-interpret-markup grob text)
63 (let* ((layout (ly:grob-layout grob))
64 (defs (ly:output-def-lookup layout 'text-font-defaults))
65 (props (ly:grob-alist-chain grob defs)))
67 (ly:text-interface::interpret-markup layout props text)))
69 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
72 ;; even though kievan noteheads do not have stems, their
73 ;; invisible stems help with beam placement
74 ;; this assures that invisible stems for kievan notes are aligned
75 ;; to the center of kievan noteheads. that is thus where the beams'
76 ;; x extrema will fall
77 (define-public (stem::kievan-offset-callback grob)
78 (let* ((note-heads (ly:grob-object grob 'note-heads))
79 (note-heads-grobs (if (not (null? note-heads))
80 (ly:grob-array->list note-heads)
82 (first-note-head (if (not (null? note-heads-grobs))
83 (car note-heads-grobs)
85 (note-head-w (if (not (null? first-note-head))
86 (ly:grob-extent first-note-head first-note-head X)
88 (interval-center note-head-w)))
91 ;; sets position of beams for Kievan notation
92 (define-public (beam::get-kievan-positions grob)
93 (let* ((stems (ly:grob-object grob 'stems))
94 (stems-grobs (if (not (null? stems))
95 (ly:grob-array->list stems)
97 (first-stem (if (not (null? stems-grobs))
100 (note-heads (if (not (null? first-stem))
101 (ly:grob-object first-stem 'note-heads)
103 (note-heads-grobs (if (not (null? note-heads))
104 (ly:grob-array->list note-heads)
106 (first-note-head (if (not (null? note-heads-grobs))
107 (car note-heads-grobs)
109 (next-stem (if (not (null? stems))
112 (next-note-heads (if (not (null? next-stem))
113 (ly:grob-object next-stem 'note-heads)
115 (next-note-heads-grobs (if (not (null? next-note-heads))
116 (ly:grob-array->list next-note-heads)
118 (next-note-head (if (not (null? next-note-heads-grobs))
119 (car next-note-heads-grobs)
121 (left-pos (ly:grob-property first-note-head 'Y-offset))
122 (right-pos (ly:grob-property next-note-head 'Y-offset))
123 (direction (ly:grob-property grob 'direction))
124 (first-nh-height (ly:grob::stencil-height first-note-head))
125 (next-nh-height (ly:grob::stencil-height next-note-head))
126 (left-height (if (= direction DOWN)
127 (+ (car first-nh-height) 0.75)
128 (- (cdr first-nh-height) 0.75)))
129 (right-height (if (= direction DOWN)
130 (+ (car next-nh-height) 0.75)
131 (- (cdr next-nh-height) 0.75))))
132 (cons (+ left-pos left-height) (+ right-pos right-height))))
134 (define-public (beam::get-kievan-quantized-positions grob)
135 (let* ((pos (ly:grob-property grob 'positions))
136 (stems (ly:grob-object grob 'stems))
137 (stems-grobs (if (not (null? stems))
138 (ly:grob-array->list stems)
142 (ly:grob-set-property! g 'stem-begin-position 0)
143 (ly:grob-set-property! g 'length 0))
147 ;; calculates each slope of a broken beam individually
148 (define-public (beam::place-broken-parts-individually grob)
149 (ly:beam::quanting grob '(+inf.0 . -inf.0) #f))
151 ;; calculates the slope of a beam as a single unit,
152 ;; even if it is broken. this assures that the beam
153 ;; will pick up where it left off after a line break
154 (define-public (beam::align-with-broken-parts grob)
155 (ly:beam::quanting grob '(+inf.0 . -inf.0) #t))
157 ;; uses the broken beam style from edition peters combines the
158 ;; values of place-broken-parts-individually and align-with-broken-parts above,
159 ;; favoring place-broken-parts-individually when the beam naturally has a steeper
160 ;; incline and align-with-broken-parts when the beam is flat
161 (define-public (beam::slope-like-broken-parts grob)
163 (/ (- (cdr y) (car y)) (- (cdr x) (car x))))
164 (let* ((quant1 (ly:beam::quanting grob '(+inf.0 . -inf.0) #t))
165 (original (ly:grob-original grob))
166 (siblings (if (ly:grob? original)
167 (ly:spanner-broken-into original)
171 (let* ((quant2 (ly:beam::quanting grob '(+inf.0 . -inf.0) #f))
172 (x-span (ly:grob-property grob 'X-positions))
173 (slope1 (slope quant1 x-span))
174 (slope2 (slope quant2 x-span))
175 (quant2 (if (not (= (sign slope1) (sign slope2)))
178 (factor (/ (atan (abs slope1)) PI-OVER-TWO))
181 (+ (* (x quant1) (- 1 factor))
182 (* (x quant2) factor)))
184 (ly:beam::quanting grob base #f)))))
186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
189 (define-public (script-or-side-position-cross-staff g)
191 (ly:script-interface::calc-cross-staff g)
192 (ly:side-position-interface::calc-cross-staff g)))
195 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
196 ;; side-position stuff
198 (define-public (only-if-beamed g)
202 (ly:grob? (ly:grob-object x 'beam)))
203 (ly:grob-array->list (ly:grob-object g
204 'side-support-elements)))))
206 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
209 (define-public (stem::calc-duration-log grob)
211 (ly:event-property (event-cause grob) 'duration)))
213 (define (stem-stub::do-calculations grob)
214 (and (ly:grob-property (ly:grob-parent grob X) 'cross-staff)
215 (not (ly:grob-property (ly:grob-parent grob X) 'transparent))))
217 (define-public (stem-stub::pure-height grob beg end)
218 (if (stem-stub::do-calculations grob)
222 (define-public (stem-stub::width grob)
223 (if (stem-stub::do-calculations grob)
224 (grob::x-parent-width grob)
227 (define-public (stem-stub::extra-spacing-height grob)
228 (if (stem-stub::do-calculations grob)
229 (let* ((dad (ly:grob-parent grob X))
230 (refp (ly:grob-common-refpoint grob dad Y))
231 (stem_ph (ly:grob-pure-height dad refp 0 1000000))
232 (my_ph (ly:grob-pure-height grob refp 0 1000000))
233 ;; only account for distance if stem is on different staff than stub
234 (dist (if (grob::has-interface refp 'hara-kiri-group-spanner-interface)
236 (- (car my_ph) (car stem_ph)))))
237 (if (interval-empty? (interval-intersection stem_ph my_ph)) #f (coord-translate stem_ph dist)))
240 (define-public (note-head::calc-kievan-duration-log grob)
243 (ly:event-property (event-cause grob) 'duration))))
245 (define-public (note-head::calc-duration-log grob)
248 (ly:event-property (event-cause grob) 'duration))))
250 (define-public (dots::calc-dot-count grob)
251 (ly:duration-dot-count
252 (ly:event-property (event-cause grob) 'duration)))
254 (define-public (dots::calc-staff-position grob)
255 (let* ((head (ly:grob-parent grob Y))
256 (log (ly:grob-property head 'duration-log)))
259 ((or (not (grob::has-interface head 'rest-interface))
260 (not (integer? log))) 0)
268 ;; Kept separate from note-head::calc-glyph-name to allow use by
269 ;; markup commands \note and \note-by-number
270 (define-public (select-head-glyph style log)
271 "Select a note head glyph string based on note head style @var{style}
272 and duration-log @var{log}."
274 ;; "default" style is directly handled in note-head.cc as a
275 ;; special case (HW says, mainly for performance reasons).
276 ;; Therefore, style "default" does not appear in this case
278 ((xcircle) "2xcircle")
279 ((harmonic) "0harmonic")
280 ((harmonic-black) "2harmonic")
281 ((harmonic-mixed) (if (<= log 1) "0harmonic"
284 ;; Oops, I actually would not call this "baroque", but, for
285 ;; backwards compatibility to 1.4, this is supposed to take
286 ;; brevis, longa and maxima from the neo-mensural font and all
287 ;; other note heads from the default font. -- jr
289 (string-append (number->string log) "neomensural")
290 (number->string log)))
292 ;; Like default, but brevis is drawn with double vertical lines
294 (string-append (number->string log) "double")
295 (number->string log)))
297 (string-append (number->string log) (symbol->string style)))
300 (string-append (number->string log) "mensural")
301 (string-append (number->string log) (symbol->string style))))
304 (string-append (number->string log) "blackmensural")
305 (string-append (number->string log) (symbol->string style))))
308 (string-append (number->string log) "semimensural")
309 (string-append (number->string log) "petrucci")))
311 (string-append (number->string log) (symbol->string style)))
313 (string-append (number->string log) "kievan"))
315 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
316 (symbol->string style)
317 (string-append (number->string (max 0 log))
318 (symbol->string style))))))
320 (define-public (note-head::calc-glyph-name grob)
321 (let* ((style (ly:grob-property grob 'style))
322 (log (if (string-match "kievan*" (symbol->string style))
323 (min 3 (ly:grob-property grob 'duration-log))
324 (min 2 (ly:grob-property grob 'duration-log)))))
325 (select-head-glyph style log)))
327 (define-public (note-head::brew-ez-stencil grob)
328 (let* ((log (ly:grob-property grob 'duration-log))
329 (pitch (ly:event-property (event-cause grob) 'pitch))
330 (pitch-index (ly:pitch-notename pitch))
331 (note-names (ly:grob-property grob 'note-names))
332 (pitch-string (if (and (vector? note-names)
333 (> (vector-length note-names) pitch-index))
334 (vector-ref note-names pitch-index)
337 (+ (modulo (+ pitch-index 2) 7)
338 (char->integer #\A))))))
339 (staff-space (ly:staff-symbol-staff-space grob))
340 (line-thickness (ly:staff-symbol-line-thickness grob))
341 (stem (ly:grob-object grob 'stem))
342 (stem-thickness (* (if (ly:grob? stem)
343 (ly:grob-property stem 'thickness)
346 (radius (/ (+ staff-space line-thickness) 2))
347 (letter (markup #:center-align #:vcenter pitch-string))
348 (filled-circle (markup #:draw-circle radius 0 #t)))
350 (ly:stencil-translate-axis
351 (grob-interpret-markup
356 (make-with-color-markup white letter))
360 (make-with-color-markup white (make-draw-circle-markup
361 (- radius stem-thickness) 0 #t)))
365 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
368 (define-public (make-rhythmic-location bar-num num den)
370 bar-num (ly:make-moment num den)))
372 (define-public (rhythmic-location? a)
375 (ly:moment? (cdr a))))
377 (define-public (make-graceless-rhythmic-location loc)
378 (make-rhythmic-location
380 (ly:moment-main-numerator (rhythmic-location-measure-position loc))
381 (ly:moment-main-denominator (rhythmic-location-measure-position loc))))
383 (define-public rhythmic-location-measure-position cdr)
384 (define-public rhythmic-location-bar-number car)
386 (define-public (rhythmic-location<? a b)
388 ((< (car a) (car b)) #t)
389 ((> (car a) (car b)) #f)
391 (ly:moment<? (cdr a) (cdr b)))))
393 (define-public (rhythmic-location<=? a b)
394 (not (rhythmic-location<? b a)))
395 (define-public (rhythmic-location>=? a b)
396 (not (rhythmic-location<? a b)))
397 (define-public (rhythmic-location>? a b)
398 (rhythmic-location<? b a))
400 (define-public (rhythmic-location=? a b)
401 (and (rhythmic-location<=? a b)
402 (rhythmic-location<=? b a)))
404 (define-public (rhythmic-location->file-string a)
405 (ly:format "~a.~a.~a"
407 (ly:moment-main-numerator (cdr a))
408 (ly:moment-main-denominator (cdr a))))
410 (define-public (rhythmic-location->string a)
411 (ly:format "bar ~a ~a"
413 (ly:moment->string (cdr a))))
415 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
418 (define-public all-visible #(#t #t #t))
419 (define-public begin-of-line-invisible #(#t #t #f))
420 (define-public center-invisible #(#t #f #t))
421 (define-public end-of-line-invisible #(#f #t #t))
422 (define-public begin-of-line-visible #(#f #f #t))
423 (define-public center-visible #(#f #t #f))
424 (define-public end-of-line-visible #(#t #f #f))
425 (define-public all-invisible #(#f #f #f))
426 (define-public (inherit-x-parent-visibility grob)
427 (let ((parent (ly:grob-parent grob X)))
428 (ly:grob-property parent 'break-visibility all-invisible)))
429 (define-public (inherit-y-parent-visibility grob)
430 (let ((parent (ly:grob-parent grob X)))
431 (ly:grob-property parent 'break-visibility)))
434 (define-public spanbar-begin-of-line-invisible #(#t #f #f))
437 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
438 ;; neighbor-interface routines
441 (define-public (shift-right-at-line-begin g)
442 "Shift an item to the right, but only at the start of the line."
443 (if (and (ly:item? g)
444 (equal? (ly:item-break-dir g) RIGHT))
445 (ly:grob-translate-axis! g 3.5 X)))
447 (define-public (pure-from-neighbor-interface::extra-spacing-height-at-beginning-of-line grob)
448 (if (= 1 (ly:item-break-dir grob))
449 (pure-from-neighbor-interface::extra-spacing-height grob)
452 (define-public (pure-from-neighbor-interface::extra-spacing-height grob)
453 (let* ((height (ly:grob-pure-height grob grob 0 10000000))
454 (from-neighbors (interval-union
456 (ly:axis-group-interface::pure-height
460 (coord-operation - from-neighbors height)))
462 (define-public (pure-from-neighbor-interface::account-for-span-bar grob)
463 (let* ((esh (pure-from-neighbor-interface::extra-spacing-height grob))
464 (hsb (ly:grob-property grob 'has-span-bar))
465 (ii (interval-intersection esh (cons -1.01 1.01))))
467 (cons (car (if (and (car hsb)
468 (ly:grob-property grob 'allow-span-bar))
470 (cdr (if (cdr hsb) esh ii)))
473 (define-public (pure-from-neighbor-interface::extra-spacing-height-including-staff grob)
474 (let ((esh (pure-from-neighbor-interface::extra-spacing-height grob))
475 (to-staff (coord-operation -
478 (ly:staff-symbol-staff-radius grob))
479 (ly:grob::stencil-height grob))))
480 (interval-union esh to-staff)))
483 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
486 (define-public (tuplet-number::calc-direction grob)
487 (ly:tuplet-bracket::calc-direction (ly:grob-object grob 'bracket)))
489 (define-public (tuplet-number::calc-denominator-text grob)
490 (number->string (ly:event-property (event-cause grob) 'denominator)))
492 (define-public (tuplet-number::calc-fraction-text grob)
493 (let ((ev (event-cause grob)))
496 (ly:event-property ev 'denominator)
497 (ly:event-property ev 'numerator))))
499 ;; a formatter function, which is simply a wrapper around an existing
500 ;; tuplet formatter function. It takes the value returned by the given
501 ;; function and appends a note of given length.
502 (define-public ((tuplet-number::append-note-wrapper function note) grob)
503 (let ((txt (if function (function grob) #f)))
506 (markup txt #:fontsize -5 #:note note UP)
507 (markup #:fontsize -5 #:note note UP))))
509 ;; Print a tuplet denominator with a different number than the one derived from
510 ;; the actual tuplet fraction
511 (define-public ((tuplet-number::non-default-tuplet-denominator-text denominator)
513 (number->string (if denominator
515 (ly:event-property (event-cause grob) 'denominator))))
517 ;; Print a tuplet fraction with different numbers than the ones derived from
518 ;; the actual tuplet fraction
519 (define-public ((tuplet-number::non-default-tuplet-fraction-text
520 denominator numerator) grob)
521 (let* ((ev (event-cause grob))
522 (den (if denominator denominator (ly:event-property ev 'denominator)))
523 (num (if numerator numerator (ly:event-property ev 'numerator))))
525 (format #f "~a:~a" den num)))
527 ;; Print a tuplet fraction with note durations appended to the numerator and the
529 (define-public ((tuplet-number::fraction-with-notes
530 denominatornote numeratornote) grob)
531 (let* ((ev (event-cause grob))
532 (denominator (ly:event-property ev 'denominator))
533 (numerator (ly:event-property ev 'numerator)))
535 ((tuplet-number::non-default-fraction-with-notes
536 denominator denominatornote numerator numeratornote) grob)))
538 ;; Print a tuplet fraction with note durations appended to the numerator and the
540 (define-public ((tuplet-number::non-default-fraction-with-notes
541 denominator denominatornote numerator numeratornote) grob)
542 (let* ((ev (event-cause grob))
543 (den (if denominator denominator (ly:event-property ev 'denominator)))
544 (num (if numerator numerator (ly:event-property ev 'numerator))))
546 (make-concat-markup (list
547 (make-simple-markup (format #f "~a" den))
548 (markup #:fontsize -5 #:note denominatornote UP)
549 (make-simple-markup " : ")
550 (make-simple-markup (format #f "~a" num))
551 (markup #:fontsize -5 #:note numeratornote UP)))))
554 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
557 (define-public (color? x)
560 (apply eq? #t (map number? x))
561 (apply eq? #t (map (lambda (y) (<= 0 y 1)) x))))
563 (define-public (rgb-color r g b) (list r g b))
566 (define-public black '(0.0 0.0 0.0))
567 (define-public white '(1.0 1.0 1.0))
568 (define-public red '(1.0 0.0 0.0))
569 (define-public green '(0.0 1.0 0.0))
570 (define-public blue '(0.0 0.0 1.0))
571 (define-public cyan '(0.0 1.0 1.0))
572 (define-public magenta '(1.0 0.0 1.0))
573 (define-public yellow '(1.0 1.0 0.0))
575 (define-public grey '(0.5 0.5 0.5))
576 (define-public darkred '(0.5 0.0 0.0))
577 (define-public darkgreen '(0.0 0.5 0.0))
578 (define-public darkblue '(0.0 0.0 0.5))
579 (define-public darkcyan '(0.0 0.5 0.5))
580 (define-public darkmagenta '(0.5 0.0 0.5))
581 (define-public darkyellow '(0.5 0.5 0.0))
584 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
587 (define-public (key-signature-interface::alteration-positions
588 entry c0-position grob)
589 (let ((step (car entry))
592 (list (+ (cdr step) (* (car step) 7) c0-position))
593 (let* ((c-position (modulo c0-position 7))
596 ;; See (flat|sharp)-positions in define-grob-properties.scm
597 (ly:grob-property grob 'flat-positions '(3))
598 (ly:grob-property grob 'sharp-positions '(3))))
599 (p (list-ref positions
600 (if (< c-position (length positions))
602 (max-position (if (pair? p) (cdr p) p))
603 (min-position (if (pair? p) (car p) (- max-position 6)))
604 (first-position (+ (modulo (- (+ c-position step)
608 (define (prepend x l) (if (> x max-position)
610 (prepend (+ x 7) (cons x l))))
611 (prepend first-position '())))))
613 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
616 (define-public (numbered-footnotes int)
617 (markup #:tiny (number->string (+ 1 int))))
619 (define-public (symbol-footnotes int)
620 (define (helper symbols out idx n)
624 (string-append out (list-ref symbols idx))
627 (markup #:tiny (helper '("*" "†" "‡" "§" "¶")
630 (+ 1 (quotient int 5)))))
632 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
635 (define-public (accidental-interface::calc-alteration grob)
636 (ly:pitch-alteration (ly:event-property (event-cause grob) 'pitch)))
638 (define-public (accidental-interface::glyph-name grob)
639 (assoc-get (ly:grob-property grob 'alteration)
640 standard-alteration-glyph-name-alist))
642 (define-public cancellation-glyph-name-alist
643 '((0 . "accidentals.natural")))
645 (define-public standard-alteration-glyph-name-alist
647 ;; ordered for optimal performance.
648 (0 . "accidentals.natural")
649 (-1/2 . "accidentals.flat")
650 (1/2 . "accidentals.sharp")
652 (1 . "accidentals.doublesharp")
653 (-1 . "accidentals.flatflat")
655 (3/4 . "accidentals.sharp.slashslash.stemstemstem")
656 (1/4 . "accidentals.sharp.slashslash.stem")
657 (-1/4 . "accidentals.mirroredflat")
658 (-3/4 . "accidentals.mirroredflat.flat")))
660 ;; FIXME: standard vs default, alteration-FOO vs FOO-alteration
661 (define-public alteration-default-glyph-name-alist
662 standard-alteration-glyph-name-alist)
664 (define-public makam-alteration-glyph-name-alist
665 '((1 . "accidentals.doublesharp")
666 (8/9 . "accidentals.sharp.slashslashslash.stemstem")
667 (5/9 . "accidentals.sharp.slashslashslash.stem")
668 (4/9 . "accidentals.sharp")
669 (1/9 . "accidentals.sharp.slashslash.stem")
670 (0 . "accidentals.natural")
671 (-1/9 . "accidentals.mirroredflat")
672 (-4/9 . "accidentals.flat.slash")
673 (-5/9 . "accidentals.flat")
674 (-8/9 . "accidentals.flat.slashslash")
675 (-1 . "accidentals.flatflat")))
677 (define-public alteration-hufnagel-glyph-name-alist
678 '((-1/2 . "accidentals.hufnagelM1")
679 (0 . "accidentals.vaticana0")
680 (1/2 . "accidentals.mensural1")))
682 (define-public alteration-medicaea-glyph-name-alist
683 '((-1/2 . "accidentals.medicaeaM1")
684 (0 . "accidentals.vaticana0")
685 (1/2 . "accidentals.mensural1")))
687 (define-public alteration-vaticana-glyph-name-alist
688 '((-1/2 . "accidentals.vaticanaM1")
689 (0 . "accidentals.vaticana0")
690 (1/2 . "accidentals.mensural1")))
692 (define-public alteration-mensural-glyph-name-alist
693 '((-1/2 . "accidentals.mensuralM1")
694 (0 . "accidentals.vaticana0")
695 (1/2 . "accidentals.mensural1")))
697 (define-public alteration-kievan-glyph-name-alist
698 '((-1/2 . "accidentals.kievanM1")
699 (1/2 . "accidentals.kievan1")))
701 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
702 ;; * Pitch Trill Heads
705 (define-public (parentheses-item::calc-parenthesis-stencils grob)
706 (let* ((font (ly:grob-default-font grob))
707 (lp (ly:font-get-glyph font "accidentals.leftparen"))
708 (rp (ly:font-get-glyph font "accidentals.rightparen")))
712 (define-public (parentheses-item::calc-angled-bracket-stencils grob)
713 (let* ((parent (ly:grob-parent grob Y))
714 (y-extent (ly:grob-extent parent parent Y))
715 (half-thickness 0.05) ; should it be a property?
716 (width 0.5) ; should it be a property?
717 (angularity 1.5) ; makes angle brackets
718 (white-padding 0.1) ; should it be a property?
719 (lp (ly:stencil-aligned-to
720 (ly:stencil-aligned-to
721 (make-parenthesis-stencil y-extent
728 (interval-widen (ly:stencil-extent lp X) white-padding))
729 (rp (ly:stencil-aligned-to
730 (ly:stencil-aligned-to
731 (make-parenthesis-stencil y-extent
738 (interval-widen (ly:stencil-extent rp X) white-padding)))
739 (set! lp (ly:make-stencil (ly:stencil-expr lp)
741 (ly:stencil-extent lp Y)))
742 (set! rp (ly:make-stencil (ly:stencil-expr rp)
744 (ly:stencil-extent rp Y)))
745 (list (stencil-whiteout lp)
746 (stencil-whiteout rp))))
748 (define (parenthesize-elements grob . rest)
749 (let* ((refp (if (null? rest)
752 (elts (ly:grob-object grob 'elements))
753 (x-ext (ly:relative-group-extent elts refp X))
754 (stencils (ly:grob-property grob 'stencils))
757 (padding (ly:grob-property grob 'padding 0.1)))
760 (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
761 (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))))
764 (define-public (parentheses-item::print me)
765 (let* ((elts (ly:grob-object me 'elements))
766 (y-ref (ly:grob-common-refpoint-of-array me elts Y))
767 (x-ref (ly:grob-common-refpoint-of-array me elts X))
768 (stencil (parenthesize-elements me x-ref))
769 (elt-y-ext (ly:relative-group-extent elts y-ref Y))
770 (y-center (interval-center elt-y-ext)))
772 (ly:stencil-translate
775 (- (ly:grob-relative-coordinate me x-ref X))
776 (- y-center (ly:grob-relative-coordinate me y-ref Y))))))
780 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
783 (define-public (chain-grob-member-functions grob value . funcs)
786 (set! value (func grob value)))
792 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
795 (define-public (bend::print spanner)
797 (< (abs (- a b)) 0.01))
799 (let* ((delta-y (* 0.5 (ly:grob-property spanner 'delta-position)))
800 (left-span (ly:spanner-bound spanner LEFT))
801 (dots (if (and (grob::has-interface left-span 'note-head-interface)
802 (ly:grob? (ly:grob-object left-span 'dot)))
803 (ly:grob-object left-span 'dot) #f))
805 (right-span (ly:spanner-bound spanner RIGHT))
806 (thickness (* (ly:grob-property spanner 'thickness)
807 (ly:output-def-lookup (ly:grob-layout spanner)
809 (padding (ly:grob-property spanner 'padding 0.5))
810 (common (ly:grob-common-refpoint right-span
811 (ly:grob-common-refpoint spanner
814 (common-y (ly:grob-common-refpoint spanner left-span Y))
815 (minimum-length (ly:grob-property spanner 'minimum-length 0.5))
819 (interval-end (ly:grob-robust-relative-extent
824 (ly:grob-relative-coordinate dots common-y Y)
825 (ly:grob-relative-coordinate spanner common-y Y)))
827 (ly:grob-robust-relative-extent dots common X))
828 ;; TODO: use real infinity constant.
830 (right-x (max (- (interval-start
831 (ly:grob-robust-relative-extent right-span common X))
833 (+ left-x minimum-length)))
834 (self-x (ly:grob-relative-coordinate spanner common X))
835 (dx (- right-x left-x))
836 (exp (list 'path thickness
844 ,dx ,(* 0.66 delta-y)
849 (cons (- left-x self-x) (- right-x self-x))
850 (cons (min 0 delta-y)
854 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
857 (define-public (grace-spacing::calc-shortest-duration grob)
858 (let* ((cols (ly:grob-object grob 'columns))
861 (ly:moment-sub (ly:grob-property
862 (ly:grob-array-ref cols (1+ idx)) 'when)
864 (ly:grob-array-ref cols idx) 'when))))
866 (moment-min (lambda (x y)
869 (if (ly:moment<? x y)
875 (fold moment-min #f (map get-difference
876 (iota (1- (ly:grob-array-length cols)))))))
879 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
882 (define-public (fingering::calc-text grob)
883 (let* ((event (event-cause grob))
884 (digit (ly:event-property event 'digit)))
886 (number->string digit 10)))
888 (define-public (string-number::calc-text grob)
889 (let ((digit (ly:event-property (event-cause grob) 'string-number)))
891 (number->string digit 10)))
893 (define-public (stroke-finger::calc-text grob)
894 (let* ((digit (ly:event-property (event-cause grob) 'digit))
895 (text (ly:event-property (event-cause grob) 'text)))
899 (vector-ref (ly:grob-property grob 'digit-names)
900 (1- (max (min 5 digit) 1))))))
903 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
906 (define-public (hairpin::calc-grow-direction grob)
907 (if (ly:in-event-class? (event-cause grob) 'decrescendo-event)
911 (define-public (dynamic-text-spanner::before-line-breaking grob)
912 "Monitor left bound of @code{DynamicTextSpanner} for absolute dynamics.
913 If found, ensure @code{DynamicText} does not collide with spanner text by
914 changing @code{'attach-dir} and @code{'padding}. Reads the
915 @code{'right-padding} property of @code{DynamicText} to fine tune space
916 between the two text elements."
917 (let ((left-bound (ly:spanner-bound grob LEFT)))
918 (if (grob::has-interface left-bound 'dynamic-text-interface)
919 (let* ((details (ly:grob-property grob 'bound-details))
920 (left-details (ly:assoc-get 'left details))
921 (my-padding (ly:assoc-get 'padding left-details))
922 (script-padding (ly:grob-property left-bound 'right-padding 0)))
924 (and (number? my-padding)
925 (ly:grob-set-nested-property! grob
926 '(bound-details left attach-dir)
928 (ly:grob-set-nested-property! grob
929 '(bound-details left padding)
930 (+ my-padding script-padding)))))))
933 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
936 (define-public (lyric-text::print grob)
937 "Allow interpretation of tildes as lyric tieing marks."
939 (let ((text (ly:grob-property grob 'text)))
941 (grob-interpret-markup grob (if (string? text)
942 (make-tied-lyric-markup text)
945 (define-public ((grob::calc-property-by-copy prop) grob)
946 (ly:event-property (event-cause grob) prop))
948 (define-public ((grob::calc-property-by-non-event-cause prop) grob)
949 (ly:grob-property (non-event-cause grob) prop))
952 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
955 (define-public (fret-board::calc-stencil grob)
956 (grob-interpret-markup
958 (make-fret-diagram-verbose-markup
959 (ly:grob-property grob 'dot-placement-list))))
962 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
965 (define-public (script-interface::calc-x-offset grob)
966 (ly:grob-property grob 'positioning-done)
967 (let* ((shift (ly:grob-property grob 'toward-stem-shift 0.0))
969 (ly:self-alignment-interface::centered-on-x-parent grob))
970 (note-head-grob (ly:grob-parent grob X))
971 (stem-grob (ly:grob-object note-head-grob 'stem)))
973 (+ note-head-location
974 ;; If the property 'toward-stem-shift is defined and the script
975 ;; has the same direction as the stem, move the script accordingly.
976 ;; Since scripts can also be over skips, we need to check whether
977 ;; the grob has a stem at all.
978 (if (ly:grob? stem-grob)
979 (let ((dir1 (ly:grob-property grob 'direction))
980 (dir2 (ly:grob-property stem-grob 'direction)))
981 (if (equal? dir1 dir2)
982 (let* ((common-refp (ly:grob-common-refpoint grob stem-grob X))
984 (ly:grob-relative-coordinate stem-grob common-refp X)))
985 (* shift (- stem-location note-head-location)))
990 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
993 (define-public (system-start-text::print grob)
994 (let* ((left-bound (ly:spanner-bound grob LEFT))
995 (left-mom (ly:grob-property left-bound 'when))
996 (name (if (moment<=? left-mom ZERO-MOMENT)
997 (ly:grob-property grob 'long-text)
998 (ly:grob-property grob 'text))))
1000 (if (and (markup? name)
1001 (!= (ly:item-break-dir left-bound) CENTER))
1003 (grob-interpret-markup grob name)
1004 (ly:grob-suicide! grob))))
1006 (define-public (system-start-text::calc-x-offset grob)
1007 (let* ((left-bound (ly:spanner-bound grob LEFT))
1008 (left-mom (ly:grob-property left-bound 'when))
1009 (layout (ly:grob-layout grob))
1010 (indent (ly:output-def-lookup layout
1011 (if (moment<=? left-mom ZERO-MOMENT)
1015 (system (ly:grob-system grob))
1016 (my-extent (ly:grob-extent grob system X))
1017 (elements (ly:grob-object system 'elements))
1018 (common (ly:grob-common-refpoint-of-array system elements X))
1019 (total-ext empty-interval)
1020 (align-x (ly:grob-property grob 'self-alignment-X 0))
1021 (padding (min 0 (- (interval-length my-extent) indent)))
1022 (right-padding (- padding
1023 (/ (* padding (1+ align-x)) 2))))
1025 ;; compensate for the variation in delimiter extents by
1026 ;; calculating an X-offset correction based on united extents
1027 ;; of all delimiters in this system
1028 (let unite-delims ((l (ly:grob-array-length elements)))
1030 (let ((elt (ly:grob-array-ref elements (1- l))))
1032 (if (grob::has-interface elt 'system-start-delimiter-interface)
1033 (let ((dims (ly:grob-extent elt common X)))
1034 (if (interval-sane? dims)
1035 (set! total-ext (interval-union total-ext dims)))))
1036 (unite-delims (1- l)))))
1039 (ly:side-position-interface::x-aligned-side grob)
1041 (- (interval-length total-ext)))))
1043 (define-public (system-start-text::calc-y-offset grob)
1045 (define (live-elements-list me)
1046 (let ((elements (ly:grob-object me 'elements)))
1048 (filter! grob::is-live?
1049 (ly:grob-array->list elements))))
1051 (let* ((left-bound (ly:spanner-bound grob LEFT))
1052 (live-elts (live-elements-list grob))
1053 (system (ly:grob-system grob))
1054 (extent empty-interval))
1056 (if (and (pair? live-elts)
1057 (interval-sane? (ly:grob-extent grob system Y)))
1058 (let get-extent ((lst live-elts))
1060 (let ((axis-group (car lst)))
1062 (if (and (ly:spanner? axis-group)
1063 (equal? (ly:spanner-bound axis-group LEFT)
1065 (set! extent (add-point extent
1066 (ly:grob-relative-coordinate
1067 axis-group system Y))))
1068 (get-extent (cdr lst)))))
1069 ;; no live axis group(s) for this instrument name -> remove from system
1070 (ly:grob-suicide! grob))
1073 (ly:self-alignment-interface::y-aligned-on-self grob)
1074 (interval-center extent))))
1077 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1080 (define-public (ambitus::print grob)
1081 (let ((heads (ly:grob-object grob 'note-heads)))
1083 (if (and (ly:grob-array? heads)
1084 (= (ly:grob-array-length heads) 2))
1085 (let* ((common (ly:grob-common-refpoint-of-array grob heads Y))
1086 (head-down (ly:grob-array-ref heads 0))
1087 (head-up (ly:grob-array-ref heads 1))
1088 (gap (ly:grob-property grob 'gap 0.35))
1089 (point-min (+ (interval-end (ly:grob-extent head-down common Y))
1091 (point-max (- (interval-start (ly:grob-extent head-up common Y))
1094 (if (< point-min point-max)
1095 (let* ((layout (ly:grob-layout grob))
1096 (line-thick (ly:output-def-lookup layout 'line-thickness))
1097 (blot (ly:output-def-lookup layout 'blot-diameter))
1098 (grob-thick (ly:grob-property grob 'thickness 2))
1099 (width (* line-thick grob-thick))
1100 (x-ext (symmetric-interval (/ width 2)))
1101 (y-ext (cons point-min point-max))
1102 (line (ly:round-filled-box x-ext y-ext blot))
1103 (y-coord (ly:grob-relative-coordinate grob common Y)))
1105 (ly:stencil-translate-axis line (- y-coord) Y))
1108 (ly:grob-suicide! grob)
1111 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1112 ;; laissez-vibrer tie
1114 ;; needed so we can make laissez-vibrer a pure print
1116 (define-public (laissez-vibrer::print grob)
1117 (ly:tie::print grob))