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>
11 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13 (define-public (grob::has-interface grob iface)
14 (memq iface (ly:grob-interfaces grob)))
16 (define-public (grob::is-live? grob)
17 (pair? (ly:grob-basic-properties grob)))
19 (define-public (make-stencil-boxer thickness padding callback)
21 "Return function that adds a box around the grob passed as argument."
24 (box-stencil (callback grob) thickness padding)))
26 (define-public (make-stencil-circler thickness padding callback)
27 "Return function that adds a circle around the grob passed as argument."
29 (lambda (grob) (circle-stencil (callback grob) thickness padding)))
31 (define-public (print-circled-text-callback grob)
32 (grob-interpret-markup grob (make-circle-markup
33 (ly:grob-property grob 'text))
36 (define-public (event-cause grob)
38 ((cause (ly:grob-property grob 'cause)))
41 ((ly:stream-event? cause) cause)
42 ((ly:grob? cause) (event-cause cause))
45 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
48 ;; The TabNoteHead tablatureFormat callback.
49 ;; Compute the text grob-property
50 (define-public (fret-number-tablature-format string
53 ((tuning (ly:context-property context 'stringTunings))
54 (pitch (ly:event-property event 'pitch))
59 (eq? 'harmonic-event (ly:event-property ev 'class)))
60 (ly:event-property event 'articulations)))))
67 (- (ly:pitch-semitones pitch)
69 ;; remove 1 because list index starts at 0 and guitar string at 1.
73 ;; The 5-string banjo has got a extra string, the fifth (duh), wich
74 ;; starts at the fifth fret on the neck. Frets on the fifth string
75 ;; are referred to relative to the other frets:
76 ;; the "first fret" on the fifth string is really the sixth fret
78 ;; We solve this by defining a new fret-number-tablature function:
79 (define-public (fret-number-tablature-format-banjo string
82 ((tuning (ly:context-property context 'stringTunings))
83 (pitch (ly:event-property event 'pitch))
87 (let ((fret (- (ly:pitch-semitones pitch) (list-ref tuning (- string 1)))))
89 ((and (> fret 0) (= string 5))
95 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
99 (define-public (stem::calc-duration-log grob)
101 (ly:event-property (event-cause grob) 'duration)))
103 (define-public (note-head::calc-duration-log grob)
106 (ly:event-property (event-cause grob) 'duration))))
108 (define-public (dots::calc-dot-count grob)
109 (ly:duration-dot-count
110 (ly:event-property (event-cause grob) 'duration)))
112 (define-public (dots::calc-staff-position grob)
114 ((head (ly:grob-parent grob Y))
115 (log (ly:grob-property head 'duration-log)))
118 ((or (not (grob::has-interface head 'rest-interface))
119 (not (integer? log))) 0)
127 (define (note-head::calc-tablature-stem-attachment grob)
133 (define-public (note-head::calc-glyph-name grob)
135 ((style (ly:grob-property grob 'style))
136 (log (min 2 (ly:grob-property grob 'duration-log))))
139 ;; "default" style is directly handled in note-head.cc as a
140 ;; special case (HW says, mainly for performance reasons).
141 ;; Therefore, style "default" does not appear in this case
143 ((xcircle) "2xcircle")
144 ((harmonic) "0harmonic")
145 ((harmonic-black) "2harmonic")
146 ((harmonic-mixed) (if (<= log 1) "0harmonic"
149 ;; Oops, I actually would not call this "baroque", but, for
150 ;; backwards compatibility to 1.4, this is supposed to take
151 ;; brevis, longa and maxima from the neo-mensural font and all
152 ;; other note heads from the default font. -- jr
154 (string-append (number->string log) "neomensural")
155 (number->string log)))
157 (string-append (number->string log) (symbol->string style)))
160 (string-append (number->string log) "mensural")
161 (string-append (number->string log) (symbol->string style))))
163 (string-append (number->string log) (symbol->string style)))
165 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
166 (symbol->string style)
167 (string-append (number->string (max 0 log))
168 (symbol->string style)))))))
170 ;; TODO junk completely?
171 (define (note-head-style->attachment-coordinates grob axis)
172 "Return pair (X . Y), containing multipliers for the note head
173 bounding box, where to attach the stem. e.g.: X==0 means horizontally
174 centered, X==1 is at the right, X == -1 is at the left."
179 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
182 (define-public ((every-nth-bar-number-visible n) barnum) (= 0 (modulo barnum n)))
184 (define-public ((modulo-bar-number-visible n m) barnum) (and (> barnum 1) (= m (modulo barnum n))))
186 (define-public ((set-bar-number-visibility n) tr)
187 (let* ((bn (ly:context-property tr 'currentBarNumber)))
188 (ly:context-set-property! tr 'barNumberVisibility (modulo-bar-number-visible n (modulo bn n)))))
190 (define-public (first-bar-number-invisible barnum) (> barnum 1))
192 (define-public (all-bar-numbers-visible barnum) #t)
194 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
195 ;; percent repeat counters
197 (define-public ((every-nth-repeat-count-visible n) count context) (= 0 (modulo count n)))
199 (define-public (all-repeat-counts-visible count context) #t)
201 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
204 (define-public all-visible #(#t #t #t))
205 (define-public begin-of-line-invisible #(#t #t #f))
206 (define-public center-invisible #(#t #f #t))
207 (define-public end-of-line-invisible #(#f #t #t))
208 (define-public begin-of-line-visible #(#f #f #t))
209 (define-public center-visible #(#f #t #f))
210 (define-public end-of-line-visible #(#t #f #f))
211 (define-public all-invisible #(#f #f #f))
213 (define-public spanbar-begin-of-line-invisible
216 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
220 ;; How should a bar line behave at a break?
221 (define bar-glyph-alist
222 '((":|:" . (":|" . "|:"))
223 (":|.|:" . (":|" . "|:"))
224 (":|.:" . (":|" . "|:"))
225 ("||:" . ("||" . "|:"))
226 ("dashed" . ("dashed" . '()))
228 ("||:" . ("||" . "|:"))
230 ("|:" . ("|" . "|:"))
233 ;; hmm... should we end with a bar line here?
234 (".|" . ("|" . ".|"))
237 (".|." . (".|." . ()))
238 ("|.|" . ("|.|" . ()))
243 ("empty" . (() . ()))
244 ("brace" . (() . "brace"))
245 ("bracket" . (() . "bracket"))
248 (define-public (bar-line::calc-glyph-name grob)
250 (glyph (ly:grob-property grob 'glyph))
251 (dir (ly:item-break-dir grob))
252 (result (assoc glyph bar-glyph-alist))
253 (glyph-name (if (= dir CENTER)
255 (if (and result (string? (index-cell (cdr result) dir)))
256 (index-cell (cdr result) dir)
261 (define-public (bar-line::calc-break-visibility grob)
262 (let* ((glyph (ly:grob-property grob 'glyph))
263 (result (assoc glyph bar-glyph-alist)))
265 (vector (string? (cadr result)) #t (string? (cddr result)))
269 (define-public (shift-right-at-line-begin g)
270 "Shift an item to the right, but only at the start of the line."
271 (if (and (ly:item? g)
272 (equal? (ly:item-break-dir g) RIGHT))
273 (ly:grob-translate-axis! g 3.5 X)))
276 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
279 (define-public (tuplet-number::calc-denominator-text grob)
280 (number->string (ly:event-property (event-cause grob) 'denominator)))
282 (define-public (tuplet-number::calc-fraction-text grob)
284 ((ev (event-cause grob)))
287 (ly:event-property ev 'denominator)
288 (ly:event-property ev 'numerator))))
291 ; a formatter function, which is simply a wrapper around an existing
292 ; tuplet formatter function. It takes the value returned by the given
293 ; function and appends a note of given length.
294 (define-public ((tuplet-number::append-note-wrapper function note) grob)
295 (let* ((txt (if function (function grob) #f)))
297 (markup txt #:fontsize -5 #:note note UP)
298 (markup #:fontsize -5 #:note note UP))))
300 ; Print a tuplet denominator with a different number than the one derived from
301 ; the actual tuplet fraction
302 (define-public ((tuplet-number::non-default-tuplet-denominator-text denominator) grob)
303 (number->string (if denominator
305 (ly:event-property (event-cause grob) 'denominator))))
307 ; Print a tuplet fraction with different numbers than the ones derived from
308 ; the actual tuplet fraction
309 (define-public ((tuplet-number::non-default-tuplet-fraction-text denominator numerator) grob)
310 (let* ((ev (event-cause grob))
311 (den (if denominator denominator (ly:event-property ev 'denominator)))
312 (num (if numerator numerator (ly:event-property ev 'numerator))))
313 (format "~a:~a" den num)))
315 ; Print a tuplet fraction with note durations appended to the numerator and the
317 (define-public ((tuplet-number::fraction-with-notes denominatornote numeratornote) grob)
318 (let* ((ev (event-cause grob))
319 (denominator (ly:event-property ev 'denominator))
320 (numerator (ly:event-property ev 'numerator)))
321 ((tuplet-number::non-default-fraction-with-notes denominator denominatornote numerator numeratornote) grob)))
323 ; Print a tuplet fraction with note durations appended to the numerator and the
325 (define-public ((tuplet-number::non-default-fraction-with-notes denominator denominatornote numerator numeratornote) grob)
326 (let* ((ev (event-cause grob))
327 (den (if denominator denominator (ly:event-property ev 'denominator)))
328 (num (if numerator numerator (ly:event-property ev 'numerator))))
329 (make-concat-markup (list
330 (make-simple-markup (format "~a" den))
331 (markup #:fontsize -5 #:note denominatornote UP)
332 (make-simple-markup " : ")
333 (make-simple-markup (format "~a" num))
334 (markup #:fontsize -5 #:note numeratornote UP)))))
337 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
340 (define-public color? list?)
341 (define-public (rgb-color r g b) (list r g b))
344 (define-public black '(0.0 0.0 0.0))
345 (define-public white '(1.0 1.0 1.0))
346 (define-public red '(1.0 0.0 0.0))
347 (define-public green '(0.0 1.0 0.0))
348 (define-public blue '(0.0 0.0 1.0))
349 (define-public cyan '(0.0 1.0 1.0))
350 (define-public magenta '(1.0 0.0 1.0))
351 (define-public yellow '(1.0 1.0 0.0))
353 (define-public grey '(0.5 0.5 0.5))
354 (define-public darkred '(0.5 0.0 0.0))
355 (define-public darkgreen '(0.0 0.5 0.0))
356 (define-public darkblue '(0.0 0.0 0.5))
357 (define-public darkcyan '(0.0 0.5 0.5))
358 (define-public darkmagenta '(0.5 0.0 0.5))
359 (define-public darkyellow '(0.5 0.5 0.0))
361 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
365 (define-public (key-signature-interface::alteration-position step alter c0-position)
366 ;; TODO: memoize - this is mostly constant.
368 ;; fes, ges, as and bes typeset in lower octave
369 (define FLAT_TOP_PITCH 2)
371 ;; ais and bis typeset in lower octave
372 (define SHARP_TOP_PITCH 4)
375 (+ (cdr step) (* (car step) 7) c0-position)
377 ((from-bottom-pos (modulo (+ 4 49 c0-position) 7))
379 (c0 (- from-bottom-pos 4)))
382 (or (and (< alter 0) (or (> p FLAT_TOP_PITCH) (> (+ p c0) 4)) (> (+ p c0) 1))
383 (and (> alter 0) (or (> p SHARP_TOP_PITCH) (> (+ p c0) 5)) (> (+ p c0) 2))
386 ;; Typeset below c_position
389 ;; Provide for the four cases in which there's a glitch
390 ;; it's a hack, but probably not worth
391 ;; the effort of finding a nicer solution.
394 ((and (= c0 2) (= p 3) (> alter 0))
396 ((and (= c0 -3) (= p -1) (> alter 0))
398 ((and (= c0 -4) (= p -1) (< alter 0))
400 ((and (= c0 -2) (= p -3) (< alter 0))
406 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
409 (define-public (accidental-interface::calc-alteration grob)
410 (ly:pitch-alteration (ly:event-property (event-cause grob) 'pitch)))
413 (define-public cancellation-glyph-name-alist
414 '((0 . "accidentals.natural")))
416 (define-public standard-alteration-glyph-name-alist
418 ;; ordered for optimal performance.
419 (0 . "accidentals.natural")
420 (-1/2 . "accidentals.flat")
421 (1/2 . "accidentals.sharp")
423 (1 . "accidentals.doublesharp")
424 (-1 . "accidentals.flatflat")
426 (3/4 . "accidentals.sharp.slashslash.stemstemstem")
427 (1/4 . "accidentals.sharp.slashslash.stem")
428 (-1/4 . "accidentals.mirroredflat")
429 (-3/4 . "accidentals.mirroredflat.flat")
432 ;; FIXME: standard vs default, alteration-FOO vs FOO-alteration
433 (define-public alteration-default-glyph-name-alist standard-alteration-glyph-name-alist)
435 (define-public makam-alteration-glyph-name-alist
436 '((1 . "accidentals.doublesharp")
437 (8/9 . "accidentals.sharp.slashslashslash.stemstem")
438 (5/9 . "accidentals.sharp.slashslashslash.stem")
439 (4/9 . "accidentals.sharp")
440 (1/9 . "accidentals.sharp.slashslash.stem")
441 (0 . "accidentals.natural")
442 (-1/9 . "accidentals.mirroredflat")
443 (-4/9 . "accidentals.flat.slash")
444 (-5/9 . "accidentals.flat")
445 (-8/9 . "accidentals.flat.slashslash")
446 (-1 . "accidentals.flatflat")
449 (define-public alteration-hufnagel-glyph-name-alist
450 '((-1/2 . "accidentals.hufnagelM1")
451 (0 . "accidentals.vaticana0")
452 (1/2 . "accidentals.mensural1")))
454 (define-public alteration-medicaea-glyph-name-alist
455 '((-1/2 . "accidentals.medicaeaM1")
456 (0 . "accidentals.vaticana0")
457 (1/2 . "accidentals.mensural1")))
459 (define-public alteration-vaticana-glyph-name-alist
460 '((-1/2 . "accidentals.vaticanaM1")
461 (0 . "accidentals.vaticana0")
462 (1/2 . "accidentals.mensural1")))
464 (define-public alteration-mensural-glyph-name-alist
465 '((-1/2 . "accidentals.mensuralM1")
466 (0 . "accidentals.vaticana0")
467 (1/2 . "accidentals.mensural1")))
470 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
471 ;; * Pitch Trill Heads
474 (define-public (parentheses-item::calc-parenthesis-stencils grob)
475 (let* ((font (ly:grob-default-font grob))
476 (lp (ly:font-get-glyph font "accidentals.leftparen"))
477 (rp (ly:font-get-glyph font "accidentals.rightparen")))
482 (define-public (grob-interpret-markup grob text)
484 ((layout (ly:grob-layout grob))
485 (defs (ly:output-def-lookup layout 'text-font-defaults))
486 (props (ly:grob-alist-chain grob defs)))
488 (ly:text-interface::interpret-markup
491 (define-public (parentheses-item::calc-angled-bracket-stencils grob)
493 (font (ly:grob-default-font grob))
494 (lp (ly:stencil-aligned-to (ly:stencil-aligned-to (grob-interpret-markup grob (ly:wide-char->utf-8 #x2329))
496 (rp (ly:stencil-aligned-to (ly:stencil-aligned-to (grob-interpret-markup grob (ly:wide-char->utf-8 #x232A))
500 (list (stencil-whiteout lp)
501 (stencil-whiteout rp))))
503 (define (parenthesize-elements grob . rest)
505 ((refp (if (null? rest)
508 (elts (ly:grob-object grob 'elements))
509 (x-ext (ly:relative-group-extent elts refp X))
510 (stencils (ly:grob-property grob 'stencils))
513 (padding (ly:grob-property grob 'padding 0.1)))
516 (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
517 (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))
521 (define (parentheses-item::print me)
523 ((elts (ly:grob-object me 'elements))
524 (y-ref (ly:grob-common-refpoint-of-array me elts Y))
525 (x-ref (ly:grob-common-refpoint-of-array me elts X))
526 (stencil (parenthesize-elements me x-ref))
527 (elt-y-ext (ly:relative-group-extent elts y-ref Y))
528 (y-center (interval-center elt-y-ext)))
530 (ly:stencil-translate
534 (ly:grob-relative-coordinate me x-ref X))
537 (ly:grob-relative-coordinate me y-ref Y))))
542 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
545 (define-public (chain-grob-member-functions grob value . funcs)
548 (set! value (func grob value)))
553 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
556 (define-public (bend::print spanner)
558 (< (abs (- a b)) 0.01))
561 ((delta-y (* 0.5 (ly:grob-property spanner 'delta-position)))
562 (left-span (ly:spanner-bound spanner LEFT))
563 (dots (if (and (grob::has-interface left-span 'note-head-interface)
564 (ly:grob? (ly:grob-object left-span 'dot)))
565 (ly:grob-object left-span 'dot) #f))
567 (right-span (ly:spanner-bound spanner RIGHT))
568 (thickness (* (ly:grob-property spanner 'thickness)
569 (ly:output-def-lookup (ly:grob-layout spanner)
571 (padding (ly:grob-property spanner 'padding 0.5))
572 (common (ly:grob-common-refpoint right-span
573 (ly:grob-common-refpoint spanner
576 (common-y (ly:grob-common-refpoint spanner left-span Y))
577 (minimum-length (ly:grob-property spanner 'minimum-length 0.5))
580 (max (interval-end (ly:grob-robust-relative-extent
584 (close (ly:grob-relative-coordinate dots common-y Y)
585 (ly:grob-relative-coordinate spanner common-y Y)))
586 (interval-end (ly:grob-robust-relative-extent dots common X))
587 -10000) ;; TODO: use real infinity constant.
589 (right-x (max (- (interval-start (ly:grob-robust-relative-extent right-span common X))
591 (+ left-x minimum-length)))
592 (self-x (ly:grob-relative-coordinate spanner common X))
593 (dx (- right-x left-x))
594 (exp (list 'path thickness
602 ,dx ,(* 0.66 delta-y)
608 (cons (- left-x self-x) (- right-x self-x))
609 (cons (min 0 delta-y)
612 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
616 (define-public (grace-spacing::calc-shortest-duration grob)
618 ((cols (ly:grob-object grob 'columns))
621 (ly:moment-sub (ly:grob-property
622 (ly:grob-array-ref cols (1+ idx)) 'when)
624 (ly:grob-array-ref cols idx) 'when))))
626 (moment-min (lambda (x y)
629 (if (ly:moment<? x y)
635 (fold moment-min #f (map get-difference
636 (iota (1- (ly:grob-array-length cols)))))))
640 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
643 (define-public (fingering::calc-text grob)
645 ((event (event-cause grob))
646 (digit (ly:event-property event 'digit)))
649 (ly:input-message (ly:event-property event 'origin)
650 "Warning: Fingering notation for finger number ~a" digit))
652 (number->string digit 10)
655 (define-public (string-number::calc-text grob)
657 ((digit (ly:event-property (event-cause grob) 'string-number)))
659 (number->string digit 10)
663 (define-public (stroke-finger::calc-text grob)
665 ((digit (ly:event-property (event-cause grob) 'digit))
666 (text (ly:event-property (event-cause grob) 'text)))
670 (vector-ref (ly:grob-property grob 'digit-names) (1- (max (min 5 digit) 1))))))
672 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
674 (define-public (hairpin::calc-grow-direction grob)
675 (if (eq? (ly:event-property (event-cause grob) 'class) 'decrescendo-event)
680 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
683 (define-public (lyric-text::print grob)
684 "Allow interpretation of tildes as lyric tieing marks."
687 ((text (ly:grob-property grob 'text)))
689 (grob-interpret-markup grob
691 (make-tied-lyric-markup text)
694 (define-public ((grob::calc-property-by-copy prop) grob)
695 (ly:event-property (event-cause grob) prop))
697 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
700 (define-public (fret-board::calc-stencil grob)
701 (grob-interpret-markup
703 (make-fret-diagram-verbose-markup
704 (ly:grob-property grob 'dot-placement-list))))
706 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
709 (define-public (script-interface::calc-x-offset grob)
710 (ly:grob-property grob 'positioning-done)
711 (let* ((shift (ly:grob-property grob 'toward-stem-shift 0.0))
712 (note-head-location (ly:self-alignment-interface::centered-on-x-parent grob))
713 (note-head-grob (ly:grob-parent grob X))
714 (stem-grob (ly:grob-object note-head-grob 'stem)))
715 (+ note-head-location
716 ;; If the property 'toward-stem-shift is defined and the script has the
717 ;; same direction as the stem, move the script accordingly. Since scripts can
718 ;; also be over skips, we need to check whether the grob has a stem at all.
719 (if (ly:grob? stem-grob)
720 (let ((dir1 (ly:grob-property grob 'direction))
721 (dir2 (ly:grob-property stem-grob 'direction)))
722 (if (equal? dir1 dir2)
723 (let* ((common-refp (ly:grob-common-refpoint grob stem-grob X))
724 (stem-location (ly:grob-relative-coordinate stem-grob common-refp X)))
725 (* shift (- stem-location
726 note-head-location)))
730 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
733 (define-public (system-start-text::print grob)
734 (let* ((left-bound (ly:spanner-bound grob LEFT))
735 (left-mom (ly:grob-property left-bound 'when))
736 (name (if (moment<=? left-mom ZERO-MOMENT)
737 (ly:grob-property grob 'long-text)
738 (ly:grob-property grob 'text))))
740 (if (and (markup? name)
741 (!= (ly:item-break-dir left-bound) CENTER))
743 (grob-interpret-markup grob name)
744 (ly:grob-suicide! grob))))
746 (define-public (system-start-text::calc-x-offset grob)
747 (let* ((left-bound (ly:spanner-bound grob LEFT))
748 (left-mom (ly:grob-property left-bound 'when))
749 (layout (ly:grob-layout grob))
750 (indent (ly:output-def-lookup layout
751 (if (moment<=? left-mom ZERO-MOMENT)
755 (system (ly:grob-system grob))
756 (my-extent (ly:grob-extent grob system X))
757 (elements (ly:grob-object system 'elements))
758 (common (ly:grob-common-refpoint-of-array system elements X))
759 (total-ext empty-interval)
760 (align-x (ly:grob-property grob 'self-alignment-X 0))
761 (padding (min 0 (- (interval-length my-extent) indent)))
762 (right-padding (- padding
763 (/ (* padding (1+ align-x)) 2))))
765 (let loop ((l (ly:grob-array-length elements)))
767 (let ((elt (ly:grob-array-ref elements (1- l))))
769 (if (grob::has-interface elt 'system-start-delimiter-interface)
770 (let ((dims (ly:grob-extent elt common X)))
771 (if (interval-sane? dims)
772 (set! total-ext (interval-union total-ext dims)))))
776 (ly:side-position-interface::x-aligned-side grob)
778 (- (interval-length total-ext)))))
780 (define-public (system-start-text::calc-y-offset grob)
782 (define (live-elements-list me)
783 (let* ((elements (ly:grob-object me 'elements))
784 (elts-length (ly:grob-array-length elements))
786 (let get-live ((len elts-length))
788 (let ((elt (ly:grob-array-ref elements (1- len))))
790 (if (grob::is-live? elt)
791 (set! live-elements (cons elt live-elements)))
792 (get-live (1- len)))))
795 (let* ((left-bound (ly:spanner-bound grob LEFT))
796 (live-elts (live-elements-list grob))
797 (system (ly:grob-system grob))
798 (extent empty-interval))
800 (if (and (pair? live-elts)
801 (interval-sane? (ly:grob-extent grob system Y)))
802 (let get-extent ((lst live-elts))
804 (let ((axis-group (car lst)))
806 (if (and (ly:spanner? axis-group)
807 (equal? (ly:spanner-bound axis-group LEFT)
809 (set! extent (add-point
811 (ly:grob-relative-coordinate axis-group system Y))))
813 (get-extent (cdr lst))))))
816 (ly:self-alignment-interface::y-aligned-on-self grob)
817 (interval-center extent))))