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 ;; calculates each slope of a broken beam individually
66 (define-public (beam::place-broken-parts-individually grob)
67 (ly:beam::quanting grob '(+inf.0 . -inf.0) #f))
69 ;; calculates the slope of a beam as a single unit,
70 ;; even if it is broken. this assures that the beam
71 ;; will pick up where it left off after a line break
72 (define-public (beam::align-with-broken-parts grob)
73 (ly:beam::quanting grob '(+inf.0 . -inf.0) #t))
75 ;; uses the broken beam style from edition peters combines the
76 ;; values of place-broken-parts-individually and align-with-broken-parts above,
77 ;; favoring place-broken-parts-individually when the beam naturally has a steeper
78 ;; incline and align-with-broken-parts when the beam is flat
79 (define-public (beam::slope-like-broken-parts grob)
81 (/ (- (cdr y) (car y)) (- (cdr x) (car x))))
82 (let* ((quant1 (ly:beam::quanting grob '(+inf.0 . -inf.0) #t))
83 (original (ly:grob-original grob))
84 (siblings (if (ly:grob? original)
85 (ly:spanner-broken-into original)
89 (let* ((quant2 (ly:beam::quanting grob '(+inf.0 . -inf.0) #f))
90 (x-span (ly:grob-property grob 'X-positions))
91 (slope1 (slope quant1 x-span))
92 (slope2 (slope quant2 x-span))
93 (quant2 (if (not (= (sign slope1) (sign slope2)))
96 (factor (/ (atan (abs slope1)) PI-OVER-TWO))
99 (+ (* (x quant1) (- 1 factor))
100 (* (x quant2) factor)))
102 (ly:beam::quanting grob base #f)))))
104 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
107 (define-public (script-or-side-position-cross-staff g)
109 (ly:script-interface::calc-cross-staff g)
110 (ly:side-position-interface::calc-cross-staff g)))
113 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
116 (define-public (stem::calc-duration-log grob)
118 (ly:event-property (event-cause grob) 'duration)))
120 (define-public (stem::length grob)
121 (let* ((ss (ly:staff-symbol-staff-space grob))
122 (beg (ly:grob-property grob 'stem-begin-position))
123 (beam (ly:grob-object grob 'beam)))
125 (abs (- (ly:stem::calc-stem-end-position grob) beg))
127 (ly:programming-error
128 "stem::length called but will not be used for beamed stem.")
131 (define-public (stem::pure-length grob beg end)
132 (let* ((ss (ly:staff-symbol-staff-space grob))
133 (beg (ly:grob-pure-property grob 'stem-begin-position 0 1000)))
134 (abs (- (ly:stem::pure-calc-stem-end-position grob 0 2147483646) beg))))
136 (define-public (note-head::calc-duration-log grob)
139 (ly:event-property (event-cause grob) 'duration))))
141 (define-public (dots::calc-dot-count grob)
142 (ly:duration-dot-count
143 (ly:event-property (event-cause grob) 'duration)))
145 (define-public (dots::calc-staff-position grob)
146 (let* ((head (ly:grob-parent grob Y))
147 (log (ly:grob-property head 'duration-log)))
150 ((or (not (grob::has-interface head 'rest-interface))
151 (not (integer? log))) 0)
159 ;; Kept separate from note-head::calc-glyph-name to allow use by
160 ;; markup commands \note and \note-by-number
161 (define-public (select-head-glyph style log)
162 "Select a note head glyph string based on note head style @var{style}
163 and duration-log @var{log}."
165 ;; "default" style is directly handled in note-head.cc as a
166 ;; special case (HW says, mainly for performance reasons).
167 ;; Therefore, style "default" does not appear in this case
169 ((xcircle) "2xcircle")
170 ((harmonic) "0harmonic")
171 ((harmonic-black) "2harmonic")
172 ((harmonic-mixed) (if (<= log 1) "0harmonic"
175 ;; Oops, I actually would not call this "baroque", but, for
176 ;; backwards compatibility to 1.4, this is supposed to take
177 ;; brevis, longa and maxima from the neo-mensural font and all
178 ;; other note heads from the default font. -- jr
180 (string-append (number->string log) "neomensural")
181 (number->string log)))
183 ;; Like default, but brevis is drawn with double vertical lines
185 (string-append (number->string log) "double")
186 (number->string log)))
188 (string-append (number->string log) (symbol->string style)))
191 (string-append (number->string log) "mensural")
192 (string-append (number->string log) (symbol->string style))))
195 (string-append (number->string log) "blackmensural")
196 (string-append (number->string log) (symbol->string style))))
199 (string-append (number->string log) "semimensural")
200 (string-append (number->string log) "petrucci")))
202 (string-append (number->string log) (symbol->string style)))
204 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
205 (symbol->string style)
206 (string-append (number->string (max 0 log))
207 (symbol->string style))))))
209 (define-public (note-head::calc-glyph-name grob)
210 (let ((style (ly:grob-property grob 'style))
211 (log (min 2 (ly:grob-property grob 'duration-log))))
213 (select-head-glyph style log)))
215 (define-public (note-head::brew-ez-stencil grob)
216 (let* ((log (ly:grob-property grob 'duration-log))
217 (pitch (ly:event-property (event-cause grob) 'pitch))
218 (pitch-index (ly:pitch-notename pitch))
219 (note-names (ly:grob-property grob 'note-names))
220 (pitch-string (if (and (vector? note-names)
221 (> (vector-length note-names) pitch-index))
222 (vector-ref note-names pitch-index)
225 (+ (modulo (+ pitch-index 2) 7)
226 (char->integer #\A))))))
227 (staff-space (ly:staff-symbol-staff-space grob))
228 (line-thickness (ly:staff-symbol-line-thickness grob))
229 (stem (ly:grob-object grob 'stem))
230 (stem-thickness (* (if (ly:grob? stem)
231 (ly:grob-property stem 'thickness)
234 (radius (/ (+ staff-space line-thickness) 2))
235 (letter (markup #:center-align #:vcenter pitch-string))
236 (filled-circle (markup #:draw-circle radius 0 #t)))
238 (ly:stencil-translate-axis
239 (grob-interpret-markup
244 (make-with-color-markup white letter))
248 (make-with-color-markup white (make-draw-circle-markup
249 (- radius stem-thickness) 0 #t)))
253 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
256 (define-public (make-rhythmic-location bar-num num den)
258 bar-num (ly:make-moment num den)))
260 (define-public (rhythmic-location? a)
263 (ly:moment? (cdr a))))
265 (define-public (make-graceless-rhythmic-location loc)
266 (make-rhythmic-location
268 (ly:moment-main-numerator (rhythmic-location-measure-position loc))
269 (ly:moment-main-denominator (rhythmic-location-measure-position loc))))
271 (define-public rhythmic-location-measure-position cdr)
272 (define-public rhythmic-location-bar-number car)
274 (define-public (rhythmic-location<? a b)
276 ((< (car a) (car b)) #t)
277 ((> (car a) (car b)) #f)
279 (ly:moment<? (cdr a) (cdr b)))))
281 (define-public (rhythmic-location<=? a b)
282 (not (rhythmic-location<? b a)))
283 (define-public (rhythmic-location>=? a b)
284 (rhythmic-location<? a b))
285 (define-public (rhythmic-location>? a b)
286 (rhythmic-location<? b a))
288 (define-public (rhythmic-location=? a b)
289 (and (rhythmic-location<=? a b)
290 (rhythmic-location<=? b a)))
292 (define-public (rhythmic-location->file-string a)
293 (ly:format "~a.~a.~a"
295 (ly:moment-main-numerator (cdr a))
296 (ly:moment-main-denominator (cdr a))))
298 (define-public (rhythmic-location->string a)
299 (ly:format "bar ~a ~a"
301 (ly:moment->string (cdr a))))
303 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
306 (define-public all-visible #(#t #t #t))
307 (define-public begin-of-line-invisible #(#t #t #f))
308 (define-public center-invisible #(#t #f #t))
309 (define-public end-of-line-invisible #(#f #t #t))
310 (define-public begin-of-line-visible #(#f #f #t))
311 (define-public center-visible #(#f #t #f))
312 (define-public end-of-line-visible #(#t #f #f))
313 (define-public all-invisible #(#f #f #f))
314 (define-public (inherit-x-parent-visibility grob)
315 (let ((parent (ly:grob-parent grob X)))
316 (ly:grob-property parent 'break-visibility all-invisible)))
317 (define-public (inherit-y-parent-visibility grob)
318 (let ((parent (ly:grob-parent grob X)))
319 (ly:grob-property parent 'break-visibility)))
322 (define-public spanbar-begin-of-line-invisible #(#t #f #f))
325 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
329 ;; How should a bar line behave at a break?
330 (define bar-glyph-alist
331 '((":|:" . (":|" . "|:"))
332 (":|.|:" . (":|" . "|:"))
333 (":|.:" . (":|" . "|:"))
334 ("||:" . ("||" . "|:"))
335 ("dashed" . ("dashed" . '()))
337 ("||:" . ("||" . "|:"))
339 ("|:" . ("|" . "|:"))
342 ;; hmm... should we end with a bar line here?
343 (".|" . ("|" . ".|"))
346 (".|." . (".|." . ()))
347 ("|.|" . ("|.|" . ()))
352 ("empty" . (() . ()))
353 ("brace" . (() . "brace"))
354 ("bracket" . (() . "bracket"))
360 (":|S" . (":|" . "S"))
361 (":|S." . (":|S" . ()))
362 ("S|:" . ("S" . "|:"))
363 (".S|:" . ("|" . "S|:"))
364 (":|S|:" . (":|" . "S|:"))
365 (":|S.|:" . (":|S" . "|:"))))
367 (define-public (bar-line::calc-glyph-name grob)
368 (let* ((glyph (ly:grob-property grob 'glyph))
369 (dir (ly:item-break-dir grob))
370 (result (assoc-get glyph bar-glyph-alist))
371 (glyph-name (if (= dir CENTER)
374 (string? (index-cell result dir)))
375 (index-cell result dir)
379 (define-public (bar-line::calc-break-visibility grob)
380 (let* ((glyph (ly:grob-property grob 'glyph))
381 (result (assoc-get glyph bar-glyph-alist)))
384 (vector (string? (car result)) #t (string? (cdr result)))
387 (define-public (shift-right-at-line-begin g)
388 "Shift an item to the right, but only at the start of the line."
389 (if (and (ly:item? g)
390 (equal? (ly:item-break-dir g) RIGHT))
391 (ly:grob-translate-axis! g 3.5 X)))
393 (define-public (pure-from-neighbor-interface::extra-spacing-height-at-beginning-of-line grob)
394 (if (= 1 (ly:item-break-dir grob))
395 (pure-from-neighbor-interface::extra-spacing-height grob)
398 (define-public (pure-from-neighbor-interface::extra-spacing-height grob)
399 (let* ((height (ly:grob::stencil-height grob))
400 (from-neighbors (interval-union
402 (ly:axis-group-interface::pure-height
406 (coord-operation - from-neighbors height)))
408 (define-public (pure-from-neighbor-interface::account-for-span-bar grob)
409 (define (other-op x) (x (cons cdr car)))
410 (let* ((esh (pure-from-neighbor-interface::extra-spacing-height grob))
411 (hsb (ly:grob-property grob 'has-span-bar)))
415 (if (and ((other-op x) hsb)
416 (not (and (eq? x car)
417 (not (ly:grob-property grob 'allow-span-bar)))))
419 (x (cons -1.01 1.01))))
421 ;; sufficient height to prevent ledger lines from moving over/under
424 (define-public (pure-from-neighbor-interface::extra-spacing-height-including-staff grob)
425 (let ((esh (pure-from-neighbor-interface::extra-spacing-height grob))
426 (to-staff (coord-operation -
429 (ly:staff-symbol-staff-radius grob))
430 (ly:grob::stencil-height grob))))
431 (interval-union esh to-staff)))
434 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
437 (define-public (tuplet-number::calc-direction grob)
438 (ly:tuplet-bracket::calc-direction (ly:grob-object grob 'bracket)))
440 (define-public (tuplet-number::calc-denominator-text grob)
441 (number->string (ly:event-property (event-cause grob) 'denominator)))
443 (define-public (tuplet-number::calc-fraction-text grob)
444 (let ((ev (event-cause grob)))
447 (ly:event-property ev 'denominator)
448 (ly:event-property ev 'numerator))))
450 ;; a formatter function, which is simply a wrapper around an existing
451 ;; tuplet formatter function. It takes the value returned by the given
452 ;; function and appends a note of given length.
453 (define-public ((tuplet-number::append-note-wrapper function note) grob)
454 (let ((txt (if function (function grob) #f)))
457 (markup txt #:fontsize -5 #:note note UP)
458 (markup #:fontsize -5 #:note note UP))))
460 ;; Print a tuplet denominator with a different number than the one derived from
461 ;; the actual tuplet fraction
462 (define-public ((tuplet-number::non-default-tuplet-denominator-text denominator)
464 (number->string (if denominator
466 (ly:event-property (event-cause grob) 'denominator))))
468 ;; Print a tuplet fraction with different numbers than the ones derived from
469 ;; the actual tuplet fraction
470 (define-public ((tuplet-number::non-default-tuplet-fraction-text
471 denominator numerator) grob)
472 (let* ((ev (event-cause grob))
473 (den (if denominator denominator (ly:event-property ev 'denominator)))
474 (num (if numerator numerator (ly:event-property ev 'numerator))))
476 (format #f "~a:~a" den num)))
478 ;; Print a tuplet fraction with note durations appended to the numerator and the
480 (define-public ((tuplet-number::fraction-with-notes
481 denominatornote numeratornote) grob)
482 (let* ((ev (event-cause grob))
483 (denominator (ly:event-property ev 'denominator))
484 (numerator (ly:event-property ev 'numerator)))
486 ((tuplet-number::non-default-fraction-with-notes
487 denominator denominatornote numerator numeratornote) grob)))
489 ;; Print a tuplet fraction with note durations appended to the numerator and the
491 (define-public ((tuplet-number::non-default-fraction-with-notes
492 denominator denominatornote numerator numeratornote) grob)
493 (let* ((ev (event-cause grob))
494 (den (if denominator denominator (ly:event-property ev 'denominator)))
495 (num (if numerator numerator (ly:event-property ev 'numerator))))
497 (make-concat-markup (list
498 (make-simple-markup (format #f "~a" den))
499 (markup #:fontsize -5 #:note denominatornote UP)
500 (make-simple-markup " : ")
501 (make-simple-markup (format #f "~a" num))
502 (markup #:fontsize -5 #:note numeratornote UP)))))
505 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
508 (define-public (color? x)
511 (apply eq? #t (map number? x))
512 (apply eq? #t (map (lambda (y) (<= 0 y 1)) x))))
514 (define-public (rgb-color r g b) (list r g b))
517 (define-public black '(0.0 0.0 0.0))
518 (define-public white '(1.0 1.0 1.0))
519 (define-public red '(1.0 0.0 0.0))
520 (define-public green '(0.0 1.0 0.0))
521 (define-public blue '(0.0 0.0 1.0))
522 (define-public cyan '(0.0 1.0 1.0))
523 (define-public magenta '(1.0 0.0 1.0))
524 (define-public yellow '(1.0 1.0 0.0))
526 (define-public grey '(0.5 0.5 0.5))
527 (define-public darkred '(0.5 0.0 0.0))
528 (define-public darkgreen '(0.0 0.5 0.0))
529 (define-public darkblue '(0.0 0.0 0.5))
530 (define-public darkcyan '(0.0 0.5 0.5))
531 (define-public darkmagenta '(0.5 0.0 0.5))
532 (define-public darkyellow '(0.5 0.5 0.0))
535 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
538 (define-public (key-signature-interface::alteration-position step alter
540 ;; TODO: memoize - this is mostly constant.
542 ;; fes, ges, as and bes typeset in lower octave
543 (define FLAT_TOP_PITCH 2)
545 ;; ais and bis typeset in lower octave
546 (define SHARP_TOP_PITCH 4)
549 (+ (cdr step) (* (car step) 7) c0-position)
550 (let* ((from-bottom-pos (modulo (+ 4 49 c0-position) 7))
552 (c0 (- from-bottom-pos 4)))
556 (or (> p FLAT_TOP_PITCH) (> (+ p c0) 4)) (> (+ p c0) 1))
558 (or (> p SHARP_TOP_PITCH) (> (+ p c0) 5)) (> (+ p c0) 2)))
560 ;; Typeset below c_position
563 ;; Provide for the four cases in which there's a glitch
564 ;; it's a hack, but probably not worth
565 ;; the effort of finding a nicer solution.
568 ((and (= c0 2) (= p 3) (> alter 0))
570 ((and (= c0 -3) (= p -1) (> alter 0))
572 ((and (= c0 -4) (= p -1) (< alter 0))
574 ((and (= c0 -2) (= p -3) (< alter 0))
580 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
583 (define-public (numbered-footnotes int)
584 (markup #:tiny (number->string (+ 1 int))))
586 (define-public (symbol-footnotes int)
587 (define (helper symbols out idx n)
591 (string-append out (list-ref symbols idx))
594 (markup #:tiny (helper '("*" "†" "‡" "§" "¶")
597 (+ 1 (quotient int 5)))))
599 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
602 (define-public (accidental-interface::calc-alteration grob)
603 (ly:pitch-alteration (ly:event-property (event-cause grob) 'pitch)))
605 (define-public cancellation-glyph-name-alist
606 '((0 . "accidentals.natural")))
608 (define-public standard-alteration-glyph-name-alist
610 ;; ordered for optimal performance.
611 (0 . "accidentals.natural")
612 (-1/2 . "accidentals.flat")
613 (1/2 . "accidentals.sharp")
615 (1 . "accidentals.doublesharp")
616 (-1 . "accidentals.flatflat")
618 (3/4 . "accidentals.sharp.slashslash.stemstemstem")
619 (1/4 . "accidentals.sharp.slashslash.stem")
620 (-1/4 . "accidentals.mirroredflat")
621 (-3/4 . "accidentals.mirroredflat.flat")))
623 ;; FIXME: standard vs default, alteration-FOO vs FOO-alteration
624 (define-public alteration-default-glyph-name-alist
625 standard-alteration-glyph-name-alist)
627 (define-public makam-alteration-glyph-name-alist
628 '((1 . "accidentals.doublesharp")
629 (8/9 . "accidentals.sharp.slashslashslash.stemstem")
630 (5/9 . "accidentals.sharp.slashslashslash.stem")
631 (4/9 . "accidentals.sharp")
632 (1/9 . "accidentals.sharp.slashslash.stem")
633 (0 . "accidentals.natural")
634 (-1/9 . "accidentals.mirroredflat")
635 (-4/9 . "accidentals.flat.slash")
636 (-5/9 . "accidentals.flat")
637 (-8/9 . "accidentals.flat.slashslash")
638 (-1 . "accidentals.flatflat")))
640 (define-public alteration-hufnagel-glyph-name-alist
641 '((-1/2 . "accidentals.hufnagelM1")
642 (0 . "accidentals.vaticana0")
643 (1/2 . "accidentals.mensural1")))
645 (define-public alteration-medicaea-glyph-name-alist
646 '((-1/2 . "accidentals.medicaeaM1")
647 (0 . "accidentals.vaticana0")
648 (1/2 . "accidentals.mensural1")))
650 (define-public alteration-vaticana-glyph-name-alist
651 '((-1/2 . "accidentals.vaticanaM1")
652 (0 . "accidentals.vaticana0")
653 (1/2 . "accidentals.mensural1")))
655 (define-public alteration-mensural-glyph-name-alist
656 '((-1/2 . "accidentals.mensuralM1")
657 (0 . "accidentals.vaticana0")
658 (1/2 . "accidentals.mensural1")))
661 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
662 ;; * Pitch Trill Heads
665 (define-public (parentheses-item::calc-parenthesis-stencils grob)
666 (let* ((font (ly:grob-default-font grob))
667 (lp (ly:font-get-glyph font "accidentals.leftparen"))
668 (rp (ly:font-get-glyph font "accidentals.rightparen")))
672 (define-public (parentheses-item::calc-angled-bracket-stencils grob)
673 (let* ((parent (ly:grob-parent grob Y))
674 (y-extent (ly:grob-extent parent parent Y))
675 (half-thickness 0.05) ; should it be a property?
676 (width 0.5) ; should it be a property?
677 (angularity 1.5) ; makes angle brackets
678 (white-padding 0.1) ; should it be a property?
679 (lp (ly:stencil-aligned-to
680 (ly:stencil-aligned-to
681 (make-parenthesis-stencil y-extent
688 (interval-widen (ly:stencil-extent lp X) white-padding))
689 (rp (ly:stencil-aligned-to
690 (ly:stencil-aligned-to
691 (make-parenthesis-stencil y-extent
698 (interval-widen (ly:stencil-extent rp X) white-padding)))
699 (set! lp (ly:make-stencil (ly:stencil-expr lp)
701 (ly:stencil-extent lp Y)))
702 (set! rp (ly:make-stencil (ly:stencil-expr rp)
704 (ly:stencil-extent rp Y)))
705 (list (stencil-whiteout lp)
706 (stencil-whiteout rp))))
708 (define (parenthesize-elements grob . rest)
709 (let* ((refp (if (null? rest)
712 (elts (ly:grob-object grob 'elements))
713 (x-ext (ly:relative-group-extent elts refp X))
714 (stencils (ly:grob-property grob 'stencils))
717 (padding (ly:grob-property grob 'padding 0.1)))
720 (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
721 (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))))
724 (define-public (parentheses-item::print me)
725 (let* ((elts (ly:grob-object me 'elements))
726 (y-ref (ly:grob-common-refpoint-of-array me elts Y))
727 (x-ref (ly:grob-common-refpoint-of-array me elts X))
728 (stencil (parenthesize-elements me x-ref))
729 (elt-y-ext (ly:relative-group-extent elts y-ref Y))
730 (y-center (interval-center elt-y-ext)))
732 (ly:stencil-translate
735 (- (ly:grob-relative-coordinate me x-ref X))
736 (- y-center (ly:grob-relative-coordinate me y-ref Y))))))
740 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
743 (define-public (chain-grob-member-functions grob value . funcs)
746 (set! value (func grob value)))
752 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
755 (define-public (bend::print spanner)
757 (< (abs (- a b)) 0.01))
759 (let* ((delta-y (* 0.5 (ly:grob-property spanner 'delta-position)))
760 (left-span (ly:spanner-bound spanner LEFT))
761 (dots (if (and (grob::has-interface left-span 'note-head-interface)
762 (ly:grob? (ly:grob-object left-span 'dot)))
763 (ly:grob-object left-span 'dot) #f))
765 (right-span (ly:spanner-bound spanner RIGHT))
766 (thickness (* (ly:grob-property spanner 'thickness)
767 (ly:output-def-lookup (ly:grob-layout spanner)
769 (padding (ly:grob-property spanner 'padding 0.5))
770 (common (ly:grob-common-refpoint right-span
771 (ly:grob-common-refpoint spanner
774 (common-y (ly:grob-common-refpoint spanner left-span Y))
775 (minimum-length (ly:grob-property spanner 'minimum-length 0.5))
779 (interval-end (ly:grob-robust-relative-extent
784 (ly:grob-relative-coordinate dots common-y Y)
785 (ly:grob-relative-coordinate spanner common-y Y)))
787 (ly:grob-robust-relative-extent dots common X))
788 ;; TODO: use real infinity constant.
790 (right-x (max (- (interval-start
791 (ly:grob-robust-relative-extent right-span common X))
793 (+ left-x minimum-length)))
794 (self-x (ly:grob-relative-coordinate spanner common X))
795 (dx (- right-x left-x))
796 (exp (list 'path thickness
804 ,dx ,(* 0.66 delta-y)
809 (cons (- left-x self-x) (- right-x self-x))
810 (cons (min 0 delta-y)
814 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
817 (define-public (grace-spacing::calc-shortest-duration grob)
818 (let* ((cols (ly:grob-object grob 'columns))
821 (ly:moment-sub (ly:grob-property
822 (ly:grob-array-ref cols (1+ idx)) 'when)
824 (ly:grob-array-ref cols idx) 'when))))
826 (moment-min (lambda (x y)
829 (if (ly:moment<? x y)
835 (fold moment-min #f (map get-difference
836 (iota (1- (ly:grob-array-length cols)))))))
839 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
842 (define-public (fingering::calc-text grob)
843 (let* ((event (event-cause grob))
844 (digit (ly:event-property event 'digit)))
847 (ly:input-message (ly:event-property event 'origin)
848 "Warning: Fingering notation for finger number ~a"
851 (number->string digit 10)))
853 (define-public (string-number::calc-text grob)
854 (let ((digit (ly:event-property (event-cause grob) 'string-number)))
856 (number->string digit 10)))
858 (define-public (stroke-finger::calc-text grob)
859 (let* ((digit (ly:event-property (event-cause grob) 'digit))
860 (text (ly:event-property (event-cause grob) 'text)))
864 (vector-ref (ly:grob-property grob 'digit-names)
865 (1- (max (min 5 digit) 1))))))
868 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
871 (define-public (hairpin::calc-grow-direction grob)
872 (if (eq? (ly:event-property (event-cause grob) 'class) 'decrescendo-event)
876 (define-public (dynamic-text-spanner::before-line-breaking grob)
877 "Monitor left bound of @code{DynamicTextSpanner} for absolute dynamics.
878 If found, ensure @code{DynamicText} does not collide with spanner text by
879 changing @code{'attach-dir} and @code{'padding}. Reads the
880 @code{'right-padding} property of @code{DynamicText} to fine tune space
881 between the two text elements."
882 (let ((left-bound (ly:spanner-bound grob LEFT)))
883 (if (grob::has-interface left-bound 'dynamic-text-interface)
884 (let* ((details (ly:grob-property grob 'bound-details))
885 (left-details (ly:assoc-get 'left details))
886 (my-padding (ly:assoc-get 'padding left-details))
887 (script-padding (ly:grob-property left-bound 'right-padding 0)))
889 (and (number? my-padding)
890 (ly:grob-set-nested-property! grob
891 '(bound-details left attach-dir)
893 (ly:grob-set-nested-property! grob
894 '(bound-details left padding)
895 (+ my-padding script-padding)))))))
898 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
901 (define-public (lyric-text::print grob)
902 "Allow interpretation of tildes as lyric tieing marks."
904 (let ((text (ly:grob-property grob 'text)))
906 (grob-interpret-markup grob (if (string? text)
907 (make-tied-lyric-markup text)
910 (define-public ((grob::calc-property-by-copy prop) grob)
911 (ly:event-property (event-cause grob) prop))
914 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
917 (define-public (fret-board::calc-stencil grob)
918 (grob-interpret-markup
920 (make-fret-diagram-verbose-markup
921 (ly:grob-property grob 'dot-placement-list))))
924 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
927 (define-public (script-interface::calc-x-offset grob)
928 (ly:grob-property grob 'positioning-done)
929 (let* ((shift (ly:grob-property grob 'toward-stem-shift 0.0))
931 (ly:self-alignment-interface::centered-on-x-parent grob))
932 (note-head-grob (ly:grob-parent grob X))
933 (stem-grob (ly:grob-object note-head-grob 'stem)))
935 (+ note-head-location
936 ;; If the property 'toward-stem-shift is defined and the script
937 ;; has the same direction as the stem, move the script accordingly.
938 ;; Since scripts can also be over skips, we need to check whether
939 ;; the grob has a stem at all.
940 (if (ly:grob? stem-grob)
941 (let ((dir1 (ly:grob-property grob 'direction))
942 (dir2 (ly:grob-property stem-grob 'direction)))
943 (if (equal? dir1 dir2)
944 (let* ((common-refp (ly:grob-common-refpoint grob stem-grob X))
946 (ly:grob-relative-coordinate stem-grob common-refp X)))
947 (* shift (- stem-location note-head-location)))
952 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
955 (define-public (system-start-text::print grob)
956 (let* ((left-bound (ly:spanner-bound grob LEFT))
957 (left-mom (ly:grob-property left-bound 'when))
958 (name (if (moment<=? left-mom ZERO-MOMENT)
959 (ly:grob-property grob 'long-text)
960 (ly:grob-property grob 'text))))
962 (if (and (markup? name)
963 (!= (ly:item-break-dir left-bound) CENTER))
965 (grob-interpret-markup grob name)
966 (ly:grob-suicide! grob))))
968 (define-public (system-start-text::calc-x-offset grob)
969 (let* ((left-bound (ly:spanner-bound grob LEFT))
970 (left-mom (ly:grob-property left-bound 'when))
971 (layout (ly:grob-layout grob))
972 (indent (ly:output-def-lookup layout
973 (if (moment<=? left-mom ZERO-MOMENT)
977 (system (ly:grob-system grob))
978 (my-extent (ly:grob-extent grob system X))
979 (elements (ly:grob-object system 'elements))
980 (common (ly:grob-common-refpoint-of-array system elements X))
981 (total-ext empty-interval)
982 (align-x (ly:grob-property grob 'self-alignment-X 0))
983 (padding (min 0 (- (interval-length my-extent) indent)))
984 (right-padding (- padding
985 (/ (* padding (1+ align-x)) 2))))
987 ;; compensate for the variation in delimiter extents by
988 ;; calculating an X-offset correction based on united extents
989 ;; of all delimiters in this system
990 (let unite-delims ((l (ly:grob-array-length elements)))
992 (let ((elt (ly:grob-array-ref elements (1- l))))
994 (if (grob::has-interface elt 'system-start-delimiter-interface)
995 (let ((dims (ly:grob-extent elt common X)))
996 (if (interval-sane? dims)
997 (set! total-ext (interval-union total-ext dims)))))
998 (unite-delims (1- l)))))
1001 (ly:side-position-interface::x-aligned-side grob)
1003 (- (interval-length total-ext)))))
1005 (define-public (system-start-text::calc-y-offset grob)
1007 (define (live-elements-list me)
1008 (let ((elements (ly:grob-object me 'elements)))
1010 (filter! grob::is-live?
1011 (ly:grob-array->list elements))))
1013 (let* ((left-bound (ly:spanner-bound grob LEFT))
1014 (live-elts (live-elements-list grob))
1015 (system (ly:grob-system grob))
1016 (extent empty-interval))
1018 (if (and (pair? live-elts)
1019 (interval-sane? (ly:grob-extent grob system Y)))
1020 (let get-extent ((lst live-elts))
1022 (let ((axis-group (car lst)))
1024 (if (and (ly:spanner? axis-group)
1025 (equal? (ly:spanner-bound axis-group LEFT)
1027 (set! extent (add-point extent
1028 (ly:grob-relative-coordinate
1029 axis-group system Y))))
1030 (get-extent (cdr lst)))))
1031 ;; no live axis group(s) for this instrument name -> remove from system
1032 (ly:grob-suicide! grob))
1035 (ly:self-alignment-interface::y-aligned-on-self grob)
1036 (interval-center extent))))
1039 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1042 (define-public (ambitus::print grob)
1043 (let ((heads (ly:grob-object grob 'note-heads)))
1045 (if (and (ly:grob-array? heads)
1046 (= (ly:grob-array-length heads) 2))
1047 (let* ((common (ly:grob-common-refpoint-of-array grob heads Y))
1048 (head-down (ly:grob-array-ref heads 0))
1049 (head-up (ly:grob-array-ref heads 1))
1050 (gap (ly:grob-property grob 'gap 0.35))
1051 (point-min (+ (interval-end (ly:grob-extent head-down common Y))
1053 (point-max (- (interval-start (ly:grob-extent head-up common Y))
1056 (if (< point-min point-max)
1057 (let* ((layout (ly:grob-layout grob))
1058 (line-thick (ly:output-def-lookup layout 'line-thickness))
1059 (blot (ly:output-def-lookup layout 'blot-diameter))
1060 (grob-thick (ly:grob-property grob 'thickness 2))
1061 (width (* line-thick grob-thick))
1062 (x-ext (symmetric-interval (/ width 2)))
1063 (y-ext (cons point-min point-max))
1064 (line (ly:round-filled-box x-ext y-ext blot))
1065 (y-coord (ly:grob-relative-coordinate grob common Y)))
1067 (ly:stencil-translate-axis line (- y-coord) Y))
1070 (ly:grob-suicide! grob)
1073 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1074 ;; laissez-vibrer tie
1076 ;; needed so we can make laissez-vibrer a pure print
1078 (define-public (laissez-vibrer::print grob)
1079 (ly:tie::print grob))