1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 1998--2009 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 (make-stencil-boxer thickness padding callback)
31 "Return function that adds a box around the grob passed as argument."
33 (box-stencil (callback grob) thickness padding)))
35 (define-public (make-stencil-circler thickness padding callback)
36 "Return function that adds a circle around the grob passed as argument."
38 (lambda (grob) (circle-stencil (callback grob) thickness padding)))
40 (define-public (print-circled-text-callback grob)
41 (grob-interpret-markup grob (make-circle-markup
42 (ly:grob-property grob 'text))))
44 (define-public (event-cause grob)
45 (let ((cause (ly:grob-property grob 'cause)))
48 ((ly:stream-event? cause) cause)
49 ((ly:grob? cause) (event-cause cause))
52 (define-public (grob-interpret-markup grob text)
53 (let* ((layout (ly:grob-layout grob))
54 (defs (ly:output-def-lookup layout 'text-font-defaults))
55 (props (ly:grob-alist-chain grob defs)))
57 (ly:text-interface::interpret-markup layout props text)))
60 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
63 (define-public (stem::calc-duration-log grob)
65 (ly:event-property (event-cause grob) 'duration)))
67 (define-public (note-head::calc-duration-log grob)
70 (ly:event-property (event-cause grob) 'duration))))
72 (define-public (dots::calc-dot-count grob)
73 (ly:duration-dot-count
74 (ly:event-property (event-cause grob) 'duration)))
76 (define-public (dots::calc-staff-position grob)
77 (let* ((head (ly:grob-parent grob Y))
78 (log (ly:grob-property head 'duration-log)))
81 ((or (not (grob::has-interface head 'rest-interface))
82 (not (integer? log))) 0)
90 ;; Kept separate from note-head::calc-glyph-name to allow use by
91 ;; markup commands \note and \note-by-number
92 (define-public (select-head-glyph style log)
93 "Select a note head glyph string based on note head style @var{style}
94 and duration-log @var{log}."
96 ;; "default" style is directly handled in note-head.cc as a
97 ;; special case (HW says, mainly for performance reasons).
98 ;; Therefore, style "default" does not appear in this case
100 ((xcircle) "2xcircle")
101 ((harmonic) "0harmonic")
102 ((harmonic-black) "2harmonic")
103 ((harmonic-mixed) (if (<= log 1) "0harmonic"
106 ;; Oops, I actually would not call this "baroque", but, for
107 ;; backwards compatibility to 1.4, this is supposed to take
108 ;; brevis, longa and maxima from the neo-mensural font and all
109 ;; other note heads from the default font. -- jr
111 (string-append (number->string log) "neomensural")
112 (number->string log)))
114 ;; Like default, but brevis is drawn with double vertical lines
116 (string-append (number->string log) "double")
117 (number->string log)))
119 (string-append (number->string log) (symbol->string style)))
122 (string-append (number->string log) "mensural")
123 (string-append (number->string log) (symbol->string style))))
125 (string-append (number->string log) (symbol->string style)))
127 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
128 (symbol->string style)
129 (string-append (number->string (max 0 log))
130 (symbol->string style))))))
132 (define-public (note-head::calc-glyph-name grob)
133 (let ((style (ly:grob-property grob 'style))
134 (log (min 2 (ly:grob-property grob 'duration-log))))
136 (select-head-glyph style log)))
138 (define-public (note-head::brew-ez-stencil grob)
139 (let* ((log (ly:grob-property grob 'duration-log))
140 (pitch (ly:event-property (event-cause grob) 'pitch))
141 (pitch-index (ly:pitch-notename pitch))
142 (note-names (ly:grob-property grob 'note-names))
143 (pitch-string (if (vector? note-names)
144 (vector-ref note-names pitch-index)
147 (+ (modulo (+ pitch-index 2) 7)
148 (char->integer #\A))))))
149 (staff-space (ly:staff-symbol-staff-space grob))
150 (line-thickness (ly:staff-symbol-line-thickness grob))
151 (stem (ly:grob-object grob 'stem))
152 (stem-thickness (* (if (ly:grob? stem)
153 (ly:grob-property stem 'thickness)
156 (radius (/ (+ staff-space line-thickness) 2))
157 (letter (markup #:center-align #:vcenter pitch-string))
158 (filled-circle (markup #:draw-circle radius 0 #t)))
160 (ly:stencil-translate-axis
161 (grob-interpret-markup
166 (make-with-color-markup white letter))
170 (make-with-color-markup white (make-draw-circle-markup
171 (- radius stem-thickness) 0 #t)))
176 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
179 (define-public all-visible #(#t #t #t))
180 (define-public begin-of-line-invisible #(#t #t #f))
181 (define-public center-invisible #(#t #f #t))
182 (define-public end-of-line-invisible #(#f #t #t))
183 (define-public begin-of-line-visible #(#f #f #t))
184 (define-public center-visible #(#f #t #f))
185 (define-public end-of-line-visible #(#t #f #f))
186 (define-public all-invisible #(#f #f #f))
188 (define-public spanbar-begin-of-line-invisible #(#t #f #f))
191 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
195 ;; How should a bar line behave at a break?
196 (define bar-glyph-alist
197 '((":|:" . (":|" . "|:"))
198 (":|.|:" . (":|" . "|:"))
199 (":|.:" . (":|" . "|:"))
200 ("||:" . ("||" . "|:"))
201 ("dashed" . ("dashed" . '()))
203 ("||:" . ("||" . "|:"))
205 ("|:" . ("|" . "|:"))
208 ;; hmm... should we end with a bar line here?
209 (".|" . ("|" . ".|"))
212 (".|." . (".|." . ()))
213 ("|.|" . ("|.|" . ()))
218 ("empty" . (() . ()))
219 ("brace" . (() . "brace"))
220 ("bracket" . (() . "bracket"))))
222 (define-public (bar-line::calc-glyph-name grob)
223 (let* ((glyph (ly:grob-property grob 'glyph))
224 (dir (ly:item-break-dir grob))
225 (result (assoc-get glyph bar-glyph-alist))
226 (glyph-name (if (= dir CENTER)
229 (string? (index-cell result dir)))
230 (index-cell result dir)
234 (define-public (bar-line::calc-break-visibility grob)
235 (let* ((glyph (ly:grob-property grob 'glyph))
236 (result (assoc-get glyph bar-glyph-alist)))
239 (vector (string? (car result)) #t (string? (cdr result)))
242 (define-public (shift-right-at-line-begin g)
243 "Shift an item to the right, but only at the start of the line."
244 (if (and (ly:item? g)
245 (equal? (ly:item-break-dir g) RIGHT))
246 (ly:grob-translate-axis! g 3.5 X)))
249 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
252 (define-public (tuplet-number::calc-denominator-text grob)
253 (number->string (ly:event-property (event-cause grob) 'denominator)))
255 (define-public (tuplet-number::calc-fraction-text grob)
256 (let ((ev (event-cause grob)))
259 (ly:event-property ev 'denominator)
260 (ly:event-property ev 'numerator))))
262 ;; a formatter function, which is simply a wrapper around an existing
263 ;; tuplet formatter function. It takes the value returned by the given
264 ;; function and appends a note of given length.
265 (define-public ((tuplet-number::append-note-wrapper function note) grob)
266 (let ((txt (if function (function grob) #f)))
269 (markup txt #:fontsize -5 #:note note UP)
270 (markup #:fontsize -5 #:note note UP))))
272 ;; Print a tuplet denominator with a different number than the one derived from
273 ;; the actual tuplet fraction
274 (define-public ((tuplet-number::non-default-tuplet-denominator-text denominator)
276 (number->string (if denominator
278 (ly:event-property (event-cause grob) 'denominator))))
280 ;; Print a tuplet fraction with different numbers than the ones derived from
281 ;; the actual tuplet fraction
282 (define-public ((tuplet-number::non-default-tuplet-fraction-text
283 denominator numerator) grob)
284 (let* ((ev (event-cause grob))
285 (den (if denominator denominator (ly:event-property ev 'denominator)))
286 (num (if numerator numerator (ly:event-property ev 'numerator))))
288 (format "~a:~a" den num)))
290 ;; Print a tuplet fraction with note durations appended to the numerator and the
292 (define-public ((tuplet-number::fraction-with-notes
293 denominatornote numeratornote) grob)
294 (let* ((ev (event-cause grob))
295 (denominator (ly:event-property ev 'denominator))
296 (numerator (ly:event-property ev 'numerator)))
298 ((tuplet-number::non-default-fraction-with-notes
299 denominator denominatornote numerator numeratornote) grob)))
301 ;; Print a tuplet fraction with note durations appended to the numerator and the
303 (define-public ((tuplet-number::non-default-fraction-with-notes
304 denominator denominatornote numerator numeratornote) grob)
305 (let* ((ev (event-cause grob))
306 (den (if denominator denominator (ly:event-property ev 'denominator)))
307 (num (if numerator numerator (ly:event-property ev 'numerator))))
309 (make-concat-markup (list
310 (make-simple-markup (format "~a" den))
311 (markup #:fontsize -5 #:note denominatornote UP)
312 (make-simple-markup " : ")
313 (make-simple-markup (format "~a" num))
314 (markup #:fontsize -5 #:note numeratornote UP)))))
317 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
320 (define-public color? list?)
321 (define-public (rgb-color r g b) (list r g b))
324 (define-public black '(0.0 0.0 0.0))
325 (define-public white '(1.0 1.0 1.0))
326 (define-public red '(1.0 0.0 0.0))
327 (define-public green '(0.0 1.0 0.0))
328 (define-public blue '(0.0 0.0 1.0))
329 (define-public cyan '(0.0 1.0 1.0))
330 (define-public magenta '(1.0 0.0 1.0))
331 (define-public yellow '(1.0 1.0 0.0))
333 (define-public grey '(0.5 0.5 0.5))
334 (define-public darkred '(0.5 0.0 0.0))
335 (define-public darkgreen '(0.0 0.5 0.0))
336 (define-public darkblue '(0.0 0.0 0.5))
337 (define-public darkcyan '(0.0 0.5 0.5))
338 (define-public darkmagenta '(0.5 0.0 0.5))
339 (define-public darkyellow '(0.5 0.5 0.0))
342 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
345 (define-public (key-signature-interface::alteration-position step alter
347 ;; TODO: memoize - this is mostly constant.
349 ;; fes, ges, as and bes typeset in lower octave
350 (define FLAT_TOP_PITCH 2)
352 ;; ais and bis typeset in lower octave
353 (define SHARP_TOP_PITCH 4)
356 (+ (cdr step) (* (car step) 7) c0-position)
357 (let* ((from-bottom-pos (modulo (+ 4 49 c0-position) 7))
359 (c0 (- from-bottom-pos 4)))
363 (or (> p FLAT_TOP_PITCH) (> (+ p c0) 4)) (> (+ p c0) 1))
365 (or (> p SHARP_TOP_PITCH) (> (+ p c0) 5)) (> (+ p c0) 2)))
367 ;; Typeset below c_position
370 ;; Provide for the four cases in which there's a glitch
371 ;; it's a hack, but probably not worth
372 ;; the effort of finding a nicer solution.
375 ((and (= c0 2) (= p 3) (> alter 0))
377 ((and (= c0 -3) (= p -1) (> alter 0))
379 ((and (= c0 -4) (= p -1) (< alter 0))
381 ((and (= c0 -2) (= p -3) (< alter 0))
387 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
390 (define-public (accidental-interface::calc-alteration grob)
391 (ly:pitch-alteration (ly:event-property (event-cause grob) 'pitch)))
393 (define-public cancellation-glyph-name-alist
394 '((0 . "accidentals.natural")))
396 (define-public standard-alteration-glyph-name-alist
398 ;; ordered for optimal performance.
399 (0 . "accidentals.natural")
400 (-1/2 . "accidentals.flat")
401 (1/2 . "accidentals.sharp")
403 (1 . "accidentals.doublesharp")
404 (-1 . "accidentals.flatflat")
406 (3/4 . "accidentals.sharp.slashslash.stemstemstem")
407 (1/4 . "accidentals.sharp.slashslash.stem")
408 (-1/4 . "accidentals.mirroredflat")
409 (-3/4 . "accidentals.mirroredflat.flat")))
411 ;; FIXME: standard vs default, alteration-FOO vs FOO-alteration
412 (define-public alteration-default-glyph-name-alist
413 standard-alteration-glyph-name-alist)
415 (define-public makam-alteration-glyph-name-alist
416 '((1 . "accidentals.doublesharp")
417 (8/9 . "accidentals.sharp.slashslashslash.stemstem")
418 (5/9 . "accidentals.sharp.slashslashslash.stem")
419 (4/9 . "accidentals.sharp")
420 (1/9 . "accidentals.sharp.slashslash.stem")
421 (0 . "accidentals.natural")
422 (-1/9 . "accidentals.mirroredflat")
423 (-4/9 . "accidentals.flat.slash")
424 (-5/9 . "accidentals.flat")
425 (-8/9 . "accidentals.flat.slashslash")
426 (-1 . "accidentals.flatflat")))
428 (define-public alteration-hufnagel-glyph-name-alist
429 '((-1/2 . "accidentals.hufnagelM1")
430 (0 . "accidentals.vaticana0")
431 (1/2 . "accidentals.mensural1")))
433 (define-public alteration-medicaea-glyph-name-alist
434 '((-1/2 . "accidentals.medicaeaM1")
435 (0 . "accidentals.vaticana0")
436 (1/2 . "accidentals.mensural1")))
438 (define-public alteration-vaticana-glyph-name-alist
439 '((-1/2 . "accidentals.vaticanaM1")
440 (0 . "accidentals.vaticana0")
441 (1/2 . "accidentals.mensural1")))
443 (define-public alteration-mensural-glyph-name-alist
444 '((-1/2 . "accidentals.mensuralM1")
445 (0 . "accidentals.vaticana0")
446 (1/2 . "accidentals.mensural1")))
449 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
450 ;; * Pitch Trill Heads
453 (define-public (parentheses-item::calc-parenthesis-stencils grob)
454 (let* ((font (ly:grob-default-font grob))
455 (lp (ly:font-get-glyph font "accidentals.leftparen"))
456 (rp (ly:font-get-glyph font "accidentals.rightparen")))
460 (define-public (parentheses-item::calc-angled-bracket-stencils grob)
461 (let* ((font (ly:grob-default-font grob))
462 (lp (ly:stencil-aligned-to (ly:stencil-aligned-to
463 (grob-interpret-markup
465 (ly:wide-char->utf-8 #x2329))
468 (rp (ly:stencil-aligned-to (ly:stencil-aligned-to
469 (grob-interpret-markup
471 (ly:wide-char->utf-8 #x232A))
475 (list (stencil-whiteout lp)
476 (stencil-whiteout rp))))
478 (define (parenthesize-elements grob . rest)
479 (let* ((refp (if (null? rest)
482 (elts (ly:grob-object grob 'elements))
483 (x-ext (ly:relative-group-extent elts refp X))
484 (stencils (ly:grob-property grob 'stencils))
487 (padding (ly:grob-property grob 'padding 0.1)))
490 (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
491 (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))))
494 (define (parentheses-item::print me)
495 (let* ((elts (ly:grob-object me 'elements))
496 (y-ref (ly:grob-common-refpoint-of-array me elts Y))
497 (x-ref (ly:grob-common-refpoint-of-array me elts X))
498 (stencil (parenthesize-elements me x-ref))
499 (elt-y-ext (ly:relative-group-extent elts y-ref Y))
500 (y-center (interval-center elt-y-ext)))
502 (ly:stencil-translate
505 (- (ly:grob-relative-coordinate me x-ref X))
506 (- y-center (ly:grob-relative-coordinate me y-ref Y))))))
510 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
513 (define-public (chain-grob-member-functions grob value . funcs)
516 (set! value (func grob value)))
522 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
525 (define-public (bend::print spanner)
527 (< (abs (- a b)) 0.01))
529 (let* ((delta-y (* 0.5 (ly:grob-property spanner 'delta-position)))
530 (left-span (ly:spanner-bound spanner LEFT))
531 (dots (if (and (grob::has-interface left-span 'note-head-interface)
532 (ly:grob? (ly:grob-object left-span 'dot)))
533 (ly:grob-object left-span 'dot) #f))
535 (right-span (ly:spanner-bound spanner RIGHT))
536 (thickness (* (ly:grob-property spanner 'thickness)
537 (ly:output-def-lookup (ly:grob-layout spanner)
539 (padding (ly:grob-property spanner 'padding 0.5))
540 (common (ly:grob-common-refpoint right-span
541 (ly:grob-common-refpoint spanner
544 (common-y (ly:grob-common-refpoint spanner left-span Y))
545 (minimum-length (ly:grob-property spanner 'minimum-length 0.5))
549 (interval-end (ly:grob-robust-relative-extent
554 (ly:grob-relative-coordinate dots common-y Y)
555 (ly:grob-relative-coordinate spanner common-y Y)))
557 (ly:grob-robust-relative-extent dots common X))
558 ;; TODO: use real infinity constant.
560 (right-x (max (- (interval-start
561 (ly:grob-robust-relative-extent right-span common X))
563 (+ left-x minimum-length)))
564 (self-x (ly:grob-relative-coordinate spanner common X))
565 (dx (- right-x left-x))
566 (exp (list 'path thickness
574 ,dx ,(* 0.66 delta-y)
579 (cons (- left-x self-x) (- right-x self-x))
580 (cons (min 0 delta-y)
584 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
587 (define-public (grace-spacing::calc-shortest-duration grob)
588 (let* ((cols (ly:grob-object grob 'columns))
591 (ly:moment-sub (ly:grob-property
592 (ly:grob-array-ref cols (1+ idx)) 'when)
594 (ly:grob-array-ref cols idx) 'when))))
596 (moment-min (lambda (x y)
599 (if (ly:moment<? x y)
605 (fold moment-min #f (map get-difference
606 (iota (1- (ly:grob-array-length cols)))))))
609 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
612 (define-public (fingering::calc-text grob)
613 (let* ((event (event-cause grob))
614 (digit (ly:event-property event 'digit)))
617 (ly:input-message (ly:event-property event 'origin)
618 "Warning: Fingering notation for finger number ~a"
621 (number->string digit 10)))
623 (define-public (string-number::calc-text grob)
624 (let ((digit (ly:event-property (event-cause grob) 'string-number)))
626 (number->string digit 10)))
628 (define-public (stroke-finger::calc-text grob)
629 (let* ((digit (ly:event-property (event-cause grob) 'digit))
630 (text (ly:event-property (event-cause grob) 'text)))
634 (vector-ref (ly:grob-property grob 'digit-names)
635 (1- (max (min 5 digit) 1))))))
638 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
641 (define-public (hairpin::calc-grow-direction grob)
642 (if (eq? (ly:event-property (event-cause grob) 'class) 'decrescendo-event)
647 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
650 (define-public (lyric-text::print grob)
651 "Allow interpretation of tildes as lyric tieing marks."
653 (let ((text (ly:grob-property grob 'text)))
655 (grob-interpret-markup grob (if (string? text)
656 (make-tied-lyric-markup text)
659 (define-public ((grob::calc-property-by-copy prop) grob)
660 (ly:event-property (event-cause grob) prop))
663 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
666 (define-public (fret-board::calc-stencil grob)
667 (grob-interpret-markup
669 (make-fret-diagram-verbose-markup
670 (ly:grob-property grob 'dot-placement-list))))
673 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
676 (define-public (script-interface::calc-x-offset grob)
677 (ly:grob-property grob 'positioning-done)
678 (let* ((shift (ly:grob-property grob 'toward-stem-shift 0.0))
680 (ly:self-alignment-interface::centered-on-x-parent grob))
681 (note-head-grob (ly:grob-parent grob X))
682 (stem-grob (ly:grob-object note-head-grob 'stem)))
684 (+ note-head-location
685 ;; If the property 'toward-stem-shift is defined and the script
686 ;; has the same direction as the stem, move the script accordingly.
687 ;; Since scripts can also be over skips, we need to check whether
688 ;; the grob has a stem at all.
689 (if (ly:grob? stem-grob)
690 (let ((dir1 (ly:grob-property grob 'direction))
691 (dir2 (ly:grob-property stem-grob 'direction)))
692 (if (equal? dir1 dir2)
693 (let* ((common-refp (ly:grob-common-refpoint grob stem-grob X))
695 (ly:grob-relative-coordinate stem-grob common-refp X)))
696 (* shift (- stem-location note-head-location)))
701 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
704 (define-public (system-start-text::print grob)
705 (let* ((left-bound (ly:spanner-bound grob LEFT))
706 (left-mom (ly:grob-property left-bound 'when))
707 (name (if (moment<=? left-mom ZERO-MOMENT)
708 (ly:grob-property grob 'long-text)
709 (ly:grob-property grob 'text))))
711 (if (and (markup? name)
712 (!= (ly:item-break-dir left-bound) CENTER))
714 (grob-interpret-markup grob name)
715 (ly:grob-suicide! grob))))
717 (define-public (system-start-text::calc-x-offset grob)
718 (let* ((left-bound (ly:spanner-bound grob LEFT))
719 (left-mom (ly:grob-property left-bound 'when))
720 (layout (ly:grob-layout grob))
721 (indent (ly:output-def-lookup layout
722 (if (moment<=? left-mom ZERO-MOMENT)
726 (system (ly:grob-system grob))
727 (my-extent (ly:grob-extent grob system X))
728 (elements (ly:grob-object system 'elements))
729 (common (ly:grob-common-refpoint-of-array system elements X))
730 (total-ext empty-interval)
731 (align-x (ly:grob-property grob 'self-alignment-X 0))
732 (padding (min 0 (- (interval-length my-extent) indent)))
733 (right-padding (- padding
734 (/ (* padding (1+ align-x)) 2))))
736 ;; compensate for the variation in delimiter extents by
737 ;; calculating an X-offset correction based on united extents
738 ;; of all delimiters in this system
739 (let unite-delims ((l (ly:grob-array-length elements)))
741 (let ((elt (ly:grob-array-ref elements (1- l))))
743 (if (grob::has-interface elt 'system-start-delimiter-interface)
744 (let ((dims (ly:grob-extent elt common X)))
745 (if (interval-sane? dims)
746 (set! total-ext (interval-union total-ext dims)))))
747 (unite-delims (1- l)))))
750 (ly:side-position-interface::x-aligned-side grob)
752 (- (interval-length total-ext)))))
754 (define-public (system-start-text::calc-y-offset grob)
756 (define (live-elements-list me)
757 (let* ((elements (ly:grob-object me 'elements))
758 (elts-length (ly:grob-array-length elements))
761 (let get-live ((len elts-length))
763 (let ((elt (ly:grob-array-ref elements (1- len))))
765 (if (grob::is-live? elt)
766 (set! live-elements (cons elt live-elements)))
767 (get-live (1- len)))))
770 (let* ((left-bound (ly:spanner-bound grob LEFT))
771 (live-elts (live-elements-list grob))
772 (system (ly:grob-system grob))
773 (extent empty-interval))
775 (if (and (pair? live-elts)
776 (interval-sane? (ly:grob-extent grob system Y)))
777 (let get-extent ((lst live-elts))
779 (let ((axis-group (car lst)))
781 (if (and (ly:spanner? axis-group)
782 (equal? (ly:spanner-bound axis-group LEFT)
784 (set! extent (add-point extent
785 (ly:grob-relative-coordinate
786 axis-group system Y))))
787 (get-extent (cdr lst)))))
788 ;; no live axis group(s) for this instrument name -> remove from system
789 (ly:grob-suicide! grob))
792 (ly:self-alignment-interface::y-aligned-on-self grob)
793 (interval-center extent))))
796 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
799 (define-public (ambitus::print grob)
800 (let ((heads (ly:grob-object grob 'note-heads)))
802 (if (and (ly:grob-array? heads)
803 (= (ly:grob-array-length heads) 2))
804 (let* ((common (ly:grob-common-refpoint-of-array grob heads Y))
805 (head-down (ly:grob-array-ref heads 0))
806 (head-up (ly:grob-array-ref heads 1))
807 (gap (ly:grob-property grob 'gap 0.35))
808 (point-min (+ (interval-end (ly:grob-extent head-down common Y))
810 (point-max (- (interval-start (ly:grob-extent head-up common Y))
813 (if (< point-min point-max)
814 (let* ((layout (ly:grob-layout grob))
815 (line-thick (ly:output-def-lookup layout 'line-thickness))
816 (blot (ly:output-def-lookup layout 'blot-diameter))
817 (grob-thick (ly:grob-property grob 'thickness 2))
818 (width (* line-thick grob-thick))
819 (x-ext (symmetric-interval (/ width 2)))
820 (y-ext (cons point-min point-max))
821 (line (ly:round-filled-box x-ext y-ext blot))
822 (y-coord (ly:grob-relative-coordinate grob common Y)))
824 (ly:stencil-translate-axis line (- y-coord) Y))
827 (ly:grob-suicide! grob)