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 ;; calculates each slope of a broken beam individually
65 (define-public (beam::place-broken-parts-individually grob)
66 (ly:beam::quanting grob '(+inf.0 . -inf.0) #f))
68 ;; calculates the slope of a beam as a single unit,
69 ;; even if it is broken. this assures that the beam
70 ;; will pick up where it left off after a line break
71 (define-public (beam::align-with-broken-parts grob)
72 (ly:beam::quanting grob '(+inf.0 . -inf.0) #t))
74 ;; uses the broken beam style from edition peters combines the
75 ;; values of place-broken-parts-individually and align-with-broken-parts above,
76 ;; favoring place-broken-parts-individually when the beam naturally has a steeper
77 ;; incline and align-with-broken-parts when the beam is flat
78 (define-public (beam::slope-like-broken-parts grob)
80 (/ (- (cdr y) (car y)) (- (cdr x) (car x))))
81 (let* ((quant1 (ly:beam::quanting grob '(+inf.0 . -inf.0) #t))
82 (original (ly:grob-original grob))
83 (siblings (if (ly:grob? original)
84 (ly:spanner-broken-into original)
88 (let* ((quant2 (ly:beam::quanting grob '(+inf.0 . -inf.0) #f))
89 (x-span (ly:grob-property grob 'X-positions))
90 (slope1 (slope quant1 x-span))
91 (slope2 (slope quant2 x-span))
92 (quant2 (if (not (= (sign slope1) (sign slope2)))
95 (factor (/ (atan (abs slope1)) PI-OVER-TWO))
98 (+ (* (x quant1) (- 1 factor))
99 (* (x quant2) factor)))
101 (ly:beam::quanting grob base #f)))))
103 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
106 (define-public (script-or-side-position-cross-staff g)
108 (ly:script-interface::calc-cross-staff g)
109 (ly:side-position-interface::calc-cross-staff g)))
112 (define-public (slur::if-not-cross-staff-suicide g)
113 (let ((cs (ly:slur::calc-cross-staff g)))
120 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
123 (define-public (stem::calc-duration-log grob)
125 (ly:event-property (event-cause grob) 'duration)))
127 (define-public (stem::length grob)
128 (let* ((ss (ly:staff-symbol-staff-space grob))
129 (beg (ly:grob-property grob 'stem-begin-position))
130 (beam (ly:grob-object grob 'beam)))
132 (abs (- (ly:stem::calc-stem-end-position grob) beg))
134 (ly:programming-error
135 "stem::length called but will not be used for beamed stem.")
138 (define-public (stem::pure-length grob beg end)
139 (let* ((ss (ly:staff-symbol-staff-space grob))
140 (beg (ly:grob-pure-property grob 'stem-begin-position 0 1000)))
141 (abs (- (ly:stem::pure-calc-stem-end-position grob 0 2147483646) beg))))
143 (define (stem-stub::do-calculations grob)
144 (and (ly:grob-property (ly:grob-parent grob X) 'cross-staff)
145 (not (ly:grob-property (ly:grob-parent grob X) 'transparent))))
147 (define-public (stem-stub::pure-height grob beg end)
148 (if (stem-stub::do-calculations grob)
152 (define-public (stem-stub::width grob)
153 (if (stem-stub::do-calculations grob)
154 (grob::x-parent-width grob)
157 (define-public (stem-stub::extra-spacing-height grob)
158 (if (stem-stub::do-calculations grob)
159 (let* ((dad (ly:grob-parent grob X))
160 (refp (ly:grob-common-refpoint grob dad Y))
161 (stem_ph (ly:grob-pure-height dad refp 0 1000000))
162 (my_ph (ly:grob-pure-height grob refp 0 1000000))
163 ;; only account for distance if stem is on different staff than stub
164 (dist (if (grob::has-interface refp 'hara-kiri-group-spanner-interface)
166 (- (car my_ph) (car stem_ph)))))
167 (if (interval-empty? (interval-intersection stem_ph my_ph)) #f (coord-translate stem_ph dist)))
170 ;; FIXME: NEED TO FIND A BETTER WAY TO HANDLE KIEVAN NOTATION
171 (define-public (note-head::calc-duration-log grob)
172 (let ((style (ly:grob-property grob 'style)))
173 (if (and (symbol? style) (string-match "kievan*" (symbol->string style)))
176 (ly:event-property (event-cause grob) 'duration)))
179 (ly:event-property (event-cause grob) 'duration))))))
181 (define-public (dots::calc-dot-count grob)
182 (ly:duration-dot-count
183 (ly:event-property (event-cause grob) 'duration)))
185 (define-public (dots::calc-staff-position grob)
186 (let* ((head (ly:grob-parent grob Y))
187 (log (ly:grob-property head 'duration-log)))
190 ((or (not (grob::has-interface head 'rest-interface))
191 (not (integer? log))) 0)
199 ;; Kept separate from note-head::calc-glyph-name to allow use by
200 ;; markup commands \note and \note-by-number
201 (define-public (select-head-glyph style log)
202 "Select a note head glyph string based on note head style @var{style}
203 and duration-log @var{log}."
205 ;; "default" style is directly handled in note-head.cc as a
206 ;; special case (HW says, mainly for performance reasons).
207 ;; Therefore, style "default" does not appear in this case
209 ((xcircle) "2xcircle")
210 ((harmonic) "0harmonic")
211 ((harmonic-black) "2harmonic")
212 ((harmonic-mixed) (if (<= log 1) "0harmonic"
215 ;; Oops, I actually would not call this "baroque", but, for
216 ;; backwards compatibility to 1.4, this is supposed to take
217 ;; brevis, longa and maxima from the neo-mensural font and all
218 ;; other note heads from the default font. -- jr
220 (string-append (number->string log) "neomensural")
221 (number->string log)))
223 ;; Like default, but brevis is drawn with double vertical lines
225 (string-append (number->string log) "double")
226 (number->string log)))
228 (string-append (number->string log) (symbol->string style)))
231 (string-append (number->string log) "mensural")
232 (string-append (number->string log) (symbol->string style))))
235 (string-append (number->string log) "blackmensural")
236 (string-append (number->string log) (symbol->string style))))
239 (string-append (number->string log) "semimensural")
240 (string-append (number->string log) "petrucci")))
242 (string-append (number->string log) (symbol->string style)))
244 (string-append (number->string log) "kievan"))
246 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
247 (symbol->string style)
248 (string-append (number->string (max 0 log))
249 (symbol->string style))))))
251 (define-public (note-head::calc-glyph-name grob)
252 (let* ((style (ly:grob-property grob 'style))
253 (log (if (string-match "kievan*" (symbol->string style))
254 (min 3 (ly:grob-property grob 'duration-log))
255 (min 2 (ly:grob-property grob 'duration-log)))))
256 (select-head-glyph style log)))
258 (define-public (note-head::brew-ez-stencil grob)
259 (let* ((log (ly:grob-property grob 'duration-log))
260 (pitch (ly:event-property (event-cause grob) 'pitch))
261 (pitch-index (ly:pitch-notename pitch))
262 (note-names (ly:grob-property grob 'note-names))
263 (pitch-string (if (and (vector? note-names)
264 (> (vector-length note-names) pitch-index))
265 (vector-ref note-names pitch-index)
268 (+ (modulo (+ pitch-index 2) 7)
269 (char->integer #\A))))))
270 (staff-space (ly:staff-symbol-staff-space grob))
271 (line-thickness (ly:staff-symbol-line-thickness grob))
272 (stem (ly:grob-object grob 'stem))
273 (stem-thickness (* (if (ly:grob? stem)
274 (ly:grob-property stem 'thickness)
277 (radius (/ (+ staff-space line-thickness) 2))
278 (letter (markup #:center-align #:vcenter pitch-string))
279 (filled-circle (markup #:draw-circle radius 0 #t)))
281 (ly:stencil-translate-axis
282 (grob-interpret-markup
287 (make-with-color-markup white letter))
291 (make-with-color-markup white (make-draw-circle-markup
292 (- radius stem-thickness) 0 #t)))
296 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
299 (define-public (make-rhythmic-location bar-num num den)
301 bar-num (ly:make-moment num den)))
303 (define-public (rhythmic-location? a)
306 (ly:moment? (cdr a))))
308 (define-public (make-graceless-rhythmic-location loc)
309 (make-rhythmic-location
311 (ly:moment-main-numerator (rhythmic-location-measure-position loc))
312 (ly:moment-main-denominator (rhythmic-location-measure-position loc))))
314 (define-public rhythmic-location-measure-position cdr)
315 (define-public rhythmic-location-bar-number car)
317 (define-public (rhythmic-location<? a b)
319 ((< (car a) (car b)) #t)
320 ((> (car a) (car b)) #f)
322 (ly:moment<? (cdr a) (cdr b)))))
324 (define-public (rhythmic-location<=? a b)
325 (not (rhythmic-location<? b a)))
326 (define-public (rhythmic-location>=? a b)
327 (not (rhythmic-location<? a b)))
328 (define-public (rhythmic-location>? a b)
329 (rhythmic-location<? b a))
331 (define-public (rhythmic-location=? a b)
332 (and (rhythmic-location<=? a b)
333 (rhythmic-location<=? b a)))
335 (define-public (rhythmic-location->file-string a)
336 (ly:format "~a.~a.~a"
338 (ly:moment-main-numerator (cdr a))
339 (ly:moment-main-denominator (cdr a))))
341 (define-public (rhythmic-location->string a)
342 (ly:format "bar ~a ~a"
344 (ly:moment->string (cdr a))))
346 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
349 (define-public all-visible #(#t #t #t))
350 (define-public begin-of-line-invisible #(#t #t #f))
351 (define-public center-invisible #(#t #f #t))
352 (define-public end-of-line-invisible #(#f #t #t))
353 (define-public begin-of-line-visible #(#f #f #t))
354 (define-public center-visible #(#f #t #f))
355 (define-public end-of-line-visible #(#t #f #f))
356 (define-public all-invisible #(#f #f #f))
357 (define-public (inherit-x-parent-visibility grob)
358 (let ((parent (ly:grob-parent grob X)))
359 (ly:grob-property parent 'break-visibility all-invisible)))
360 (define-public (inherit-y-parent-visibility grob)
361 (let ((parent (ly:grob-parent grob X)))
362 (ly:grob-property parent 'break-visibility)))
365 (define-public spanbar-begin-of-line-invisible #(#t #f #f))
367 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
368 ;; neighbor-interface routines
371 (define-public (shift-right-at-line-begin g)
372 "Shift an item to the right, but only at the start of the line."
373 (if (and (ly:item? g)
374 (equal? (ly:item-break-dir g) RIGHT))
375 (ly:grob-translate-axis! g 3.5 X)))
377 (define-public (pure-from-neighbor-interface::extra-spacing-height-at-beginning-of-line grob)
378 (if (= 1 (ly:item-break-dir grob))
379 (pure-from-neighbor-interface::extra-spacing-height grob)
382 (define-public (pure-from-neighbor-interface::extra-spacing-height grob)
383 (let* ((height (ly:grob-pure-height grob grob 0 10000000))
384 (from-neighbors (interval-union
386 (ly:axis-group-interface::pure-height
390 (coord-operation - from-neighbors height)))
392 (define-public (pure-from-neighbor-interface::account-for-span-bar grob)
393 (let* ((esh (pure-from-neighbor-interface::extra-spacing-height grob))
394 (hsb (ly:grob-property grob 'has-span-bar))
395 (ii (interval-intersection esh (cons -1.01 1.01))))
397 (cons (car (if (and (car hsb)
398 (ly:grob-property grob 'allow-span-bar))
400 (cdr (if (cdr hsb) esh ii)))
403 (define-public (pure-from-neighbor-interface::extra-spacing-height-including-staff grob)
404 (let ((esh (pure-from-neighbor-interface::extra-spacing-height grob))
405 (to-staff (coord-operation -
408 (ly:staff-symbol-staff-radius grob))
409 (ly:grob::stencil-height grob))))
410 (interval-union esh to-staff)))
413 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
416 (define-public (tuplet-number::calc-direction grob)
417 (ly:tuplet-bracket::calc-direction (ly:grob-object grob 'bracket)))
419 (define-public (tuplet-number::calc-denominator-text grob)
420 (number->string (ly:event-property (event-cause grob) 'denominator)))
422 (define-public (tuplet-number::calc-fraction-text grob)
423 (let ((ev (event-cause grob)))
426 (ly:event-property ev 'denominator)
427 (ly:event-property ev 'numerator))))
429 ;; a formatter function, which is simply a wrapper around an existing
430 ;; tuplet formatter function. It takes the value returned by the given
431 ;; function and appends a note of given length.
432 (define-public ((tuplet-number::append-note-wrapper function note) grob)
433 (let ((txt (if function (function grob) #f)))
436 (markup txt #:fontsize -5 #:note note UP)
437 (markup #:fontsize -5 #:note note UP))))
439 ;; Print a tuplet denominator with a different number than the one derived from
440 ;; the actual tuplet fraction
441 (define-public ((tuplet-number::non-default-tuplet-denominator-text denominator)
443 (number->string (if denominator
445 (ly:event-property (event-cause grob) 'denominator))))
447 ;; Print a tuplet fraction with different numbers than the ones derived from
448 ;; the actual tuplet fraction
449 (define-public ((tuplet-number::non-default-tuplet-fraction-text
450 denominator numerator) grob)
451 (let* ((ev (event-cause grob))
452 (den (if denominator denominator (ly:event-property ev 'denominator)))
453 (num (if numerator numerator (ly:event-property ev 'numerator))))
455 (format #f "~a:~a" den num)))
457 ;; Print a tuplet fraction with note durations appended to the numerator and the
459 (define-public ((tuplet-number::fraction-with-notes
460 denominatornote numeratornote) grob)
461 (let* ((ev (event-cause grob))
462 (denominator (ly:event-property ev 'denominator))
463 (numerator (ly:event-property ev 'numerator)))
465 ((tuplet-number::non-default-fraction-with-notes
466 denominator denominatornote numerator numeratornote) grob)))
468 ;; Print a tuplet fraction with note durations appended to the numerator and the
470 (define-public ((tuplet-number::non-default-fraction-with-notes
471 denominator denominatornote numerator numeratornote) grob)
472 (let* ((ev (event-cause grob))
473 (den (if denominator denominator (ly:event-property ev 'denominator)))
474 (num (if numerator numerator (ly:event-property ev 'numerator))))
476 (make-concat-markup (list
477 (make-simple-markup (format #f "~a" den))
478 (markup #:fontsize -5 #:note denominatornote UP)
479 (make-simple-markup " : ")
480 (make-simple-markup (format #f "~a" num))
481 (markup #:fontsize -5 #:note numeratornote UP)))))
484 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
487 (define-public (color? x)
490 (apply eq? #t (map number? x))
491 (apply eq? #t (map (lambda (y) (<= 0 y 1)) x))))
493 (define-public (rgb-color r g b) (list r g b))
496 (define-public black '(0.0 0.0 0.0))
497 (define-public white '(1.0 1.0 1.0))
498 (define-public red '(1.0 0.0 0.0))
499 (define-public green '(0.0 1.0 0.0))
500 (define-public blue '(0.0 0.0 1.0))
501 (define-public cyan '(0.0 1.0 1.0))
502 (define-public magenta '(1.0 0.0 1.0))
503 (define-public yellow '(1.0 1.0 0.0))
505 (define-public grey '(0.5 0.5 0.5))
506 (define-public darkred '(0.5 0.0 0.0))
507 (define-public darkgreen '(0.0 0.5 0.0))
508 (define-public darkblue '(0.0 0.0 0.5))
509 (define-public darkcyan '(0.0 0.5 0.5))
510 (define-public darkmagenta '(0.5 0.0 0.5))
511 (define-public darkyellow '(0.5 0.5 0.0))
514 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
517 (define-public (key-signature-interface::alteration-positions
518 entry c0-position grob)
519 (let ((step (car entry))
522 (list (+ (cdr step) (* (car step) 7) c0-position))
523 (let* ((c-position (modulo c0-position 7))
526 ;; See (flat|sharp)-positions in define-grob-properties.scm
527 (ly:grob-property grob 'flat-positions '(3))
528 (ly:grob-property grob 'sharp-positions '(3))))
529 (p (list-ref positions
530 (if (< c-position (length positions))
532 (max-position (if (pair? p) (cdr p) p))
533 (min-position (if (pair? p) (car p) (- max-position 6)))
534 (first-position (+ (modulo (- (+ c-position step)
538 (define (prepend x l) (if (> x max-position)
540 (prepend (+ x 7) (cons x l))))
541 (prepend first-position '())))))
543 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
546 (define-public (numbered-footnotes int)
547 (markup #:tiny (number->string (+ 1 int))))
549 (define-public (symbol-footnotes int)
550 (define (helper symbols out idx n)
554 (string-append out (list-ref symbols idx))
557 (markup #:tiny (helper '("*" "†" "‡" "§" "¶")
560 (+ 1 (quotient int 5)))))
562 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
565 (define-public (accidental-interface::calc-alteration grob)
566 (ly:pitch-alteration (ly:event-property (event-cause grob) 'pitch)))
568 (define-public (accidental-interface::glyph-name grob)
569 (assoc-get (ly:grob-property grob 'alteration)
570 standard-alteration-glyph-name-alist))
572 (define-public cancellation-glyph-name-alist
573 '((0 . "accidentals.natural")))
575 (define-public standard-alteration-glyph-name-alist
577 ;; ordered for optimal performance.
578 (0 . "accidentals.natural")
579 (-1/2 . "accidentals.flat")
580 (1/2 . "accidentals.sharp")
582 (1 . "accidentals.doublesharp")
583 (-1 . "accidentals.flatflat")
585 (3/4 . "accidentals.sharp.slashslash.stemstemstem")
586 (1/4 . "accidentals.sharp.slashslash.stem")
587 (-1/4 . "accidentals.mirroredflat")
588 (-3/4 . "accidentals.mirroredflat.flat")))
590 ;; FIXME: standard vs default, alteration-FOO vs FOO-alteration
591 (define-public alteration-default-glyph-name-alist
592 standard-alteration-glyph-name-alist)
594 (define-public makam-alteration-glyph-name-alist
595 '((1 . "accidentals.doublesharp")
596 (8/9 . "accidentals.sharp.slashslashslash.stemstem")
597 (5/9 . "accidentals.sharp.slashslashslash.stem")
598 (4/9 . "accidentals.sharp")
599 (1/9 . "accidentals.sharp.slashslash.stem")
600 (0 . "accidentals.natural")
601 (-1/9 . "accidentals.mirroredflat")
602 (-4/9 . "accidentals.flat.slash")
603 (-5/9 . "accidentals.flat")
604 (-8/9 . "accidentals.flat.slashslash")
605 (-1 . "accidentals.flatflat")))
607 (define-public alteration-hufnagel-glyph-name-alist
608 '((-1/2 . "accidentals.hufnagelM1")
609 (0 . "accidentals.vaticana0")
610 (1/2 . "accidentals.mensural1")))
612 (define-public alteration-medicaea-glyph-name-alist
613 '((-1/2 . "accidentals.medicaeaM1")
614 (0 . "accidentals.vaticana0")
615 (1/2 . "accidentals.mensural1")))
617 (define-public alteration-vaticana-glyph-name-alist
618 '((-1/2 . "accidentals.vaticanaM1")
619 (0 . "accidentals.vaticana0")
620 (1/2 . "accidentals.mensural1")))
622 (define-public alteration-mensural-glyph-name-alist
623 '((-1/2 . "accidentals.mensuralM1")
624 (0 . "accidentals.vaticana0")
625 (1/2 . "accidentals.mensural1")))
627 (define-public alteration-kievan-glyph-name-alist
628 '((-1/2 . "accidentals.kievanM1")
629 (1/2 . "accidentals.kievan1")))
631 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
632 ;; * Pitch Trill Heads
635 (define-public (parentheses-item::calc-parenthesis-stencils grob)
636 (let* ((font (ly:grob-default-font grob))
637 (lp (ly:font-get-glyph font "accidentals.leftparen"))
638 (rp (ly:font-get-glyph font "accidentals.rightparen")))
642 (define-public (parentheses-item::calc-angled-bracket-stencils grob)
643 (let* ((parent (ly:grob-parent grob Y))
644 (y-extent (ly:grob-extent parent parent Y))
645 (half-thickness 0.05) ; should it be a property?
646 (width 0.5) ; should it be a property?
647 (angularity 1.5) ; makes angle brackets
648 (white-padding 0.1) ; should it be a property?
649 (lp (ly:stencil-aligned-to
650 (ly:stencil-aligned-to
651 (make-parenthesis-stencil y-extent
658 (interval-widen (ly:stencil-extent lp X) white-padding))
659 (rp (ly:stencil-aligned-to
660 (ly:stencil-aligned-to
661 (make-parenthesis-stencil y-extent
668 (interval-widen (ly:stencil-extent rp X) white-padding)))
669 (set! lp (ly:make-stencil (ly:stencil-expr lp)
671 (ly:stencil-extent lp Y)))
672 (set! rp (ly:make-stencil (ly:stencil-expr rp)
674 (ly:stencil-extent rp Y)))
675 (list (stencil-whiteout lp)
676 (stencil-whiteout rp))))
678 (define (parenthesize-elements grob . rest)
679 (let* ((refp (if (null? rest)
682 (elts (ly:grob-object grob 'elements))
683 (x-ext (ly:relative-group-extent elts refp X))
684 (stencils (ly:grob-property grob 'stencils))
687 (padding (ly:grob-property grob 'padding 0.1)))
690 (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
691 (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))))
694 (define-public (parentheses-item::print me)
695 (let* ((elts (ly:grob-object me 'elements))
696 (y-ref (ly:grob-common-refpoint-of-array me elts Y))
697 (x-ref (ly:grob-common-refpoint-of-array me elts X))
698 (stencil (parenthesize-elements me x-ref))
699 (elt-y-ext (ly:relative-group-extent elts y-ref Y))
700 (y-center (interval-center elt-y-ext)))
702 (ly:stencil-translate
705 (- (ly:grob-relative-coordinate me x-ref X))
706 (- y-center (ly:grob-relative-coordinate me y-ref Y))))))
710 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
713 (define-public (chain-grob-member-functions grob value . funcs)
716 (set! value (func grob value)))
722 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
725 (define-public (bend::print spanner)
727 (< (abs (- a b)) 0.01))
729 (let* ((delta-y (* 0.5 (ly:grob-property spanner 'delta-position)))
730 (left-span (ly:spanner-bound spanner LEFT))
731 (dots (if (and (grob::has-interface left-span 'note-head-interface)
732 (ly:grob? (ly:grob-object left-span 'dot)))
733 (ly:grob-object left-span 'dot) #f))
735 (right-span (ly:spanner-bound spanner RIGHT))
736 (thickness (* (ly:grob-property spanner 'thickness)
737 (ly:output-def-lookup (ly:grob-layout spanner)
739 (padding (ly:grob-property spanner 'padding 0.5))
740 (common (ly:grob-common-refpoint right-span
741 (ly:grob-common-refpoint spanner
744 (common-y (ly:grob-common-refpoint spanner left-span Y))
745 (minimum-length (ly:grob-property spanner 'minimum-length 0.5))
749 (interval-end (ly:grob-robust-relative-extent
754 (ly:grob-relative-coordinate dots common-y Y)
755 (ly:grob-relative-coordinate spanner common-y Y)))
757 (ly:grob-robust-relative-extent dots common X))
758 ;; TODO: use real infinity constant.
760 (right-x (max (- (interval-start
761 (ly:grob-robust-relative-extent right-span common X))
763 (+ left-x minimum-length)))
764 (self-x (ly:grob-relative-coordinate spanner common X))
765 (dx (- right-x left-x))
766 (exp (list 'path thickness
774 ,dx ,(* 0.66 delta-y)
779 (cons (- left-x self-x) (- right-x self-x))
780 (cons (min 0 delta-y)
784 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
787 (define-public (grace-spacing::calc-shortest-duration grob)
788 (let* ((cols (ly:grob-object grob 'columns))
791 (ly:moment-sub (ly:grob-property
792 (ly:grob-array-ref cols (1+ idx)) 'when)
794 (ly:grob-array-ref cols idx) 'when))))
796 (moment-min (lambda (x y)
799 (if (ly:moment<? x y)
805 (fold moment-min #f (map get-difference
806 (iota (1- (ly:grob-array-length cols)))))))
809 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
812 (define-public (fingering::calc-text grob)
813 (let* ((event (event-cause grob))
814 (digit (ly:event-property event 'digit)))
816 (number->string digit 10)))
818 (define-public (string-number::calc-text grob)
819 (let ((digit (ly:event-property (event-cause grob) 'string-number)))
821 (number->string digit 10)))
823 (define-public (stroke-finger::calc-text grob)
824 (let* ((digit (ly:event-property (event-cause grob) 'digit))
825 (text (ly:event-property (event-cause grob) 'text)))
829 (vector-ref (ly:grob-property grob 'digit-names)
830 (1- (max (min 5 digit) 1))))))
833 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
836 (define-public (hairpin::calc-grow-direction grob)
837 (if (ly:in-event-class? (event-cause grob) 'decrescendo-event)
841 (define-public (dynamic-text-spanner::before-line-breaking grob)
842 "Monitor left bound of @code{DynamicTextSpanner} for absolute dynamics.
843 If found, ensure @code{DynamicText} does not collide with spanner text by
844 changing @code{'attach-dir} and @code{'padding}. Reads the
845 @code{'right-padding} property of @code{DynamicText} to fine tune space
846 between the two text elements."
847 (let ((left-bound (ly:spanner-bound grob LEFT)))
848 (if (grob::has-interface left-bound 'dynamic-text-interface)
849 (let* ((details (ly:grob-property grob 'bound-details))
850 (left-details (ly:assoc-get 'left details))
851 (my-padding (ly:assoc-get 'padding left-details))
852 (script-padding (ly:grob-property left-bound 'right-padding 0)))
854 (and (number? my-padding)
855 (ly:grob-set-nested-property! grob
856 '(bound-details left attach-dir)
858 (ly:grob-set-nested-property! grob
859 '(bound-details left padding)
860 (+ my-padding script-padding)))))))
863 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
866 (define-public (lyric-text::print grob)
867 "Allow interpretation of tildes as lyric tieing marks."
869 (let ((text (ly:grob-property grob 'text)))
871 (grob-interpret-markup grob (if (string? text)
872 (make-tied-lyric-markup text)
875 (define-public ((grob::calc-property-by-copy prop) grob)
876 (ly:event-property (event-cause grob) prop))
879 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
882 (define-public (fret-board::calc-stencil grob)
883 (grob-interpret-markup
885 (make-fret-diagram-verbose-markup
886 (ly:grob-property grob 'dot-placement-list))))
889 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
892 (define-public (script-interface::calc-x-offset grob)
893 (ly:grob-property grob 'positioning-done)
894 (let* ((shift (ly:grob-property grob 'toward-stem-shift 0.0))
896 (ly:self-alignment-interface::centered-on-x-parent grob))
897 (note-head-grob (ly:grob-parent grob X))
898 (stem-grob (ly:grob-object note-head-grob 'stem)))
900 (+ note-head-location
901 ;; If the property 'toward-stem-shift is defined and the script
902 ;; has the same direction as the stem, move the script accordingly.
903 ;; Since scripts can also be over skips, we need to check whether
904 ;; the grob has a stem at all.
905 (if (ly:grob? stem-grob)
906 (let ((dir1 (ly:grob-property grob 'direction))
907 (dir2 (ly:grob-property stem-grob 'direction)))
908 (if (equal? dir1 dir2)
909 (let* ((common-refp (ly:grob-common-refpoint grob stem-grob X))
911 (ly:grob-relative-coordinate stem-grob common-refp X)))
912 (* shift (- stem-location note-head-location)))
917 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
920 (define-public (system-start-text::print grob)
921 (let* ((left-bound (ly:spanner-bound grob LEFT))
922 (left-mom (ly:grob-property left-bound 'when))
923 (name (if (moment<=? left-mom ZERO-MOMENT)
924 (ly:grob-property grob 'long-text)
925 (ly:grob-property grob 'text))))
927 (if (and (markup? name)
928 (!= (ly:item-break-dir left-bound) CENTER))
930 (grob-interpret-markup grob name)
931 (ly:grob-suicide! grob))))
933 (define-public (system-start-text::calc-x-offset grob)
934 (let* ((left-bound (ly:spanner-bound grob LEFT))
935 (left-mom (ly:grob-property left-bound 'when))
936 (layout (ly:grob-layout grob))
937 (indent (ly:output-def-lookup layout
938 (if (moment<=? left-mom ZERO-MOMENT)
942 (system (ly:grob-system grob))
943 (my-extent (ly:grob-extent grob system X))
944 (elements (ly:grob-object system 'elements))
945 (common (ly:grob-common-refpoint-of-array system elements X))
946 (total-ext empty-interval)
947 (align-x (ly:grob-property grob 'self-alignment-X 0))
948 (padding (min 0 (- (interval-length my-extent) indent)))
949 (right-padding (- padding
950 (/ (* padding (1+ align-x)) 2))))
952 ;; compensate for the variation in delimiter extents by
953 ;; calculating an X-offset correction based on united extents
954 ;; of all delimiters in this system
955 (let unite-delims ((l (ly:grob-array-length elements)))
957 (let ((elt (ly:grob-array-ref elements (1- l))))
959 (if (grob::has-interface elt 'system-start-delimiter-interface)
960 (let ((dims (ly:grob-extent elt common X)))
961 (if (interval-sane? dims)
962 (set! total-ext (interval-union total-ext dims)))))
963 (unite-delims (1- l)))))
966 (ly:side-position-interface::x-aligned-side grob)
968 (- (interval-length total-ext)))))
970 (define-public (system-start-text::calc-y-offset grob)
972 (define (live-elements-list me)
973 (let ((elements (ly:grob-object me 'elements)))
975 (filter! grob::is-live?
976 (ly:grob-array->list elements))))
978 (let* ((left-bound (ly:spanner-bound grob LEFT))
979 (live-elts (live-elements-list grob))
980 (system (ly:grob-system grob))
981 (extent empty-interval))
983 (if (and (pair? live-elts)
984 (interval-sane? (ly:grob-extent grob system Y)))
985 (let get-extent ((lst live-elts))
987 (let ((axis-group (car lst)))
989 (if (and (ly:spanner? axis-group)
990 (equal? (ly:spanner-bound axis-group LEFT)
992 (set! extent (add-point extent
993 (ly:grob-relative-coordinate
994 axis-group system Y))))
995 (get-extent (cdr lst)))))
996 ;; no live axis group(s) for this instrument name -> remove from system
997 (ly:grob-suicide! grob))
1000 (ly:self-alignment-interface::y-aligned-on-self grob)
1001 (interval-center extent))))
1004 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1007 (define-public (ambitus::print grob)
1008 (let ((heads (ly:grob-object grob 'note-heads)))
1010 (if (and (ly:grob-array? heads)
1011 (= (ly:grob-array-length heads) 2))
1012 (let* ((common (ly:grob-common-refpoint-of-array grob heads Y))
1013 (head-down (ly:grob-array-ref heads 0))
1014 (head-up (ly:grob-array-ref heads 1))
1015 (gap (ly:grob-property grob 'gap 0.35))
1016 (point-min (+ (interval-end (ly:grob-extent head-down common Y))
1018 (point-max (- (interval-start (ly:grob-extent head-up common Y))
1021 (if (< point-min point-max)
1022 (let* ((layout (ly:grob-layout grob))
1023 (line-thick (ly:output-def-lookup layout 'line-thickness))
1024 (blot (ly:output-def-lookup layout 'blot-diameter))
1025 (grob-thick (ly:grob-property grob 'thickness 2))
1026 (width (* line-thick grob-thick))
1027 (x-ext (symmetric-interval (/ width 2)))
1028 (y-ext (cons point-min point-max))
1029 (line (ly:round-filled-box x-ext y-ext blot))
1030 (y-coord (ly:grob-relative-coordinate grob common Y)))
1032 (ly:stencil-translate-axis line (- y-coord) Y))
1035 (ly:grob-suicide! grob)
1038 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1039 ;; laissez-vibrer tie
1041 ;; needed so we can make laissez-vibrer a pure print
1043 (define-public (laissez-vibrer::print grob)
1044 (ly:tie::print grob))