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 ;; Using this as a callback for a grob's Y-extent promises
62 ;; that the grob's stencil does not depend on line-spacing.
63 ;; We use this promise to figure the space required by Clefs
64 ;; and such at the note-spacing stage.
66 (define-public grob::all-heights-from-stencil
67 (ly:make-unpure-pure-container
68 ly:grob::stencil-height
69 (lambda (grob start end) (ly:grob::stencil-height grob))))
71 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
74 ;; even though kievan noteheads do not have stems, their
75 ;; invisible stems help with beam placement
76 ;; this assures that invisible stems for kievan notes are aligned
77 ;; to the center of kievan noteheads. that is thus where the beams'
78 ;; x extrema will fall
79 (define-public (stem::kievan-offset-callback grob)
80 (let* ((note-heads (ly:grob-object grob 'note-heads))
81 (note-heads-grobs (if (not (null? note-heads))
82 (ly:grob-array->list note-heads)
84 (first-note-head (if (not (null? note-heads-grobs))
85 (car note-heads-grobs)
87 (note-head-w (if (not (null? first-note-head))
88 (ly:grob-extent first-note-head first-note-head X)
90 (interval-center note-head-w)))
93 ;; sets position of beams for Kievan notation
94 (define-public (beam::get-kievan-positions grob)
95 (let* ((stems (ly:grob-object grob 'stems))
96 (stems-grobs (if (not (null? stems))
97 (ly:grob-array->list stems)
99 (first-stem (if (not (null? stems-grobs))
102 (note-heads (if (not (null? first-stem))
103 (ly:grob-object first-stem 'note-heads)
105 (note-heads-grobs (if (not (null? note-heads))
106 (ly:grob-array->list note-heads)
108 (first-note-head (if (not (null? note-heads-grobs))
109 (car note-heads-grobs)
111 (next-stem (if (not (null? stems))
114 (next-note-heads (if (not (null? next-stem))
115 (ly:grob-object next-stem 'note-heads)
117 (next-note-heads-grobs (if (not (null? next-note-heads))
118 (ly:grob-array->list next-note-heads)
120 (next-note-head (if (not (null? next-note-heads-grobs))
121 (car next-note-heads-grobs)
123 (left-pos (ly:grob-property first-note-head 'Y-offset))
124 (right-pos (ly:grob-property next-note-head 'Y-offset))
125 (direction (ly:grob-property grob 'direction))
126 (first-nh-height (ly:grob::stencil-height first-note-head))
127 (next-nh-height (ly:grob::stencil-height next-note-head))
128 (left-height (if (= direction DOWN)
129 (+ (car first-nh-height) 0.75)
130 (- (cdr first-nh-height) 0.75)))
131 (right-height (if (= direction DOWN)
132 (+ (car next-nh-height) 0.75)
133 (- (cdr next-nh-height) 0.75))))
134 (cons (+ left-pos left-height) (+ right-pos right-height))))
136 (define-public (beam::get-kievan-quantized-positions grob)
137 (let* ((pos (ly:grob-property grob 'positions))
138 (stems (ly:grob-object grob 'stems))
139 (stems-grobs (if (not (null? stems))
140 (ly:grob-array->list stems)
144 (ly:grob-set-property! g 'stem-begin-position 0)
145 (ly:grob-set-property! g 'length 0))
149 ;; calculates each slope of a broken beam individually
150 (define-public (beam::place-broken-parts-individually grob)
151 (ly:beam::quanting grob '(+inf.0 . -inf.0) #f))
153 ;; calculates the slope of a beam as a single unit,
154 ;; even if it is broken. this assures that the beam
155 ;; will pick up where it left off after a line break
156 (define-public (beam::align-with-broken-parts grob)
157 (ly:beam::quanting grob '(+inf.0 . -inf.0) #t))
159 ;; uses the broken beam style from edition peters combines the
160 ;; values of place-broken-parts-individually and align-with-broken-parts above,
161 ;; favoring place-broken-parts-individually when the beam naturally has a steeper
162 ;; incline and align-with-broken-parts when the beam is flat
163 (define-public (beam::slope-like-broken-parts grob)
165 (/ (- (cdr y) (car y)) (- (cdr x) (car x))))
166 (let* ((quant1 (ly:beam::quanting grob '(+inf.0 . -inf.0) #t))
167 (original (ly:grob-original grob))
168 (siblings (if (ly:grob? original)
169 (ly:spanner-broken-into original)
173 (let* ((quant2 (ly:beam::quanting grob '(+inf.0 . -inf.0) #f))
174 (x-span (ly:grob-property grob 'X-positions))
175 (slope1 (slope quant1 x-span))
176 (slope2 (slope quant2 x-span))
177 (quant2 (if (not (= (sign slope1) (sign slope2)))
180 (factor (/ (atan (abs slope1)) PI-OVER-TWO))
183 (+ (* (x quant1) (- 1 factor))
184 (* (x quant2) factor)))
186 (ly:beam::quanting grob base #f)))))
188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
191 (define-public (script-or-side-position-cross-staff g)
193 (ly:script-interface::calc-cross-staff g)
194 (ly:side-position-interface::calc-cross-staff g)))
197 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
198 ;; side-position stuff
200 (define-public (only-if-beamed g)
201 (any (lambda (x) (ly:grob? (ly:grob-object x 'beam)))
202 (ly:grob-array->list (ly:grob-object g 'side-support-elements))))
204 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
207 (define-public (stem::calc-duration-log grob)
209 (ly:event-property (event-cause grob) 'duration)))
211 (define (stem-stub::do-calculations grob)
212 (and (ly:grob-property (ly:grob-parent grob X) 'cross-staff)
213 (not (ly:grob-property (ly:grob-parent grob X) 'transparent))))
215 (define-public (stem-stub::pure-height grob beg end)
216 (if (stem-stub::do-calculations grob)
220 (define-public (stem-stub::width grob)
221 (if (stem-stub::do-calculations grob)
222 (grob::x-parent-width grob)
225 (define-public (stem-stub::extra-spacing-height grob)
226 (if (stem-stub::do-calculations grob)
227 (let* ((dad (ly:grob-parent grob X))
228 (refp (ly:grob-common-refpoint grob dad Y))
229 (stem_ph (ly:grob-pure-height dad refp 0 1000000))
230 (my_ph (ly:grob-pure-height grob refp 0 1000000))
231 ;; only account for distance if stem is on different staff than stub
232 (dist (if (grob::has-interface refp 'hara-kiri-group-spanner-interface)
234 (- (car my_ph) (car stem_ph)))))
235 (if (interval-empty? (interval-intersection stem_ph my_ph)) #f (coord-translate stem_ph dist)))
238 (define-public (note-head::calc-kievan-duration-log grob)
241 (ly:event-property (event-cause grob) 'duration))))
243 (define-public (note-head::calc-duration-log grob)
246 (ly:event-property (event-cause grob) 'duration))))
248 (define-public (dots::calc-dot-count grob)
249 (ly:duration-dot-count
250 (ly:event-property (event-cause grob) 'duration)))
252 (define-public (dots::calc-staff-position grob)
253 (let* ((head (ly:grob-parent grob Y))
254 (log (ly:grob-property head 'duration-log)))
257 ((or (not (grob::has-interface head 'rest-interface))
258 (not (integer? log))) 0)
266 ;; Kept separate from note-head::calc-glyph-name to allow use by
267 ;; markup commands \note and \note-by-number
268 (define-public (select-head-glyph style log)
269 "Select a note head glyph string based on note head style @var{style}
270 and duration-log @var{log}."
272 ;; "default" style is directly handled in note-head.cc as a
273 ;; special case (HW says, mainly for performance reasons).
274 ;; Therefore, style "default" does not appear in this case
276 ((xcircle) "2xcircle")
277 ((harmonic) "0harmonic")
278 ((harmonic-black) "2harmonic")
279 ((harmonic-mixed) (if (<= log 1) "0harmonic"
282 ;; Oops, I actually would not call this "baroque", but, for
283 ;; backwards compatibility to 1.4, this is supposed to take
284 ;; brevis, longa and maxima from the neo-mensural font and all
285 ;; other note heads from the default font. -- jr
287 (string-append (number->string log) "neomensural")
288 (number->string log)))
290 ;; Like default, but brevis is drawn with double vertical lines
292 (string-append (number->string log) "double")
293 (number->string log)))
295 (string-append (number->string log) (symbol->string style)))
298 (string-append (number->string log) "mensural")
299 (string-append (number->string log) (symbol->string style))))
302 (string-append (number->string log) "blackmensural")
303 (string-append (number->string log) (symbol->string style))))
306 (string-append (number->string log) "semimensural")
307 (string-append (number->string log) "petrucci")))
309 (string-append (number->string log) (symbol->string style)))
311 (string-append (number->string log) "kievan"))
313 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
314 (symbol->string style)
315 (string-append (number->string (max 0 log))
316 (symbol->string style))))))
318 (define-public (note-head::calc-glyph-name grob)
319 (let* ((style (ly:grob-property grob 'style))
320 (log (if (string-match "kievan*" (symbol->string style))
321 (min 3 (ly:grob-property grob 'duration-log))
322 (min 2 (ly:grob-property grob 'duration-log)))))
323 (select-head-glyph style log)))
325 (define-public (note-head::brew-ez-stencil grob)
326 (let* ((log (ly:grob-property grob 'duration-log))
327 (pitch (ly:event-property (event-cause grob) 'pitch))
328 (pitch-index (ly:pitch-notename pitch))
329 (note-names (ly:grob-property grob 'note-names))
330 (pitch-string (if (and (vector? note-names)
331 (> (vector-length note-names) pitch-index))
332 (vector-ref note-names pitch-index)
335 (+ (modulo (+ pitch-index 2) 7)
336 (char->integer #\A))))))
337 (staff-space (ly:staff-symbol-staff-space grob))
338 (line-thickness (ly:staff-symbol-line-thickness grob))
339 (stem (ly:grob-object grob 'stem))
340 (stem-thickness (* (if (ly:grob? stem)
341 (ly:grob-property stem 'thickness)
344 (radius (/ (+ staff-space line-thickness) 2))
345 (letter (markup #:center-align #:vcenter pitch-string))
346 (filled-circle (markup #:draw-circle radius 0 #t)))
348 (ly:stencil-translate-axis
349 (grob-interpret-markup
354 (make-with-color-markup white letter))
358 (make-with-color-markup white (make-draw-circle-markup
359 (- radius stem-thickness) 0 #t)))
363 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
366 (define-public (make-rhythmic-location bar-num num den)
368 bar-num (ly:make-moment num den)))
370 (define-public (rhythmic-location? a)
373 (ly:moment? (cdr a))))
375 (define-public (make-graceless-rhythmic-location loc)
376 (make-rhythmic-location
378 (ly:moment-main-numerator (rhythmic-location-measure-position loc))
379 (ly:moment-main-denominator (rhythmic-location-measure-position loc))))
381 (define-public rhythmic-location-measure-position cdr)
382 (define-public rhythmic-location-bar-number car)
384 (define-public (rhythmic-location<? a b)
386 ((< (car a) (car b)) #t)
387 ((> (car a) (car b)) #f)
389 (ly:moment<? (cdr a) (cdr b)))))
391 (define-public (rhythmic-location<=? a b)
392 (not (rhythmic-location<? b a)))
393 (define-public (rhythmic-location>=? a b)
394 (not (rhythmic-location<? a b)))
395 (define-public (rhythmic-location>? a b)
396 (rhythmic-location<? b a))
398 (define-public (rhythmic-location=? a b)
399 (and (rhythmic-location<=? a b)
400 (rhythmic-location<=? b a)))
402 (define-public (rhythmic-location->file-string a)
403 (ly:format "~a.~a.~a"
405 (ly:moment-main-numerator (cdr a))
406 (ly:moment-main-denominator (cdr a))))
408 (define-public (rhythmic-location->string a)
409 (ly:format "bar ~a ~a"
411 (ly:moment->string (cdr a))))
413 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
416 (define-public all-visible #(#t #t #t))
417 (define-public begin-of-line-invisible #(#t #t #f))
418 (define-public center-invisible #(#t #f #t))
419 (define-public end-of-line-invisible #(#f #t #t))
420 (define-public begin-of-line-visible #(#f #f #t))
421 (define-public center-visible #(#f #t #f))
422 (define-public end-of-line-visible #(#t #f #f))
423 (define-public all-invisible #(#f #f #f))
424 (define-public (inherit-x-parent-visibility grob)
425 (let ((parent (ly:grob-parent grob X)))
426 (ly:grob-property parent 'break-visibility all-invisible)))
427 (define-public (inherit-y-parent-visibility grob)
428 (let ((parent (ly:grob-parent grob X)))
429 (ly:grob-property parent 'break-visibility)))
432 (define-public spanbar-begin-of-line-invisible #(#t #f #f))
435 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
436 ;; neighbor-interface routines
439 (define-public (shift-right-at-line-begin g)
440 "Shift an item to the right, but only at the start of the line."
441 (if (and (ly:item? g)
442 (equal? (ly:item-break-dir g) RIGHT))
443 (ly:grob-translate-axis! g 3.5 X)))
445 (define-public (pure-from-neighbor-interface::extra-spacing-height-at-beginning-of-line grob)
446 (if (= 1 (ly:item-break-dir grob))
447 (pure-from-neighbor-interface::extra-spacing-height grob)
450 (define-public (pure-from-neighbor-interface::extra-spacing-height grob)
451 (let* ((height (ly:grob-pure-height grob grob 0 10000000))
452 (from-neighbors (interval-union
454 (ly:axis-group-interface::pure-height
458 (coord-operation - from-neighbors height)))
460 (define-public (pure-from-neighbor-interface::account-for-span-bar grob)
461 (let* ((esh (pure-from-neighbor-interface::extra-spacing-height grob))
462 (hsb (ly:grob-property grob 'has-span-bar))
463 (ii (interval-intersection esh (cons -1.01 1.01))))
465 (cons (car (if (and (car hsb)
466 (ly:grob-property grob 'allow-span-bar))
468 (cdr (if (cdr hsb) esh ii)))
471 (define-public (pure-from-neighbor-interface::extra-spacing-height-including-staff grob)
472 (let ((esh (pure-from-neighbor-interface::extra-spacing-height grob))
473 (to-staff (coord-operation -
476 (ly:staff-symbol-staff-radius grob))
477 (ly:grob::stencil-height grob))))
478 (interval-union esh to-staff)))
481 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
484 (define-public (tuplet-number::calc-direction grob)
485 (ly:tuplet-bracket::calc-direction (ly:grob-object grob 'bracket)))
487 (define-public (tuplet-number::calc-denominator-text grob)
488 (number->string (ly:event-property (event-cause grob) 'denominator)))
490 (define-public (tuplet-number::calc-fraction-text grob)
491 (let ((ev (event-cause grob)))
494 (ly:event-property ev 'denominator)
495 (ly:event-property ev 'numerator))))
497 ;; a formatter function, which is simply a wrapper around an existing
498 ;; tuplet formatter function. It takes the value returned by the given
499 ;; function and appends a note of given length.
500 (define-public ((tuplet-number::append-note-wrapper function note) grob)
501 (let ((txt (if function (function grob) #f)))
504 (markup txt #:fontsize -5 #:note note UP)
505 (markup #:fontsize -5 #:note note UP))))
507 ;; Print a tuplet denominator with a different number than the one derived from
508 ;; the actual tuplet fraction
509 (define-public ((tuplet-number::non-default-tuplet-denominator-text denominator)
511 (number->string (if denominator
513 (ly:event-property (event-cause grob) 'denominator))))
515 ;; Print a tuplet fraction with different numbers than the ones derived from
516 ;; the actual tuplet fraction
517 (define-public ((tuplet-number::non-default-tuplet-fraction-text
518 denominator numerator) grob)
519 (let* ((ev (event-cause grob))
520 (den (if denominator denominator (ly:event-property ev 'denominator)))
521 (num (if numerator numerator (ly:event-property ev 'numerator))))
523 (format #f "~a:~a" den num)))
525 ;; Print a tuplet fraction with note durations appended to the numerator and the
527 (define-public ((tuplet-number::fraction-with-notes
528 denominatornote numeratornote) grob)
529 (let* ((ev (event-cause grob))
530 (denominator (ly:event-property ev 'denominator))
531 (numerator (ly:event-property ev 'numerator)))
533 ((tuplet-number::non-default-fraction-with-notes
534 denominator denominatornote numerator numeratornote) grob)))
536 ;; Print a tuplet fraction with note durations appended to the numerator and the
538 (define-public ((tuplet-number::non-default-fraction-with-notes
539 denominator denominatornote numerator numeratornote) grob)
540 (let* ((ev (event-cause grob))
541 (den (if denominator denominator (ly:event-property ev 'denominator)))
542 (num (if numerator numerator (ly:event-property ev 'numerator))))
544 (make-concat-markup (list
545 (make-simple-markup (format #f "~a" den))
546 (markup #:fontsize -5 #:note denominatornote UP)
547 (make-simple-markup " : ")
548 (make-simple-markup (format #f "~a" num))
549 (markup #:fontsize -5 #:note numeratornote UP)))))
552 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
555 (define-public (color? x)
558 (apply eq? #t (map number? x))
559 (apply eq? #t (map (lambda (y) (<= 0 y 1)) x))))
561 (define-public (rgb-color r g b) (list r g b))
564 (define-public black '(0.0 0.0 0.0))
565 (define-public white '(1.0 1.0 1.0))
566 (define-public red '(1.0 0.0 0.0))
567 (define-public green '(0.0 1.0 0.0))
568 (define-public blue '(0.0 0.0 1.0))
569 (define-public cyan '(0.0 1.0 1.0))
570 (define-public magenta '(1.0 0.0 1.0))
571 (define-public yellow '(1.0 1.0 0.0))
573 (define-public grey '(0.5 0.5 0.5))
574 (define-public darkred '(0.5 0.0 0.0))
575 (define-public darkgreen '(0.0 0.5 0.0))
576 (define-public darkblue '(0.0 0.0 0.5))
577 (define-public darkcyan '(0.0 0.5 0.5))
578 (define-public darkmagenta '(0.5 0.0 0.5))
579 (define-public darkyellow '(0.5 0.5 0.0))
582 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
585 (define-public (key-signature-interface::alteration-positions
586 entry c0-position grob)
587 (let ((step (car entry))
590 (list (+ (cdr step) (* (car step) 7) c0-position))
591 (let* ((c-position (modulo c0-position 7))
594 ;; See (flat|sharp)-positions in define-grob-properties.scm
595 (ly:grob-property grob 'flat-positions '(3))
596 (ly:grob-property grob 'sharp-positions '(3))))
597 (p (list-ref positions
598 (if (< c-position (length positions))
600 (max-position (if (pair? p) (cdr p) p))
601 (min-position (if (pair? p) (car p) (- max-position 6)))
602 (first-position (+ (modulo (- (+ c-position step)
606 (define (prepend x l) (if (> x max-position)
608 (prepend (+ x 7) (cons x l))))
609 (prepend first-position '())))))
611 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
614 (define-public (numbered-footnotes int)
615 (markup #:tiny (number->string (+ 1 int))))
617 (define-public (symbol-footnotes int)
618 (define (helper symbols out idx n)
622 (string-append out (list-ref symbols idx))
625 (markup #:tiny (helper '("*" "†" "‡" "§" "¶")
628 (+ 1 (quotient int 5)))))
630 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
633 (define-public (accidental-interface::calc-alteration grob)
634 (ly:pitch-alteration (ly:event-property (event-cause grob) 'pitch)))
636 (define-public (accidental-interface::glyph-name grob)
637 (assoc-get (ly:grob-property grob 'alteration)
638 standard-alteration-glyph-name-alist))
640 (define-public cancellation-glyph-name-alist
641 '((0 . "accidentals.natural")))
643 (define-public standard-alteration-glyph-name-alist
645 ;; ordered for optimal performance.
646 (0 . "accidentals.natural")
647 (-1/2 . "accidentals.flat")
648 (1/2 . "accidentals.sharp")
650 (1 . "accidentals.doublesharp")
651 (-1 . "accidentals.flatflat")
653 (3/4 . "accidentals.sharp.slashslash.stemstemstem")
654 (1/4 . "accidentals.sharp.slashslash.stem")
655 (-1/4 . "accidentals.mirroredflat")
656 (-3/4 . "accidentals.mirroredflat.flat")))
658 ;; FIXME: standard vs default, alteration-FOO vs FOO-alteration
659 (define-public alteration-default-glyph-name-alist
660 standard-alteration-glyph-name-alist)
662 (define-public makam-alteration-glyph-name-alist
663 '((1 . "accidentals.doublesharp")
664 (8/9 . "accidentals.sharp.slashslashslash.stemstem")
665 (5/9 . "accidentals.sharp.slashslashslash.stem")
666 (4/9 . "accidentals.sharp")
667 (1/9 . "accidentals.sharp.slashslash.stem")
668 (0 . "accidentals.natural")
669 (-1/9 . "accidentals.mirroredflat")
670 (-4/9 . "accidentals.flat.slash")
671 (-5/9 . "accidentals.flat")
672 (-8/9 . "accidentals.flat.slashslash")
673 (-1 . "accidentals.flatflat")))
675 (define-public alteration-hufnagel-glyph-name-alist
676 '((-1/2 . "accidentals.hufnagelM1")
677 (0 . "accidentals.vaticana0")
678 (1/2 . "accidentals.mensural1")))
680 (define-public alteration-medicaea-glyph-name-alist
681 '((-1/2 . "accidentals.medicaeaM1")
682 (0 . "accidentals.vaticana0")
683 (1/2 . "accidentals.mensural1")))
685 (define-public alteration-vaticana-glyph-name-alist
686 '((-1/2 . "accidentals.vaticanaM1")
687 (0 . "accidentals.vaticana0")
688 (1/2 . "accidentals.mensural1")))
690 (define-public alteration-mensural-glyph-name-alist
691 '((-1/2 . "accidentals.mensuralM1")
692 (0 . "accidentals.vaticana0")
693 (1/2 . "accidentals.mensural1")))
695 (define-public alteration-kievan-glyph-name-alist
696 '((-1/2 . "accidentals.kievanM1")
697 (1/2 . "accidentals.kievan1")))
699 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
700 ;; * Pitch Trill Heads
703 (define-public (parentheses-item::calc-parenthesis-stencils grob)
704 (let* ((font (ly:grob-default-font grob))
705 (lp (ly:font-get-glyph font "accidentals.leftparen"))
706 (rp (ly:font-get-glyph font "accidentals.rightparen")))
710 (define-public (parentheses-item::calc-angled-bracket-stencils grob)
711 (let* ((parent (ly:grob-parent grob Y))
712 (y-extent (ly:grob-extent parent parent Y))
713 (half-thickness 0.05) ; should it be a property?
714 (width 0.5) ; should it be a property?
715 (angularity 1.5) ; makes angle brackets
716 (white-padding 0.1) ; should it be a property?
717 (lp (ly:stencil-aligned-to
718 (ly:stencil-aligned-to
719 (make-parenthesis-stencil y-extent
726 (interval-widen (ly:stencil-extent lp X) white-padding))
727 (rp (ly:stencil-aligned-to
728 (ly:stencil-aligned-to
729 (make-parenthesis-stencil y-extent
736 (interval-widen (ly:stencil-extent rp X) white-padding)))
737 (set! lp (ly:make-stencil (ly:stencil-expr lp)
739 (ly:stencil-extent lp Y)))
740 (set! rp (ly:make-stencil (ly:stencil-expr rp)
742 (ly:stencil-extent rp Y)))
743 (list (stencil-whiteout lp)
744 (stencil-whiteout rp))))
746 (define (parenthesize-elements grob . rest)
747 (let* ((refp (if (null? rest)
750 (elts (ly:grob-object grob 'elements))
751 (x-ext (ly:relative-group-extent elts refp X))
752 (stencils (ly:grob-property grob 'stencils))
755 (padding (ly:grob-property grob 'padding 0.1)))
758 (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
759 (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))))
762 (define-public (parentheses-item::print me)
763 (let* ((elts (ly:grob-object me 'elements))
764 (y-ref (ly:grob-common-refpoint-of-array me elts Y))
765 (x-ref (ly:grob-common-refpoint-of-array me elts X))
766 (stencil (parenthesize-elements me x-ref))
767 (elt-y-ext (ly:relative-group-extent elts y-ref Y))
768 (y-center (interval-center elt-y-ext)))
770 (ly:stencil-translate
773 (- (ly:grob-relative-coordinate me x-ref X))
774 (- y-center (ly:grob-relative-coordinate me y-ref Y))))))
778 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
781 (define-public (chain-grob-member-functions grob value . funcs)
784 (set! value (func grob value)))
790 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
793 (define-public (bend::print spanner)
795 (< (abs (- a b)) 0.01))
797 (let* ((delta-y (* 0.5 (ly:grob-property spanner 'delta-position)))
798 (left-span (ly:spanner-bound spanner LEFT))
799 (dots (if (and (grob::has-interface left-span 'note-head-interface)
800 (ly:grob? (ly:grob-object left-span 'dot)))
801 (ly:grob-object left-span 'dot) #f))
803 (right-span (ly:spanner-bound spanner RIGHT))
804 (thickness (* (ly:grob-property spanner 'thickness)
805 (ly:output-def-lookup (ly:grob-layout spanner)
807 (padding (ly:grob-property spanner 'padding 0.5))
808 (common (ly:grob-common-refpoint right-span
809 (ly:grob-common-refpoint spanner
812 (common-y (ly:grob-common-refpoint spanner left-span Y))
813 (minimum-length (ly:grob-property spanner 'minimum-length 0.5))
817 (interval-end (ly:grob-robust-relative-extent
822 (ly:grob-relative-coordinate dots common-y Y)
823 (ly:grob-relative-coordinate spanner common-y Y)))
825 (ly:grob-robust-relative-extent dots common X))
826 ;; TODO: use real infinity constant.
828 (right-x (max (- (interval-start
829 (ly:grob-robust-relative-extent right-span common X))
831 (+ left-x minimum-length)))
832 (self-x (ly:grob-relative-coordinate spanner common X))
833 (dx (- right-x left-x))
834 (exp (list 'path thickness
842 ,dx ,(* 0.66 delta-y)
847 (cons (- left-x self-x) (- right-x self-x))
848 (cons (min 0 delta-y)
852 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
855 (define-public (grace-spacing::calc-shortest-duration grob)
856 (let* ((cols (ly:grob-object grob 'columns))
859 (ly:moment-sub (ly:grob-property
860 (ly:grob-array-ref cols (1+ idx)) 'when)
862 (ly:grob-array-ref cols idx) 'when))))
864 (moment-min (lambda (x y)
867 (if (ly:moment<? x y)
873 (fold moment-min #f (map get-difference
874 (iota (1- (ly:grob-array-length cols)))))))
877 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
880 (define-public (fingering::calc-text grob)
881 (let ((event (event-cause grob)))
882 (or (ly:event-property event 'text #f)
883 (number->string (ly:event-property event 'digit) 10))))
885 (define-public (string-number::calc-text grob)
886 (let ((event (event-cause grob)))
887 (or (ly:event-property event 'text #f)
888 (number->string (ly:event-property event 'string-number) 10))))
890 (define-public (stroke-finger::calc-text grob)
891 (let ((event (event-cause grob)))
892 (or (ly:event-property event 'text #f)
893 (vector-ref (ly:grob-property grob 'digit-names)
895 (min 5 (ly:event-property event 'digit))))))))
898 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
901 (define-public (hairpin::calc-grow-direction grob)
902 (if (ly:in-event-class? (event-cause grob) 'decrescendo-event)
906 (define-public (dynamic-text-spanner::before-line-breaking grob)
907 "Monitor left bound of @code{DynamicTextSpanner} for absolute dynamics.
908 If found, ensure @code{DynamicText} does not collide with spanner text by
909 changing @code{'attach-dir} and @code{'padding}. Reads the
910 @code{'right-padding} property of @code{DynamicText} to fine tune space
911 between the two text elements."
912 (let ((left-bound (ly:spanner-bound grob LEFT)))
913 (if (grob::has-interface left-bound 'dynamic-text-interface)
914 (let* ((details (ly:grob-property grob 'bound-details))
915 (left-details (ly:assoc-get 'left details))
916 (my-padding (ly:assoc-get 'padding left-details))
917 (script-padding (ly:grob-property left-bound 'right-padding 0)))
919 (and (number? my-padding)
920 (ly:grob-set-nested-property! grob
921 '(bound-details left attach-dir)
923 (ly:grob-set-nested-property! grob
924 '(bound-details left padding)
925 (+ my-padding script-padding)))))))
928 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
931 (define-public (lyric-text::print grob)
932 "Allow interpretation of tildes as lyric tieing marks."
934 (let ((text (ly:grob-property grob 'text)))
936 (grob-interpret-markup grob (if (string? text)
937 (make-tied-lyric-markup text)
940 (define-public ((grob::calc-property-by-copy prop) grob)
941 (ly:event-property (event-cause grob) prop))
943 (define-public ((grob::calc-property-by-non-event-cause prop) grob)
944 (ly:grob-property (non-event-cause grob) prop))
947 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
950 (define-public (fret-board::calc-stencil grob)
951 (grob-interpret-markup
953 (make-fret-diagram-verbose-markup
954 (ly:grob-property grob 'dot-placement-list))))
957 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
960 (define-public (script-interface::calc-x-offset grob)
961 (ly:grob-property grob 'positioning-done)
962 (let* ((shift (ly:grob-property grob 'toward-stem-shift 0.0))
964 (ly:self-alignment-interface::centered-on-x-parent grob))
965 (note-head-grob (ly:grob-parent grob X))
966 (stem-grob (ly:grob-object note-head-grob 'stem)))
968 (+ note-head-location
969 ;; If the property 'toward-stem-shift is defined and the script
970 ;; has the same direction as the stem, move the script accordingly.
971 ;; Since scripts can also be over skips, we need to check whether
972 ;; the grob has a stem at all.
973 (if (ly:grob? stem-grob)
974 (let ((dir1 (ly:grob-property grob 'direction))
975 (dir2 (ly:grob-property stem-grob 'direction)))
976 (if (equal? dir1 dir2)
977 (let* ((common-refp (ly:grob-common-refpoint grob stem-grob X))
979 (ly:grob-relative-coordinate stem-grob common-refp X)))
980 (* shift (- stem-location note-head-location)))
985 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
988 (define-public (system-start-text::print grob)
989 (let* ((left-bound (ly:spanner-bound grob LEFT))
990 (left-mom (ly:grob-property left-bound 'when))
991 (name (if (moment<=? left-mom ZERO-MOMENT)
992 (ly:grob-property grob 'long-text)
993 (ly:grob-property grob 'text))))
995 (if (and (markup? name)
996 (!= (ly:item-break-dir left-bound) CENTER))
998 (grob-interpret-markup grob name)
999 (ly:grob-suicide! grob))))
1001 (define-public (system-start-text::calc-x-offset grob)
1002 (let* ((left-bound (ly:spanner-bound grob LEFT))
1003 (left-mom (ly:grob-property left-bound 'when))
1004 (layout (ly:grob-layout grob))
1005 (indent (ly:output-def-lookup layout
1006 (if (moment<=? left-mom ZERO-MOMENT)
1010 (system (ly:grob-system grob))
1011 (my-extent (ly:grob-extent grob system X))
1012 (elements (ly:grob-object system 'elements))
1013 (common (ly:grob-common-refpoint-of-array system elements X))
1014 (total-ext empty-interval)
1015 (align-x (ly:grob-property grob 'self-alignment-X 0))
1016 (padding (min 0 (- (interval-length my-extent) indent)))
1017 (right-padding (- padding
1018 (/ (* padding (1+ align-x)) 2))))
1020 ;; compensate for the variation in delimiter extents by
1021 ;; calculating an X-offset correction based on united extents
1022 ;; of all delimiters in this system
1023 (let unite-delims ((l (ly:grob-array-length elements)))
1025 (let ((elt (ly:grob-array-ref elements (1- l))))
1027 (if (grob::has-interface elt 'system-start-delimiter-interface)
1028 (let ((dims (ly:grob-extent elt common X)))
1029 (if (interval-sane? dims)
1030 (set! total-ext (interval-union total-ext dims)))))
1031 (unite-delims (1- l)))))
1034 (ly:side-position-interface::x-aligned-side grob)
1036 (- (interval-length total-ext)))))
1038 (define-public (system-start-text::calc-y-offset grob)
1040 (define (live-elements-list me)
1041 (let ((elements (ly:grob-object me 'elements)))
1043 (filter! grob::is-live?
1044 (ly:grob-array->list elements))))
1046 (let* ((left-bound (ly:spanner-bound grob LEFT))
1047 (live-elts (live-elements-list grob))
1048 (system (ly:grob-system grob))
1049 (extent empty-interval))
1051 (if (and (pair? live-elts)
1052 (interval-sane? (ly:grob-extent grob system Y)))
1053 (let get-extent ((lst live-elts))
1055 (let ((axis-group (car lst)))
1057 (if (and (ly:spanner? axis-group)
1058 (equal? (ly:spanner-bound axis-group LEFT)
1060 (set! extent (add-point extent
1061 (ly:grob-relative-coordinate
1062 axis-group system Y))))
1063 (get-extent (cdr lst)))))
1064 ;; no live axis group(s) for this instrument name -> remove from system
1065 (ly:grob-suicide! grob))
1068 (ly:self-alignment-interface::y-aligned-on-self grob)
1069 (interval-center extent))))
1072 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1075 (define-public (ambitus::print grob)
1076 (let ((heads (ly:grob-object grob 'note-heads)))
1078 (if (and (ly:grob-array? heads)
1079 (= (ly:grob-array-length heads) 2))
1080 (let* ((common (ly:grob-common-refpoint-of-array grob heads Y))
1081 (head-down (ly:grob-array-ref heads 0))
1082 (head-up (ly:grob-array-ref heads 1))
1083 (gap (ly:grob-property grob 'gap 0.35))
1084 (point-min (+ (interval-end (ly:grob-extent head-down common Y))
1086 (point-max (- (interval-start (ly:grob-extent head-up common Y))
1089 (if (< point-min point-max)
1090 (let* ((layout (ly:grob-layout grob))
1091 (line-thick (ly:output-def-lookup layout 'line-thickness))
1092 (blot (ly:output-def-lookup layout 'blot-diameter))
1093 (grob-thick (ly:grob-property grob 'thickness 2))
1094 (width (* line-thick grob-thick))
1095 (x-ext (symmetric-interval (/ width 2)))
1096 (y-ext (cons point-min point-max))
1097 (line (ly:round-filled-box x-ext y-ext blot))
1098 (y-coord (ly:grob-relative-coordinate grob common Y)))
1100 (ly:stencil-translate-axis line (- y-coord) Y))
1103 (ly:grob-suicide! grob)
1106 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1107 ;; laissez-vibrer tie
1109 ;; needed so we can make laissez-vibrer a pure print
1111 (define-public (laissez-vibrer::print grob)
1112 (ly:tie::print grob))