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 (make-stencil-boxer thickness padding callback)
30 "Return function that adds a box around the grob passed as argument."
32 (box-stencil (callback grob) thickness padding)))
34 (define-public (make-stencil-circler thickness padding callback)
35 "Return function that adds a circle around the grob passed as argument."
37 (circle-stencil (callback grob) thickness padding)))
39 (define-public (print-circled-text-callback grob)
40 (grob-interpret-markup grob (make-circle-markup
41 (ly:grob-property grob 'text))))
43 (define-public (event-cause grob)
44 (let ((cause (ly:grob-property grob 'cause)))
47 ((ly:stream-event? cause) cause)
48 ((ly:grob? cause) (event-cause cause))
51 (define-public (grob-interpret-markup grob text)
52 (let* ((layout (ly:grob-layout grob))
53 (defs (ly:output-def-lookup layout 'text-font-defaults))
54 (props (ly:grob-alist-chain grob defs)))
56 (ly:text-interface::interpret-markup layout props text)))
59 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
62 (define-public (script-or-side-position-cross-staff g)
64 (ly:script-interface::calc-cross-staff g)
65 (ly:side-position-interface::calc-cross-staff g)))
68 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
71 (define-public (stem::calc-duration-log grob)
73 (ly:event-property (event-cause grob) 'duration)))
75 (define-public (stem::length grob)
76 (let* ((d (ly:grob-property grob 'direction))
77 (ss (ly:staff-symbol-staff-space grob))
78 (beg (ly:grob-property grob 'stem-begin-position))
79 (beam (ly:grob-object grob 'beam)))
81 (abs (- (ly:stem::calc-stem-end-position grob) beg))
82 (ly:grob-property grob 'length))))
84 (define-public (stem::pure-length grob beg end)
85 (let* ((d (ly:grob-property grob 'direction))
86 (ss (ly:staff-symbol-staff-space grob))
87 (beg (ly:grob-pure-property grob 'stem-begin-position 0 1000)))
88 (abs (- (ly:stem::pure-calc-stem-end-position grob 0 2147483646) beg))))
90 (define-public (note-head::calc-duration-log grob)
93 (ly:event-property (event-cause grob) 'duration))))
95 (define-public (dots::calc-dot-count grob)
96 (ly:duration-dot-count
97 (ly:event-property (event-cause grob) 'duration)))
99 (define-public (dots::calc-staff-position grob)
100 (let* ((head (ly:grob-parent grob Y))
101 (log (ly:grob-property head 'duration-log)))
104 ((or (not (grob::has-interface head 'rest-interface))
105 (not (integer? log))) 0)
113 ;; Kept separate from note-head::calc-glyph-name to allow use by
114 ;; markup commands \note and \note-by-number
115 (define-public (select-head-glyph style log)
116 "Select a note head glyph string based on note head style @var{style}
117 and duration-log @var{log}."
119 ;; "default" style is directly handled in note-head.cc as a
120 ;; special case (HW says, mainly for performance reasons).
121 ;; Therefore, style "default" does not appear in this case
123 ((xcircle) "2xcircle")
124 ((harmonic) "0harmonic")
125 ((harmonic-black) "2harmonic")
126 ((harmonic-mixed) (if (<= log 1) "0harmonic"
129 ;; Oops, I actually would not call this "baroque", but, for
130 ;; backwards compatibility to 1.4, this is supposed to take
131 ;; brevis, longa and maxima from the neo-mensural font and all
132 ;; other note heads from the default font. -- jr
134 (string-append (number->string log) "neomensural")
135 (number->string log)))
137 ;; Like default, but brevis is drawn with double vertical lines
139 (string-append (number->string log) "double")
140 (number->string log)))
142 (string-append (number->string log) (symbol->string style)))
145 (string-append (number->string log) "mensural")
146 (string-append (number->string log) (symbol->string style))))
149 (string-append (number->string log) "blackmensural")
150 (string-append (number->string log) (symbol->string style))))
153 (string-append (number->string log) "semimensural")
154 (string-append (number->string log) "petrucci")))
156 (string-append (number->string log) (symbol->string style)))
158 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
159 (symbol->string style)
160 (string-append (number->string (max 0 log))
161 (symbol->string style))))))
163 (define-public (note-head::calc-glyph-name grob)
164 (let ((style (ly:grob-property grob 'style))
165 (log (min 2 (ly:grob-property grob 'duration-log))))
167 (select-head-glyph style log)))
169 (define-public (note-head::brew-ez-stencil grob)
170 (let* ((log (ly:grob-property grob 'duration-log))
171 (pitch (ly:event-property (event-cause grob) 'pitch))
172 (pitch-index (ly:pitch-notename pitch))
173 (note-names (ly:grob-property grob 'note-names))
174 (pitch-string (if (and (vector? note-names)
175 (> (vector-length note-names) pitch-index))
176 (vector-ref note-names pitch-index)
179 (+ (modulo (+ pitch-index 2) 7)
180 (char->integer #\A))))))
181 (staff-space (ly:staff-symbol-staff-space grob))
182 (line-thickness (ly:staff-symbol-line-thickness grob))
183 (stem (ly:grob-object grob 'stem))
184 (stem-thickness (* (if (ly:grob? stem)
185 (ly:grob-property stem 'thickness)
188 (radius (/ (+ staff-space line-thickness) 2))
189 (letter (markup #:center-align #:vcenter pitch-string))
190 (filled-circle (markup #:draw-circle radius 0 #t)))
192 (ly:stencil-translate-axis
193 (grob-interpret-markup
198 (make-with-color-markup white letter))
202 (make-with-color-markup white (make-draw-circle-markup
203 (- radius stem-thickness) 0 #t)))
207 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
210 (define-public (make-rhythmic-location bar-num num den)
212 bar-num (ly:make-moment num den)))
214 (define-public (rhythmic-location? a)
217 (ly:moment? (cdr a))))
219 (define-public (make-graceless-rhythmic-location loc)
220 (make-rhythmic-location
222 (ly:moment-main-numerator (rhythmic-location-measure-position loc))
223 (ly:moment-main-denominator (rhythmic-location-measure-position loc))))
225 (define-public rhythmic-location-measure-position cdr)
226 (define-public rhythmic-location-bar-number car)
228 (define-public (rhythmic-location<? a b)
230 ((< (car a) (car b)) #t)
231 ((> (car a) (car b)) #f)
233 (ly:moment<? (cdr a) (cdr b)))))
235 (define-public (rhythmic-location<=? a b)
236 (not (rhythmic-location<? b a)))
237 (define-public (rhythmic-location>=? a b)
238 (rhythmic-location<? a b))
239 (define-public (rhythmic-location>? a b)
240 (rhythmic-location<? b a))
242 (define-public (rhythmic-location=? a b)
243 (and (rhythmic-location<=? a b)
244 (rhythmic-location<=? b a)))
246 (define-public (rhythmic-location->file-string a)
247 (ly:format "~a.~a.~a"
249 (ly:moment-main-numerator (cdr a))
250 (ly:moment-main-denominator (cdr a))))
252 (define-public (rhythmic-location->string a)
253 (ly:format "bar ~a ~a"
255 (ly:moment->string (cdr a))))
257 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
260 (define-public all-visible #(#t #t #t))
261 (define-public begin-of-line-invisible #(#t #t #f))
262 (define-public center-invisible #(#t #f #t))
263 (define-public end-of-line-invisible #(#f #t #t))
264 (define-public begin-of-line-visible #(#f #f #t))
265 (define-public center-visible #(#f #t #f))
266 (define-public end-of-line-visible #(#t #f #f))
267 (define-public all-invisible #(#f #f #f))
268 (define-public (inherit-x-parent-visibility grob)
269 (let ((parent (ly:grob-parent grob X)))
270 (ly:grob-property parent 'break-visibility all-invisible)))
271 (define-public (inherit-y-parent-visibility grob)
272 (let ((parent (ly:grob-parent grob X)))
273 (ly:grob-property parent 'break-visibility)))
276 (define-public spanbar-begin-of-line-invisible #(#t #f #f))
279 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
283 ;; How should a bar line behave at a break?
284 (define bar-glyph-alist
285 '((":|:" . (":|" . "|:"))
286 (":|.|:" . (":|" . "|:"))
287 (":|.:" . (":|" . "|:"))
288 ("||:" . ("||" . "|:"))
289 ("dashed" . ("dashed" . '()))
291 ("||:" . ("||" . "|:"))
293 ("|:" . ("|" . "|:"))
296 ;; hmm... should we end with a bar line here?
297 (".|" . ("|" . ".|"))
300 (".|." . (".|." . ()))
301 ("|.|" . ("|.|" . ()))
306 ("empty" . (() . ()))
307 ("brace" . (() . "brace"))
308 ("bracket" . (() . "bracket"))
314 (":|S" . (":|" . "S"))
315 (":|S." . (":|S" . ()))
316 ("S|:" . ("S" . "|:"))
317 (".S|:" . ("|" . "S|:"))
318 (":|S|:" . (":|" . "S|:"))
319 (":|S.|:" . (":|S" . "|:"))))
321 (define-public (bar-line::calc-glyph-name grob)
322 (let* ((glyph (ly:grob-property grob 'glyph))
323 (dir (ly:item-break-dir grob))
324 (result (assoc-get glyph bar-glyph-alist))
325 (glyph-name (if (= dir CENTER)
328 (string? (index-cell result dir)))
329 (index-cell result dir)
333 (define-public (bar-line::calc-break-visibility grob)
334 (let* ((glyph (ly:grob-property grob 'glyph))
335 (result (assoc-get glyph bar-glyph-alist)))
338 (vector (string? (car result)) #t (string? (cdr result)))
341 (define-public (shift-right-at-line-begin g)
342 "Shift an item to the right, but only at the start of the line."
343 (if (and (ly:item? g)
344 (equal? (ly:item-break-dir g) RIGHT))
345 (ly:grob-translate-axis! g 3.5 X)))
348 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
351 (define-public (tuplet-number::calc-direction grob)
352 (ly:tuplet-bracket::calc-direction (ly:grob-object grob 'bracket)))
354 (define-public (tuplet-number::calc-denominator-text grob)
355 (number->string (ly:event-property (event-cause grob) 'denominator)))
357 (define-public (tuplet-number::calc-fraction-text grob)
358 (let ((ev (event-cause grob)))
361 (ly:event-property ev 'denominator)
362 (ly:event-property ev 'numerator))))
364 ;; a formatter function, which is simply a wrapper around an existing
365 ;; tuplet formatter function. It takes the value returned by the given
366 ;; function and appends a note of given length.
367 (define-public ((tuplet-number::append-note-wrapper function note) grob)
368 (let ((txt (if function (function grob) #f)))
371 (markup txt #:fontsize -5 #:note note UP)
372 (markup #:fontsize -5 #:note note UP))))
374 ;; Print a tuplet denominator with a different number than the one derived from
375 ;; the actual tuplet fraction
376 (define-public ((tuplet-number::non-default-tuplet-denominator-text denominator)
378 (number->string (if denominator
380 (ly:event-property (event-cause grob) 'denominator))))
382 ;; Print a tuplet fraction with different numbers than the ones derived from
383 ;; the actual tuplet fraction
384 (define-public ((tuplet-number::non-default-tuplet-fraction-text
385 denominator numerator) grob)
386 (let* ((ev (event-cause grob))
387 (den (if denominator denominator (ly:event-property ev 'denominator)))
388 (num (if numerator numerator (ly:event-property ev 'numerator))))
390 (format #f "~a:~a" den num)))
392 ;; Print a tuplet fraction with note durations appended to the numerator and the
394 (define-public ((tuplet-number::fraction-with-notes
395 denominatornote numeratornote) grob)
396 (let* ((ev (event-cause grob))
397 (denominator (ly:event-property ev 'denominator))
398 (numerator (ly:event-property ev 'numerator)))
400 ((tuplet-number::non-default-fraction-with-notes
401 denominator denominatornote numerator numeratornote) grob)))
403 ;; Print a tuplet fraction with note durations appended to the numerator and the
405 (define-public ((tuplet-number::non-default-fraction-with-notes
406 denominator denominatornote numerator numeratornote) grob)
407 (let* ((ev (event-cause grob))
408 (den (if denominator denominator (ly:event-property ev 'denominator)))
409 (num (if numerator numerator (ly:event-property ev 'numerator))))
411 (make-concat-markup (list
412 (make-simple-markup (format #f "~a" den))
413 (markup #:fontsize -5 #:note denominatornote UP)
414 (make-simple-markup " : ")
415 (make-simple-markup (format #f "~a" num))
416 (markup #:fontsize -5 #:note numeratornote UP)))))
419 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
422 (define-public (color? x)
425 (apply eq? #t (map number? x))
426 (apply eq? #t (map (lambda (y) (<= 0 y 1)) x))))
428 (define-public (rgb-color r g b) (list r g b))
431 (define-public black '(0.0 0.0 0.0))
432 (define-public white '(1.0 1.0 1.0))
433 (define-public red '(1.0 0.0 0.0))
434 (define-public green '(0.0 1.0 0.0))
435 (define-public blue '(0.0 0.0 1.0))
436 (define-public cyan '(0.0 1.0 1.0))
437 (define-public magenta '(1.0 0.0 1.0))
438 (define-public yellow '(1.0 1.0 0.0))
440 (define-public grey '(0.5 0.5 0.5))
441 (define-public darkred '(0.5 0.0 0.0))
442 (define-public darkgreen '(0.0 0.5 0.0))
443 (define-public darkblue '(0.0 0.0 0.5))
444 (define-public darkcyan '(0.0 0.5 0.5))
445 (define-public darkmagenta '(0.5 0.0 0.5))
446 (define-public darkyellow '(0.5 0.5 0.0))
449 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
452 (define-public (key-signature-interface::alteration-position step alter
454 ;; TODO: memoize - this is mostly constant.
456 ;; fes, ges, as and bes typeset in lower octave
457 (define FLAT_TOP_PITCH 2)
459 ;; ais and bis typeset in lower octave
460 (define SHARP_TOP_PITCH 4)
463 (+ (cdr step) (* (car step) 7) c0-position)
464 (let* ((from-bottom-pos (modulo (+ 4 49 c0-position) 7))
466 (c0 (- from-bottom-pos 4)))
470 (or (> p FLAT_TOP_PITCH) (> (+ p c0) 4)) (> (+ p c0) 1))
472 (or (> p SHARP_TOP_PITCH) (> (+ p c0) 5)) (> (+ p c0) 2)))
474 ;; Typeset below c_position
477 ;; Provide for the four cases in which there's a glitch
478 ;; it's a hack, but probably not worth
479 ;; the effort of finding a nicer solution.
482 ((and (= c0 2) (= p 3) (> alter 0))
484 ((and (= c0 -3) (= p -1) (> alter 0))
486 ((and (= c0 -4) (= p -1) (< alter 0))
488 ((and (= c0 -2) (= p -3) (< alter 0))
494 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
497 (define-public (numbered-footnotes int)
498 (markup #:tiny (number->string (+ 1 int))))
500 (define-public (symbol-footnotes int)
501 (define (helper symbols out idx n)
505 (string-append out (list-ref symbols idx))
508 (markup #:tiny (helper '("*" "†" "‡" "§" "¶")
511 (+ 1 (quotient int 5)))))
513 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
516 (define-public (accidental-interface::calc-alteration grob)
517 (ly:pitch-alteration (ly:event-property (event-cause grob) 'pitch)))
519 (define-public cancellation-glyph-name-alist
520 '((0 . "accidentals.natural")))
522 (define-public standard-alteration-glyph-name-alist
524 ;; ordered for optimal performance.
525 (0 . "accidentals.natural")
526 (-1/2 . "accidentals.flat")
527 (1/2 . "accidentals.sharp")
529 (1 . "accidentals.doublesharp")
530 (-1 . "accidentals.flatflat")
532 (3/4 . "accidentals.sharp.slashslash.stemstemstem")
533 (1/4 . "accidentals.sharp.slashslash.stem")
534 (-1/4 . "accidentals.mirroredflat")
535 (-3/4 . "accidentals.mirroredflat.flat")))
537 ;; FIXME: standard vs default, alteration-FOO vs FOO-alteration
538 (define-public alteration-default-glyph-name-alist
539 standard-alteration-glyph-name-alist)
541 (define-public makam-alteration-glyph-name-alist
542 '((1 . "accidentals.doublesharp")
543 (8/9 . "accidentals.sharp.slashslashslash.stemstem")
544 (5/9 . "accidentals.sharp.slashslashslash.stem")
545 (4/9 . "accidentals.sharp")
546 (1/9 . "accidentals.sharp.slashslash.stem")
547 (0 . "accidentals.natural")
548 (-1/9 . "accidentals.mirroredflat")
549 (-4/9 . "accidentals.flat.slash")
550 (-5/9 . "accidentals.flat")
551 (-8/9 . "accidentals.flat.slashslash")
552 (-1 . "accidentals.flatflat")))
554 (define-public alteration-hufnagel-glyph-name-alist
555 '((-1/2 . "accidentals.hufnagelM1")
556 (0 . "accidentals.vaticana0")
557 (1/2 . "accidentals.mensural1")))
559 (define-public alteration-medicaea-glyph-name-alist
560 '((-1/2 . "accidentals.medicaeaM1")
561 (0 . "accidentals.vaticana0")
562 (1/2 . "accidentals.mensural1")))
564 (define-public alteration-vaticana-glyph-name-alist
565 '((-1/2 . "accidentals.vaticanaM1")
566 (0 . "accidentals.vaticana0")
567 (1/2 . "accidentals.mensural1")))
569 (define-public alteration-mensural-glyph-name-alist
570 '((-1/2 . "accidentals.mensuralM1")
571 (0 . "accidentals.vaticana0")
572 (1/2 . "accidentals.mensural1")))
575 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
576 ;; * Pitch Trill Heads
579 (define-public (parentheses-item::calc-parenthesis-stencils grob)
580 (let* ((font (ly:grob-default-font grob))
581 (lp (ly:font-get-glyph font "accidentals.leftparen"))
582 (rp (ly:font-get-glyph font "accidentals.rightparen")))
586 (define-public (parentheses-item::calc-angled-bracket-stencils grob)
587 (let* ((parent (ly:grob-parent grob Y))
588 (y-extent (ly:grob-extent parent parent Y))
589 (half-thickness 0.05) ; should it be a property?
590 (width 0.5) ; should it be a property?
591 (angularity 1.5) ; makes angle brackets
592 (white-padding 0.1) ; should it be a property?
593 (lp (ly:stencil-aligned-to
594 (ly:stencil-aligned-to
595 (make-parenthesis-stencil y-extent
602 (interval-widen (ly:stencil-extent lp X) white-padding))
603 (rp (ly:stencil-aligned-to
604 (ly:stencil-aligned-to
605 (make-parenthesis-stencil y-extent
612 (interval-widen (ly:stencil-extent rp X) white-padding)))
613 (set! lp (ly:make-stencil (ly:stencil-expr lp)
615 (ly:stencil-extent lp Y)))
616 (set! rp (ly:make-stencil (ly:stencil-expr rp)
618 (ly:stencil-extent rp Y)))
619 (list (stencil-whiteout lp)
620 (stencil-whiteout rp))))
622 (define (parenthesize-elements grob . rest)
623 (let* ((refp (if (null? rest)
626 (elts (ly:grob-object grob 'elements))
627 (x-ext (ly:relative-group-extent elts refp X))
628 (stencils (ly:grob-property grob 'stencils))
631 (padding (ly:grob-property grob 'padding 0.1)))
634 (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
635 (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))))
638 (define-public (parentheses-item::print me)
639 (let* ((elts (ly:grob-object me 'elements))
640 (y-ref (ly:grob-common-refpoint-of-array me elts Y))
641 (x-ref (ly:grob-common-refpoint-of-array me elts X))
642 (stencil (parenthesize-elements me x-ref))
643 (elt-y-ext (ly:relative-group-extent elts y-ref Y))
644 (y-center (interval-center elt-y-ext)))
646 (ly:stencil-translate
649 (- (ly:grob-relative-coordinate me x-ref X))
650 (- y-center (ly:grob-relative-coordinate me y-ref Y))))))
654 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
657 (define-public (chain-grob-member-functions grob value . funcs)
660 (set! value (func grob value)))
666 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
669 (define-public (bend::print spanner)
671 (< (abs (- a b)) 0.01))
673 (let* ((delta-y (* 0.5 (ly:grob-property spanner 'delta-position)))
674 (left-span (ly:spanner-bound spanner LEFT))
675 (dots (if (and (grob::has-interface left-span 'note-head-interface)
676 (ly:grob? (ly:grob-object left-span 'dot)))
677 (ly:grob-object left-span 'dot) #f))
679 (right-span (ly:spanner-bound spanner RIGHT))
680 (thickness (* (ly:grob-property spanner 'thickness)
681 (ly:output-def-lookup (ly:grob-layout spanner)
683 (padding (ly:grob-property spanner 'padding 0.5))
684 (common (ly:grob-common-refpoint right-span
685 (ly:grob-common-refpoint spanner
688 (common-y (ly:grob-common-refpoint spanner left-span Y))
689 (minimum-length (ly:grob-property spanner 'minimum-length 0.5))
693 (interval-end (ly:grob-robust-relative-extent
698 (ly:grob-relative-coordinate dots common-y Y)
699 (ly:grob-relative-coordinate spanner common-y Y)))
701 (ly:grob-robust-relative-extent dots common X))
702 ;; TODO: use real infinity constant.
704 (right-x (max (- (interval-start
705 (ly:grob-robust-relative-extent right-span common X))
707 (+ left-x minimum-length)))
708 (self-x (ly:grob-relative-coordinate spanner common X))
709 (dx (- right-x left-x))
710 (exp (list 'path thickness
718 ,dx ,(* 0.66 delta-y)
723 (cons (- left-x self-x) (- right-x self-x))
724 (cons (min 0 delta-y)
728 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
731 (define-public (grace-spacing::calc-shortest-duration grob)
732 (let* ((cols (ly:grob-object grob 'columns))
735 (ly:moment-sub (ly:grob-property
736 (ly:grob-array-ref cols (1+ idx)) 'when)
738 (ly:grob-array-ref cols idx) 'when))))
740 (moment-min (lambda (x y)
743 (if (ly:moment<? x y)
749 (fold moment-min #f (map get-difference
750 (iota (1- (ly:grob-array-length cols)))))))
753 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
756 (define-public (fingering::calc-text grob)
757 (let* ((event (event-cause grob))
758 (digit (ly:event-property event 'digit)))
761 (ly:input-message (ly:event-property event 'origin)
762 "Warning: Fingering notation for finger number ~a"
765 (number->string digit 10)))
767 (define-public (string-number::calc-text grob)
768 (let ((digit (ly:event-property (event-cause grob) 'string-number)))
770 (number->string digit 10)))
772 (define-public (stroke-finger::calc-text grob)
773 (let* ((digit (ly:event-property (event-cause grob) 'digit))
774 (text (ly:event-property (event-cause grob) 'text)))
778 (vector-ref (ly:grob-property grob 'digit-names)
779 (1- (max (min 5 digit) 1))))))
782 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
785 (define-public (hairpin::calc-grow-direction grob)
786 (if (eq? (ly:event-property (event-cause grob) 'class) 'decrescendo-event)
790 (define-public (dynamic-text-spanner::before-line-breaking grob)
791 "Monitor left bound of @code{DynamicTextSpanner} for absolute dynamics.
792 If found, ensure @code{DynamicText} does not collide with spanner text by
793 changing @code{'attach-dir} and @code{'padding}. Reads the
794 @code{'right-padding} property of @code{DynamicText} to fine tune space
795 between the two text elements."
796 (let ((left-bound (ly:spanner-bound grob LEFT)))
797 (if (grob::has-interface left-bound 'dynamic-text-interface)
798 (let* ((details (ly:grob-property grob 'bound-details))
799 (left-details (ly:assoc-get 'left details))
800 (my-padding (ly:assoc-get 'padding left-details))
801 (script-padding (ly:grob-property left-bound 'right-padding 0)))
803 (and (number? my-padding)
804 (ly:grob-set-nested-property! grob
805 '(bound-details left attach-dir)
807 (ly:grob-set-nested-property! grob
808 '(bound-details left padding)
809 (+ my-padding script-padding)))))))
812 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
815 (define-public (lyric-text::print grob)
816 "Allow interpretation of tildes as lyric tieing marks."
818 (let ((text (ly:grob-property grob 'text)))
820 (grob-interpret-markup grob (if (string? text)
821 (make-tied-lyric-markup text)
824 (define-public ((grob::calc-property-by-copy prop) grob)
825 (ly:event-property (event-cause grob) prop))
828 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
831 (define-public (fret-board::calc-stencil grob)
832 (grob-interpret-markup
834 (make-fret-diagram-verbose-markup
835 (ly:grob-property grob 'dot-placement-list))))
838 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
841 (define-public (script-interface::calc-x-offset grob)
842 (ly:grob-property grob 'positioning-done)
843 (let* ((shift (ly:grob-property grob 'toward-stem-shift 0.0))
845 (ly:self-alignment-interface::centered-on-x-parent grob))
846 (note-head-grob (ly:grob-parent grob X))
847 (stem-grob (ly:grob-object note-head-grob 'stem)))
849 (+ note-head-location
850 ;; If the property 'toward-stem-shift is defined and the script
851 ;; has the same direction as the stem, move the script accordingly.
852 ;; Since scripts can also be over skips, we need to check whether
853 ;; the grob has a stem at all.
854 (if (ly:grob? stem-grob)
855 (let ((dir1 (ly:grob-property grob 'direction))
856 (dir2 (ly:grob-property stem-grob 'direction)))
857 (if (equal? dir1 dir2)
858 (let* ((common-refp (ly:grob-common-refpoint grob stem-grob X))
860 (ly:grob-relative-coordinate stem-grob common-refp X)))
861 (* shift (- stem-location note-head-location)))
866 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
869 (define-public (system-start-text::print grob)
870 (let* ((left-bound (ly:spanner-bound grob LEFT))
871 (left-mom (ly:grob-property left-bound 'when))
872 (name (if (moment<=? left-mom ZERO-MOMENT)
873 (ly:grob-property grob 'long-text)
874 (ly:grob-property grob 'text))))
876 (if (and (markup? name)
877 (!= (ly:item-break-dir left-bound) CENTER))
879 (grob-interpret-markup grob name)
880 (ly:grob-suicide! grob))))
882 (define-public (system-start-text::calc-x-offset grob)
883 (let* ((left-bound (ly:spanner-bound grob LEFT))
884 (left-mom (ly:grob-property left-bound 'when))
885 (layout (ly:grob-layout grob))
886 (indent (ly:output-def-lookup layout
887 (if (moment<=? left-mom ZERO-MOMENT)
891 (system (ly:grob-system grob))
892 (my-extent (ly:grob-extent grob system X))
893 (elements (ly:grob-object system 'elements))
894 (common (ly:grob-common-refpoint-of-array system elements X))
895 (total-ext empty-interval)
896 (align-x (ly:grob-property grob 'self-alignment-X 0))
897 (padding (min 0 (- (interval-length my-extent) indent)))
898 (right-padding (- padding
899 (/ (* padding (1+ align-x)) 2))))
901 ;; compensate for the variation in delimiter extents by
902 ;; calculating an X-offset correction based on united extents
903 ;; of all delimiters in this system
904 (let unite-delims ((l (ly:grob-array-length elements)))
906 (let ((elt (ly:grob-array-ref elements (1- l))))
908 (if (grob::has-interface elt 'system-start-delimiter-interface)
909 (let ((dims (ly:grob-extent elt common X)))
910 (if (interval-sane? dims)
911 (set! total-ext (interval-union total-ext dims)))))
912 (unite-delims (1- l)))))
915 (ly:side-position-interface::x-aligned-side grob)
917 (- (interval-length total-ext)))))
919 (define-public (system-start-text::calc-y-offset grob)
921 (define (live-elements-list me)
922 (let ((elements (ly:grob-object me 'elements)))
924 (filter! grob::is-live?
925 (ly:grob-array->list elements))))
927 (let* ((left-bound (ly:spanner-bound grob LEFT))
928 (live-elts (live-elements-list grob))
929 (system (ly:grob-system grob))
930 (extent empty-interval))
932 (if (and (pair? live-elts)
933 (interval-sane? (ly:grob-extent grob system Y)))
934 (let get-extent ((lst live-elts))
936 (let ((axis-group (car lst)))
938 (if (and (ly:spanner? axis-group)
939 (equal? (ly:spanner-bound axis-group LEFT)
941 (set! extent (add-point extent
942 (ly:grob-relative-coordinate
943 axis-group system Y))))
944 (get-extent (cdr lst)))))
945 ;; no live axis group(s) for this instrument name -> remove from system
946 (ly:grob-suicide! grob))
949 (ly:self-alignment-interface::y-aligned-on-self grob)
950 (interval-center extent))))
953 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
956 (define-public (ambitus::print grob)
957 (let ((heads (ly:grob-object grob 'note-heads)))
959 (if (and (ly:grob-array? heads)
960 (= (ly:grob-array-length heads) 2))
961 (let* ((common (ly:grob-common-refpoint-of-array grob heads Y))
962 (head-down (ly:grob-array-ref heads 0))
963 (head-up (ly:grob-array-ref heads 1))
964 (gap (ly:grob-property grob 'gap 0.35))
965 (point-min (+ (interval-end (ly:grob-extent head-down common Y))
967 (point-max (- (interval-start (ly:grob-extent head-up common Y))
970 (if (< point-min point-max)
971 (let* ((layout (ly:grob-layout grob))
972 (line-thick (ly:output-def-lookup layout 'line-thickness))
973 (blot (ly:output-def-lookup layout 'blot-diameter))
974 (grob-thick (ly:grob-property grob 'thickness 2))
975 (width (* line-thick grob-thick))
976 (x-ext (symmetric-interval (/ width 2)))
977 (y-ext (cons point-min point-max))
978 (line (ly:round-filled-box x-ext y-ext blot))
979 (y-coord (ly:grob-relative-coordinate grob common Y)))
981 (ly:stencil-translate-axis line (- y-coord) Y))
984 (ly:grob-suicide! grob)
987 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
988 ;; laissez-vibrer tie
990 ;; needed so we can make laissez-vibrer a pure print
992 (define-public (laissez-vibrer::print grob)
993 (ly:tie::print grob))