1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 1998--2011 Jan Nieuwenhuizen <janneke@gnu.org>
4 ;;;; Han-Wen Nienhuys <hanwen@xs4all.nl>
6 ;;;; LilyPond is free software: you can redistribute it and/or modify
7 ;;;; it under the terms of the GNU General Public License as published by
8 ;;;; the Free Software Foundation, either version 3 of the License, or
9 ;;;; (at your option) any later version.
11 ;;;; LilyPond is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;;; GNU General Public License for more details.
16 ;;;; You should have received a copy of the GNU General Public License
17 ;;;; along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
23 (define-public (grob::has-interface grob iface)
24 (memq iface (ly:grob-interfaces grob)))
26 (define-public (grob::is-live? grob)
27 (pair? (ly:grob-basic-properties grob)))
29 (define-public (grob::x-parent-width grob)
30 (ly:grob-property (ly:grob-parent grob X) 'X-extent))
32 (define-public (make-stencil-boxer thickness padding callback)
33 "Return function that adds a box around the grob passed as argument."
35 (box-stencil (callback grob) thickness padding)))
37 (define-public (make-stencil-circler thickness padding callback)
38 "Return function that adds a circle around the grob passed as argument."
40 (circle-stencil (callback grob) thickness padding)))
42 (define-public (print-circled-text-callback grob)
43 (grob-interpret-markup grob (make-circle-markup
44 (ly:grob-property grob 'text))))
46 (define-public (event-cause grob)
47 (let ((cause (ly:grob-property grob 'cause)))
50 ((ly:stream-event? cause) cause)
51 ((ly:grob? cause) (event-cause cause))
54 (define-public (grob-interpret-markup grob text)
55 (let* ((layout (ly:grob-layout grob))
56 (defs (ly:output-def-lookup layout 'text-font-defaults))
57 (props (ly:grob-alist-chain grob defs)))
59 (ly:text-interface::interpret-markup layout props text)))
62 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
65 (define-public (script-or-side-position-cross-staff g)
67 (ly:script-interface::calc-cross-staff g)
68 (ly:side-position-interface::calc-cross-staff g)))
71 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
74 (define-public (stem::calc-duration-log grob)
76 (ly:event-property (event-cause grob) 'duration)))
78 (define-public (stem::length grob)
79 (let* ((ss (ly:staff-symbol-staff-space grob))
80 (beg (ly:grob-property grob 'stem-begin-position))
81 (beam (ly:grob-object grob 'beam)))
83 (abs (- (ly:stem::calc-stem-end-position grob) beg))
86 "stem::length called but will not be used for beamed stem.")
89 (define-public (stem::pure-length grob beg end)
90 (let* ((ss (ly:staff-symbol-staff-space grob))
91 (beg (ly:grob-pure-property grob 'stem-begin-position 0 1000)))
92 (abs (- (ly:stem::pure-calc-stem-end-position grob 0 2147483646) beg))))
94 (define-public (note-head::calc-duration-log grob)
97 (ly:event-property (event-cause grob) 'duration))))
99 (define-public (dots::calc-dot-count grob)
100 (ly:duration-dot-count
101 (ly:event-property (event-cause grob) 'duration)))
103 (define-public (dots::calc-staff-position grob)
104 (let* ((head (ly:grob-parent grob Y))
105 (log (ly:grob-property head 'duration-log)))
108 ((or (not (grob::has-interface head 'rest-interface))
109 (not (integer? log))) 0)
117 ;; Kept separate from note-head::calc-glyph-name to allow use by
118 ;; markup commands \note and \note-by-number
119 (define-public (select-head-glyph style log)
120 "Select a note head glyph string based on note head style @var{style}
121 and duration-log @var{log}."
123 ;; "default" style is directly handled in note-head.cc as a
124 ;; special case (HW says, mainly for performance reasons).
125 ;; Therefore, style "default" does not appear in this case
127 ((xcircle) "2xcircle")
128 ((harmonic) "0harmonic")
129 ((harmonic-black) "2harmonic")
130 ((harmonic-mixed) (if (<= log 1) "0harmonic"
133 ;; Oops, I actually would not call this "baroque", but, for
134 ;; backwards compatibility to 1.4, this is supposed to take
135 ;; brevis, longa and maxima from the neo-mensural font and all
136 ;; other note heads from the default font. -- jr
138 (string-append (number->string log) "neomensural")
139 (number->string log)))
141 ;; Like default, but brevis is drawn with double vertical lines
143 (string-append (number->string log) "double")
144 (number->string log)))
146 (string-append (number->string log) (symbol->string style)))
149 (string-append (number->string log) "mensural")
150 (string-append (number->string log) (symbol->string style))))
153 (string-append (number->string log) "blackmensural")
154 (string-append (number->string log) (symbol->string style))))
157 (string-append (number->string log) "semimensural")
158 (string-append (number->string log) "petrucci")))
160 (string-append (number->string log) (symbol->string style)))
162 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
163 (symbol->string style)
164 (string-append (number->string (max 0 log))
165 (symbol->string style))))))
167 (define-public (note-head::calc-glyph-name grob)
168 (let ((style (ly:grob-property grob 'style))
169 (log (min 2 (ly:grob-property grob 'duration-log))))
171 (select-head-glyph style log)))
173 (define-public (note-head::brew-ez-stencil grob)
174 (let* ((log (ly:grob-property grob 'duration-log))
175 (pitch (ly:event-property (event-cause grob) 'pitch))
176 (pitch-index (ly:pitch-notename pitch))
177 (note-names (ly:grob-property grob 'note-names))
178 (pitch-string (if (and (vector? note-names)
179 (> (vector-length note-names) pitch-index))
180 (vector-ref note-names pitch-index)
183 (+ (modulo (+ pitch-index 2) 7)
184 (char->integer #\A))))))
185 (staff-space (ly:staff-symbol-staff-space grob))
186 (line-thickness (ly:staff-symbol-line-thickness grob))
187 (stem (ly:grob-object grob 'stem))
188 (stem-thickness (* (if (ly:grob? stem)
189 (ly:grob-property stem 'thickness)
192 (radius (/ (+ staff-space line-thickness) 2))
193 (letter (markup #:center-align #:vcenter pitch-string))
194 (filled-circle (markup #:draw-circle radius 0 #t)))
196 (ly:stencil-translate-axis
197 (grob-interpret-markup
202 (make-with-color-markup white letter))
206 (make-with-color-markup white (make-draw-circle-markup
207 (- radius stem-thickness) 0 #t)))
211 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
214 (define-public (make-rhythmic-location bar-num num den)
216 bar-num (ly:make-moment num den)))
218 (define-public (rhythmic-location? a)
221 (ly:moment? (cdr a))))
223 (define-public (make-graceless-rhythmic-location loc)
224 (make-rhythmic-location
226 (ly:moment-main-numerator (rhythmic-location-measure-position loc))
227 (ly:moment-main-denominator (rhythmic-location-measure-position loc))))
229 (define-public rhythmic-location-measure-position cdr)
230 (define-public rhythmic-location-bar-number car)
232 (define-public (rhythmic-location<? a b)
234 ((< (car a) (car b)) #t)
235 ((> (car a) (car b)) #f)
237 (ly:moment<? (cdr a) (cdr b)))))
239 (define-public (rhythmic-location<=? a b)
240 (not (rhythmic-location<? b a)))
241 (define-public (rhythmic-location>=? a b)
242 (rhythmic-location<? a b))
243 (define-public (rhythmic-location>? a b)
244 (rhythmic-location<? b a))
246 (define-public (rhythmic-location=? a b)
247 (and (rhythmic-location<=? a b)
248 (rhythmic-location<=? b a)))
250 (define-public (rhythmic-location->file-string a)
251 (ly:format "~a.~a.~a"
253 (ly:moment-main-numerator (cdr a))
254 (ly:moment-main-denominator (cdr a))))
256 (define-public (rhythmic-location->string a)
257 (ly:format "bar ~a ~a"
259 (ly:moment->string (cdr a))))
261 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
264 (define-public all-visible #(#t #t #t))
265 (define-public begin-of-line-invisible #(#t #t #f))
266 (define-public center-invisible #(#t #f #t))
267 (define-public end-of-line-invisible #(#f #t #t))
268 (define-public begin-of-line-visible #(#f #f #t))
269 (define-public center-visible #(#f #t #f))
270 (define-public end-of-line-visible #(#t #f #f))
271 (define-public all-invisible #(#f #f #f))
272 (define-public (inherit-x-parent-visibility grob)
273 (let ((parent (ly:grob-parent grob X)))
274 (ly:grob-property parent 'break-visibility all-invisible)))
275 (define-public (inherit-y-parent-visibility grob)
276 (let ((parent (ly:grob-parent grob X)))
277 (ly:grob-property parent 'break-visibility)))
280 (define-public spanbar-begin-of-line-invisible #(#t #f #f))
283 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
287 ;; How should a bar line behave at a break?
288 (define bar-glyph-alist
289 '((":|:" . (":|" . "|:"))
290 (":|.|:" . (":|" . "|:"))
291 (":|.:" . (":|" . "|:"))
292 ("||:" . ("||" . "|:"))
293 ("dashed" . ("dashed" . '()))
295 ("||:" . ("||" . "|:"))
297 ("|:" . ("|" . "|:"))
300 ;; hmm... should we end with a bar line here?
301 (".|" . ("|" . ".|"))
304 (".|." . (".|." . ()))
305 ("|.|" . ("|.|" . ()))
310 ("empty" . (() . ()))
311 ("brace" . (() . "brace"))
312 ("bracket" . (() . "bracket"))
318 (":|S" . (":|" . "S"))
319 (":|S." . (":|S" . ()))
320 ("S|:" . ("S" . "|:"))
321 (".S|:" . ("|" . "S|:"))
322 (":|S|:" . (":|" . "S|:"))
323 (":|S.|:" . (":|S" . "|:"))))
325 (define-public (bar-line::calc-glyph-name grob)
326 (let* ((glyph (ly:grob-property grob 'glyph))
327 (dir (ly:item-break-dir grob))
328 (result (assoc-get glyph bar-glyph-alist))
329 (glyph-name (if (= dir CENTER)
332 (string? (index-cell result dir)))
333 (index-cell result dir)
337 (define-public (bar-line::calc-break-visibility grob)
338 (let* ((glyph (ly:grob-property grob 'glyph))
339 (result (assoc-get glyph bar-glyph-alist)))
342 (vector (string? (car result)) #t (string? (cdr result)))
345 (define-public (shift-right-at-line-begin g)
346 "Shift an item to the right, but only at the start of the line."
347 (if (and (ly:item? g)
348 (equal? (ly:item-break-dir g) RIGHT))
349 (ly:grob-translate-axis! g 3.5 X)))
351 (define-public (span-bar-stub::height grob)
352 (ly:grob-property grob 'elements-filtered)
353 (ly:axis-group-interface::height grob))
355 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
358 (define-public (tuplet-number::calc-direction grob)
359 (ly:tuplet-bracket::calc-direction (ly:grob-object grob 'bracket)))
361 (define-public (tuplet-number::calc-denominator-text grob)
362 (number->string (ly:event-property (event-cause grob) 'denominator)))
364 (define-public (tuplet-number::calc-fraction-text grob)
365 (let ((ev (event-cause grob)))
368 (ly:event-property ev 'denominator)
369 (ly:event-property ev 'numerator))))
371 ;; a formatter function, which is simply a wrapper around an existing
372 ;; tuplet formatter function. It takes the value returned by the given
373 ;; function and appends a note of given length.
374 (define-public ((tuplet-number::append-note-wrapper function note) grob)
375 (let ((txt (if function (function grob) #f)))
378 (markup txt #:fontsize -5 #:note note UP)
379 (markup #:fontsize -5 #:note note UP))))
381 ;; Print a tuplet denominator with a different number than the one derived from
382 ;; the actual tuplet fraction
383 (define-public ((tuplet-number::non-default-tuplet-denominator-text denominator)
385 (number->string (if denominator
387 (ly:event-property (event-cause grob) 'denominator))))
389 ;; Print a tuplet fraction with different numbers than the ones derived from
390 ;; the actual tuplet fraction
391 (define-public ((tuplet-number::non-default-tuplet-fraction-text
392 denominator numerator) grob)
393 (let* ((ev (event-cause grob))
394 (den (if denominator denominator (ly:event-property ev 'denominator)))
395 (num (if numerator numerator (ly:event-property ev 'numerator))))
397 (format #f "~a:~a" den num)))
399 ;; Print a tuplet fraction with note durations appended to the numerator and the
401 (define-public ((tuplet-number::fraction-with-notes
402 denominatornote numeratornote) grob)
403 (let* ((ev (event-cause grob))
404 (denominator (ly:event-property ev 'denominator))
405 (numerator (ly:event-property ev 'numerator)))
407 ((tuplet-number::non-default-fraction-with-notes
408 denominator denominatornote numerator numeratornote) grob)))
410 ;; Print a tuplet fraction with note durations appended to the numerator and the
412 (define-public ((tuplet-number::non-default-fraction-with-notes
413 denominator denominatornote numerator numeratornote) grob)
414 (let* ((ev (event-cause grob))
415 (den (if denominator denominator (ly:event-property ev 'denominator)))
416 (num (if numerator numerator (ly:event-property ev 'numerator))))
418 (make-concat-markup (list
419 (make-simple-markup (format #f "~a" den))
420 (markup #:fontsize -5 #:note denominatornote UP)
421 (make-simple-markup " : ")
422 (make-simple-markup (format #f "~a" num))
423 (markup #:fontsize -5 #:note numeratornote UP)))))
426 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
429 (define-public (color? x)
432 (apply eq? #t (map number? x))
433 (apply eq? #t (map (lambda (y) (<= 0 y 1)) x))))
435 (define-public (rgb-color r g b) (list r g b))
438 (define-public black '(0.0 0.0 0.0))
439 (define-public white '(1.0 1.0 1.0))
440 (define-public red '(1.0 0.0 0.0))
441 (define-public green '(0.0 1.0 0.0))
442 (define-public blue '(0.0 0.0 1.0))
443 (define-public cyan '(0.0 1.0 1.0))
444 (define-public magenta '(1.0 0.0 1.0))
445 (define-public yellow '(1.0 1.0 0.0))
447 (define-public grey '(0.5 0.5 0.5))
448 (define-public darkred '(0.5 0.0 0.0))
449 (define-public darkgreen '(0.0 0.5 0.0))
450 (define-public darkblue '(0.0 0.0 0.5))
451 (define-public darkcyan '(0.0 0.5 0.5))
452 (define-public darkmagenta '(0.5 0.0 0.5))
453 (define-public darkyellow '(0.5 0.5 0.0))
456 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
459 (define-public (key-signature-interface::alteration-position step alter
461 ;; TODO: memoize - this is mostly constant.
463 ;; fes, ges, as and bes typeset in lower octave
464 (define FLAT_TOP_PITCH 2)
466 ;; ais and bis typeset in lower octave
467 (define SHARP_TOP_PITCH 4)
470 (+ (cdr step) (* (car step) 7) c0-position)
471 (let* ((from-bottom-pos (modulo (+ 4 49 c0-position) 7))
473 (c0 (- from-bottom-pos 4)))
477 (or (> p FLAT_TOP_PITCH) (> (+ p c0) 4)) (> (+ p c0) 1))
479 (or (> p SHARP_TOP_PITCH) (> (+ p c0) 5)) (> (+ p c0) 2)))
481 ;; Typeset below c_position
484 ;; Provide for the four cases in which there's a glitch
485 ;; it's a hack, but probably not worth
486 ;; the effort of finding a nicer solution.
489 ((and (= c0 2) (= p 3) (> alter 0))
491 ((and (= c0 -3) (= p -1) (> alter 0))
493 ((and (= c0 -4) (= p -1) (< alter 0))
495 ((and (= c0 -2) (= p -3) (< alter 0))
501 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
504 (define-public (numbered-footnotes int)
505 (markup #:tiny (number->string (+ 1 int))))
507 (define-public (symbol-footnotes int)
508 (define (helper symbols out idx n)
512 (string-append out (list-ref symbols idx))
515 (markup #:tiny (helper '("*" "†" "‡" "§" "¶")
518 (+ 1 (quotient int 5)))))
520 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
523 (define-public (accidental-interface::calc-alteration grob)
524 (ly:pitch-alteration (ly:event-property (event-cause grob) 'pitch)))
526 (define-public cancellation-glyph-name-alist
527 '((0 . "accidentals.natural")))
529 (define-public standard-alteration-glyph-name-alist
531 ;; ordered for optimal performance.
532 (0 . "accidentals.natural")
533 (-1/2 . "accidentals.flat")
534 (1/2 . "accidentals.sharp")
536 (1 . "accidentals.doublesharp")
537 (-1 . "accidentals.flatflat")
539 (3/4 . "accidentals.sharp.slashslash.stemstemstem")
540 (1/4 . "accidentals.sharp.slashslash.stem")
541 (-1/4 . "accidentals.mirroredflat")
542 (-3/4 . "accidentals.mirroredflat.flat")))
544 ;; FIXME: standard vs default, alteration-FOO vs FOO-alteration
545 (define-public alteration-default-glyph-name-alist
546 standard-alteration-glyph-name-alist)
548 (define-public makam-alteration-glyph-name-alist
549 '((1 . "accidentals.doublesharp")
550 (8/9 . "accidentals.sharp.slashslashslash.stemstem")
551 (5/9 . "accidentals.sharp.slashslashslash.stem")
552 (4/9 . "accidentals.sharp")
553 (1/9 . "accidentals.sharp.slashslash.stem")
554 (0 . "accidentals.natural")
555 (-1/9 . "accidentals.mirroredflat")
556 (-4/9 . "accidentals.flat.slash")
557 (-5/9 . "accidentals.flat")
558 (-8/9 . "accidentals.flat.slashslash")
559 (-1 . "accidentals.flatflat")))
561 (define-public alteration-hufnagel-glyph-name-alist
562 '((-1/2 . "accidentals.hufnagelM1")
563 (0 . "accidentals.vaticana0")
564 (1/2 . "accidentals.mensural1")))
566 (define-public alteration-medicaea-glyph-name-alist
567 '((-1/2 . "accidentals.medicaeaM1")
568 (0 . "accidentals.vaticana0")
569 (1/2 . "accidentals.mensural1")))
571 (define-public alteration-vaticana-glyph-name-alist
572 '((-1/2 . "accidentals.vaticanaM1")
573 (0 . "accidentals.vaticana0")
574 (1/2 . "accidentals.mensural1")))
576 (define-public alteration-mensural-glyph-name-alist
577 '((-1/2 . "accidentals.mensuralM1")
578 (0 . "accidentals.vaticana0")
579 (1/2 . "accidentals.mensural1")))
582 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
583 ;; * Pitch Trill Heads
586 (define-public (parentheses-item::calc-parenthesis-stencils grob)
587 (let* ((font (ly:grob-default-font grob))
588 (lp (ly:font-get-glyph font "accidentals.leftparen"))
589 (rp (ly:font-get-glyph font "accidentals.rightparen")))
593 (define-public (parentheses-item::calc-angled-bracket-stencils grob)
594 (let* ((parent (ly:grob-parent grob Y))
595 (y-extent (ly:grob-extent parent parent Y))
596 (half-thickness 0.05) ; should it be a property?
597 (width 0.5) ; should it be a property?
598 (angularity 1.5) ; makes angle brackets
599 (white-padding 0.1) ; should it be a property?
600 (lp (ly:stencil-aligned-to
601 (ly:stencil-aligned-to
602 (make-parenthesis-stencil y-extent
609 (interval-widen (ly:stencil-extent lp X) white-padding))
610 (rp (ly:stencil-aligned-to
611 (ly:stencil-aligned-to
612 (make-parenthesis-stencil y-extent
619 (interval-widen (ly:stencil-extent rp X) white-padding)))
620 (set! lp (ly:make-stencil (ly:stencil-expr lp)
622 (ly:stencil-extent lp Y)))
623 (set! rp (ly:make-stencil (ly:stencil-expr rp)
625 (ly:stencil-extent rp Y)))
626 (list (stencil-whiteout lp)
627 (stencil-whiteout rp))))
629 (define (parenthesize-elements grob . rest)
630 (let* ((refp (if (null? rest)
633 (elts (ly:grob-object grob 'elements))
634 (x-ext (ly:relative-group-extent elts refp X))
635 (stencils (ly:grob-property grob 'stencils))
638 (padding (ly:grob-property grob 'padding 0.1)))
641 (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
642 (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))))
645 (define-public (parentheses-item::print me)
646 (let* ((elts (ly:grob-object me 'elements))
647 (y-ref (ly:grob-common-refpoint-of-array me elts Y))
648 (x-ref (ly:grob-common-refpoint-of-array me elts X))
649 (stencil (parenthesize-elements me x-ref))
650 (elt-y-ext (ly:relative-group-extent elts y-ref Y))
651 (y-center (interval-center elt-y-ext)))
653 (ly:stencil-translate
656 (- (ly:grob-relative-coordinate me x-ref X))
657 (- y-center (ly:grob-relative-coordinate me y-ref Y))))))
661 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
664 (define-public (chain-grob-member-functions grob value . funcs)
667 (set! value (func grob value)))
673 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
676 (define-public (bend::print spanner)
678 (< (abs (- a b)) 0.01))
680 (let* ((delta-y (* 0.5 (ly:grob-property spanner 'delta-position)))
681 (left-span (ly:spanner-bound spanner LEFT))
682 (dots (if (and (grob::has-interface left-span 'note-head-interface)
683 (ly:grob? (ly:grob-object left-span 'dot)))
684 (ly:grob-object left-span 'dot) #f))
686 (right-span (ly:spanner-bound spanner RIGHT))
687 (thickness (* (ly:grob-property spanner 'thickness)
688 (ly:output-def-lookup (ly:grob-layout spanner)
690 (padding (ly:grob-property spanner 'padding 0.5))
691 (common (ly:grob-common-refpoint right-span
692 (ly:grob-common-refpoint spanner
695 (common-y (ly:grob-common-refpoint spanner left-span Y))
696 (minimum-length (ly:grob-property spanner 'minimum-length 0.5))
700 (interval-end (ly:grob-robust-relative-extent
705 (ly:grob-relative-coordinate dots common-y Y)
706 (ly:grob-relative-coordinate spanner common-y Y)))
708 (ly:grob-robust-relative-extent dots common X))
709 ;; TODO: use real infinity constant.
711 (right-x (max (- (interval-start
712 (ly:grob-robust-relative-extent right-span common X))
714 (+ left-x minimum-length)))
715 (self-x (ly:grob-relative-coordinate spanner common X))
716 (dx (- right-x left-x))
717 (exp (list 'path thickness
725 ,dx ,(* 0.66 delta-y)
730 (cons (- left-x self-x) (- right-x self-x))
731 (cons (min 0 delta-y)
735 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
738 (define-public (grace-spacing::calc-shortest-duration grob)
739 (let* ((cols (ly:grob-object grob 'columns))
742 (ly:moment-sub (ly:grob-property
743 (ly:grob-array-ref cols (1+ idx)) 'when)
745 (ly:grob-array-ref cols idx) 'when))))
747 (moment-min (lambda (x y)
750 (if (ly:moment<? x y)
756 (fold moment-min #f (map get-difference
757 (iota (1- (ly:grob-array-length cols)))))))
760 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
763 (define-public (fingering::calc-text grob)
764 (let* ((event (event-cause grob))
765 (digit (ly:event-property event 'digit)))
768 (ly:input-message (ly:event-property event 'origin)
769 "Warning: Fingering notation for finger number ~a"
772 (number->string digit 10)))
774 (define-public (string-number::calc-text grob)
775 (let ((digit (ly:event-property (event-cause grob) 'string-number)))
777 (number->string digit 10)))
779 (define-public (stroke-finger::calc-text grob)
780 (let* ((digit (ly:event-property (event-cause grob) 'digit))
781 (text (ly:event-property (event-cause grob) 'text)))
785 (vector-ref (ly:grob-property grob 'digit-names)
786 (1- (max (min 5 digit) 1))))))
789 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
792 (define-public (hairpin::calc-grow-direction grob)
793 (if (eq? (ly:event-property (event-cause grob) 'class) 'decrescendo-event)
797 (define-public (dynamic-text-spanner::before-line-breaking grob)
798 "Monitor left bound of @code{DynamicTextSpanner} for absolute dynamics.
799 If found, ensure @code{DynamicText} does not collide with spanner text by
800 changing @code{'attach-dir} and @code{'padding}. Reads the
801 @code{'right-padding} property of @code{DynamicText} to fine tune space
802 between the two text elements."
803 (let ((left-bound (ly:spanner-bound grob LEFT)))
804 (if (grob::has-interface left-bound 'dynamic-text-interface)
805 (let* ((details (ly:grob-property grob 'bound-details))
806 (left-details (ly:assoc-get 'left details))
807 (my-padding (ly:assoc-get 'padding left-details))
808 (script-padding (ly:grob-property left-bound 'right-padding 0)))
810 (and (number? my-padding)
811 (ly:grob-set-nested-property! grob
812 '(bound-details left attach-dir)
814 (ly:grob-set-nested-property! grob
815 '(bound-details left padding)
816 (+ my-padding script-padding)))))))
819 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
822 (define-public (lyric-text::print grob)
823 "Allow interpretation of tildes as lyric tieing marks."
825 (let ((text (ly:grob-property grob 'text)))
827 (grob-interpret-markup grob (if (string? text)
828 (make-tied-lyric-markup text)
831 (define-public ((grob::calc-property-by-copy prop) grob)
832 (ly:event-property (event-cause grob) prop))
835 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
838 (define-public (fret-board::calc-stencil grob)
839 (grob-interpret-markup
841 (make-fret-diagram-verbose-markup
842 (ly:grob-property grob 'dot-placement-list))))
845 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
848 (define-public (script-interface::calc-x-offset grob)
849 (ly:grob-property grob 'positioning-done)
850 (let* ((shift (ly:grob-property grob 'toward-stem-shift 0.0))
852 (ly:self-alignment-interface::centered-on-x-parent grob))
853 (note-head-grob (ly:grob-parent grob X))
854 (stem-grob (ly:grob-object note-head-grob 'stem)))
856 (+ note-head-location
857 ;; If the property 'toward-stem-shift is defined and the script
858 ;; has the same direction as the stem, move the script accordingly.
859 ;; Since scripts can also be over skips, we need to check whether
860 ;; the grob has a stem at all.
861 (if (ly:grob? stem-grob)
862 (let ((dir1 (ly:grob-property grob 'direction))
863 (dir2 (ly:grob-property stem-grob 'direction)))
864 (if (equal? dir1 dir2)
865 (let* ((common-refp (ly:grob-common-refpoint grob stem-grob X))
867 (ly:grob-relative-coordinate stem-grob common-refp X)))
868 (* shift (- stem-location note-head-location)))
873 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
876 (define-public (system-start-text::print grob)
877 (let* ((left-bound (ly:spanner-bound grob LEFT))
878 (left-mom (ly:grob-property left-bound 'when))
879 (name (if (moment<=? left-mom ZERO-MOMENT)
880 (ly:grob-property grob 'long-text)
881 (ly:grob-property grob 'text))))
883 (if (and (markup? name)
884 (!= (ly:item-break-dir left-bound) CENTER))
886 (grob-interpret-markup grob name)
887 (ly:grob-suicide! grob))))
889 (define-public (system-start-text::calc-x-offset grob)
890 (let* ((left-bound (ly:spanner-bound grob LEFT))
891 (left-mom (ly:grob-property left-bound 'when))
892 (layout (ly:grob-layout grob))
893 (indent (ly:output-def-lookup layout
894 (if (moment<=? left-mom ZERO-MOMENT)
898 (system (ly:grob-system grob))
899 (my-extent (ly:grob-extent grob system X))
900 (elements (ly:grob-object system 'elements))
901 (common (ly:grob-common-refpoint-of-array system elements X))
902 (total-ext empty-interval)
903 (align-x (ly:grob-property grob 'self-alignment-X 0))
904 (padding (min 0 (- (interval-length my-extent) indent)))
905 (right-padding (- padding
906 (/ (* padding (1+ align-x)) 2))))
908 ;; compensate for the variation in delimiter extents by
909 ;; calculating an X-offset correction based on united extents
910 ;; of all delimiters in this system
911 (let unite-delims ((l (ly:grob-array-length elements)))
913 (let ((elt (ly:grob-array-ref elements (1- l))))
915 (if (grob::has-interface elt 'system-start-delimiter-interface)
916 (let ((dims (ly:grob-extent elt common X)))
917 (if (interval-sane? dims)
918 (set! total-ext (interval-union total-ext dims)))))
919 (unite-delims (1- l)))))
922 (ly:side-position-interface::x-aligned-side grob)
924 (- (interval-length total-ext)))))
926 (define-public (system-start-text::calc-y-offset grob)
928 (define (live-elements-list me)
929 (let ((elements (ly:grob-object me 'elements)))
931 (filter! grob::is-live?
932 (ly:grob-array->list elements))))
934 (let* ((left-bound (ly:spanner-bound grob LEFT))
935 (live-elts (live-elements-list grob))
936 (system (ly:grob-system grob))
937 (extent empty-interval))
939 (if (and (pair? live-elts)
940 (interval-sane? (ly:grob-extent grob system Y)))
941 (let get-extent ((lst live-elts))
943 (let ((axis-group (car lst)))
945 (if (and (ly:spanner? axis-group)
946 (equal? (ly:spanner-bound axis-group LEFT)
948 (set! extent (add-point extent
949 (ly:grob-relative-coordinate
950 axis-group system Y))))
951 (get-extent (cdr lst)))))
952 ;; no live axis group(s) for this instrument name -> remove from system
953 (ly:grob-suicide! grob))
956 (ly:self-alignment-interface::y-aligned-on-self grob)
957 (interval-center extent))))
960 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
963 (define-public (ambitus::print grob)
964 (let ((heads (ly:grob-object grob 'note-heads)))
966 (if (and (ly:grob-array? heads)
967 (= (ly:grob-array-length heads) 2))
968 (let* ((common (ly:grob-common-refpoint-of-array grob heads Y))
969 (head-down (ly:grob-array-ref heads 0))
970 (head-up (ly:grob-array-ref heads 1))
971 (gap (ly:grob-property grob 'gap 0.35))
972 (point-min (+ (interval-end (ly:grob-extent head-down common Y))
974 (point-max (- (interval-start (ly:grob-extent head-up common Y))
977 (if (< point-min point-max)
978 (let* ((layout (ly:grob-layout grob))
979 (line-thick (ly:output-def-lookup layout 'line-thickness))
980 (blot (ly:output-def-lookup layout 'blot-diameter))
981 (grob-thick (ly:grob-property grob 'thickness 2))
982 (width (* line-thick grob-thick))
983 (x-ext (symmetric-interval (/ width 2)))
984 (y-ext (cons point-min point-max))
985 (line (ly:round-filled-box x-ext y-ext blot))
986 (y-coord (ly:grob-relative-coordinate grob common Y)))
988 (ly:stencil-translate-axis line (- y-coord) Y))
991 (ly:grob-suicide! grob)
994 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
995 ;; laissez-vibrer tie
997 ;; needed so we can make laissez-vibrer a pure print
999 (define-public (laissez-vibrer::print grob)
1000 (ly:tie::print grob))