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* ((ss (ly:staff-symbol-staff-space grob))
77 (beg (ly:grob-property grob 'stem-begin-position))
78 (beam (ly:grob-object grob 'beam)))
80 (abs (- (ly:stem::calc-stem-end-position grob) beg))
82 "stem::length called but will not be used for beamed stem."))))
84 (define-public (stem::pure-length grob beg end)
85 (let* ((ss (ly:staff-symbol-staff-space grob))
86 (beg (ly:grob-pure-property grob 'stem-begin-position 0 1000)))
87 (abs (- (ly:stem::pure-calc-stem-end-position grob 0 2147483646) beg))))
89 (define-public (note-head::calc-duration-log grob)
92 (ly:event-property (event-cause grob) 'duration))))
94 (define-public (dots::calc-dot-count grob)
95 (ly:duration-dot-count
96 (ly:event-property (event-cause grob) 'duration)))
98 (define-public (dots::calc-staff-position grob)
99 (let* ((head (ly:grob-parent grob Y))
100 (log (ly:grob-property head 'duration-log)))
103 ((or (not (grob::has-interface head 'rest-interface))
104 (not (integer? log))) 0)
112 ;; Kept separate from note-head::calc-glyph-name to allow use by
113 ;; markup commands \note and \note-by-number
114 (define-public (select-head-glyph style log)
115 "Select a note head glyph string based on note head style @var{style}
116 and duration-log @var{log}."
118 ;; "default" style is directly handled in note-head.cc as a
119 ;; special case (HW says, mainly for performance reasons).
120 ;; Therefore, style "default" does not appear in this case
122 ((xcircle) "2xcircle")
123 ((harmonic) "0harmonic")
124 ((harmonic-black) "2harmonic")
125 ((harmonic-mixed) (if (<= log 1) "0harmonic"
128 ;; Oops, I actually would not call this "baroque", but, for
129 ;; backwards compatibility to 1.4, this is supposed to take
130 ;; brevis, longa and maxima from the neo-mensural font and all
131 ;; other note heads from the default font. -- jr
133 (string-append (number->string log) "neomensural")
134 (number->string log)))
136 ;; Like default, but brevis is drawn with double vertical lines
138 (string-append (number->string log) "double")
139 (number->string log)))
141 (string-append (number->string log) (symbol->string style)))
144 (string-append (number->string log) "mensural")
145 (string-append (number->string log) (symbol->string style))))
148 (string-append (number->string log) "blackmensural")
149 (string-append (number->string log) (symbol->string style))))
152 (string-append (number->string log) "semimensural")
153 (string-append (number->string log) "petrucci")))
155 (string-append (number->string log) (symbol->string style)))
157 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
158 (symbol->string style)
159 (string-append (number->string (max 0 log))
160 (symbol->string style))))))
162 (define-public (note-head::calc-glyph-name grob)
163 (let ((style (ly:grob-property grob 'style))
164 (log (min 2 (ly:grob-property grob 'duration-log))))
166 (select-head-glyph style log)))
168 (define-public (note-head::brew-ez-stencil grob)
169 (let* ((log (ly:grob-property grob 'duration-log))
170 (pitch (ly:event-property (event-cause grob) 'pitch))
171 (pitch-index (ly:pitch-notename pitch))
172 (note-names (ly:grob-property grob 'note-names))
173 (pitch-string (if (and (vector? note-names)
174 (> (vector-length note-names) pitch-index))
175 (vector-ref note-names pitch-index)
178 (+ (modulo (+ pitch-index 2) 7)
179 (char->integer #\A))))))
180 (staff-space (ly:staff-symbol-staff-space grob))
181 (line-thickness (ly:staff-symbol-line-thickness grob))
182 (stem (ly:grob-object grob 'stem))
183 (stem-thickness (* (if (ly:grob? stem)
184 (ly:grob-property stem 'thickness)
187 (radius (/ (+ staff-space line-thickness) 2))
188 (letter (markup #:center-align #:vcenter pitch-string))
189 (filled-circle (markup #:draw-circle radius 0 #t)))
191 (ly:stencil-translate-axis
192 (grob-interpret-markup
197 (make-with-color-markup white letter))
201 (make-with-color-markup white (make-draw-circle-markup
202 (- radius stem-thickness) 0 #t)))
206 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
209 (define-public (make-rhythmic-location bar-num num den)
211 bar-num (ly:make-moment num den)))
213 (define-public (rhythmic-location? a)
216 (ly:moment? (cdr a))))
218 (define-public (make-graceless-rhythmic-location loc)
219 (make-rhythmic-location
221 (ly:moment-main-numerator (rhythmic-location-measure-position loc))
222 (ly:moment-main-denominator (rhythmic-location-measure-position loc))))
224 (define-public rhythmic-location-measure-position cdr)
225 (define-public rhythmic-location-bar-number car)
227 (define-public (rhythmic-location<? a b)
229 ((< (car a) (car b)) #t)
230 ((> (car a) (car b)) #f)
232 (ly:moment<? (cdr a) (cdr b)))))
234 (define-public (rhythmic-location<=? a b)
235 (not (rhythmic-location<? b a)))
236 (define-public (rhythmic-location>=? a b)
237 (rhythmic-location<? a b))
238 (define-public (rhythmic-location>? a b)
239 (rhythmic-location<? b a))
241 (define-public (rhythmic-location=? a b)
242 (and (rhythmic-location<=? a b)
243 (rhythmic-location<=? b a)))
245 (define-public (rhythmic-location->file-string a)
246 (ly:format "~a.~a.~a"
248 (ly:moment-main-numerator (cdr a))
249 (ly:moment-main-denominator (cdr a))))
251 (define-public (rhythmic-location->string a)
252 (ly:format "bar ~a ~a"
254 (ly:moment->string (cdr a))))
256 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
259 (define-public all-visible #(#t #t #t))
260 (define-public begin-of-line-invisible #(#t #t #f))
261 (define-public center-invisible #(#t #f #t))
262 (define-public end-of-line-invisible #(#f #t #t))
263 (define-public begin-of-line-visible #(#f #f #t))
264 (define-public center-visible #(#f #t #f))
265 (define-public end-of-line-visible #(#t #f #f))
266 (define-public all-invisible #(#f #f #f))
267 (define-public (inherit-x-parent-visibility grob)
268 (let ((parent (ly:grob-parent grob X)))
269 (ly:grob-property parent 'break-visibility all-invisible)))
270 (define-public (inherit-y-parent-visibility grob)
271 (let ((parent (ly:grob-parent grob X)))
272 (ly:grob-property parent 'break-visibility)))
275 (define-public spanbar-begin-of-line-invisible #(#t #f #f))
278 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
282 ;; How should a bar line behave at a break?
283 (define bar-glyph-alist
284 '((":|:" . (":|" . "|:"))
285 (":|.|:" . (":|" . "|:"))
286 (":|.:" . (":|" . "|:"))
287 ("||:" . ("||" . "|:"))
288 ("dashed" . ("dashed" . '()))
290 ("||:" . ("||" . "|:"))
292 ("|:" . ("|" . "|:"))
295 ;; hmm... should we end with a bar line here?
296 (".|" . ("|" . ".|"))
299 (".|." . (".|." . ()))
300 ("|.|" . ("|.|" . ()))
305 ("empty" . (() . ()))
306 ("brace" . (() . "brace"))
307 ("bracket" . (() . "bracket"))
313 (":|S" . (":|" . "S"))
314 (":|S." . (":|S" . ()))
315 ("S|:" . ("S" . "|:"))
316 (".S|:" . ("|" . "S|:"))
317 (":|S|:" . (":|" . "S|:"))
318 (":|S.|:" . (":|S" . "|:"))))
320 (define-public (bar-line::calc-glyph-name grob)
321 (let* ((glyph (ly:grob-property grob 'glyph))
322 (dir (ly:item-break-dir grob))
323 (result (assoc-get glyph bar-glyph-alist))
324 (glyph-name (if (= dir CENTER)
327 (string? (index-cell result dir)))
328 (index-cell result dir)
332 (define-public (bar-line::calc-break-visibility grob)
333 (let* ((glyph (ly:grob-property grob 'glyph))
334 (result (assoc-get glyph bar-glyph-alist)))
337 (vector (string? (car result)) #t (string? (cdr result)))
340 (define-public (shift-right-at-line-begin g)
341 "Shift an item to the right, but only at the start of the line."
342 (if (and (ly:item? g)
343 (equal? (ly:item-break-dir g) RIGHT))
344 (ly:grob-translate-axis! g 3.5 X)))
347 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
350 (define-public (tuplet-number::calc-direction grob)
351 (ly:tuplet-bracket::calc-direction (ly:grob-object grob 'bracket)))
353 (define-public (tuplet-number::calc-denominator-text grob)
354 (number->string (ly:event-property (event-cause grob) 'denominator)))
356 (define-public (tuplet-number::calc-fraction-text grob)
357 (let ((ev (event-cause grob)))
360 (ly:event-property ev 'denominator)
361 (ly:event-property ev 'numerator))))
363 ;; a formatter function, which is simply a wrapper around an existing
364 ;; tuplet formatter function. It takes the value returned by the given
365 ;; function and appends a note of given length.
366 (define-public ((tuplet-number::append-note-wrapper function note) grob)
367 (let ((txt (if function (function grob) #f)))
370 (markup txt #:fontsize -5 #:note note UP)
371 (markup #:fontsize -5 #:note note UP))))
373 ;; Print a tuplet denominator with a different number than the one derived from
374 ;; the actual tuplet fraction
375 (define-public ((tuplet-number::non-default-tuplet-denominator-text denominator)
377 (number->string (if denominator
379 (ly:event-property (event-cause grob) 'denominator))))
381 ;; Print a tuplet fraction with different numbers than the ones derived from
382 ;; the actual tuplet fraction
383 (define-public ((tuplet-number::non-default-tuplet-fraction-text
384 denominator numerator) grob)
385 (let* ((ev (event-cause grob))
386 (den (if denominator denominator (ly:event-property ev 'denominator)))
387 (num (if numerator numerator (ly:event-property ev 'numerator))))
389 (format #f "~a:~a" den num)))
391 ;; Print a tuplet fraction with note durations appended to the numerator and the
393 (define-public ((tuplet-number::fraction-with-notes
394 denominatornote numeratornote) grob)
395 (let* ((ev (event-cause grob))
396 (denominator (ly:event-property ev 'denominator))
397 (numerator (ly:event-property ev 'numerator)))
399 ((tuplet-number::non-default-fraction-with-notes
400 denominator denominatornote numerator numeratornote) grob)))
402 ;; Print a tuplet fraction with note durations appended to the numerator and the
404 (define-public ((tuplet-number::non-default-fraction-with-notes
405 denominator denominatornote numerator numeratornote) grob)
406 (let* ((ev (event-cause grob))
407 (den (if denominator denominator (ly:event-property ev 'denominator)))
408 (num (if numerator numerator (ly:event-property ev 'numerator))))
410 (make-concat-markup (list
411 (make-simple-markup (format #f "~a" den))
412 (markup #:fontsize -5 #:note denominatornote UP)
413 (make-simple-markup " : ")
414 (make-simple-markup (format #f "~a" num))
415 (markup #:fontsize -5 #:note numeratornote UP)))))
418 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
421 (define-public (color? x)
424 (apply eq? #t (map number? x))
425 (apply eq? #t (map (lambda (y) (<= 0 y 1)) x))))
427 (define-public (rgb-color r g b) (list r g b))
430 (define-public black '(0.0 0.0 0.0))
431 (define-public white '(1.0 1.0 1.0))
432 (define-public red '(1.0 0.0 0.0))
433 (define-public green '(0.0 1.0 0.0))
434 (define-public blue '(0.0 0.0 1.0))
435 (define-public cyan '(0.0 1.0 1.0))
436 (define-public magenta '(1.0 0.0 1.0))
437 (define-public yellow '(1.0 1.0 0.0))
439 (define-public grey '(0.5 0.5 0.5))
440 (define-public darkred '(0.5 0.0 0.0))
441 (define-public darkgreen '(0.0 0.5 0.0))
442 (define-public darkblue '(0.0 0.0 0.5))
443 (define-public darkcyan '(0.0 0.5 0.5))
444 (define-public darkmagenta '(0.5 0.0 0.5))
445 (define-public darkyellow '(0.5 0.5 0.0))
448 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
451 (define-public (key-signature-interface::alteration-position step alter
453 ;; TODO: memoize - this is mostly constant.
455 ;; fes, ges, as and bes typeset in lower octave
456 (define FLAT_TOP_PITCH 2)
458 ;; ais and bis typeset in lower octave
459 (define SHARP_TOP_PITCH 4)
462 (+ (cdr step) (* (car step) 7) c0-position)
463 (let* ((from-bottom-pos (modulo (+ 4 49 c0-position) 7))
465 (c0 (- from-bottom-pos 4)))
469 (or (> p FLAT_TOP_PITCH) (> (+ p c0) 4)) (> (+ p c0) 1))
471 (or (> p SHARP_TOP_PITCH) (> (+ p c0) 5)) (> (+ p c0) 2)))
473 ;; Typeset below c_position
476 ;; Provide for the four cases in which there's a glitch
477 ;; it's a hack, but probably not worth
478 ;; the effort of finding a nicer solution.
481 ((and (= c0 2) (= p 3) (> alter 0))
483 ((and (= c0 -3) (= p -1) (> alter 0))
485 ((and (= c0 -4) (= p -1) (< alter 0))
487 ((and (= c0 -2) (= p -3) (< alter 0))
493 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
496 (define-public (numbered-footnotes int)
497 (markup #:tiny (number->string (+ 1 int))))
499 (define-public (symbol-footnotes int)
500 (define (helper symbols out idx n)
504 (string-append out (list-ref symbols idx))
507 (markup #:tiny (helper '("*" "†" "‡" "§" "¶")
510 (+ 1 (quotient int 5)))))
512 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
515 (define-public (accidental-interface::calc-alteration grob)
516 (ly:pitch-alteration (ly:event-property (event-cause grob) 'pitch)))
518 (define-public cancellation-glyph-name-alist
519 '((0 . "accidentals.natural")))
521 (define-public standard-alteration-glyph-name-alist
523 ;; ordered for optimal performance.
524 (0 . "accidentals.natural")
525 (-1/2 . "accidentals.flat")
526 (1/2 . "accidentals.sharp")
528 (1 . "accidentals.doublesharp")
529 (-1 . "accidentals.flatflat")
531 (3/4 . "accidentals.sharp.slashslash.stemstemstem")
532 (1/4 . "accidentals.sharp.slashslash.stem")
533 (-1/4 . "accidentals.mirroredflat")
534 (-3/4 . "accidentals.mirroredflat.flat")))
536 ;; FIXME: standard vs default, alteration-FOO vs FOO-alteration
537 (define-public alteration-default-glyph-name-alist
538 standard-alteration-glyph-name-alist)
540 (define-public makam-alteration-glyph-name-alist
541 '((1 . "accidentals.doublesharp")
542 (8/9 . "accidentals.sharp.slashslashslash.stemstem")
543 (5/9 . "accidentals.sharp.slashslashslash.stem")
544 (4/9 . "accidentals.sharp")
545 (1/9 . "accidentals.sharp.slashslash.stem")
546 (0 . "accidentals.natural")
547 (-1/9 . "accidentals.mirroredflat")
548 (-4/9 . "accidentals.flat.slash")
549 (-5/9 . "accidentals.flat")
550 (-8/9 . "accidentals.flat.slashslash")
551 (-1 . "accidentals.flatflat")))
553 (define-public alteration-hufnagel-glyph-name-alist
554 '((-1/2 . "accidentals.hufnagelM1")
555 (0 . "accidentals.vaticana0")
556 (1/2 . "accidentals.mensural1")))
558 (define-public alteration-medicaea-glyph-name-alist
559 '((-1/2 . "accidentals.medicaeaM1")
560 (0 . "accidentals.vaticana0")
561 (1/2 . "accidentals.mensural1")))
563 (define-public alteration-vaticana-glyph-name-alist
564 '((-1/2 . "accidentals.vaticanaM1")
565 (0 . "accidentals.vaticana0")
566 (1/2 . "accidentals.mensural1")))
568 (define-public alteration-mensural-glyph-name-alist
569 '((-1/2 . "accidentals.mensuralM1")
570 (0 . "accidentals.vaticana0")
571 (1/2 . "accidentals.mensural1")))
574 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
575 ;; * Pitch Trill Heads
578 (define-public (parentheses-item::calc-parenthesis-stencils grob)
579 (let* ((font (ly:grob-default-font grob))
580 (lp (ly:font-get-glyph font "accidentals.leftparen"))
581 (rp (ly:font-get-glyph font "accidentals.rightparen")))
585 (define-public (parentheses-item::calc-angled-bracket-stencils grob)
586 (let* ((parent (ly:grob-parent grob Y))
587 (y-extent (ly:grob-extent parent parent Y))
588 (half-thickness 0.05) ; should it be a property?
589 (width 0.5) ; should it be a property?
590 (angularity 1.5) ; makes angle brackets
591 (white-padding 0.1) ; should it be a property?
592 (lp (ly:stencil-aligned-to
593 (ly:stencil-aligned-to
594 (make-parenthesis-stencil y-extent
601 (interval-widen (ly:stencil-extent lp X) white-padding))
602 (rp (ly:stencil-aligned-to
603 (ly:stencil-aligned-to
604 (make-parenthesis-stencil y-extent
611 (interval-widen (ly:stencil-extent rp X) white-padding)))
612 (set! lp (ly:make-stencil (ly:stencil-expr lp)
614 (ly:stencil-extent lp Y)))
615 (set! rp (ly:make-stencil (ly:stencil-expr rp)
617 (ly:stencil-extent rp Y)))
618 (list (stencil-whiteout lp)
619 (stencil-whiteout rp))))
621 (define (parenthesize-elements grob . rest)
622 (let* ((refp (if (null? rest)
625 (elts (ly:grob-object grob 'elements))
626 (x-ext (ly:relative-group-extent elts refp X))
627 (stencils (ly:grob-property grob 'stencils))
630 (padding (ly:grob-property grob 'padding 0.1)))
633 (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
634 (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))))
637 (define-public (parentheses-item::print me)
638 (let* ((elts (ly:grob-object me 'elements))
639 (y-ref (ly:grob-common-refpoint-of-array me elts Y))
640 (x-ref (ly:grob-common-refpoint-of-array me elts X))
641 (stencil (parenthesize-elements me x-ref))
642 (elt-y-ext (ly:relative-group-extent elts y-ref Y))
643 (y-center (interval-center elt-y-ext)))
645 (ly:stencil-translate
648 (- (ly:grob-relative-coordinate me x-ref X))
649 (- y-center (ly:grob-relative-coordinate me y-ref Y))))))
653 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
656 (define-public (chain-grob-member-functions grob value . funcs)
659 (set! value (func grob value)))
665 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
668 (define-public (bend::print spanner)
670 (< (abs (- a b)) 0.01))
672 (let* ((delta-y (* 0.5 (ly:grob-property spanner 'delta-position)))
673 (left-span (ly:spanner-bound spanner LEFT))
674 (dots (if (and (grob::has-interface left-span 'note-head-interface)
675 (ly:grob? (ly:grob-object left-span 'dot)))
676 (ly:grob-object left-span 'dot) #f))
678 (right-span (ly:spanner-bound spanner RIGHT))
679 (thickness (* (ly:grob-property spanner 'thickness)
680 (ly:output-def-lookup (ly:grob-layout spanner)
682 (padding (ly:grob-property spanner 'padding 0.5))
683 (common (ly:grob-common-refpoint right-span
684 (ly:grob-common-refpoint spanner
687 (common-y (ly:grob-common-refpoint spanner left-span Y))
688 (minimum-length (ly:grob-property spanner 'minimum-length 0.5))
692 (interval-end (ly:grob-robust-relative-extent
697 (ly:grob-relative-coordinate dots common-y Y)
698 (ly:grob-relative-coordinate spanner common-y Y)))
700 (ly:grob-robust-relative-extent dots common X))
701 ;; TODO: use real infinity constant.
703 (right-x (max (- (interval-start
704 (ly:grob-robust-relative-extent right-span common X))
706 (+ left-x minimum-length)))
707 (self-x (ly:grob-relative-coordinate spanner common X))
708 (dx (- right-x left-x))
709 (exp (list 'path thickness
717 ,dx ,(* 0.66 delta-y)
722 (cons (- left-x self-x) (- right-x self-x))
723 (cons (min 0 delta-y)
727 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
730 (define-public (grace-spacing::calc-shortest-duration grob)
731 (let* ((cols (ly:grob-object grob 'columns))
734 (ly:moment-sub (ly:grob-property
735 (ly:grob-array-ref cols (1+ idx)) 'when)
737 (ly:grob-array-ref cols idx) 'when))))
739 (moment-min (lambda (x y)
742 (if (ly:moment<? x y)
748 (fold moment-min #f (map get-difference
749 (iota (1- (ly:grob-array-length cols)))))))
752 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
755 (define-public (fingering::calc-text grob)
756 (let* ((event (event-cause grob))
757 (digit (ly:event-property event 'digit)))
760 (ly:input-message (ly:event-property event 'origin)
761 "Warning: Fingering notation for finger number ~a"
764 (number->string digit 10)))
766 (define-public (string-number::calc-text grob)
767 (let ((digit (ly:event-property (event-cause grob) 'string-number)))
769 (number->string digit 10)))
771 (define-public (stroke-finger::calc-text grob)
772 (let* ((digit (ly:event-property (event-cause grob) 'digit))
773 (text (ly:event-property (event-cause grob) 'text)))
777 (vector-ref (ly:grob-property grob 'digit-names)
778 (1- (max (min 5 digit) 1))))))
781 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
784 (define-public (hairpin::calc-grow-direction grob)
785 (if (eq? (ly:event-property (event-cause grob) 'class) 'decrescendo-event)
789 (define-public (dynamic-text-spanner::before-line-breaking grob)
790 "Monitor left bound of @code{DynamicTextSpanner} for absolute dynamics.
791 If found, ensure @code{DynamicText} does not collide with spanner text by
792 changing @code{'attach-dir} and @code{'padding}. Reads the
793 @code{'right-padding} property of @code{DynamicText} to fine tune space
794 between the two text elements."
795 (let ((left-bound (ly:spanner-bound grob LEFT)))
796 (if (grob::has-interface left-bound 'dynamic-text-interface)
797 (let* ((details (ly:grob-property grob 'bound-details))
798 (left-details (ly:assoc-get 'left details))
799 (my-padding (ly:assoc-get 'padding left-details))
800 (script-padding (ly:grob-property left-bound 'right-padding 0)))
802 (and (number? my-padding)
803 (ly:grob-set-nested-property! grob
804 '(bound-details left attach-dir)
806 (ly:grob-set-nested-property! grob
807 '(bound-details left padding)
808 (+ my-padding script-padding)))))))
811 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
814 (define-public (lyric-text::print grob)
815 "Allow interpretation of tildes as lyric tieing marks."
817 (let ((text (ly:grob-property grob 'text)))
819 (grob-interpret-markup grob (if (string? text)
820 (make-tied-lyric-markup text)
823 (define-public ((grob::calc-property-by-copy prop) grob)
824 (ly:event-property (event-cause grob) prop))
827 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
830 (define-public (fret-board::calc-stencil grob)
831 (grob-interpret-markup
833 (make-fret-diagram-verbose-markup
834 (ly:grob-property grob 'dot-placement-list))))
837 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
840 (define-public (script-interface::calc-x-offset grob)
841 (ly:grob-property grob 'positioning-done)
842 (let* ((shift (ly:grob-property grob 'toward-stem-shift 0.0))
844 (ly:self-alignment-interface::centered-on-x-parent grob))
845 (note-head-grob (ly:grob-parent grob X))
846 (stem-grob (ly:grob-object note-head-grob 'stem)))
848 (+ note-head-location
849 ;; If the property 'toward-stem-shift is defined and the script
850 ;; has the same direction as the stem, move the script accordingly.
851 ;; Since scripts can also be over skips, we need to check whether
852 ;; the grob has a stem at all.
853 (if (ly:grob? stem-grob)
854 (let ((dir1 (ly:grob-property grob 'direction))
855 (dir2 (ly:grob-property stem-grob 'direction)))
856 (if (equal? dir1 dir2)
857 (let* ((common-refp (ly:grob-common-refpoint grob stem-grob X))
859 (ly:grob-relative-coordinate stem-grob common-refp X)))
860 (* shift (- stem-location note-head-location)))
865 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
868 (define-public (system-start-text::print grob)
869 (let* ((left-bound (ly:spanner-bound grob LEFT))
870 (left-mom (ly:grob-property left-bound 'when))
871 (name (if (moment<=? left-mom ZERO-MOMENT)
872 (ly:grob-property grob 'long-text)
873 (ly:grob-property grob 'text))))
875 (if (and (markup? name)
876 (!= (ly:item-break-dir left-bound) CENTER))
878 (grob-interpret-markup grob name)
879 (ly:grob-suicide! grob))))
881 (define-public (system-start-text::calc-x-offset grob)
882 (let* ((left-bound (ly:spanner-bound grob LEFT))
883 (left-mom (ly:grob-property left-bound 'when))
884 (layout (ly:grob-layout grob))
885 (indent (ly:output-def-lookup layout
886 (if (moment<=? left-mom ZERO-MOMENT)
890 (system (ly:grob-system grob))
891 (my-extent (ly:grob-extent grob system X))
892 (elements (ly:grob-object system 'elements))
893 (common (ly:grob-common-refpoint-of-array system elements X))
894 (total-ext empty-interval)
895 (align-x (ly:grob-property grob 'self-alignment-X 0))
896 (padding (min 0 (- (interval-length my-extent) indent)))
897 (right-padding (- padding
898 (/ (* padding (1+ align-x)) 2))))
900 ;; compensate for the variation in delimiter extents by
901 ;; calculating an X-offset correction based on united extents
902 ;; of all delimiters in this system
903 (let unite-delims ((l (ly:grob-array-length elements)))
905 (let ((elt (ly:grob-array-ref elements (1- l))))
907 (if (grob::has-interface elt 'system-start-delimiter-interface)
908 (let ((dims (ly:grob-extent elt common X)))
909 (if (interval-sane? dims)
910 (set! total-ext (interval-union total-ext dims)))))
911 (unite-delims (1- l)))))
914 (ly:side-position-interface::x-aligned-side grob)
916 (- (interval-length total-ext)))))
918 (define-public (system-start-text::calc-y-offset grob)
920 (define (live-elements-list me)
921 (let ((elements (ly:grob-object me 'elements)))
923 (filter! grob::is-live?
924 (ly:grob-array->list elements))))
926 (let* ((left-bound (ly:spanner-bound grob LEFT))
927 (live-elts (live-elements-list grob))
928 (system (ly:grob-system grob))
929 (extent empty-interval))
931 (if (and (pair? live-elts)
932 (interval-sane? (ly:grob-extent grob system Y)))
933 (let get-extent ((lst live-elts))
935 (let ((axis-group (car lst)))
937 (if (and (ly:spanner? axis-group)
938 (equal? (ly:spanner-bound axis-group LEFT)
940 (set! extent (add-point extent
941 (ly:grob-relative-coordinate
942 axis-group system Y))))
943 (get-extent (cdr lst)))))
944 ;; no live axis group(s) for this instrument name -> remove from system
945 (ly:grob-suicide! grob))
948 (ly:self-alignment-interface::y-aligned-on-self grob)
949 (interval-center extent))))
952 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
955 (define-public (ambitus::print grob)
956 (let ((heads (ly:grob-object grob 'note-heads)))
958 (if (and (ly:grob-array? heads)
959 (= (ly:grob-array-length heads) 2))
960 (let* ((common (ly:grob-common-refpoint-of-array grob heads Y))
961 (head-down (ly:grob-array-ref heads 0))
962 (head-up (ly:grob-array-ref heads 1))
963 (gap (ly:grob-property grob 'gap 0.35))
964 (point-min (+ (interval-end (ly:grob-extent head-down common Y))
966 (point-max (- (interval-start (ly:grob-extent head-up common Y))
969 (if (< point-min point-max)
970 (let* ((layout (ly:grob-layout grob))
971 (line-thick (ly:output-def-lookup layout 'line-thickness))
972 (blot (ly:output-def-lookup layout 'blot-diameter))
973 (grob-thick (ly:grob-property grob 'thickness 2))
974 (width (* line-thick grob-thick))
975 (x-ext (symmetric-interval (/ width 2)))
976 (y-ext (cons point-min point-max))
977 (line (ly:round-filled-box x-ext y-ext blot))
978 (y-coord (ly:grob-relative-coordinate grob common Y)))
980 (ly:stencil-translate-axis line (- y-coord) Y))
983 (ly:grob-suicide! grob)
986 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
987 ;; laissez-vibrer tie
989 ;; needed so we can make laissez-vibrer a pure print
991 (define-public (laissez-vibrer::print grob)
992 (ly:tie::print grob))