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 (stem::calc-duration-log grob)
64 (ly:event-property (event-cause grob) 'duration)))
66 (define-public (stem::length val)
68 (let* ((d (ly:grob-property grob 'direction))
69 (ss (ly:staff-symbol-staff-space grob))
70 (beg (ly:stem::calc-stem-begin-position grob))
71 (y1 (* beg (* 0.5 ss)))
72 (y2 (* ((if (eqv? d DOWN) - +) beg val) (* 0.5 ss))))
77 (define-public (note-head::calc-duration-log grob)
80 (ly:event-property (event-cause grob) 'duration))))
82 (define-public (dots::calc-dot-count grob)
83 (ly:duration-dot-count
84 (ly:event-property (event-cause grob) 'duration)))
86 (define-public (dots::calc-staff-position grob)
87 (let* ((head (ly:grob-parent grob Y))
88 (log (ly:grob-property head 'duration-log)))
91 ((or (not (grob::has-interface head 'rest-interface))
92 (not (integer? log))) 0)
100 ;; Kept separate from note-head::calc-glyph-name to allow use by
101 ;; markup commands \note and \note-by-number
102 (define-public (select-head-glyph style log)
103 "Select a note head glyph string based on note head style @var{style}
104 and duration-log @var{log}."
106 ;; "default" style is directly handled in note-head.cc as a
107 ;; special case (HW says, mainly for performance reasons).
108 ;; Therefore, style "default" does not appear in this case
110 ((xcircle) "2xcircle")
111 ((harmonic) "0harmonic")
112 ((harmonic-black) "2harmonic")
113 ((harmonic-mixed) (if (<= log 1) "0harmonic"
116 ;; Oops, I actually would not call this "baroque", but, for
117 ;; backwards compatibility to 1.4, this is supposed to take
118 ;; brevis, longa and maxima from the neo-mensural font and all
119 ;; other note heads from the default font. -- jr
121 (string-append (number->string log) "neomensural")
122 (number->string log)))
124 ;; Like default, but brevis is drawn with double vertical lines
126 (string-append (number->string log) "double")
127 (number->string log)))
129 (string-append (number->string log) (symbol->string style)))
132 (string-append (number->string log) "mensural")
133 (string-append (number->string log) (symbol->string style))))
136 (string-append (number->string log) "blackmensural")
137 (string-append (number->string log) (symbol->string style))))
140 (string-append (number->string log) "semimensural")
141 (string-append (number->string log) "petrucci")))
143 (string-append (number->string log) (symbol->string style)))
145 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
146 (symbol->string style)
147 (string-append (number->string (max 0 log))
148 (symbol->string style))))))
150 (define-public (note-head::calc-glyph-name grob)
151 (let ((style (ly:grob-property grob 'style))
152 (log (min 2 (ly:grob-property grob 'duration-log))))
154 (select-head-glyph style log)))
156 (define-public (note-head::brew-ez-stencil grob)
157 (let* ((log (ly:grob-property grob 'duration-log))
158 (pitch (ly:event-property (event-cause grob) 'pitch))
159 (pitch-index (ly:pitch-notename pitch))
160 (note-names (ly:grob-property grob 'note-names))
161 (pitch-string (if (and (vector? note-names)
162 (> (vector-length note-names) pitch-index))
163 (vector-ref note-names pitch-index)
166 (+ (modulo (+ pitch-index 2) 7)
167 (char->integer #\A))))))
168 (staff-space (ly:staff-symbol-staff-space grob))
169 (line-thickness (ly:staff-symbol-line-thickness grob))
170 (stem (ly:grob-object grob 'stem))
171 (stem-thickness (* (if (ly:grob? stem)
172 (ly:grob-property stem 'thickness)
175 (radius (/ (+ staff-space line-thickness) 2))
176 (letter (markup #:center-align #:vcenter pitch-string))
177 (filled-circle (markup #:draw-circle radius 0 #t)))
179 (ly:stencil-translate-axis
180 (grob-interpret-markup
185 (make-with-color-markup white letter))
189 (make-with-color-markup white (make-draw-circle-markup
190 (- radius stem-thickness) 0 #t)))
194 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
197 (define-public (make-rhythmic-location bar-num num den)
199 bar-num (ly:make-moment num den)))
201 (define-public (rhythmic-location? a)
204 (ly:moment? (cdr a))))
206 (define-public (make-graceless-rhythmic-location loc)
207 (make-rhythmic-location
209 (ly:moment-main-numerator (rhythmic-location-measure-position loc))
210 (ly:moment-main-denominator (rhythmic-location-measure-position loc))))
212 (define-public rhythmic-location-measure-position cdr)
213 (define-public rhythmic-location-bar-number car)
215 (define-public (rhythmic-location<? a b)
217 ((< (car a) (car b)) #t)
218 ((> (car a) (car b)) #f)
220 (ly:moment<? (cdr a) (cdr b)))))
222 (define-public (rhythmic-location<=? a b)
223 (not (rhythmic-location<? b a)))
224 (define-public (rhythmic-location>=? a b)
225 (rhythmic-location<? a b))
226 (define-public (rhythmic-location>? a b)
227 (rhythmic-location<? b a))
229 (define-public (rhythmic-location=? a b)
230 (and (rhythmic-location<=? a b)
231 (rhythmic-location<=? b a)))
233 (define-public (rhythmic-location->file-string a)
234 (ly:format "~a.~a.~a"
236 (ly:moment-main-numerator (cdr a))
237 (ly:moment-main-denominator (cdr a))))
239 (define-public (rhythmic-location->string a)
240 (ly:format "bar ~a ~a"
242 (ly:moment->string (cdr a))))
244 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
247 (define-public all-visible #(#t #t #t))
248 (define-public begin-of-line-invisible #(#t #t #f))
249 (define-public center-invisible #(#t #f #t))
250 (define-public end-of-line-invisible #(#f #t #t))
251 (define-public begin-of-line-visible #(#f #f #t))
252 (define-public center-visible #(#f #t #f))
253 (define-public end-of-line-visible #(#t #f #f))
254 (define-public all-invisible #(#f #f #f))
255 (define-public (inherit-x-parent-visibility grob)
256 (let ((parent (ly:grob-parent grob X)))
257 (ly:grob-property parent 'break-visibility all-invisible)))
258 (define-public (inherit-y-parent-visibility grob)
259 (let ((parent (ly:grob-parent grob X)))
260 (ly:grob-property parent 'break-visibility)))
263 (define-public spanbar-begin-of-line-invisible #(#t #f #f))
266 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
270 ;; How should a bar line behave at a break?
271 (define bar-glyph-alist
272 '((":|:" . (":|" . "|:"))
273 (":|.|:" . (":|" . "|:"))
274 (":|.:" . (":|" . "|:"))
275 ("||:" . ("||" . "|:"))
276 ("dashed" . ("dashed" . '()))
278 ("||:" . ("||" . "|:"))
280 ("|:" . ("|" . "|:"))
283 ;; hmm... should we end with a bar line here?
284 (".|" . ("|" . ".|"))
287 (".|." . (".|." . ()))
288 ("|.|" . ("|.|" . ()))
293 ("empty" . (() . ()))
294 ("brace" . (() . "brace"))
295 ("bracket" . (() . "bracket"))
301 (":|S" . (":|" . "S"))
302 (":|S." . (":|S" . ()))
303 ("S|:" . ("S" . "|:"))
304 (".S|:" . ("|" . "S|:"))
305 (":|S|:" . (":|" . "S|:"))
306 (":|S.|:" . (":|S" . "|:"))))
308 (define-public (bar-line::calc-glyph-name grob)
309 (let* ((glyph (ly:grob-property grob 'glyph))
310 (dir (ly:item-break-dir grob))
311 (result (assoc-get glyph bar-glyph-alist))
312 (glyph-name (if (= dir CENTER)
315 (string? (index-cell result dir)))
316 (index-cell result dir)
320 (define-public (bar-line::calc-break-visibility grob)
321 (let* ((glyph (ly:grob-property grob 'glyph))
322 (result (assoc-get glyph bar-glyph-alist)))
325 (vector (string? (car result)) #t (string? (cdr result)))
328 (define-public (shift-right-at-line-begin g)
329 "Shift an item to the right, but only at the start of the line."
330 (if (and (ly:item? g)
331 (equal? (ly:item-break-dir g) RIGHT))
332 (ly:grob-translate-axis! g 3.5 X)))
335 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
338 (define-public (tuplet-number::calc-direction grob)
339 (ly:tuplet-bracket::calc-direction (ly:grob-object grob 'bracket)))
341 (define-public (tuplet-number::calc-denominator-text grob)
342 (number->string (ly:event-property (event-cause grob) 'denominator)))
344 (define-public (tuplet-number::calc-fraction-text grob)
345 (let ((ev (event-cause grob)))
348 (ly:event-property ev 'denominator)
349 (ly:event-property ev 'numerator))))
351 ;; a formatter function, which is simply a wrapper around an existing
352 ;; tuplet formatter function. It takes the value returned by the given
353 ;; function and appends a note of given length.
354 (define-public ((tuplet-number::append-note-wrapper function note) grob)
355 (let ((txt (if function (function grob) #f)))
358 (markup txt #:fontsize -5 #:note note UP)
359 (markup #:fontsize -5 #:note note UP))))
361 ;; Print a tuplet denominator with a different number than the one derived from
362 ;; the actual tuplet fraction
363 (define-public ((tuplet-number::non-default-tuplet-denominator-text denominator)
365 (number->string (if denominator
367 (ly:event-property (event-cause grob) 'denominator))))
369 ;; Print a tuplet fraction with different numbers than the ones derived from
370 ;; the actual tuplet fraction
371 (define-public ((tuplet-number::non-default-tuplet-fraction-text
372 denominator numerator) grob)
373 (let* ((ev (event-cause grob))
374 (den (if denominator denominator (ly:event-property ev 'denominator)))
375 (num (if numerator numerator (ly:event-property ev 'numerator))))
377 (format #f "~a:~a" den num)))
379 ;; Print a tuplet fraction with note durations appended to the numerator and the
381 (define-public ((tuplet-number::fraction-with-notes
382 denominatornote numeratornote) grob)
383 (let* ((ev (event-cause grob))
384 (denominator (ly:event-property ev 'denominator))
385 (numerator (ly:event-property ev 'numerator)))
387 ((tuplet-number::non-default-fraction-with-notes
388 denominator denominatornote numerator numeratornote) grob)))
390 ;; Print a tuplet fraction with note durations appended to the numerator and the
392 (define-public ((tuplet-number::non-default-fraction-with-notes
393 denominator denominatornote numerator numeratornote) grob)
394 (let* ((ev (event-cause grob))
395 (den (if denominator denominator (ly:event-property ev 'denominator)))
396 (num (if numerator numerator (ly:event-property ev 'numerator))))
398 (make-concat-markup (list
399 (make-simple-markup (format #f "~a" den))
400 (markup #:fontsize -5 #:note denominatornote UP)
401 (make-simple-markup " : ")
402 (make-simple-markup (format #f "~a" num))
403 (markup #:fontsize -5 #:note numeratornote UP)))))
406 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
409 (define-public (color? x)
412 (apply eq? #t (map number? x))
413 (apply eq? #t (map (lambda (y) (<= 0 y 1)) x))))
415 (define-public (rgb-color r g b) (list r g b))
418 (define-public black '(0.0 0.0 0.0))
419 (define-public white '(1.0 1.0 1.0))
420 (define-public red '(1.0 0.0 0.0))
421 (define-public green '(0.0 1.0 0.0))
422 (define-public blue '(0.0 0.0 1.0))
423 (define-public cyan '(0.0 1.0 1.0))
424 (define-public magenta '(1.0 0.0 1.0))
425 (define-public yellow '(1.0 1.0 0.0))
427 (define-public grey '(0.5 0.5 0.5))
428 (define-public darkred '(0.5 0.0 0.0))
429 (define-public darkgreen '(0.0 0.5 0.0))
430 (define-public darkblue '(0.0 0.0 0.5))
431 (define-public darkcyan '(0.0 0.5 0.5))
432 (define-public darkmagenta '(0.5 0.0 0.5))
433 (define-public darkyellow '(0.5 0.5 0.0))
436 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
439 (define-public (key-signature-interface::alteration-position step alter
441 ;; TODO: memoize - this is mostly constant.
443 ;; fes, ges, as and bes typeset in lower octave
444 (define FLAT_TOP_PITCH 2)
446 ;; ais and bis typeset in lower octave
447 (define SHARP_TOP_PITCH 4)
450 (+ (cdr step) (* (car step) 7) c0-position)
451 (let* ((from-bottom-pos (modulo (+ 4 49 c0-position) 7))
453 (c0 (- from-bottom-pos 4)))
457 (or (> p FLAT_TOP_PITCH) (> (+ p c0) 4)) (> (+ p c0) 1))
459 (or (> p SHARP_TOP_PITCH) (> (+ p c0) 5)) (> (+ p c0) 2)))
461 ;; Typeset below c_position
464 ;; Provide for the four cases in which there's a glitch
465 ;; it's a hack, but probably not worth
466 ;; the effort of finding a nicer solution.
469 ((and (= c0 2) (= p 3) (> alter 0))
471 ((and (= c0 -3) (= p -1) (> alter 0))
473 ((and (= c0 -4) (= p -1) (< alter 0))
475 ((and (= c0 -2) (= p -3) (< alter 0))
481 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
484 (define-public (numbered-footnotes int)
485 (markup #:tiny (number->string (+ 1 int))))
487 (define-public (symbol-footnotes int)
488 (define (helper symbols out idx n)
492 (string-append out (list-ref symbols idx))
495 (markup #:tiny (helper '("*" "†" "‡" "§" "¶")
498 (+ 1 (quotient int 5)))))
500 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
503 (define-public (accidental-interface::calc-alteration grob)
504 (ly:pitch-alteration (ly:event-property (event-cause grob) 'pitch)))
506 (define-public cancellation-glyph-name-alist
507 '((0 . "accidentals.natural")))
509 (define-public standard-alteration-glyph-name-alist
511 ;; ordered for optimal performance.
512 (0 . "accidentals.natural")
513 (-1/2 . "accidentals.flat")
514 (1/2 . "accidentals.sharp")
516 (1 . "accidentals.doublesharp")
517 (-1 . "accidentals.flatflat")
519 (3/4 . "accidentals.sharp.slashslash.stemstemstem")
520 (1/4 . "accidentals.sharp.slashslash.stem")
521 (-1/4 . "accidentals.mirroredflat")
522 (-3/4 . "accidentals.mirroredflat.flat")))
524 ;; FIXME: standard vs default, alteration-FOO vs FOO-alteration
525 (define-public alteration-default-glyph-name-alist
526 standard-alteration-glyph-name-alist)
528 (define-public makam-alteration-glyph-name-alist
529 '((1 . "accidentals.doublesharp")
530 (8/9 . "accidentals.sharp.slashslashslash.stemstem")
531 (5/9 . "accidentals.sharp.slashslashslash.stem")
532 (4/9 . "accidentals.sharp")
533 (1/9 . "accidentals.sharp.slashslash.stem")
534 (0 . "accidentals.natural")
535 (-1/9 . "accidentals.mirroredflat")
536 (-4/9 . "accidentals.flat.slash")
537 (-5/9 . "accidentals.flat")
538 (-8/9 . "accidentals.flat.slashslash")
539 (-1 . "accidentals.flatflat")))
541 (define-public alteration-hufnagel-glyph-name-alist
542 '((-1/2 . "accidentals.hufnagelM1")
543 (0 . "accidentals.vaticana0")
544 (1/2 . "accidentals.mensural1")))
546 (define-public alteration-medicaea-glyph-name-alist
547 '((-1/2 . "accidentals.medicaeaM1")
548 (0 . "accidentals.vaticana0")
549 (1/2 . "accidentals.mensural1")))
551 (define-public alteration-vaticana-glyph-name-alist
552 '((-1/2 . "accidentals.vaticanaM1")
553 (0 . "accidentals.vaticana0")
554 (1/2 . "accidentals.mensural1")))
556 (define-public alteration-mensural-glyph-name-alist
557 '((-1/2 . "accidentals.mensuralM1")
558 (0 . "accidentals.vaticana0")
559 (1/2 . "accidentals.mensural1")))
562 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
563 ;; * Pitch Trill Heads
566 (define-public (parentheses-item::calc-parenthesis-stencils grob)
567 (let* ((font (ly:grob-default-font grob))
568 (lp (ly:font-get-glyph font "accidentals.leftparen"))
569 (rp (ly:font-get-glyph font "accidentals.rightparen")))
573 (define-public (parentheses-item::calc-angled-bracket-stencils grob)
574 (let* ((parent (ly:grob-parent grob Y))
575 (y-extent (ly:grob-extent parent parent Y))
576 (half-thickness 0.05) ; should it be a property?
577 (width 0.5) ; should it be a property?
578 (angularity 1.5) ; makes angle brackets
579 (white-padding 0.1) ; should it be a property?
580 (lp (ly:stencil-aligned-to
581 (ly:stencil-aligned-to
582 (make-parenthesis-stencil y-extent
589 (interval-widen (ly:stencil-extent lp X) white-padding))
590 (rp (ly:stencil-aligned-to
591 (ly:stencil-aligned-to
592 (make-parenthesis-stencil y-extent
599 (interval-widen (ly:stencil-extent rp X) white-padding)))
600 (set! lp (ly:make-stencil (ly:stencil-expr lp)
602 (ly:stencil-extent lp Y)))
603 (set! rp (ly:make-stencil (ly:stencil-expr rp)
605 (ly:stencil-extent rp Y)))
606 (list (stencil-whiteout lp)
607 (stencil-whiteout rp))))
609 (define (parenthesize-elements grob . rest)
610 (let* ((refp (if (null? rest)
613 (elts (ly:grob-object grob 'elements))
614 (x-ext (ly:relative-group-extent elts refp X))
615 (stencils (ly:grob-property grob 'stencils))
618 (padding (ly:grob-property grob 'padding 0.1)))
621 (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
622 (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))))
625 (define-public (parentheses-item::print me)
626 (let* ((elts (ly:grob-object me 'elements))
627 (y-ref (ly:grob-common-refpoint-of-array me elts Y))
628 (x-ref (ly:grob-common-refpoint-of-array me elts X))
629 (stencil (parenthesize-elements me x-ref))
630 (elt-y-ext (ly:relative-group-extent elts y-ref Y))
631 (y-center (interval-center elt-y-ext)))
633 (ly:stencil-translate
636 (- (ly:grob-relative-coordinate me x-ref X))
637 (- y-center (ly:grob-relative-coordinate me y-ref Y))))))
641 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
644 (define-public (chain-grob-member-functions grob value . funcs)
647 (set! value (func grob value)))
653 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
656 (define-public (bend::print spanner)
658 (< (abs (- a b)) 0.01))
660 (let* ((delta-y (* 0.5 (ly:grob-property spanner 'delta-position)))
661 (left-span (ly:spanner-bound spanner LEFT))
662 (dots (if (and (grob::has-interface left-span 'note-head-interface)
663 (ly:grob? (ly:grob-object left-span 'dot)))
664 (ly:grob-object left-span 'dot) #f))
666 (right-span (ly:spanner-bound spanner RIGHT))
667 (thickness (* (ly:grob-property spanner 'thickness)
668 (ly:output-def-lookup (ly:grob-layout spanner)
670 (padding (ly:grob-property spanner 'padding 0.5))
671 (common (ly:grob-common-refpoint right-span
672 (ly:grob-common-refpoint spanner
675 (common-y (ly:grob-common-refpoint spanner left-span Y))
676 (minimum-length (ly:grob-property spanner 'minimum-length 0.5))
680 (interval-end (ly:grob-robust-relative-extent
685 (ly:grob-relative-coordinate dots common-y Y)
686 (ly:grob-relative-coordinate spanner common-y Y)))
688 (ly:grob-robust-relative-extent dots common X))
689 ;; TODO: use real infinity constant.
691 (right-x (max (- (interval-start
692 (ly:grob-robust-relative-extent right-span common X))
694 (+ left-x minimum-length)))
695 (self-x (ly:grob-relative-coordinate spanner common X))
696 (dx (- right-x left-x))
697 (exp (list 'path thickness
705 ,dx ,(* 0.66 delta-y)
710 (cons (- left-x self-x) (- right-x self-x))
711 (cons (min 0 delta-y)
715 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
718 (define-public (grace-spacing::calc-shortest-duration grob)
719 (let* ((cols (ly:grob-object grob 'columns))
722 (ly:moment-sub (ly:grob-property
723 (ly:grob-array-ref cols (1+ idx)) 'when)
725 (ly:grob-array-ref cols idx) 'when))))
727 (moment-min (lambda (x y)
730 (if (ly:moment<? x y)
736 (fold moment-min #f (map get-difference
737 (iota (1- (ly:grob-array-length cols)))))))
740 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
743 (define-public (fingering::calc-text grob)
744 (let* ((event (event-cause grob))
745 (digit (ly:event-property event 'digit)))
748 (ly:input-message (ly:event-property event 'origin)
749 "Warning: Fingering notation for finger number ~a"
752 (number->string digit 10)))
754 (define-public (string-number::calc-text grob)
755 (let ((digit (ly:event-property (event-cause grob) 'string-number)))
757 (number->string digit 10)))
759 (define-public (stroke-finger::calc-text grob)
760 (let* ((digit (ly:event-property (event-cause grob) 'digit))
761 (text (ly:event-property (event-cause grob) 'text)))
765 (vector-ref (ly:grob-property grob 'digit-names)
766 (1- (max (min 5 digit) 1))))))
769 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
772 (define-public (hairpin::calc-grow-direction grob)
773 (if (eq? (ly:event-property (event-cause grob) 'class) 'decrescendo-event)
777 (define-public (dynamic-text-spanner::before-line-breaking grob)
778 "Monitor left bound of @code{DynamicTextSpanner} for absolute dynamics.
779 If found, ensure @code{DynamicText} does not collide with spanner text by
780 changing @code{'attach-dir} and @code{'padding}. Reads the
781 @code{'right-padding} property of @code{DynamicText} to fine tune space
782 between the two text elements."
783 (let ((left-bound (ly:spanner-bound grob LEFT)))
784 (if (grob::has-interface left-bound 'dynamic-text-interface)
785 (let* ((details (ly:grob-property grob 'bound-details))
786 (left-details (ly:assoc-get 'left details))
787 (my-padding (ly:assoc-get 'padding left-details))
788 (script-padding (ly:grob-property left-bound 'right-padding 0)))
790 (and (number? my-padding)
791 (ly:grob-set-nested-property! grob
792 '(bound-details left attach-dir)
794 (ly:grob-set-nested-property! grob
795 '(bound-details left padding)
796 (+ my-padding script-padding)))))))
799 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
802 (define-public (lyric-text::print grob)
803 "Allow interpretation of tildes as lyric tieing marks."
805 (let ((text (ly:grob-property grob 'text)))
807 (grob-interpret-markup grob (if (string? text)
808 (make-tied-lyric-markup text)
811 (define-public ((grob::calc-property-by-copy prop) grob)
812 (ly:event-property (event-cause grob) prop))
815 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
818 (define-public (fret-board::calc-stencil grob)
819 (grob-interpret-markup
821 (make-fret-diagram-verbose-markup
822 (ly:grob-property grob 'dot-placement-list))))
825 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
828 (define-public (script-interface::calc-x-offset grob)
829 (ly:grob-property grob 'positioning-done)
830 (let* ((shift (ly:grob-property grob 'toward-stem-shift 0.0))
832 (ly:self-alignment-interface::centered-on-x-parent grob))
833 (note-head-grob (ly:grob-parent grob X))
834 (stem-grob (ly:grob-object note-head-grob 'stem)))
836 (+ note-head-location
837 ;; If the property 'toward-stem-shift is defined and the script
838 ;; has the same direction as the stem, move the script accordingly.
839 ;; Since scripts can also be over skips, we need to check whether
840 ;; the grob has a stem at all.
841 (if (ly:grob? stem-grob)
842 (let ((dir1 (ly:grob-property grob 'direction))
843 (dir2 (ly:grob-property stem-grob 'direction)))
844 (if (equal? dir1 dir2)
845 (let* ((common-refp (ly:grob-common-refpoint grob stem-grob X))
847 (ly:grob-relative-coordinate stem-grob common-refp X)))
848 (* shift (- stem-location note-head-location)))
853 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
856 (define-public (system-start-text::print grob)
857 (let* ((left-bound (ly:spanner-bound grob LEFT))
858 (left-mom (ly:grob-property left-bound 'when))
859 (name (if (moment<=? left-mom ZERO-MOMENT)
860 (ly:grob-property grob 'long-text)
861 (ly:grob-property grob 'text))))
863 (if (and (markup? name)
864 (!= (ly:item-break-dir left-bound) CENTER))
866 (grob-interpret-markup grob name)
867 (ly:grob-suicide! grob))))
869 (define-public (system-start-text::calc-x-offset grob)
870 (let* ((left-bound (ly:spanner-bound grob LEFT))
871 (left-mom (ly:grob-property left-bound 'when))
872 (layout (ly:grob-layout grob))
873 (indent (ly:output-def-lookup layout
874 (if (moment<=? left-mom ZERO-MOMENT)
878 (system (ly:grob-system grob))
879 (my-extent (ly:grob-extent grob system X))
880 (elements (ly:grob-object system 'elements))
881 (common (ly:grob-common-refpoint-of-array system elements X))
882 (total-ext empty-interval)
883 (align-x (ly:grob-property grob 'self-alignment-X 0))
884 (padding (min 0 (- (interval-length my-extent) indent)))
885 (right-padding (- padding
886 (/ (* padding (1+ align-x)) 2))))
888 ;; compensate for the variation in delimiter extents by
889 ;; calculating an X-offset correction based on united extents
890 ;; of all delimiters in this system
891 (let unite-delims ((l (ly:grob-array-length elements)))
893 (let ((elt (ly:grob-array-ref elements (1- l))))
895 (if (grob::has-interface elt 'system-start-delimiter-interface)
896 (let ((dims (ly:grob-extent elt common X)))
897 (if (interval-sane? dims)
898 (set! total-ext (interval-union total-ext dims)))))
899 (unite-delims (1- l)))))
902 (ly:side-position-interface::x-aligned-side grob)
904 (- (interval-length total-ext)))))
906 (define-public (system-start-text::calc-y-offset grob)
908 (define (live-elements-list me)
909 (let ((elements (ly:grob-object me 'elements)))
911 (filter! grob::is-live?
912 (ly:grob-array->list elements))))
914 (let* ((left-bound (ly:spanner-bound grob LEFT))
915 (live-elts (live-elements-list grob))
916 (system (ly:grob-system grob))
917 (extent empty-interval))
919 (if (and (pair? live-elts)
920 (interval-sane? (ly:grob-extent grob system Y)))
921 (let get-extent ((lst live-elts))
923 (let ((axis-group (car lst)))
925 (if (and (ly:spanner? axis-group)
926 (equal? (ly:spanner-bound axis-group LEFT)
928 (set! extent (add-point extent
929 (ly:grob-relative-coordinate
930 axis-group system Y))))
931 (get-extent (cdr lst)))))
932 ;; no live axis group(s) for this instrument name -> remove from system
933 (ly:grob-suicide! grob))
936 (ly:self-alignment-interface::y-aligned-on-self grob)
937 (interval-center extent))))
940 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
943 (define-public (ambitus::print grob)
944 (let ((heads (ly:grob-object grob 'note-heads)))
946 (if (and (ly:grob-array? heads)
947 (= (ly:grob-array-length heads) 2))
948 (let* ((common (ly:grob-common-refpoint-of-array grob heads Y))
949 (head-down (ly:grob-array-ref heads 0))
950 (head-up (ly:grob-array-ref heads 1))
951 (gap (ly:grob-property grob 'gap 0.35))
952 (point-min (+ (interval-end (ly:grob-extent head-down common Y))
954 (point-max (- (interval-start (ly:grob-extent head-up common Y))
957 (if (< point-min point-max)
958 (let* ((layout (ly:grob-layout grob))
959 (line-thick (ly:output-def-lookup layout 'line-thickness))
960 (blot (ly:output-def-lookup layout 'blot-diameter))
961 (grob-thick (ly:grob-property grob 'thickness 2))
962 (width (* line-thick grob-thick))
963 (x-ext (symmetric-interval (/ width 2)))
964 (y-ext (cons point-min point-max))
965 (line (ly:round-filled-box x-ext y-ext blot))
966 (y-coord (ly:grob-relative-coordinate grob common Y)))
968 (ly:stencil-translate-axis line (- y-coord) Y))
971 (ly:grob-suicide! grob)
974 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
975 ;; laissez-vibrer tie
977 ;; needed so we can make laissez-vibrer a pure print
979 (define-public (laissez-vibrer::print grob)
980 (ly:tie::print grob))