1 ;;;; output-lib.scm -- implement Scheme output helper functions
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2009 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@xs4all.nl>
9 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12 (define-public (grob::has-interface grob iface)
13 (memq iface (ly:grob-interfaces grob)))
15 (define-public (grob::is-live? grob)
16 (pair? (ly:grob-basic-properties grob)))
18 (define-public (make-stencil-boxer thickness padding callback)
20 "Return function that adds a box around the grob passed as argument."
22 (box-stencil (callback grob) thickness padding)))
24 (define-public (make-stencil-circler thickness padding callback)
25 "Return function that adds a circle around the grob passed as argument."
27 (lambda (grob) (circle-stencil (callback grob) thickness padding)))
29 (define-public (print-circled-text-callback grob)
30 (grob-interpret-markup grob (make-circle-markup
31 (ly:grob-property grob 'text))))
33 (define-public (event-cause grob)
34 (let ((cause (ly:grob-property grob 'cause)))
37 ((ly:stream-event? cause) cause)
38 ((ly:grob? cause) (event-cause cause))
41 (define-public (grob-interpret-markup grob text)
42 (let* ((layout (ly:grob-layout grob))
43 (defs (ly:output-def-lookup layout 'text-font-defaults))
44 (props (ly:grob-alist-chain grob defs)))
46 (ly:text-interface::interpret-markup layout props text)))
49 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
52 (define-public (stem::calc-duration-log grob)
54 (ly:event-property (event-cause grob) 'duration)))
56 (define-public (note-head::calc-duration-log grob)
59 (ly:event-property (event-cause grob) 'duration))))
61 (define-public (dots::calc-dot-count grob)
62 (ly:duration-dot-count
63 (ly:event-property (event-cause grob) 'duration)))
65 (define-public (dots::calc-staff-position grob)
66 (let* ((head (ly:grob-parent grob Y))
67 (log (ly:grob-property head 'duration-log)))
70 ((or (not (grob::has-interface head 'rest-interface))
71 (not (integer? log))) 0)
80 (define-public (note-head::calc-glyph-name grob)
81 (let ((style (ly:grob-property grob 'style))
82 (log (min 2 (ly:grob-property grob 'duration-log))))
85 ;; "default" style is directly handled in note-head.cc as a
86 ;; special case (HW says, mainly for performance reasons).
87 ;; Therefore, style "default" does not appear in this case
89 ((xcircle) "2xcircle")
90 ((harmonic) "0harmonic")
91 ((harmonic-black) "2harmonic")
92 ((harmonic-mixed) (if (<= log 1) "0harmonic"
95 ;; Oops, I actually would not call this "baroque", but, for
96 ;; backwards compatibility to 1.4, this is supposed to take
97 ;; brevis, longa and maxima from the neo-mensural font and all
98 ;; other note heads from the default font. -- jr
100 (string-append (number->string log) "neomensural")
101 (number->string log)))
103 ;; Like default, but brevis is drawn with double vertical lines
105 (string-append (number->string log) "double")
106 (number->string log)))
108 (string-append (number->string log) (symbol->string style)))
111 (string-append (number->string log) "mensural")
112 (string-append (number->string log) (symbol->string style))))
114 (string-append (number->string log) (symbol->string style)))
116 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
117 (symbol->string style)
118 (string-append (number->string (max 0 log))
119 (symbol->string style)))))))
121 (define-public (note-head::brew-ez-stencil grob)
122 (let* ((log (ly:grob-property grob 'duration-log))
123 (pitch (ly:event-property (event-cause grob) 'pitch))
124 (pitch-index (ly:pitch-notename pitch))
125 (note-names (ly:grob-property grob 'note-names))
126 (pitch-string (if (vector? note-names)
127 (vector-ref note-names pitch-index)
130 (+ (modulo (+ pitch-index 2) 7)
131 (char->integer #\A))))))
132 (staff-space (ly:staff-symbol-staff-space grob))
133 (line-thickness (ly:staff-symbol-line-thickness grob))
134 (stem (ly:grob-object grob 'stem))
135 (stem-thickness (* (if (ly:grob? stem)
136 (ly:grob-property stem 'thickness)
139 (radius (/ (+ staff-space line-thickness) 2))
140 (letter (markup #:center-align #:vcenter pitch-string))
141 (filled-circle (markup #:draw-circle radius 0 #t)))
143 (grob-interpret-markup
148 (make-with-color-markup white letter))
152 (make-with-color-markup white (make-draw-circle-markup
153 (- radius stem-thickness) 0 #t)))
156 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
159 (define-public all-visible #(#t #t #t))
160 (define-public begin-of-line-invisible #(#t #t #f))
161 (define-public center-invisible #(#t #f #t))
162 (define-public end-of-line-invisible #(#f #t #t))
163 (define-public begin-of-line-visible #(#f #f #t))
164 (define-public center-visible #(#f #t #f))
165 (define-public end-of-line-visible #(#t #f #f))
166 (define-public all-invisible #(#f #f #f))
168 (define-public spanbar-begin-of-line-invisible #(#t #f #f))
171 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
175 ;; How should a bar line behave at a break?
176 (define bar-glyph-alist
177 '((":|:" . (":|" . "|:"))
178 (":|.|:" . (":|" . "|:"))
179 (":|.:" . (":|" . "|:"))
180 ("||:" . ("||" . "|:"))
181 ("dashed" . ("dashed" . '()))
183 ("||:" . ("||" . "|:"))
185 ("|:" . ("|" . "|:"))
188 ;; hmm... should we end with a bar line here?
189 (".|" . ("|" . ".|"))
192 (".|." . (".|." . ()))
193 ("|.|" . ("|.|" . ()))
198 ("empty" . (() . ()))
199 ("brace" . (() . "brace"))
200 ("bracket" . (() . "bracket"))))
202 (define-public (bar-line::calc-glyph-name grob)
203 (let* ((glyph (ly:grob-property grob 'glyph))
204 (dir (ly:item-break-dir grob))
205 (result (assoc-get glyph bar-glyph-alist))
206 (glyph-name (if (= dir CENTER)
209 (string? (index-cell result dir)))
210 (index-cell result dir)
214 (define-public (bar-line::calc-break-visibility grob)
215 (let* ((glyph (ly:grob-property grob 'glyph))
216 (result (assoc-get glyph bar-glyph-alist)))
219 (vector (string? (car result)) #t (string? (cdr result)))
222 (define-public (shift-right-at-line-begin g)
223 "Shift an item to the right, but only at the start of the line."
224 (if (and (ly:item? g)
225 (equal? (ly:item-break-dir g) RIGHT))
226 (ly:grob-translate-axis! g 3.5 X)))
229 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
232 (define-public (tuplet-number::calc-denominator-text grob)
233 (number->string (ly:event-property (event-cause grob) 'denominator)))
235 (define-public (tuplet-number::calc-fraction-text grob)
236 (let ((ev (event-cause grob)))
239 (ly:event-property ev 'denominator)
240 (ly:event-property ev 'numerator))))
242 ;; a formatter function, which is simply a wrapper around an existing
243 ;; tuplet formatter function. It takes the value returned by the given
244 ;; function and appends a note of given length.
245 (define-public ((tuplet-number::append-note-wrapper function note) grob)
246 (let ((txt (if function (function grob) #f)))
249 (markup txt #:fontsize -5 #:note note UP)
250 (markup #:fontsize -5 #:note note UP))))
252 ;; Print a tuplet denominator with a different number than the one derived from
253 ;; the actual tuplet fraction
254 (define-public ((tuplet-number::non-default-tuplet-denominator-text denominator)
256 (number->string (if denominator
258 (ly:event-property (event-cause grob) 'denominator))))
260 ;; Print a tuplet fraction with different numbers than the ones derived from
261 ;; the actual tuplet fraction
262 (define-public ((tuplet-number::non-default-tuplet-fraction-text
263 denominator numerator) grob)
264 (let* ((ev (event-cause grob))
265 (den (if denominator denominator (ly:event-property ev 'denominator)))
266 (num (if numerator numerator (ly:event-property ev 'numerator))))
268 (format "~a:~a" den num)))
270 ;; Print a tuplet fraction with note durations appended to the numerator and the
272 (define-public ((tuplet-number::fraction-with-notes
273 denominatornote numeratornote) grob)
274 (let* ((ev (event-cause grob))
275 (denominator (ly:event-property ev 'denominator))
276 (numerator (ly:event-property ev 'numerator)))
278 ((tuplet-number::non-default-fraction-with-notes
279 denominator denominatornote numerator numeratornote) grob)))
281 ;; Print a tuplet fraction with note durations appended to the numerator and the
283 (define-public ((tuplet-number::non-default-fraction-with-notes
284 denominator denominatornote numerator numeratornote) grob)
285 (let* ((ev (event-cause grob))
286 (den (if denominator denominator (ly:event-property ev 'denominator)))
287 (num (if numerator numerator (ly:event-property ev 'numerator))))
289 (make-concat-markup (list
290 (make-simple-markup (format "~a" den))
291 (markup #:fontsize -5 #:note denominatornote UP)
292 (make-simple-markup " : ")
293 (make-simple-markup (format "~a" num))
294 (markup #:fontsize -5 #:note numeratornote UP)))))
297 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
300 (define-public color? list?)
301 (define-public (rgb-color r g b) (list r g b))
304 (define-public black '(0.0 0.0 0.0))
305 (define-public white '(1.0 1.0 1.0))
306 (define-public red '(1.0 0.0 0.0))
307 (define-public green '(0.0 1.0 0.0))
308 (define-public blue '(0.0 0.0 1.0))
309 (define-public cyan '(0.0 1.0 1.0))
310 (define-public magenta '(1.0 0.0 1.0))
311 (define-public yellow '(1.0 1.0 0.0))
313 (define-public grey '(0.5 0.5 0.5))
314 (define-public darkred '(0.5 0.0 0.0))
315 (define-public darkgreen '(0.0 0.5 0.0))
316 (define-public darkblue '(0.0 0.0 0.5))
317 (define-public darkcyan '(0.0 0.5 0.5))
318 (define-public darkmagenta '(0.5 0.0 0.5))
319 (define-public darkyellow '(0.5 0.5 0.0))
322 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
325 (define-public (key-signature-interface::alteration-position step alter
327 ;; TODO: memoize - this is mostly constant.
329 ;; fes, ges, as and bes typeset in lower octave
330 (define FLAT_TOP_PITCH 2)
332 ;; ais and bis typeset in lower octave
333 (define SHARP_TOP_PITCH 4)
336 (+ (cdr step) (* (car step) 7) c0-position)
337 (let* ((from-bottom-pos (modulo (+ 4 49 c0-position) 7))
339 (c0 (- from-bottom-pos 4)))
343 (or (> p FLAT_TOP_PITCH) (> (+ p c0) 4)) (> (+ p c0) 1))
345 (or (> p SHARP_TOP_PITCH) (> (+ p c0) 5)) (> (+ p c0) 2)))
347 ;; Typeset below c_position
350 ;; Provide for the four cases in which there's a glitch
351 ;; it's a hack, but probably not worth
352 ;; the effort of finding a nicer solution.
355 ((and (= c0 2) (= p 3) (> alter 0))
357 ((and (= c0 -3) (= p -1) (> alter 0))
359 ((and (= c0 -4) (= p -1) (< alter 0))
361 ((and (= c0 -2) (= p -3) (< alter 0))
367 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
370 (define-public (accidental-interface::calc-alteration grob)
371 (ly:pitch-alteration (ly:event-property (event-cause grob) 'pitch)))
373 (define-public cancellation-glyph-name-alist
374 '((0 . "accidentals.natural")))
376 (define-public standard-alteration-glyph-name-alist
378 ;; ordered for optimal performance.
379 (0 . "accidentals.natural")
380 (-1/2 . "accidentals.flat")
381 (1/2 . "accidentals.sharp")
383 (1 . "accidentals.doublesharp")
384 (-1 . "accidentals.flatflat")
386 (3/4 . "accidentals.sharp.slashslash.stemstemstem")
387 (1/4 . "accidentals.sharp.slashslash.stem")
388 (-1/4 . "accidentals.mirroredflat")
389 (-3/4 . "accidentals.mirroredflat.flat")))
391 ;; FIXME: standard vs default, alteration-FOO vs FOO-alteration
392 (define-public alteration-default-glyph-name-alist
393 standard-alteration-glyph-name-alist)
395 (define-public makam-alteration-glyph-name-alist
396 '((1 . "accidentals.doublesharp")
397 (8/9 . "accidentals.sharp.slashslashslash.stemstem")
398 (5/9 . "accidentals.sharp.slashslashslash.stem")
399 (4/9 . "accidentals.sharp")
400 (1/9 . "accidentals.sharp.slashslash.stem")
401 (0 . "accidentals.natural")
402 (-1/9 . "accidentals.mirroredflat")
403 (-4/9 . "accidentals.flat.slash")
404 (-5/9 . "accidentals.flat")
405 (-8/9 . "accidentals.flat.slashslash")
406 (-1 . "accidentals.flatflat")))
408 (define-public alteration-hufnagel-glyph-name-alist
409 '((-1/2 . "accidentals.hufnagelM1")
410 (0 . "accidentals.vaticana0")
411 (1/2 . "accidentals.mensural1")))
413 (define-public alteration-medicaea-glyph-name-alist
414 '((-1/2 . "accidentals.medicaeaM1")
415 (0 . "accidentals.vaticana0")
416 (1/2 . "accidentals.mensural1")))
418 (define-public alteration-vaticana-glyph-name-alist
419 '((-1/2 . "accidentals.vaticanaM1")
420 (0 . "accidentals.vaticana0")
421 (1/2 . "accidentals.mensural1")))
423 (define-public alteration-mensural-glyph-name-alist
424 '((-1/2 . "accidentals.mensuralM1")
425 (0 . "accidentals.vaticana0")
426 (1/2 . "accidentals.mensural1")))
429 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
430 ;; * Pitch Trill Heads
433 (define-public (parentheses-item::calc-parenthesis-stencils grob)
434 (let* ((font (ly:grob-default-font grob))
435 (lp (ly:font-get-glyph font "accidentals.leftparen"))
436 (rp (ly:font-get-glyph font "accidentals.rightparen")))
440 (define-public (parentheses-item::calc-angled-bracket-stencils grob)
441 (let* ((font (ly:grob-default-font grob))
442 (lp (ly:stencil-aligned-to (ly:stencil-aligned-to
443 (grob-interpret-markup
445 (ly:wide-char->utf-8 #x2329))
448 (rp (ly:stencil-aligned-to (ly:stencil-aligned-to
449 (grob-interpret-markup
451 (ly:wide-char->utf-8 #x232A))
455 (list (stencil-whiteout lp)
456 (stencil-whiteout rp))))
458 (define (parenthesize-elements grob . rest)
459 (let* ((refp (if (null? rest)
462 (elts (ly:grob-object grob 'elements))
463 (x-ext (ly:relative-group-extent elts refp X))
464 (stencils (ly:grob-property grob 'stencils))
467 (padding (ly:grob-property grob 'padding 0.1)))
470 (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
471 (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))))
474 (define (parentheses-item::print me)
475 (let* ((elts (ly:grob-object me 'elements))
476 (y-ref (ly:grob-common-refpoint-of-array me elts Y))
477 (x-ref (ly:grob-common-refpoint-of-array me elts X))
478 (stencil (parenthesize-elements me x-ref))
479 (elt-y-ext (ly:relative-group-extent elts y-ref Y))
480 (y-center (interval-center elt-y-ext)))
482 (ly:stencil-translate
485 (- (ly:grob-relative-coordinate me x-ref X))
486 (- y-center (ly:grob-relative-coordinate me y-ref Y))))))
490 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
493 (define-public (chain-grob-member-functions grob value . funcs)
496 (set! value (func grob value)))
502 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
505 (define-public (bend::print spanner)
507 (< (abs (- a b)) 0.01))
509 (let* ((delta-y (* 0.5 (ly:grob-property spanner 'delta-position)))
510 (left-span (ly:spanner-bound spanner LEFT))
511 (dots (if (and (grob::has-interface left-span 'note-head-interface)
512 (ly:grob? (ly:grob-object left-span 'dot)))
513 (ly:grob-object left-span 'dot) #f))
515 (right-span (ly:spanner-bound spanner RIGHT))
516 (thickness (* (ly:grob-property spanner 'thickness)
517 (ly:output-def-lookup (ly:grob-layout spanner)
519 (padding (ly:grob-property spanner 'padding 0.5))
520 (common (ly:grob-common-refpoint right-span
521 (ly:grob-common-refpoint spanner
524 (common-y (ly:grob-common-refpoint spanner left-span Y))
525 (minimum-length (ly:grob-property spanner 'minimum-length 0.5))
529 (interval-end (ly:grob-robust-relative-extent
534 (ly:grob-relative-coordinate dots common-y Y)
535 (ly:grob-relative-coordinate spanner common-y Y)))
537 (ly:grob-robust-relative-extent dots common X))
538 ;; TODO: use real infinity constant.
540 (right-x (max (- (interval-start
541 (ly:grob-robust-relative-extent right-span common X))
543 (+ left-x minimum-length)))
544 (self-x (ly:grob-relative-coordinate spanner common X))
545 (dx (- right-x left-x))
546 (exp (list 'path thickness
554 ,dx ,(* 0.66 delta-y)
559 (cons (- left-x self-x) (- right-x self-x))
560 (cons (min 0 delta-y)
564 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
567 (define-public (grace-spacing::calc-shortest-duration grob)
568 (let* ((cols (ly:grob-object grob 'columns))
571 (ly:moment-sub (ly:grob-property
572 (ly:grob-array-ref cols (1+ idx)) 'when)
574 (ly:grob-array-ref cols idx) 'when))))
576 (moment-min (lambda (x y)
579 (if (ly:moment<? x y)
585 (fold moment-min #f (map get-difference
586 (iota (1- (ly:grob-array-length cols)))))))
589 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
592 (define-public (fingering::calc-text grob)
593 (let* ((event (event-cause grob))
594 (digit (ly:event-property event 'digit)))
597 (ly:input-message (ly:event-property event 'origin)
598 "Warning: Fingering notation for finger number ~a"
601 (number->string digit 10)))
603 (define-public (string-number::calc-text grob)
604 (let ((digit (ly:event-property (event-cause grob) 'string-number)))
606 (number->string digit 10)))
608 (define-public (stroke-finger::calc-text grob)
609 (let* ((digit (ly:event-property (event-cause grob) 'digit))
610 (text (ly:event-property (event-cause grob) 'text)))
614 (vector-ref (ly:grob-property grob 'digit-names)
615 (1- (max (min 5 digit) 1))))))
618 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
621 (define-public (hairpin::calc-grow-direction grob)
622 (if (eq? (ly:event-property (event-cause grob) 'class) 'decrescendo-event)
627 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
630 (define-public (lyric-text::print grob)
631 "Allow interpretation of tildes as lyric tieing marks."
633 (let ((text (ly:grob-property grob 'text)))
635 (grob-interpret-markup grob (if (string? text)
636 (make-tied-lyric-markup text)
639 (define-public ((grob::calc-property-by-copy prop) grob)
640 (ly:event-property (event-cause grob) prop))
643 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
646 (define-public (fret-board::calc-stencil grob)
647 (grob-interpret-markup
649 (make-fret-diagram-verbose-markup
650 (ly:grob-property grob 'dot-placement-list))))
653 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
656 (define-public (script-interface::calc-x-offset grob)
657 (ly:grob-property grob 'positioning-done)
658 (let* ((shift (ly:grob-property grob 'toward-stem-shift 0.0))
660 (ly:self-alignment-interface::centered-on-x-parent grob))
661 (note-head-grob (ly:grob-parent grob X))
662 (stem-grob (ly:grob-object note-head-grob 'stem)))
664 (+ note-head-location
665 ;; If the property 'toward-stem-shift is defined and the script
666 ;; has the same direction as the stem, move the script accordingly.
667 ;; Since scripts can also be over skips, we need to check whether
668 ;; the grob has a stem at all.
669 (if (ly:grob? stem-grob)
670 (let ((dir1 (ly:grob-property grob 'direction))
671 (dir2 (ly:grob-property stem-grob 'direction)))
672 (if (equal? dir1 dir2)
673 (let* ((common-refp (ly:grob-common-refpoint grob stem-grob X))
675 (ly:grob-relative-coordinate stem-grob common-refp X)))
676 (* shift (- stem-location note-head-location)))
681 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
684 (define-public (system-start-text::print grob)
685 (let* ((left-bound (ly:spanner-bound grob LEFT))
686 (left-mom (ly:grob-property left-bound 'when))
687 (name (if (moment<=? left-mom ZERO-MOMENT)
688 (ly:grob-property grob 'long-text)
689 (ly:grob-property grob 'text))))
691 (if (and (markup? name)
692 (!= (ly:item-break-dir left-bound) CENTER))
694 (grob-interpret-markup grob name)
695 (ly:grob-suicide! grob))))
697 (define-public (system-start-text::calc-x-offset grob)
698 (let* ((left-bound (ly:spanner-bound grob LEFT))
699 (left-mom (ly:grob-property left-bound 'when))
700 (layout (ly:grob-layout grob))
701 (indent (ly:output-def-lookup layout
702 (if (moment<=? left-mom ZERO-MOMENT)
706 (system (ly:grob-system grob))
707 (my-extent (ly:grob-extent grob system X))
708 (elements (ly:grob-object system 'elements))
709 (common (ly:grob-common-refpoint-of-array system elements X))
710 (total-ext empty-interval)
711 (align-x (ly:grob-property grob 'self-alignment-X 0))
712 (padding (min 0 (- (interval-length my-extent) indent)))
713 (right-padding (- padding
714 (/ (* padding (1+ align-x)) 2))))
716 ;; compensate for the variation in delimiter extents by
717 ;; calculating an X-offset correction based on united extents
718 ;; of all delimiters in this system
719 (let unite-delims ((l (ly:grob-array-length elements)))
721 (let ((elt (ly:grob-array-ref elements (1- l))))
723 (if (grob::has-interface elt 'system-start-delimiter-interface)
724 (let ((dims (ly:grob-extent elt common X)))
725 (if (interval-sane? dims)
726 (set! total-ext (interval-union total-ext dims)))))
727 (unite-delims (1- l)))))
730 (ly:side-position-interface::x-aligned-side grob)
732 (- (interval-length total-ext)))))
734 (define-public (system-start-text::calc-y-offset grob)
736 (define (live-elements-list me)
737 (let* ((elements (ly:grob-object me 'elements))
738 (elts-length (ly:grob-array-length elements))
741 (let get-live ((len elts-length))
743 (let ((elt (ly:grob-array-ref elements (1- len))))
745 (if (grob::is-live? elt)
746 (set! live-elements (cons elt live-elements)))
747 (get-live (1- len)))))
750 (let* ((left-bound (ly:spanner-bound grob LEFT))
751 (live-elts (live-elements-list grob))
752 (system (ly:grob-system grob))
753 (extent empty-interval))
755 (if (and (pair? live-elts)
756 (interval-sane? (ly:grob-extent grob system Y)))
757 (let get-extent ((lst live-elts))
759 (let ((axis-group (car lst)))
761 (if (and (ly:spanner? axis-group)
762 (equal? (ly:spanner-bound axis-group LEFT)
764 (set! extent (add-point extent
765 (ly:grob-relative-coordinate
766 axis-group system Y))))
767 (get-extent (cdr lst)))))
768 ;; no live axis group(s) for this instrument name -> remove from system
769 (ly:grob-suicide! grob))
772 (ly:self-alignment-interface::y-aligned-on-self grob)
773 (interval-center extent))))
776 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
779 (define-public (ambitus::print grob)
780 (let ((heads (ly:grob-object grob 'note-heads)))
782 (if (and (ly:grob-array? heads)
783 (= (ly:grob-array-length heads) 2))
784 (let* ((common (ly:grob-common-refpoint-of-array grob heads Y))
785 (head-down (ly:grob-array-ref heads 0))
786 (head-up (ly:grob-array-ref heads 1))
787 (gap (ly:grob-property grob 'gap 0.35))
788 (point-min (+ (interval-end (ly:grob-extent head-down common Y))
790 (point-max (- (interval-start (ly:grob-extent head-up common Y))
793 (if (< point-min point-max)
794 (let* ((layout (ly:grob-layout grob))
795 (line-thick (ly:output-def-lookup layout 'line-thickness))
796 (blot (ly:output-def-lookup layout 'blot-diameter))
797 (grob-thick (ly:grob-property grob 'thickness 2))
798 (width (* line-thick grob-thick))
799 (x-ext (symmetric-interval (/ width 2)))
800 (y-ext (cons point-min point-max))
801 (line (ly:round-filled-box x-ext y-ext blot))
802 (y-coord (ly:grob-relative-coordinate grob common Y)))
804 (ly:stencil-translate-axis line (- y-coord) Y))
807 (ly:grob-suicide! grob)