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 ;; The TabNoteHead tablatureFormat callback.
53 ;; Compute the text grob-property
54 (define-public (fret-number-tablature-format string context event)
55 (let* ((tuning (ly:context-property context 'stringTunings))
56 (pitch (ly:event-property event 'pitch))
61 (eq? 'harmonic-event (ly:event-property ev 'class)))
62 (ly:event-property event 'articulations)))))
68 (- (ly:pitch-semitones pitch)
70 ;; remove 1 because list index starts at 0
71 ;;and guitar string at 1.
74 ;; The 5-string banjo has got a extra string, the fifth (duh), which
75 ;; starts at the fifth fret on the neck. Frets on the fifth string
76 ;; are referred to relative to the other frets:
77 ;; the "first fret" on the fifth string is really the sixth fret
79 ;; We solve this by defining a new fret-number-tablature function:
80 (define-public (fret-number-tablature-format-banjo string context event)
81 (let* ((tuning (ly:context-property context 'stringTunings))
82 (pitch (ly:event-property event 'pitch)))
86 (let ((fret (- (ly:pitch-semitones pitch) (list-ref tuning (1- string)))))
88 ((and (> fret 0) (= string 5))
93 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
96 (define-public (stem::calc-duration-log grob)
98 (ly:event-property (event-cause grob) 'duration)))
100 (define-public (note-head::calc-duration-log grob)
103 (ly:event-property (event-cause grob) 'duration))))
105 (define-public (dots::calc-dot-count grob)
106 (ly:duration-dot-count
107 (ly:event-property (event-cause grob) 'duration)))
109 (define-public (dots::calc-staff-position grob)
110 (let* ((head (ly:grob-parent grob Y))
111 (log (ly:grob-property head 'duration-log)))
114 ((or (not (grob::has-interface head 'rest-interface))
115 (not (integer? log))) 0)
124 (define-public (note-head::calc-glyph-name grob)
125 (let ((style (ly:grob-property grob 'style))
126 (log (min 2 (ly:grob-property grob 'duration-log))))
129 ;; "default" style is directly handled in note-head.cc as a
130 ;; special case (HW says, mainly for performance reasons).
131 ;; Therefore, style "default" does not appear in this case
133 ((xcircle) "2xcircle")
134 ((harmonic) "0harmonic")
135 ((harmonic-black) "2harmonic")
136 ((harmonic-mixed) (if (<= log 1) "0harmonic"
139 ;; Oops, I actually would not call this "baroque", but, for
140 ;; backwards compatibility to 1.4, this is supposed to take
141 ;; brevis, longa and maxima from the neo-mensural font and all
142 ;; other note heads from the default font. -- jr
144 (string-append (number->string log) "neomensural")
145 (number->string log)))
147 (string-append (number->string log) (symbol->string style)))
150 (string-append (number->string log) "mensural")
151 (string-append (number->string log) (symbol->string style))))
153 (string-append (number->string log) (symbol->string style)))
155 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
156 (symbol->string style)
157 (string-append (number->string (max 0 log))
158 (symbol->string style)))))))
161 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
164 (define-public ((every-nth-bar-number-visible n) barnum)
165 (= 0 (modulo barnum n)))
167 (define-public ((modulo-bar-number-visible n m) barnum) (and (> barnum 1) (= m (modulo barnum n))))
169 (define-public ((set-bar-number-visibility n) tr)
170 (let ((bn (ly:context-property tr 'currentBarNumber)))
171 (ly:context-set-property! tr 'barNumberVisibility
172 (modulo-bar-number-visible n (modulo bn n)))))
174 (define-public (first-bar-number-invisible barnum) (> barnum 1))
176 (define-public (all-bar-numbers-visible barnum) #t)
179 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
180 ;; percent repeat counters
182 (define-public ((every-nth-repeat-count-visible n) count context)
183 (= 0 (modulo count n)))
185 (define-public (all-repeat-counts-visible count context) #t)
188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
191 (define-public all-visible #(#t #t #t))
192 (define-public begin-of-line-invisible #(#t #t #f))
193 (define-public center-invisible #(#t #f #t))
194 (define-public end-of-line-invisible #(#f #t #t))
195 (define-public begin-of-line-visible #(#f #f #t))
196 (define-public center-visible #(#f #t #f))
197 (define-public end-of-line-visible #(#t #f #f))
198 (define-public all-invisible #(#f #f #f))
200 (define-public spanbar-begin-of-line-invisible #(#t #f #f))
203 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
207 ;; How should a bar line behave at a break?
208 (define bar-glyph-alist
209 '((":|:" . (":|" . "|:"))
210 (":|.|:" . (":|" . "|:"))
211 (":|.:" . (":|" . "|:"))
212 ("||:" . ("||" . "|:"))
213 ("dashed" . ("dashed" . '()))
215 ("||:" . ("||" . "|:"))
217 ("|:" . ("|" . "|:"))
220 ;; hmm... should we end with a bar line here?
221 (".|" . ("|" . ".|"))
224 (".|." . (".|." . ()))
225 ("|.|" . ("|.|" . ()))
230 ("empty" . (() . ()))
231 ("brace" . (() . "brace"))
232 ("bracket" . (() . "bracket"))))
234 (define-public (bar-line::calc-glyph-name grob)
235 (let* ((glyph (ly:grob-property grob 'glyph))
236 (dir (ly:item-break-dir grob))
237 (result (assoc glyph bar-glyph-alist))
238 (glyph-name (if (= dir CENTER)
241 (string? (index-cell (cdr result) dir)))
242 (index-cell (cdr result) dir)
246 (define-public (bar-line::calc-break-visibility grob)
247 (let* ((glyph (ly:grob-property grob 'glyph))
248 (result (assoc glyph bar-glyph-alist)))
251 (vector (string? (cadr result)) #t (string? (cddr result)))
254 (define-public (shift-right-at-line-begin g)
255 "Shift an item to the right, but only at the start of the line."
256 (if (and (ly:item? g)
257 (equal? (ly:item-break-dir g) RIGHT))
258 (ly:grob-translate-axis! g 3.5 X)))
261 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
264 (define-public (tuplet-number::calc-denominator-text grob)
265 (number->string (ly:event-property (event-cause grob) 'denominator)))
267 (define-public (tuplet-number::calc-fraction-text grob)
268 (let ((ev (event-cause grob)))
271 (ly:event-property ev 'denominator)
272 (ly:event-property ev 'numerator))))
274 ;; a formatter function, which is simply a wrapper around an existing
275 ;; tuplet formatter function. It takes the value returned by the given
276 ;; function and appends a note of given length.
277 (define-public ((tuplet-number::append-note-wrapper function note) grob)
278 (let ((txt (if function (function grob) #f)))
281 (markup txt #:fontsize -5 #:note note UP)
282 (markup #:fontsize -5 #:note note UP))))
284 ;; Print a tuplet denominator with a different number than the one derived from
285 ;; the actual tuplet fraction
286 (define-public ((tuplet-number::non-default-tuplet-denominator-text denominator)
288 (number->string (if denominator
290 (ly:event-property (event-cause grob) 'denominator))))
292 ;; Print a tuplet fraction with different numbers than the ones derived from
293 ;; the actual tuplet fraction
294 (define-public ((tuplet-number::non-default-tuplet-fraction-text
295 denominator numerator) grob)
296 (let* ((ev (event-cause grob))
297 (den (if denominator denominator (ly:event-property ev 'denominator)))
298 (num (if numerator numerator (ly:event-property ev 'numerator))))
300 (format "~a:~a" den num)))
302 ;; Print a tuplet fraction with note durations appended to the numerator and the
304 (define-public ((tuplet-number::fraction-with-notes
305 denominatornote numeratornote) grob)
306 (let* ((ev (event-cause grob))
307 (denominator (ly:event-property ev 'denominator))
308 (numerator (ly:event-property ev 'numerator)))
310 ((tuplet-number::non-default-fraction-with-notes
311 denominator denominatornote numerator numeratornote) grob)))
313 ;; Print a tuplet fraction with note durations appended to the numerator and the
315 (define-public ((tuplet-number::non-default-fraction-with-notes
316 denominator denominatornote numerator numeratornote) grob)
317 (let* ((ev (event-cause grob))
318 (den (if denominator denominator (ly:event-property ev 'denominator)))
319 (num (if numerator numerator (ly:event-property ev 'numerator))))
321 (make-concat-markup (list
322 (make-simple-markup (format "~a" den))
323 (markup #:fontsize -5 #:note denominatornote UP)
324 (make-simple-markup " : ")
325 (make-simple-markup (format "~a" num))
326 (markup #:fontsize -5 #:note numeratornote UP)))))
329 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
332 (define-public color? list?)
333 (define-public (rgb-color r g b) (list r g b))
336 (define-public black '(0.0 0.0 0.0))
337 (define-public white '(1.0 1.0 1.0))
338 (define-public red '(1.0 0.0 0.0))
339 (define-public green '(0.0 1.0 0.0))
340 (define-public blue '(0.0 0.0 1.0))
341 (define-public cyan '(0.0 1.0 1.0))
342 (define-public magenta '(1.0 0.0 1.0))
343 (define-public yellow '(1.0 1.0 0.0))
345 (define-public grey '(0.5 0.5 0.5))
346 (define-public darkred '(0.5 0.0 0.0))
347 (define-public darkgreen '(0.0 0.5 0.0))
348 (define-public darkblue '(0.0 0.0 0.5))
349 (define-public darkcyan '(0.0 0.5 0.5))
350 (define-public darkmagenta '(0.5 0.0 0.5))
351 (define-public darkyellow '(0.5 0.5 0.0))
354 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
357 (define-public (key-signature-interface::alteration-position step alter
359 ;; TODO: memoize - this is mostly constant.
361 ;; fes, ges, as and bes typeset in lower octave
362 (define FLAT_TOP_PITCH 2)
364 ;; ais and bis typeset in lower octave
365 (define SHARP_TOP_PITCH 4)
368 (+ (cdr step) (* (car step) 7) c0-position)
369 (let* ((from-bottom-pos (modulo (+ 4 49 c0-position) 7))
371 (c0 (- from-bottom-pos 4)))
375 (or (> p FLAT_TOP_PITCH) (> (+ p c0) 4)) (> (+ p c0) 1))
377 (or (> p SHARP_TOP_PITCH) (> (+ p c0) 5)) (> (+ p c0) 2)))
379 ;; Typeset below c_position
382 ;; Provide for the four cases in which there's a glitch
383 ;; it's a hack, but probably not worth
384 ;; the effort of finding a nicer solution.
387 ((and (= c0 2) (= p 3) (> alter 0))
389 ((and (= c0 -3) (= p -1) (> alter 0))
391 ((and (= c0 -4) (= p -1) (< alter 0))
393 ((and (= c0 -2) (= p -3) (< alter 0))
399 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
402 (define-public (accidental-interface::calc-alteration grob)
403 (ly:pitch-alteration (ly:event-property (event-cause grob) 'pitch)))
405 (define-public cancellation-glyph-name-alist
406 '((0 . "accidentals.natural")))
408 (define-public standard-alteration-glyph-name-alist
410 ;; ordered for optimal performance.
411 (0 . "accidentals.natural")
412 (-1/2 . "accidentals.flat")
413 (1/2 . "accidentals.sharp")
415 (1 . "accidentals.doublesharp")
416 (-1 . "accidentals.flatflat")
418 (3/4 . "accidentals.sharp.slashslash.stemstemstem")
419 (1/4 . "accidentals.sharp.slashslash.stem")
420 (-1/4 . "accidentals.mirroredflat")
421 (-3/4 . "accidentals.mirroredflat.flat")))
423 ;; FIXME: standard vs default, alteration-FOO vs FOO-alteration
424 (define-public alteration-default-glyph-name-alist
425 standard-alteration-glyph-name-alist)
427 (define-public makam-alteration-glyph-name-alist
428 '((1 . "accidentals.doublesharp")
429 (8/9 . "accidentals.sharp.slashslashslash.stemstem")
430 (5/9 . "accidentals.sharp.slashslashslash.stem")
431 (4/9 . "accidentals.sharp")
432 (1/9 . "accidentals.sharp.slashslash.stem")
433 (0 . "accidentals.natural")
434 (-1/9 . "accidentals.mirroredflat")
435 (-4/9 . "accidentals.flat.slash")
436 (-5/9 . "accidentals.flat")
437 (-8/9 . "accidentals.flat.slashslash")
438 (-1 . "accidentals.flatflat")))
440 (define-public alteration-hufnagel-glyph-name-alist
441 '((-1/2 . "accidentals.hufnagelM1")
442 (0 . "accidentals.vaticana0")
443 (1/2 . "accidentals.mensural1")))
445 (define-public alteration-medicaea-glyph-name-alist
446 '((-1/2 . "accidentals.medicaeaM1")
447 (0 . "accidentals.vaticana0")
448 (1/2 . "accidentals.mensural1")))
450 (define-public alteration-vaticana-glyph-name-alist
451 '((-1/2 . "accidentals.vaticanaM1")
452 (0 . "accidentals.vaticana0")
453 (1/2 . "accidentals.mensural1")))
455 (define-public alteration-mensural-glyph-name-alist
456 '((-1/2 . "accidentals.mensuralM1")
457 (0 . "accidentals.vaticana0")
458 (1/2 . "accidentals.mensural1")))
461 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
462 ;; * Pitch Trill Heads
465 (define-public (parentheses-item::calc-parenthesis-stencils grob)
466 (let* ((font (ly:grob-default-font grob))
467 (lp (ly:font-get-glyph font "accidentals.leftparen"))
468 (rp (ly:font-get-glyph font "accidentals.rightparen")))
472 (define-public (parentheses-item::calc-angled-bracket-stencils grob)
473 (let* ((font (ly:grob-default-font grob))
474 (lp (ly:stencil-aligned-to (ly:stencil-aligned-to
475 (grob-interpret-markup
477 (ly:wide-char->utf-8 #x2329))
480 (rp (ly:stencil-aligned-to (ly:stencil-aligned-to
481 (grob-interpret-markup
483 (ly:wide-char->utf-8 #x232A))
487 (list (stencil-whiteout lp)
488 (stencil-whiteout rp))))
490 (define (parenthesize-elements grob . rest)
491 (let* ((refp (if (null? rest)
494 (elts (ly:grob-object grob 'elements))
495 (x-ext (ly:relative-group-extent elts refp X))
496 (stencils (ly:grob-property grob 'stencils))
499 (padding (ly:grob-property grob 'padding 0.1)))
502 (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
503 (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))))
506 (define (parentheses-item::print me)
507 (let* ((elts (ly:grob-object me 'elements))
508 (y-ref (ly:grob-common-refpoint-of-array me elts Y))
509 (x-ref (ly:grob-common-refpoint-of-array me elts X))
510 (stencil (parenthesize-elements me x-ref))
511 (elt-y-ext (ly:relative-group-extent elts y-ref Y))
512 (y-center (interval-center elt-y-ext)))
514 (ly:stencil-translate
517 (- (ly:grob-relative-coordinate me x-ref X))
518 (- y-center (ly:grob-relative-coordinate me y-ref Y))))))
522 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
525 (define-public (chain-grob-member-functions grob value . funcs)
528 (set! value (func grob value)))
534 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
537 (define-public (bend::print spanner)
539 (< (abs (- a b)) 0.01))
541 (let* ((delta-y (* 0.5 (ly:grob-property spanner 'delta-position)))
542 (left-span (ly:spanner-bound spanner LEFT))
543 (dots (if (and (grob::has-interface left-span 'note-head-interface)
544 (ly:grob? (ly:grob-object left-span 'dot)))
545 (ly:grob-object left-span 'dot) #f))
547 (right-span (ly:spanner-bound spanner RIGHT))
548 (thickness (* (ly:grob-property spanner 'thickness)
549 (ly:output-def-lookup (ly:grob-layout spanner)
551 (padding (ly:grob-property spanner 'padding 0.5))
552 (common (ly:grob-common-refpoint right-span
553 (ly:grob-common-refpoint spanner
556 (common-y (ly:grob-common-refpoint spanner left-span Y))
557 (minimum-length (ly:grob-property spanner 'minimum-length 0.5))
561 (interval-end (ly:grob-robust-relative-extent
566 (ly:grob-relative-coordinate dots common-y Y)
567 (ly:grob-relative-coordinate spanner common-y Y)))
569 (ly:grob-robust-relative-extent dots common X))
570 ;; TODO: use real infinity constant.
572 (right-x (max (- (interval-start
573 (ly:grob-robust-relative-extent right-span common X))
575 (+ left-x minimum-length)))
576 (self-x (ly:grob-relative-coordinate spanner common X))
577 (dx (- right-x left-x))
578 (exp (list 'path thickness
586 ,dx ,(* 0.66 delta-y)
591 (cons (- left-x self-x) (- right-x self-x))
592 (cons (min 0 delta-y)
596 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
599 (define-public (grace-spacing::calc-shortest-duration grob)
600 (let* ((cols (ly:grob-object grob 'columns))
603 (ly:moment-sub (ly:grob-property
604 (ly:grob-array-ref cols (1+ idx)) 'when)
606 (ly:grob-array-ref cols idx) 'when))))
608 (moment-min (lambda (x y)
611 (if (ly:moment<? x y)
617 (fold moment-min #f (map get-difference
618 (iota (1- (ly:grob-array-length cols)))))))
621 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
624 (define-public (fingering::calc-text grob)
625 (let* ((event (event-cause grob))
626 (digit (ly:event-property event 'digit)))
629 (ly:input-message (ly:event-property event 'origin)
630 "Warning: Fingering notation for finger number ~a"
633 (number->string digit 10)))
635 (define-public (string-number::calc-text grob)
636 (let ((digit (ly:event-property (event-cause grob) 'string-number)))
638 (number->string digit 10)))
640 (define-public (stroke-finger::calc-text grob)
641 (let* ((digit (ly:event-property (event-cause grob) 'digit))
642 (text (ly:event-property (event-cause grob) 'text)))
646 (vector-ref (ly:grob-property grob 'digit-names)
647 (1- (max (min 5 digit) 1))))))
650 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
653 (define-public (hairpin::calc-grow-direction grob)
654 (if (eq? (ly:event-property (event-cause grob) 'class) 'decrescendo-event)
659 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
662 (define-public (lyric-text::print grob)
663 "Allow interpretation of tildes as lyric tieing marks."
665 (let ((text (ly:grob-property grob 'text)))
667 (grob-interpret-markup grob (if (string? text)
668 (make-tied-lyric-markup text)
671 (define-public ((grob::calc-property-by-copy prop) grob)
672 (ly:event-property (event-cause grob) prop))
675 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
678 (define-public (fret-board::calc-stencil grob)
679 (grob-interpret-markup
681 (make-fret-diagram-verbose-markup
682 (ly:grob-property grob 'dot-placement-list))))
685 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
688 (define-public (script-interface::calc-x-offset grob)
689 (ly:grob-property grob 'positioning-done)
690 (let* ((shift (ly:grob-property grob 'toward-stem-shift 0.0))
692 (ly:self-alignment-interface::centered-on-x-parent grob))
693 (note-head-grob (ly:grob-parent grob X))
694 (stem-grob (ly:grob-object note-head-grob 'stem)))
696 (+ note-head-location
697 ;; If the property 'toward-stem-shift is defined and the script
698 ;; has the same direction as the stem, move the script accordingly.
699 ;; Since scripts can also be over skips, we need to check whether
700 ;; the grob has a stem at all.
701 (if (ly:grob? stem-grob)
702 (let ((dir1 (ly:grob-property grob 'direction))
703 (dir2 (ly:grob-property stem-grob 'direction)))
704 (if (equal? dir1 dir2)
705 (let* ((common-refp (ly:grob-common-refpoint grob stem-grob X))
707 (ly:grob-relative-coordinate stem-grob common-refp X)))
708 (* shift (- stem-location note-head-location)))
713 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
716 (define-public (system-start-text::print grob)
717 (let* ((left-bound (ly:spanner-bound grob LEFT))
718 (left-mom (ly:grob-property left-bound 'when))
719 (name (if (moment<=? left-mom ZERO-MOMENT)
720 (ly:grob-property grob 'long-text)
721 (ly:grob-property grob 'text))))
723 (if (and (markup? name)
724 (!= (ly:item-break-dir left-bound) CENTER))
726 (grob-interpret-markup grob name)
727 (ly:grob-suicide! grob))))
729 (define-public (system-start-text::calc-x-offset grob)
730 (let* ((left-bound (ly:spanner-bound grob LEFT))
731 (left-mom (ly:grob-property left-bound 'when))
732 (layout (ly:grob-layout grob))
733 (indent (ly:output-def-lookup layout
734 (if (moment<=? left-mom ZERO-MOMENT)
738 (system (ly:grob-system grob))
739 (my-extent (ly:grob-extent grob system X))
740 (elements (ly:grob-object system 'elements))
741 (common (ly:grob-common-refpoint-of-array system elements X))
742 (total-ext empty-interval)
743 (align-x (ly:grob-property grob 'self-alignment-X 0))
744 (padding (min 0 (- (interval-length my-extent) indent)))
745 (right-padding (- padding
746 (/ (* padding (1+ align-x)) 2))))
748 ;; compensate for the variation in delimiter extents by
749 ;; calculating an X-offset correction based on united extents
750 ;; of all delimiters in this system
751 (let unite-delims ((l (ly:grob-array-length elements)))
753 (let ((elt (ly:grob-array-ref elements (1- l))))
755 (if (grob::has-interface elt 'system-start-delimiter-interface)
756 (let ((dims (ly:grob-extent elt common X)))
757 (if (interval-sane? dims)
758 (set! total-ext (interval-union total-ext dims)))))
759 (unite-delims (1- l)))))
762 (ly:side-position-interface::x-aligned-side grob)
764 (- (interval-length total-ext)))))
766 (define-public (system-start-text::calc-y-offset grob)
768 (define (live-elements-list me)
769 (let* ((elements (ly:grob-object me 'elements))
770 (elts-length (ly:grob-array-length elements))
773 (let get-live ((len elts-length))
775 (let ((elt (ly:grob-array-ref elements (1- len))))
777 (if (grob::is-live? elt)
778 (set! live-elements (cons elt live-elements)))
779 (get-live (1- len)))))
782 (let* ((left-bound (ly:spanner-bound grob LEFT))
783 (live-elts (live-elements-list grob))
784 (system (ly:grob-system grob))
785 (extent empty-interval))
787 (if (and (pair? live-elts)
788 (interval-sane? (ly:grob-extent grob system Y)))
789 (let get-extent ((lst live-elts))
791 (let ((axis-group (car lst)))
793 (if (and (ly:spanner? axis-group)
794 (equal? (ly:spanner-bound axis-group LEFT)
796 (set! extent (add-point extent
797 (ly:grob-relative-coordinate
798 axis-group system Y))))
799 (get-extent (cdr lst))))))
802 (ly:self-alignment-interface::y-aligned-on-self grob)
803 (interval-center extent))))