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)))
61 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
64 ;; calculates each slope of a broken beam individually
65 (define-public (beam::place-broken-parts-individually grob)
66 (ly:beam::quanting grob '(+inf.0 . -inf.0) #f))
68 ;; calculates the slope of a beam as a single unit,
69 ;; even if it is broken. this assures that the beam
70 ;; will pick up where it left off after a line break
71 (define-public (beam::align-with-broken-parts grob)
72 (ly:beam::quanting grob '(+inf.0 . -inf.0) #t))
74 ;; uses the broken beam style from edition peters combines the
75 ;; values of place-broken-parts-individually and align-with-broken-parts above,
76 ;; favoring place-broken-parts-individually when the beam naturally has a steeper
77 ;; incline and align-with-broken-parts when the beam is flat
78 (define-public (beam::slope-like-broken-parts grob)
80 (/ (- (cdr y) (car y)) (- (cdr x) (car x))))
81 (let* ((quant1 (ly:beam::quanting grob '(+inf.0 . -inf.0) #t))
82 (original (ly:grob-original grob))
83 (siblings (if (ly:grob? original)
84 (ly:spanner-broken-into original)
88 (let* ((quant2 (ly:beam::quanting grob '(+inf.0 . -inf.0) #f))
89 (x-span (ly:grob-property grob 'X-positions))
90 (slope1 (slope quant1 x-span))
91 (slope2 (slope quant2 x-span))
92 (quant2 (if (not (= (sign slope1) (sign slope2)))
95 (factor (/ (atan (abs slope1)) PI-OVER-TWO))
98 (+ (* (x quant1) (- 1 factor))
99 (* (x quant2) factor)))
101 (ly:beam::quanting grob base #f)))))
103 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
106 (define-public (script-or-side-position-cross-staff g)
108 (ly:script-interface::calc-cross-staff g)
109 (ly:side-position-interface::calc-cross-staff g)))
112 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
115 (define-public (stem::calc-duration-log grob)
117 (ly:event-property (event-cause grob) 'duration)))
119 (define-public (stem::length grob)
120 (let* ((ss (ly:staff-symbol-staff-space grob))
121 (beg (ly:grob-property grob 'stem-begin-position))
122 (beam (ly:grob-object grob 'beam)))
124 (abs (- (ly:stem::calc-stem-end-position grob) beg))
126 (ly:programming-error
127 "stem::length called but will not be used for beamed stem.")
130 (define-public (stem::pure-length grob beg end)
131 (let* ((ss (ly:staff-symbol-staff-space grob))
132 (beg (ly:grob-pure-property grob 'stem-begin-position 0 1000)))
133 (abs (- (ly:stem::pure-calc-stem-end-position grob 0 2147483646) beg))))
135 (define-public (note-head::calc-duration-log grob)
138 (ly:event-property (event-cause grob) 'duration))))
140 (define-public (dots::calc-dot-count grob)
141 (ly:duration-dot-count
142 (ly:event-property (event-cause grob) 'duration)))
144 (define-public (dots::calc-staff-position grob)
145 (let* ((head (ly:grob-parent grob Y))
146 (log (ly:grob-property head 'duration-log)))
149 ((or (not (grob::has-interface head 'rest-interface))
150 (not (integer? log))) 0)
158 ;; Kept separate from note-head::calc-glyph-name to allow use by
159 ;; markup commands \note and \note-by-number
160 (define-public (select-head-glyph style log)
161 "Select a note head glyph string based on note head style @var{style}
162 and duration-log @var{log}."
164 ;; "default" style is directly handled in note-head.cc as a
165 ;; special case (HW says, mainly for performance reasons).
166 ;; Therefore, style "default" does not appear in this case
168 ((xcircle) "2xcircle")
169 ((harmonic) "0harmonic")
170 ((harmonic-black) "2harmonic")
171 ((harmonic-mixed) (if (<= log 1) "0harmonic"
174 ;; Oops, I actually would not call this "baroque", but, for
175 ;; backwards compatibility to 1.4, this is supposed to take
176 ;; brevis, longa and maxima from the neo-mensural font and all
177 ;; other note heads from the default font. -- jr
179 (string-append (number->string log) "neomensural")
180 (number->string log)))
182 ;; Like default, but brevis is drawn with double vertical lines
184 (string-append (number->string log) "double")
185 (number->string log)))
187 (string-append (number->string log) (symbol->string style)))
190 (string-append (number->string log) "mensural")
191 (string-append (number->string log) (symbol->string style))))
194 (string-append (number->string log) "blackmensural")
195 (string-append (number->string log) (symbol->string style))))
198 (string-append (number->string log) "semimensural")
199 (string-append (number->string log) "petrucci")))
201 (string-append (number->string log) (symbol->string style)))
203 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
204 (symbol->string style)
205 (string-append (number->string (max 0 log))
206 (symbol->string style))))))
208 (define-public (note-head::calc-glyph-name grob)
209 (let ((style (ly:grob-property grob 'style))
210 (log (min 2 (ly:grob-property grob 'duration-log))))
212 (select-head-glyph style log)))
214 (define-public (note-head::brew-ez-stencil grob)
215 (let* ((log (ly:grob-property grob 'duration-log))
216 (pitch (ly:event-property (event-cause grob) 'pitch))
217 (pitch-index (ly:pitch-notename pitch))
218 (note-names (ly:grob-property grob 'note-names))
219 (pitch-string (if (and (vector? note-names)
220 (> (vector-length note-names) pitch-index))
221 (vector-ref note-names pitch-index)
224 (+ (modulo (+ pitch-index 2) 7)
225 (char->integer #\A))))))
226 (staff-space (ly:staff-symbol-staff-space grob))
227 (line-thickness (ly:staff-symbol-line-thickness grob))
228 (stem (ly:grob-object grob 'stem))
229 (stem-thickness (* (if (ly:grob? stem)
230 (ly:grob-property stem 'thickness)
233 (radius (/ (+ staff-space line-thickness) 2))
234 (letter (markup #:center-align #:vcenter pitch-string))
235 (filled-circle (markup #:draw-circle radius 0 #t)))
237 (ly:stencil-translate-axis
238 (grob-interpret-markup
243 (make-with-color-markup white letter))
247 (make-with-color-markup white (make-draw-circle-markup
248 (- radius stem-thickness) 0 #t)))
252 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
255 (define-public (make-rhythmic-location bar-num num den)
257 bar-num (ly:make-moment num den)))
259 (define-public (rhythmic-location? a)
262 (ly:moment? (cdr a))))
264 (define-public (make-graceless-rhythmic-location loc)
265 (make-rhythmic-location
267 (ly:moment-main-numerator (rhythmic-location-measure-position loc))
268 (ly:moment-main-denominator (rhythmic-location-measure-position loc))))
270 (define-public rhythmic-location-measure-position cdr)
271 (define-public rhythmic-location-bar-number car)
273 (define-public (rhythmic-location<? a b)
275 ((< (car a) (car b)) #t)
276 ((> (car a) (car b)) #f)
278 (ly:moment<? (cdr a) (cdr b)))))
280 (define-public (rhythmic-location<=? a b)
281 (not (rhythmic-location<? b a)))
282 (define-public (rhythmic-location>=? a b)
283 (rhythmic-location<? a b))
284 (define-public (rhythmic-location>? a b)
285 (rhythmic-location<? b a))
287 (define-public (rhythmic-location=? a b)
288 (and (rhythmic-location<=? a b)
289 (rhythmic-location<=? b a)))
291 (define-public (rhythmic-location->file-string a)
292 (ly:format "~a.~a.~a"
294 (ly:moment-main-numerator (cdr a))
295 (ly:moment-main-denominator (cdr a))))
297 (define-public (rhythmic-location->string a)
298 (ly:format "bar ~a ~a"
300 (ly:moment->string (cdr a))))
302 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
305 (define-public all-visible #(#t #t #t))
306 (define-public begin-of-line-invisible #(#t #t #f))
307 (define-public center-invisible #(#t #f #t))
308 (define-public end-of-line-invisible #(#f #t #t))
309 (define-public begin-of-line-visible #(#f #f #t))
310 (define-public center-visible #(#f #t #f))
311 (define-public end-of-line-visible #(#t #f #f))
312 (define-public all-invisible #(#f #f #f))
313 (define-public (inherit-x-parent-visibility grob)
314 (let ((parent (ly:grob-parent grob X)))
315 (ly:grob-property parent 'break-visibility all-invisible)))
316 (define-public (inherit-y-parent-visibility grob)
317 (let ((parent (ly:grob-parent grob X)))
318 (ly:grob-property parent 'break-visibility)))
321 (define-public spanbar-begin-of-line-invisible #(#t #f #f))
324 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
328 ;; How should a bar line behave at a break?
329 (define bar-glyph-alist
330 '((":|:" . (":|" . "|:"))
331 (":|.|:" . (":|" . "|:"))
332 (":|.:" . (":|" . "|:"))
333 ("||:" . ("||" . "|:"))
334 ("dashed" . ("dashed" . '()))
336 ("||:" . ("||" . "|:"))
338 ("|:" . ("|" . "|:"))
341 ;; hmm... should we end with a bar line here?
342 (".|" . ("|" . ".|"))
345 (".|." . (".|." . ()))
346 ("|.|" . ("|.|" . ()))
351 ("empty" . (() . ()))
352 ("brace" . (() . "brace"))
353 ("bracket" . (() . "bracket"))
359 (":|S" . (":|" . "S"))
360 (":|S." . (":|S" . ()))
361 ("S|:" . ("S" . "|:"))
362 (".S|:" . ("|" . "S|:"))
363 (":|S|:" . (":|" . "S|:"))
364 (":|S.|:" . (":|S" . "|:"))))
366 (define-public (bar-line::calc-glyph-name grob)
367 (let* ((glyph (ly:grob-property grob 'glyph))
368 (dir (ly:item-break-dir grob))
369 (result (assoc-get glyph bar-glyph-alist))
370 (glyph-name (if (= dir CENTER)
373 (string? (index-cell result dir)))
374 (index-cell result dir)
378 (define-public (bar-line::calc-break-visibility grob)
379 (let* ((glyph (ly:grob-property grob 'glyph))
380 (result (assoc-get glyph bar-glyph-alist)))
383 (vector (string? (car result)) #t (string? (cdr result)))
386 (define-public (shift-right-at-line-begin g)
387 "Shift an item to the right, but only at the start of the line."
388 (if (and (ly:item? g)
389 (equal? (ly:item-break-dir g) RIGHT))
390 (ly:grob-translate-axis! g 3.5 X)))
392 (define-public (pure-from-neighbor-interface::extra-spacing-height-at-beginning-of-line grob)
393 (if (= 1 (ly:item-break-dir grob))
394 (pure-from-neighbor-interface::extra-spacing-height grob)
397 (define-public (pure-from-neighbor-interface::extra-spacing-height grob)
398 (let* ((height (ly:grob::stencil-height grob))
399 (from-neighbors (interval-union
401 (ly:axis-group-interface::pure-height
405 (coord-operation - from-neighbors height)))
407 (define-public (pure-from-neighbor-interface::account-for-span-bar grob)
408 (let* ((esh (pure-from-neighbor-interface::extra-spacing-height grob))
409 (hsb (ly:grob-property grob 'has-span-bar))
410 (ii (interval-intersection esh (cons -1.01 1.01))))
412 (cons (car (if (and (car hsb)
413 (ly:grob-property grob 'allow-span-bar))
415 (cdr (if (cdr hsb) esh ii)))
418 (define-public (pure-from-neighbor-interface::extra-spacing-height-including-staff grob)
419 (let ((esh (pure-from-neighbor-interface::extra-spacing-height grob))
420 (to-staff (coord-operation -
423 (ly:staff-symbol-staff-radius grob))
424 (ly:grob::stencil-height grob))))
425 (interval-union esh to-staff)))
428 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
431 (define-public (tuplet-number::calc-direction grob)
432 (ly:tuplet-bracket::calc-direction (ly:grob-object grob 'bracket)))
434 (define-public (tuplet-number::calc-denominator-text grob)
435 (number->string (ly:event-property (event-cause grob) 'denominator)))
437 (define-public (tuplet-number::calc-fraction-text grob)
438 (let ((ev (event-cause grob)))
441 (ly:event-property ev 'denominator)
442 (ly:event-property ev 'numerator))))
444 ;; a formatter function, which is simply a wrapper around an existing
445 ;; tuplet formatter function. It takes the value returned by the given
446 ;; function and appends a note of given length.
447 (define-public ((tuplet-number::append-note-wrapper function note) grob)
448 (let ((txt (if function (function grob) #f)))
451 (markup txt #:fontsize -5 #:note note UP)
452 (markup #:fontsize -5 #:note note UP))))
454 ;; Print a tuplet denominator with a different number than the one derived from
455 ;; the actual tuplet fraction
456 (define-public ((tuplet-number::non-default-tuplet-denominator-text denominator)
458 (number->string (if denominator
460 (ly:event-property (event-cause grob) 'denominator))))
462 ;; Print a tuplet fraction with different numbers than the ones derived from
463 ;; the actual tuplet fraction
464 (define-public ((tuplet-number::non-default-tuplet-fraction-text
465 denominator numerator) grob)
466 (let* ((ev (event-cause grob))
467 (den (if denominator denominator (ly:event-property ev 'denominator)))
468 (num (if numerator numerator (ly:event-property ev 'numerator))))
470 (format #f "~a:~a" den num)))
472 ;; Print a tuplet fraction with note durations appended to the numerator and the
474 (define-public ((tuplet-number::fraction-with-notes
475 denominatornote numeratornote) grob)
476 (let* ((ev (event-cause grob))
477 (denominator (ly:event-property ev 'denominator))
478 (numerator (ly:event-property ev 'numerator)))
480 ((tuplet-number::non-default-fraction-with-notes
481 denominator denominatornote numerator numeratornote) grob)))
483 ;; Print a tuplet fraction with note durations appended to the numerator and the
485 (define-public ((tuplet-number::non-default-fraction-with-notes
486 denominator denominatornote numerator numeratornote) grob)
487 (let* ((ev (event-cause grob))
488 (den (if denominator denominator (ly:event-property ev 'denominator)))
489 (num (if numerator numerator (ly:event-property ev 'numerator))))
491 (make-concat-markup (list
492 (make-simple-markup (format #f "~a" den))
493 (markup #:fontsize -5 #:note denominatornote UP)
494 (make-simple-markup " : ")
495 (make-simple-markup (format #f "~a" num))
496 (markup #:fontsize -5 #:note numeratornote UP)))))
499 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
502 (define-public (color? x)
505 (apply eq? #t (map number? x))
506 (apply eq? #t (map (lambda (y) (<= 0 y 1)) x))))
508 (define-public (rgb-color r g b) (list r g b))
511 (define-public black '(0.0 0.0 0.0))
512 (define-public white '(1.0 1.0 1.0))
513 (define-public red '(1.0 0.0 0.0))
514 (define-public green '(0.0 1.0 0.0))
515 (define-public blue '(0.0 0.0 1.0))
516 (define-public cyan '(0.0 1.0 1.0))
517 (define-public magenta '(1.0 0.0 1.0))
518 (define-public yellow '(1.0 1.0 0.0))
520 (define-public grey '(0.5 0.5 0.5))
521 (define-public darkred '(0.5 0.0 0.0))
522 (define-public darkgreen '(0.0 0.5 0.0))
523 (define-public darkblue '(0.0 0.0 0.5))
524 (define-public darkcyan '(0.0 0.5 0.5))
525 (define-public darkmagenta '(0.5 0.0 0.5))
526 (define-public darkyellow '(0.5 0.5 0.0))
529 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
532 (define-public (key-signature-interface::alteration-position step alter
534 ;; TODO: memoize - this is mostly constant.
536 ;; fes, ges, as and bes typeset in lower octave
537 (define FLAT_TOP_PITCH 2)
539 ;; ais and bis typeset in lower octave
540 (define SHARP_TOP_PITCH 4)
543 (+ (cdr step) (* (car step) 7) c0-position)
544 (let* ((from-bottom-pos (modulo (+ 4 49 c0-position) 7))
546 (c0 (- from-bottom-pos 4)))
550 (or (> p FLAT_TOP_PITCH) (> (+ p c0) 4)) (> (+ p c0) 1))
552 (or (> p SHARP_TOP_PITCH) (> (+ p c0) 5)) (> (+ p c0) 2)))
554 ;; Typeset below c_position
557 ;; Provide for the four cases in which there's a glitch
558 ;; it's a hack, but probably not worth
559 ;; the effort of finding a nicer solution.
562 ((and (= c0 2) (= p 3) (> alter 0))
564 ((and (= c0 -3) (= p -1) (> alter 0))
566 ((and (= c0 -4) (= p -1) (< alter 0))
568 ((and (= c0 -2) (= p -3) (< alter 0))
574 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
577 (define-public (numbered-footnotes int)
578 (markup #:tiny (number->string (+ 1 int))))
580 (define-public (symbol-footnotes int)
581 (define (helper symbols out idx n)
585 (string-append out (list-ref symbols idx))
588 (markup #:tiny (helper '("*" "†" "‡" "§" "¶")
591 (+ 1 (quotient int 5)))))
593 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
596 (define-public (accidental-interface::calc-alteration grob)
597 (ly:pitch-alteration (ly:event-property (event-cause grob) 'pitch)))
599 (define-public cancellation-glyph-name-alist
600 '((0 . "accidentals.natural")))
602 (define-public standard-alteration-glyph-name-alist
604 ;; ordered for optimal performance.
605 (0 . "accidentals.natural")
606 (-1/2 . "accidentals.flat")
607 (1/2 . "accidentals.sharp")
609 (1 . "accidentals.doublesharp")
610 (-1 . "accidentals.flatflat")
612 (3/4 . "accidentals.sharp.slashslash.stemstemstem")
613 (1/4 . "accidentals.sharp.slashslash.stem")
614 (-1/4 . "accidentals.mirroredflat")
615 (-3/4 . "accidentals.mirroredflat.flat")))
617 ;; FIXME: standard vs default, alteration-FOO vs FOO-alteration
618 (define-public alteration-default-glyph-name-alist
619 standard-alteration-glyph-name-alist)
621 (define-public makam-alteration-glyph-name-alist
622 '((1 . "accidentals.doublesharp")
623 (8/9 . "accidentals.sharp.slashslashslash.stemstem")
624 (5/9 . "accidentals.sharp.slashslashslash.stem")
625 (4/9 . "accidentals.sharp")
626 (1/9 . "accidentals.sharp.slashslash.stem")
627 (0 . "accidentals.natural")
628 (-1/9 . "accidentals.mirroredflat")
629 (-4/9 . "accidentals.flat.slash")
630 (-5/9 . "accidentals.flat")
631 (-8/9 . "accidentals.flat.slashslash")
632 (-1 . "accidentals.flatflat")))
634 (define-public alteration-hufnagel-glyph-name-alist
635 '((-1/2 . "accidentals.hufnagelM1")
636 (0 . "accidentals.vaticana0")
637 (1/2 . "accidentals.mensural1")))
639 (define-public alteration-medicaea-glyph-name-alist
640 '((-1/2 . "accidentals.medicaeaM1")
641 (0 . "accidentals.vaticana0")
642 (1/2 . "accidentals.mensural1")))
644 (define-public alteration-vaticana-glyph-name-alist
645 '((-1/2 . "accidentals.vaticanaM1")
646 (0 . "accidentals.vaticana0")
647 (1/2 . "accidentals.mensural1")))
649 (define-public alteration-mensural-glyph-name-alist
650 '((-1/2 . "accidentals.mensuralM1")
651 (0 . "accidentals.vaticana0")
652 (1/2 . "accidentals.mensural1")))
655 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
656 ;; * Pitch Trill Heads
659 (define-public (parentheses-item::calc-parenthesis-stencils grob)
660 (let* ((font (ly:grob-default-font grob))
661 (lp (ly:font-get-glyph font "accidentals.leftparen"))
662 (rp (ly:font-get-glyph font "accidentals.rightparen")))
666 (define-public (parentheses-item::calc-angled-bracket-stencils grob)
667 (let* ((parent (ly:grob-parent grob Y))
668 (y-extent (ly:grob-extent parent parent Y))
669 (half-thickness 0.05) ; should it be a property?
670 (width 0.5) ; should it be a property?
671 (angularity 1.5) ; makes angle brackets
672 (white-padding 0.1) ; should it be a property?
673 (lp (ly:stencil-aligned-to
674 (ly:stencil-aligned-to
675 (make-parenthesis-stencil y-extent
682 (interval-widen (ly:stencil-extent lp X) white-padding))
683 (rp (ly:stencil-aligned-to
684 (ly:stencil-aligned-to
685 (make-parenthesis-stencil y-extent
692 (interval-widen (ly:stencil-extent rp X) white-padding)))
693 (set! lp (ly:make-stencil (ly:stencil-expr lp)
695 (ly:stencil-extent lp Y)))
696 (set! rp (ly:make-stencil (ly:stencil-expr rp)
698 (ly:stencil-extent rp Y)))
699 (list (stencil-whiteout lp)
700 (stencil-whiteout rp))))
702 (define (parenthesize-elements grob . rest)
703 (let* ((refp (if (null? rest)
706 (elts (ly:grob-object grob 'elements))
707 (x-ext (ly:relative-group-extent elts refp X))
708 (stencils (ly:grob-property grob 'stencils))
711 (padding (ly:grob-property grob 'padding 0.1)))
714 (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
715 (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))))
718 (define-public (parentheses-item::print me)
719 (let* ((elts (ly:grob-object me 'elements))
720 (y-ref (ly:grob-common-refpoint-of-array me elts Y))
721 (x-ref (ly:grob-common-refpoint-of-array me elts X))
722 (stencil (parenthesize-elements me x-ref))
723 (elt-y-ext (ly:relative-group-extent elts y-ref Y))
724 (y-center (interval-center elt-y-ext)))
726 (ly:stencil-translate
729 (- (ly:grob-relative-coordinate me x-ref X))
730 (- y-center (ly:grob-relative-coordinate me y-ref Y))))))
734 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
737 (define-public (chain-grob-member-functions grob value . funcs)
740 (set! value (func grob value)))
746 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
749 (define-public (bend::print spanner)
751 (< (abs (- a b)) 0.01))
753 (let* ((delta-y (* 0.5 (ly:grob-property spanner 'delta-position)))
754 (left-span (ly:spanner-bound spanner LEFT))
755 (dots (if (and (grob::has-interface left-span 'note-head-interface)
756 (ly:grob? (ly:grob-object left-span 'dot)))
757 (ly:grob-object left-span 'dot) #f))
759 (right-span (ly:spanner-bound spanner RIGHT))
760 (thickness (* (ly:grob-property spanner 'thickness)
761 (ly:output-def-lookup (ly:grob-layout spanner)
763 (padding (ly:grob-property spanner 'padding 0.5))
764 (common (ly:grob-common-refpoint right-span
765 (ly:grob-common-refpoint spanner
768 (common-y (ly:grob-common-refpoint spanner left-span Y))
769 (minimum-length (ly:grob-property spanner 'minimum-length 0.5))
773 (interval-end (ly:grob-robust-relative-extent
778 (ly:grob-relative-coordinate dots common-y Y)
779 (ly:grob-relative-coordinate spanner common-y Y)))
781 (ly:grob-robust-relative-extent dots common X))
782 ;; TODO: use real infinity constant.
784 (right-x (max (- (interval-start
785 (ly:grob-robust-relative-extent right-span common X))
787 (+ left-x minimum-length)))
788 (self-x (ly:grob-relative-coordinate spanner common X))
789 (dx (- right-x left-x))
790 (exp (list 'path thickness
798 ,dx ,(* 0.66 delta-y)
803 (cons (- left-x self-x) (- right-x self-x))
804 (cons (min 0 delta-y)
808 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
811 (define-public (grace-spacing::calc-shortest-duration grob)
812 (let* ((cols (ly:grob-object grob 'columns))
815 (ly:moment-sub (ly:grob-property
816 (ly:grob-array-ref cols (1+ idx)) 'when)
818 (ly:grob-array-ref cols idx) 'when))))
820 (moment-min (lambda (x y)
823 (if (ly:moment<? x y)
829 (fold moment-min #f (map get-difference
830 (iota (1- (ly:grob-array-length cols)))))))
833 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
836 (define-public (fingering::calc-text grob)
837 (let* ((event (event-cause grob))
838 (digit (ly:event-property event 'digit)))
841 (ly:input-message (ly:event-property event 'origin)
842 "Warning: Fingering notation for finger number ~a"
845 (number->string digit 10)))
847 (define-public (string-number::calc-text grob)
848 (let ((digit (ly:event-property (event-cause grob) 'string-number)))
850 (number->string digit 10)))
852 (define-public (stroke-finger::calc-text grob)
853 (let* ((digit (ly:event-property (event-cause grob) 'digit))
854 (text (ly:event-property (event-cause grob) 'text)))
858 (vector-ref (ly:grob-property grob 'digit-names)
859 (1- (max (min 5 digit) 1))))))
862 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
865 (define-public (hairpin::calc-grow-direction grob)
866 (if (eq? (ly:event-property (event-cause grob) 'class) 'decrescendo-event)
870 (define-public (dynamic-text-spanner::before-line-breaking grob)
871 "Monitor left bound of @code{DynamicTextSpanner} for absolute dynamics.
872 If found, ensure @code{DynamicText} does not collide with spanner text by
873 changing @code{'attach-dir} and @code{'padding}. Reads the
874 @code{'right-padding} property of @code{DynamicText} to fine tune space
875 between the two text elements."
876 (let ((left-bound (ly:spanner-bound grob LEFT)))
877 (if (grob::has-interface left-bound 'dynamic-text-interface)
878 (let* ((details (ly:grob-property grob 'bound-details))
879 (left-details (ly:assoc-get 'left details))
880 (my-padding (ly:assoc-get 'padding left-details))
881 (script-padding (ly:grob-property left-bound 'right-padding 0)))
883 (and (number? my-padding)
884 (ly:grob-set-nested-property! grob
885 '(bound-details left attach-dir)
887 (ly:grob-set-nested-property! grob
888 '(bound-details left padding)
889 (+ my-padding script-padding)))))))
892 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
895 (define-public (lyric-text::print grob)
896 "Allow interpretation of tildes as lyric tieing marks."
898 (let ((text (ly:grob-property grob 'text)))
900 (grob-interpret-markup grob (if (string? text)
901 (make-tied-lyric-markup text)
904 (define-public ((grob::calc-property-by-copy prop) grob)
905 (ly:event-property (event-cause grob) prop))
908 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
911 (define-public (fret-board::calc-stencil grob)
912 (grob-interpret-markup
914 (make-fret-diagram-verbose-markup
915 (ly:grob-property grob 'dot-placement-list))))
918 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
921 (define-public (script-interface::calc-x-offset grob)
922 (ly:grob-property grob 'positioning-done)
923 (let* ((shift (ly:grob-property grob 'toward-stem-shift 0.0))
925 (ly:self-alignment-interface::centered-on-x-parent grob))
926 (note-head-grob (ly:grob-parent grob X))
927 (stem-grob (ly:grob-object note-head-grob 'stem)))
929 (+ note-head-location
930 ;; If the property 'toward-stem-shift is defined and the script
931 ;; has the same direction as the stem, move the script accordingly.
932 ;; Since scripts can also be over skips, we need to check whether
933 ;; the grob has a stem at all.
934 (if (ly:grob? stem-grob)
935 (let ((dir1 (ly:grob-property grob 'direction))
936 (dir2 (ly:grob-property stem-grob 'direction)))
937 (if (equal? dir1 dir2)
938 (let* ((common-refp (ly:grob-common-refpoint grob stem-grob X))
940 (ly:grob-relative-coordinate stem-grob common-refp X)))
941 (* shift (- stem-location note-head-location)))
946 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
949 (define-public (system-start-text::print grob)
950 (let* ((left-bound (ly:spanner-bound grob LEFT))
951 (left-mom (ly:grob-property left-bound 'when))
952 (name (if (moment<=? left-mom ZERO-MOMENT)
953 (ly:grob-property grob 'long-text)
954 (ly:grob-property grob 'text))))
956 (if (and (markup? name)
957 (!= (ly:item-break-dir left-bound) CENTER))
959 (grob-interpret-markup grob name)
960 (ly:grob-suicide! grob))))
962 (define-public (system-start-text::calc-x-offset grob)
963 (let* ((left-bound (ly:spanner-bound grob LEFT))
964 (left-mom (ly:grob-property left-bound 'when))
965 (layout (ly:grob-layout grob))
966 (indent (ly:output-def-lookup layout
967 (if (moment<=? left-mom ZERO-MOMENT)
971 (system (ly:grob-system grob))
972 (my-extent (ly:grob-extent grob system X))
973 (elements (ly:grob-object system 'elements))
974 (common (ly:grob-common-refpoint-of-array system elements X))
975 (total-ext empty-interval)
976 (align-x (ly:grob-property grob 'self-alignment-X 0))
977 (padding (min 0 (- (interval-length my-extent) indent)))
978 (right-padding (- padding
979 (/ (* padding (1+ align-x)) 2))))
981 ;; compensate for the variation in delimiter extents by
982 ;; calculating an X-offset correction based on united extents
983 ;; of all delimiters in this system
984 (let unite-delims ((l (ly:grob-array-length elements)))
986 (let ((elt (ly:grob-array-ref elements (1- l))))
988 (if (grob::has-interface elt 'system-start-delimiter-interface)
989 (let ((dims (ly:grob-extent elt common X)))
990 (if (interval-sane? dims)
991 (set! total-ext (interval-union total-ext dims)))))
992 (unite-delims (1- l)))))
995 (ly:side-position-interface::x-aligned-side grob)
997 (- (interval-length total-ext)))))
999 (define-public (system-start-text::calc-y-offset grob)
1001 (define (live-elements-list me)
1002 (let ((elements (ly:grob-object me 'elements)))
1004 (filter! grob::is-live?
1005 (ly:grob-array->list elements))))
1007 (let* ((left-bound (ly:spanner-bound grob LEFT))
1008 (live-elts (live-elements-list grob))
1009 (system (ly:grob-system grob))
1010 (extent empty-interval))
1012 (if (and (pair? live-elts)
1013 (interval-sane? (ly:grob-extent grob system Y)))
1014 (let get-extent ((lst live-elts))
1016 (let ((axis-group (car lst)))
1018 (if (and (ly:spanner? axis-group)
1019 (equal? (ly:spanner-bound axis-group LEFT)
1021 (set! extent (add-point extent
1022 (ly:grob-relative-coordinate
1023 axis-group system Y))))
1024 (get-extent (cdr lst)))))
1025 ;; no live axis group(s) for this instrument name -> remove from system
1026 (ly:grob-suicide! grob))
1029 (ly:self-alignment-interface::y-aligned-on-self grob)
1030 (interval-center extent))))
1033 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1036 (define-public (ambitus::print grob)
1037 (let ((heads (ly:grob-object grob 'note-heads)))
1039 (if (and (ly:grob-array? heads)
1040 (= (ly:grob-array-length heads) 2))
1041 (let* ((common (ly:grob-common-refpoint-of-array grob heads Y))
1042 (head-down (ly:grob-array-ref heads 0))
1043 (head-up (ly:grob-array-ref heads 1))
1044 (gap (ly:grob-property grob 'gap 0.35))
1045 (point-min (+ (interval-end (ly:grob-extent head-down common Y))
1047 (point-max (- (interval-start (ly:grob-extent head-up common Y))
1050 (if (< point-min point-max)
1051 (let* ((layout (ly:grob-layout grob))
1052 (line-thick (ly:output-def-lookup layout 'line-thickness))
1053 (blot (ly:output-def-lookup layout 'blot-diameter))
1054 (grob-thick (ly:grob-property grob 'thickness 2))
1055 (width (* line-thick grob-thick))
1056 (x-ext (symmetric-interval (/ width 2)))
1057 (y-ext (cons point-min point-max))
1058 (line (ly:round-filled-box x-ext y-ext blot))
1059 (y-coord (ly:grob-relative-coordinate grob common Y)))
1061 (ly:stencil-translate-axis line (- y-coord) Y))
1064 (ly:grob-suicide! grob)
1067 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1068 ;; laissez-vibrer tie
1070 ;; needed so we can make laissez-vibrer a pure print
1072 (define-public (laissez-vibrer::print grob)
1073 (ly:tie::print grob))