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 (stem-stub::do-calculations grob)
136 (and (ly:grob-property (ly:grob-parent grob X) 'cross-staff)
137 (not (ly:grob-property (ly:grob-parent grob X) 'transparent))))
139 (define-public (stem-stub::pure-height grob beg end)
140 (if (stem-stub::do-calculations grob)
144 (define-public (stem-stub::width grob)
145 (if (stem-stub::do-calculations grob)
146 (grob::x-parent-width grob)
149 (define-public (stem-stub::extra-spacing-height grob)
150 (if (stem-stub::do-calculations grob)
151 (let* ((dad (ly:grob-parent grob X))
152 (refp (ly:grob-common-refpoint grob dad Y))
153 (stem_ph (ly:grob-pure-height dad refp 0 1000000))
154 (my_ph (ly:grob-pure-height grob refp 0 1000000))
155 ;; only account for distance if stem is on different staff than stub
156 (dist (if (grob::has-interface refp 'hara-kiri-group-spanner-interface)
158 (- (car my_ph) (car stem_ph)))))
159 (if (interval-empty? (interval-intersection stem_ph my_ph)) #f (coord-translate stem_ph dist)))
162 (define-public (note-head::calc-duration-log grob)
165 (ly:event-property (event-cause grob) 'duration))))
167 (define-public (dots::calc-dot-count grob)
168 (ly:duration-dot-count
169 (ly:event-property (event-cause grob) 'duration)))
171 (define-public (dots::calc-staff-position grob)
172 (let* ((head (ly:grob-parent grob Y))
173 (log (ly:grob-property head 'duration-log)))
176 ((or (not (grob::has-interface head 'rest-interface))
177 (not (integer? log))) 0)
185 ;; Kept separate from note-head::calc-glyph-name to allow use by
186 ;; markup commands \note and \note-by-number
187 (define-public (select-head-glyph style log)
188 "Select a note head glyph string based on note head style @var{style}
189 and duration-log @var{log}."
191 ;; "default" style is directly handled in note-head.cc as a
192 ;; special case (HW says, mainly for performance reasons).
193 ;; Therefore, style "default" does not appear in this case
195 ((xcircle) "2xcircle")
196 ((harmonic) "0harmonic")
197 ((harmonic-black) "2harmonic")
198 ((harmonic-mixed) (if (<= log 1) "0harmonic"
201 ;; Oops, I actually would not call this "baroque", but, for
202 ;; backwards compatibility to 1.4, this is supposed to take
203 ;; brevis, longa and maxima from the neo-mensural font and all
204 ;; other note heads from the default font. -- jr
206 (string-append (number->string log) "neomensural")
207 (number->string log)))
209 ;; Like default, but brevis is drawn with double vertical lines
211 (string-append (number->string log) "double")
212 (number->string log)))
214 (string-append (number->string log) (symbol->string style)))
217 (string-append (number->string log) "mensural")
218 (string-append (number->string log) (symbol->string style))))
221 (string-append (number->string log) "blackmensural")
222 (string-append (number->string log) (symbol->string style))))
225 (string-append (number->string log) "semimensural")
226 (string-append (number->string log) "petrucci")))
228 (string-append (number->string log) (symbol->string style)))
230 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
231 (symbol->string style)
232 (string-append (number->string (max 0 log))
233 (symbol->string style))))))
235 (define-public (note-head::calc-glyph-name grob)
236 (let ((style (ly:grob-property grob 'style))
237 (log (min 2 (ly:grob-property grob 'duration-log))))
239 (select-head-glyph style log)))
241 (define-public (note-head::brew-ez-stencil grob)
242 (let* ((log (ly:grob-property grob 'duration-log))
243 (pitch (ly:event-property (event-cause grob) 'pitch))
244 (pitch-index (ly:pitch-notename pitch))
245 (note-names (ly:grob-property grob 'note-names))
246 (pitch-string (if (and (vector? note-names)
247 (> (vector-length note-names) pitch-index))
248 (vector-ref note-names pitch-index)
251 (+ (modulo (+ pitch-index 2) 7)
252 (char->integer #\A))))))
253 (staff-space (ly:staff-symbol-staff-space grob))
254 (line-thickness (ly:staff-symbol-line-thickness grob))
255 (stem (ly:grob-object grob 'stem))
256 (stem-thickness (* (if (ly:grob? stem)
257 (ly:grob-property stem 'thickness)
260 (radius (/ (+ staff-space line-thickness) 2))
261 (letter (markup #:center-align #:vcenter pitch-string))
262 (filled-circle (markup #:draw-circle radius 0 #t)))
264 (ly:stencil-translate-axis
265 (grob-interpret-markup
270 (make-with-color-markup white letter))
274 (make-with-color-markup white (make-draw-circle-markup
275 (- radius stem-thickness) 0 #t)))
279 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
282 (define-public (make-rhythmic-location bar-num num den)
284 bar-num (ly:make-moment num den)))
286 (define-public (rhythmic-location? a)
289 (ly:moment? (cdr a))))
291 (define-public (make-graceless-rhythmic-location loc)
292 (make-rhythmic-location
294 (ly:moment-main-numerator (rhythmic-location-measure-position loc))
295 (ly:moment-main-denominator (rhythmic-location-measure-position loc))))
297 (define-public rhythmic-location-measure-position cdr)
298 (define-public rhythmic-location-bar-number car)
300 (define-public (rhythmic-location<? a b)
302 ((< (car a) (car b)) #t)
303 ((> (car a) (car b)) #f)
305 (ly:moment<? (cdr a) (cdr b)))))
307 (define-public (rhythmic-location<=? a b)
308 (not (rhythmic-location<? b a)))
309 (define-public (rhythmic-location>=? a b)
310 (rhythmic-location<? a b))
311 (define-public (rhythmic-location>? a b)
312 (rhythmic-location<? b a))
314 (define-public (rhythmic-location=? a b)
315 (and (rhythmic-location<=? a b)
316 (rhythmic-location<=? b a)))
318 (define-public (rhythmic-location->file-string a)
319 (ly:format "~a.~a.~a"
321 (ly:moment-main-numerator (cdr a))
322 (ly:moment-main-denominator (cdr a))))
324 (define-public (rhythmic-location->string a)
325 (ly:format "bar ~a ~a"
327 (ly:moment->string (cdr a))))
329 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
332 (define-public all-visible #(#t #t #t))
333 (define-public begin-of-line-invisible #(#t #t #f))
334 (define-public center-invisible #(#t #f #t))
335 (define-public end-of-line-invisible #(#f #t #t))
336 (define-public begin-of-line-visible #(#f #f #t))
337 (define-public center-visible #(#f #t #f))
338 (define-public end-of-line-visible #(#t #f #f))
339 (define-public all-invisible #(#f #f #f))
340 (define-public (inherit-x-parent-visibility grob)
341 (let ((parent (ly:grob-parent grob X)))
342 (ly:grob-property parent 'break-visibility all-invisible)))
343 (define-public (inherit-y-parent-visibility grob)
344 (let ((parent (ly:grob-parent grob X)))
345 (ly:grob-property parent 'break-visibility)))
348 (define-public spanbar-begin-of-line-invisible #(#t #f #f))
351 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
355 ;; How should a bar line behave at a break?
356 (define bar-glyph-alist
357 '((":|:" . (":|" . "|:"))
358 (":|.|:" . (":|" . "|:"))
359 (":|.:" . (":|" . "|:"))
360 ("||:" . ("||" . "|:"))
361 ("dashed" . ("dashed" . '()))
363 ("||:" . ("||" . "|:"))
365 ("|:" . ("|" . "|:"))
368 ;; hmm... should we end with a bar line here?
369 (".|" . ("|" . ".|"))
372 (".|." . (".|." . ()))
373 ("|.|" . ("|.|" . ()))
378 ("empty" . (() . ()))
379 ("brace" . (() . "brace"))
380 ("bracket" . (() . "bracket"))
386 (":|S" . (":|" . "S"))
387 (":|S." . (":|S" . ()))
388 ("S|:" . ("S" . "|:"))
389 (".S|:" . ("|" . "S|:"))
390 (":|S|:" . (":|" . "S|:"))
391 (":|S.|:" . (":|S" . "|:"))))
393 (define-public (bar-line::calc-glyph-name grob)
394 (let* ((glyph (ly:grob-property grob 'glyph))
395 (dir (ly:item-break-dir grob))
396 (result (assoc-get glyph bar-glyph-alist))
397 (glyph-name (if (= dir CENTER)
400 (string? (index-cell result dir)))
401 (index-cell result dir)
405 (define-public (bar-line::calc-break-visibility grob)
406 (let* ((glyph (ly:grob-property grob 'glyph))
407 (result (assoc-get glyph bar-glyph-alist)))
410 (vector (string? (car result)) #t (string? (cdr result)))
413 (define-public (shift-right-at-line-begin g)
414 "Shift an item to the right, but only at the start of the line."
415 (if (and (ly:item? g)
416 (equal? (ly:item-break-dir g) RIGHT))
417 (ly:grob-translate-axis! g 3.5 X)))
419 (define-public (pure-from-neighbor-interface::extra-spacing-height-at-beginning-of-line grob)
420 (if (= 1 (ly:item-break-dir grob))
421 (pure-from-neighbor-interface::extra-spacing-height grob)
424 (define-public (pure-from-neighbor-interface::extra-spacing-height grob)
425 (let* ((height (ly:grob::stencil-height grob))
426 (from-neighbors (interval-union
428 (ly:axis-group-interface::pure-height
432 (coord-operation - from-neighbors height)))
434 (define-public (pure-from-neighbor-interface::account-for-span-bar grob)
435 (let* ((esh (pure-from-neighbor-interface::extra-spacing-height grob))
436 (hsb (ly:grob-property grob 'has-span-bar))
437 (ii (interval-intersection esh (cons -1.01 1.01))))
439 (cons (car (if (and (car hsb)
440 (ly:grob-property grob 'allow-span-bar))
442 (cdr (if (cdr hsb) esh ii)))
445 (define-public (pure-from-neighbor-interface::extra-spacing-height-including-staff grob)
446 (let ((esh (pure-from-neighbor-interface::extra-spacing-height grob))
447 (to-staff (coord-operation -
450 (ly:staff-symbol-staff-radius grob))
451 (ly:grob::stencil-height grob))))
452 (interval-union esh to-staff)))
455 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
458 (define-public (tuplet-number::calc-direction grob)
459 (ly:tuplet-bracket::calc-direction (ly:grob-object grob 'bracket)))
461 (define-public (tuplet-number::calc-denominator-text grob)
462 (number->string (ly:event-property (event-cause grob) 'denominator)))
464 (define-public (tuplet-number::calc-fraction-text grob)
465 (let ((ev (event-cause grob)))
468 (ly:event-property ev 'denominator)
469 (ly:event-property ev 'numerator))))
471 ;; a formatter function, which is simply a wrapper around an existing
472 ;; tuplet formatter function. It takes the value returned by the given
473 ;; function and appends a note of given length.
474 (define-public ((tuplet-number::append-note-wrapper function note) grob)
475 (let ((txt (if function (function grob) #f)))
478 (markup txt #:fontsize -5 #:note note UP)
479 (markup #:fontsize -5 #:note note UP))))
481 ;; Print a tuplet denominator with a different number than the one derived from
482 ;; the actual tuplet fraction
483 (define-public ((tuplet-number::non-default-tuplet-denominator-text denominator)
485 (number->string (if denominator
487 (ly:event-property (event-cause grob) 'denominator))))
489 ;; Print a tuplet fraction with different numbers than the ones derived from
490 ;; the actual tuplet fraction
491 (define-public ((tuplet-number::non-default-tuplet-fraction-text
492 denominator numerator) 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 (format #f "~a:~a" den num)))
499 ;; Print a tuplet fraction with note durations appended to the numerator and the
501 (define-public ((tuplet-number::fraction-with-notes
502 denominatornote numeratornote) grob)
503 (let* ((ev (event-cause grob))
504 (denominator (ly:event-property ev 'denominator))
505 (numerator (ly:event-property ev 'numerator)))
507 ((tuplet-number::non-default-fraction-with-notes
508 denominator denominatornote numerator numeratornote) grob)))
510 ;; Print a tuplet fraction with note durations appended to the numerator and the
512 (define-public ((tuplet-number::non-default-fraction-with-notes
513 denominator denominatornote numerator numeratornote) grob)
514 (let* ((ev (event-cause grob))
515 (den (if denominator denominator (ly:event-property ev 'denominator)))
516 (num (if numerator numerator (ly:event-property ev 'numerator))))
518 (make-concat-markup (list
519 (make-simple-markup (format #f "~a" den))
520 (markup #:fontsize -5 #:note denominatornote UP)
521 (make-simple-markup " : ")
522 (make-simple-markup (format #f "~a" num))
523 (markup #:fontsize -5 #:note numeratornote UP)))))
526 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
529 (define-public (color? x)
532 (apply eq? #t (map number? x))
533 (apply eq? #t (map (lambda (y) (<= 0 y 1)) x))))
535 (define-public (rgb-color r g b) (list r g b))
538 (define-public black '(0.0 0.0 0.0))
539 (define-public white '(1.0 1.0 1.0))
540 (define-public red '(1.0 0.0 0.0))
541 (define-public green '(0.0 1.0 0.0))
542 (define-public blue '(0.0 0.0 1.0))
543 (define-public cyan '(0.0 1.0 1.0))
544 (define-public magenta '(1.0 0.0 1.0))
545 (define-public yellow '(1.0 1.0 0.0))
547 (define-public grey '(0.5 0.5 0.5))
548 (define-public darkred '(0.5 0.0 0.0))
549 (define-public darkgreen '(0.0 0.5 0.0))
550 (define-public darkblue '(0.0 0.0 0.5))
551 (define-public darkcyan '(0.0 0.5 0.5))
552 (define-public darkmagenta '(0.5 0.0 0.5))
553 (define-public darkyellow '(0.5 0.5 0.0))
556 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
559 (define-public (key-signature-interface::alteration-position step alter
561 ;; TODO: memoize - this is mostly constant.
563 ;; fes, ges, as and bes typeset in lower octave
564 (define FLAT_TOP_PITCH 2)
566 ;; ais and bis typeset in lower octave
567 (define SHARP_TOP_PITCH 4)
570 (+ (cdr step) (* (car step) 7) c0-position)
571 (let* ((from-bottom-pos (modulo (+ 4 49 c0-position) 7))
573 (c0 (- from-bottom-pos 4)))
577 (or (> p FLAT_TOP_PITCH) (> (+ p c0) 4)) (> (+ p c0) 1))
579 (or (> p SHARP_TOP_PITCH) (> (+ p c0) 5)) (> (+ p c0) 2)))
581 ;; Typeset below c_position
584 ;; Provide for the four cases in which there's a glitch
585 ;; it's a hack, but probably not worth
586 ;; the effort of finding a nicer solution.
589 ((and (= c0 2) (= p 3) (> alter 0))
591 ((and (= c0 -3) (= p -1) (> alter 0))
593 ((and (= c0 -4) (= p -1) (< alter 0))
595 ((and (= c0 -2) (= p -3) (< alter 0))
601 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
604 (define-public (numbered-footnotes int)
605 (markup #:tiny (number->string (+ 1 int))))
607 (define-public (symbol-footnotes int)
608 (define (helper symbols out idx n)
612 (string-append out (list-ref symbols idx))
615 (markup #:tiny (helper '("*" "†" "‡" "§" "¶")
618 (+ 1 (quotient int 5)))))
620 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
623 (define-public (accidental-interface::calc-alteration grob)
624 (ly:pitch-alteration (ly:event-property (event-cause grob) 'pitch)))
626 (define-public cancellation-glyph-name-alist
627 '((0 . "accidentals.natural")))
629 (define-public standard-alteration-glyph-name-alist
631 ;; ordered for optimal performance.
632 (0 . "accidentals.natural")
633 (-1/2 . "accidentals.flat")
634 (1/2 . "accidentals.sharp")
636 (1 . "accidentals.doublesharp")
637 (-1 . "accidentals.flatflat")
639 (3/4 . "accidentals.sharp.slashslash.stemstemstem")
640 (1/4 . "accidentals.sharp.slashslash.stem")
641 (-1/4 . "accidentals.mirroredflat")
642 (-3/4 . "accidentals.mirroredflat.flat")))
644 ;; FIXME: standard vs default, alteration-FOO vs FOO-alteration
645 (define-public alteration-default-glyph-name-alist
646 standard-alteration-glyph-name-alist)
648 (define-public makam-alteration-glyph-name-alist
649 '((1 . "accidentals.doublesharp")
650 (8/9 . "accidentals.sharp.slashslashslash.stemstem")
651 (5/9 . "accidentals.sharp.slashslashslash.stem")
652 (4/9 . "accidentals.sharp")
653 (1/9 . "accidentals.sharp.slashslash.stem")
654 (0 . "accidentals.natural")
655 (-1/9 . "accidentals.mirroredflat")
656 (-4/9 . "accidentals.flat.slash")
657 (-5/9 . "accidentals.flat")
658 (-8/9 . "accidentals.flat.slashslash")
659 (-1 . "accidentals.flatflat")))
661 (define-public alteration-hufnagel-glyph-name-alist
662 '((-1/2 . "accidentals.hufnagelM1")
663 (0 . "accidentals.vaticana0")
664 (1/2 . "accidentals.mensural1")))
666 (define-public alteration-medicaea-glyph-name-alist
667 '((-1/2 . "accidentals.medicaeaM1")
668 (0 . "accidentals.vaticana0")
669 (1/2 . "accidentals.mensural1")))
671 (define-public alteration-vaticana-glyph-name-alist
672 '((-1/2 . "accidentals.vaticanaM1")
673 (0 . "accidentals.vaticana0")
674 (1/2 . "accidentals.mensural1")))
676 (define-public alteration-mensural-glyph-name-alist
677 '((-1/2 . "accidentals.mensuralM1")
678 (0 . "accidentals.vaticana0")
679 (1/2 . "accidentals.mensural1")))
682 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
683 ;; * Pitch Trill Heads
686 (define-public (parentheses-item::calc-parenthesis-stencils grob)
687 (let* ((font (ly:grob-default-font grob))
688 (lp (ly:font-get-glyph font "accidentals.leftparen"))
689 (rp (ly:font-get-glyph font "accidentals.rightparen")))
693 (define-public (parentheses-item::calc-angled-bracket-stencils grob)
694 (let* ((parent (ly:grob-parent grob Y))
695 (y-extent (ly:grob-extent parent parent Y))
696 (half-thickness 0.05) ; should it be a property?
697 (width 0.5) ; should it be a property?
698 (angularity 1.5) ; makes angle brackets
699 (white-padding 0.1) ; should it be a property?
700 (lp (ly:stencil-aligned-to
701 (ly:stencil-aligned-to
702 (make-parenthesis-stencil y-extent
709 (interval-widen (ly:stencil-extent lp X) white-padding))
710 (rp (ly:stencil-aligned-to
711 (ly:stencil-aligned-to
712 (make-parenthesis-stencil y-extent
719 (interval-widen (ly:stencil-extent rp X) white-padding)))
720 (set! lp (ly:make-stencil (ly:stencil-expr lp)
722 (ly:stencil-extent lp Y)))
723 (set! rp (ly:make-stencil (ly:stencil-expr rp)
725 (ly:stencil-extent rp Y)))
726 (list (stencil-whiteout lp)
727 (stencil-whiteout rp))))
729 (define (parenthesize-elements grob . rest)
730 (let* ((refp (if (null? rest)
733 (elts (ly:grob-object grob 'elements))
734 (x-ext (ly:relative-group-extent elts refp X))
735 (stencils (ly:grob-property grob 'stencils))
738 (padding (ly:grob-property grob 'padding 0.1)))
741 (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
742 (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))))
745 (define-public (parentheses-item::print me)
746 (let* ((elts (ly:grob-object me 'elements))
747 (y-ref (ly:grob-common-refpoint-of-array me elts Y))
748 (x-ref (ly:grob-common-refpoint-of-array me elts X))
749 (stencil (parenthesize-elements me x-ref))
750 (elt-y-ext (ly:relative-group-extent elts y-ref Y))
751 (y-center (interval-center elt-y-ext)))
753 (ly:stencil-translate
756 (- (ly:grob-relative-coordinate me x-ref X))
757 (- y-center (ly:grob-relative-coordinate me y-ref Y))))))
761 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
764 (define-public (chain-grob-member-functions grob value . funcs)
767 (set! value (func grob value)))
773 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
776 (define-public (bend::print spanner)
778 (< (abs (- a b)) 0.01))
780 (let* ((delta-y (* 0.5 (ly:grob-property spanner 'delta-position)))
781 (left-span (ly:spanner-bound spanner LEFT))
782 (dots (if (and (grob::has-interface left-span 'note-head-interface)
783 (ly:grob? (ly:grob-object left-span 'dot)))
784 (ly:grob-object left-span 'dot) #f))
786 (right-span (ly:spanner-bound spanner RIGHT))
787 (thickness (* (ly:grob-property spanner 'thickness)
788 (ly:output-def-lookup (ly:grob-layout spanner)
790 (padding (ly:grob-property spanner 'padding 0.5))
791 (common (ly:grob-common-refpoint right-span
792 (ly:grob-common-refpoint spanner
795 (common-y (ly:grob-common-refpoint spanner left-span Y))
796 (minimum-length (ly:grob-property spanner 'minimum-length 0.5))
800 (interval-end (ly:grob-robust-relative-extent
805 (ly:grob-relative-coordinate dots common-y Y)
806 (ly:grob-relative-coordinate spanner common-y Y)))
808 (ly:grob-robust-relative-extent dots common X))
809 ;; TODO: use real infinity constant.
811 (right-x (max (- (interval-start
812 (ly:grob-robust-relative-extent right-span common X))
814 (+ left-x minimum-length)))
815 (self-x (ly:grob-relative-coordinate spanner common X))
816 (dx (- right-x left-x))
817 (exp (list 'path thickness
825 ,dx ,(* 0.66 delta-y)
830 (cons (- left-x self-x) (- right-x self-x))
831 (cons (min 0 delta-y)
835 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
838 (define-public (grace-spacing::calc-shortest-duration grob)
839 (let* ((cols (ly:grob-object grob 'columns))
842 (ly:moment-sub (ly:grob-property
843 (ly:grob-array-ref cols (1+ idx)) 'when)
845 (ly:grob-array-ref cols idx) 'when))))
847 (moment-min (lambda (x y)
850 (if (ly:moment<? x y)
856 (fold moment-min #f (map get-difference
857 (iota (1- (ly:grob-array-length cols)))))))
860 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
863 (define-public (fingering::calc-text grob)
864 (let* ((event (event-cause grob))
865 (digit (ly:event-property event 'digit)))
868 (ly:input-message (ly:event-property event 'origin)
869 "Warning: Fingering notation for finger number ~a"
872 (number->string digit 10)))
874 (define-public (string-number::calc-text grob)
875 (let ((digit (ly:event-property (event-cause grob) 'string-number)))
877 (number->string digit 10)))
879 (define-public (stroke-finger::calc-text grob)
880 (let* ((digit (ly:event-property (event-cause grob) 'digit))
881 (text (ly:event-property (event-cause grob) 'text)))
885 (vector-ref (ly:grob-property grob 'digit-names)
886 (1- (max (min 5 digit) 1))))))
889 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
892 (define-public (hairpin::calc-grow-direction grob)
893 (if (eq? (ly:event-property (event-cause grob) 'class) 'decrescendo-event)
897 (define-public (dynamic-text-spanner::before-line-breaking grob)
898 "Monitor left bound of @code{DynamicTextSpanner} for absolute dynamics.
899 If found, ensure @code{DynamicText} does not collide with spanner text by
900 changing @code{'attach-dir} and @code{'padding}. Reads the
901 @code{'right-padding} property of @code{DynamicText} to fine tune space
902 between the two text elements."
903 (let ((left-bound (ly:spanner-bound grob LEFT)))
904 (if (grob::has-interface left-bound 'dynamic-text-interface)
905 (let* ((details (ly:grob-property grob 'bound-details))
906 (left-details (ly:assoc-get 'left details))
907 (my-padding (ly:assoc-get 'padding left-details))
908 (script-padding (ly:grob-property left-bound 'right-padding 0)))
910 (and (number? my-padding)
911 (ly:grob-set-nested-property! grob
912 '(bound-details left attach-dir)
914 (ly:grob-set-nested-property! grob
915 '(bound-details left padding)
916 (+ my-padding script-padding)))))))
919 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
922 (define-public (lyric-text::print grob)
923 "Allow interpretation of tildes as lyric tieing marks."
925 (let ((text (ly:grob-property grob 'text)))
927 (grob-interpret-markup grob (if (string? text)
928 (make-tied-lyric-markup text)
931 (define-public ((grob::calc-property-by-copy prop) grob)
932 (ly:event-property (event-cause grob) prop))
935 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
938 (define-public (fret-board::calc-stencil grob)
939 (grob-interpret-markup
941 (make-fret-diagram-verbose-markup
942 (ly:grob-property grob 'dot-placement-list))))
945 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
948 (define-public (script-interface::calc-x-offset grob)
949 (ly:grob-property grob 'positioning-done)
950 (let* ((shift (ly:grob-property grob 'toward-stem-shift 0.0))
952 (ly:self-alignment-interface::centered-on-x-parent grob))
953 (note-head-grob (ly:grob-parent grob X))
954 (stem-grob (ly:grob-object note-head-grob 'stem)))
956 (+ note-head-location
957 ;; If the property 'toward-stem-shift is defined and the script
958 ;; has the same direction as the stem, move the script accordingly.
959 ;; Since scripts can also be over skips, we need to check whether
960 ;; the grob has a stem at all.
961 (if (ly:grob? stem-grob)
962 (let ((dir1 (ly:grob-property grob 'direction))
963 (dir2 (ly:grob-property stem-grob 'direction)))
964 (if (equal? dir1 dir2)
965 (let* ((common-refp (ly:grob-common-refpoint grob stem-grob X))
967 (ly:grob-relative-coordinate stem-grob common-refp X)))
968 (* shift (- stem-location note-head-location)))
973 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
976 (define-public (system-start-text::print grob)
977 (let* ((left-bound (ly:spanner-bound grob LEFT))
978 (left-mom (ly:grob-property left-bound 'when))
979 (name (if (moment<=? left-mom ZERO-MOMENT)
980 (ly:grob-property grob 'long-text)
981 (ly:grob-property grob 'text))))
983 (if (and (markup? name)
984 (!= (ly:item-break-dir left-bound) CENTER))
986 (grob-interpret-markup grob name)
987 (ly:grob-suicide! grob))))
989 (define-public (system-start-text::calc-x-offset grob)
990 (let* ((left-bound (ly:spanner-bound grob LEFT))
991 (left-mom (ly:grob-property left-bound 'when))
992 (layout (ly:grob-layout grob))
993 (indent (ly:output-def-lookup layout
994 (if (moment<=? left-mom ZERO-MOMENT)
998 (system (ly:grob-system grob))
999 (my-extent (ly:grob-extent grob system X))
1000 (elements (ly:grob-object system 'elements))
1001 (common (ly:grob-common-refpoint-of-array system elements X))
1002 (total-ext empty-interval)
1003 (align-x (ly:grob-property grob 'self-alignment-X 0))
1004 (padding (min 0 (- (interval-length my-extent) indent)))
1005 (right-padding (- padding
1006 (/ (* padding (1+ align-x)) 2))))
1008 ;; compensate for the variation in delimiter extents by
1009 ;; calculating an X-offset correction based on united extents
1010 ;; of all delimiters in this system
1011 (let unite-delims ((l (ly:grob-array-length elements)))
1013 (let ((elt (ly:grob-array-ref elements (1- l))))
1015 (if (grob::has-interface elt 'system-start-delimiter-interface)
1016 (let ((dims (ly:grob-extent elt common X)))
1017 (if (interval-sane? dims)
1018 (set! total-ext (interval-union total-ext dims)))))
1019 (unite-delims (1- l)))))
1022 (ly:side-position-interface::x-aligned-side grob)
1024 (- (interval-length total-ext)))))
1026 (define-public (system-start-text::calc-y-offset grob)
1028 (define (live-elements-list me)
1029 (let ((elements (ly:grob-object me 'elements)))
1031 (filter! grob::is-live?
1032 (ly:grob-array->list elements))))
1034 (let* ((left-bound (ly:spanner-bound grob LEFT))
1035 (live-elts (live-elements-list grob))
1036 (system (ly:grob-system grob))
1037 (extent empty-interval))
1039 (if (and (pair? live-elts)
1040 (interval-sane? (ly:grob-extent grob system Y)))
1041 (let get-extent ((lst live-elts))
1043 (let ((axis-group (car lst)))
1045 (if (and (ly:spanner? axis-group)
1046 (equal? (ly:spanner-bound axis-group LEFT)
1048 (set! extent (add-point extent
1049 (ly:grob-relative-coordinate
1050 axis-group system Y))))
1051 (get-extent (cdr lst)))))
1052 ;; no live axis group(s) for this instrument name -> remove from system
1053 (ly:grob-suicide! grob))
1056 (ly:self-alignment-interface::y-aligned-on-self grob)
1057 (interval-center extent))))
1060 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1063 (define-public (ambitus::print grob)
1064 (let ((heads (ly:grob-object grob 'note-heads)))
1066 (if (and (ly:grob-array? heads)
1067 (= (ly:grob-array-length heads) 2))
1068 (let* ((common (ly:grob-common-refpoint-of-array grob heads Y))
1069 (head-down (ly:grob-array-ref heads 0))
1070 (head-up (ly:grob-array-ref heads 1))
1071 (gap (ly:grob-property grob 'gap 0.35))
1072 (point-min (+ (interval-end (ly:grob-extent head-down common Y))
1074 (point-max (- (interval-start (ly:grob-extent head-up common Y))
1077 (if (< point-min point-max)
1078 (let* ((layout (ly:grob-layout grob))
1079 (line-thick (ly:output-def-lookup layout 'line-thickness))
1080 (blot (ly:output-def-lookup layout 'blot-diameter))
1081 (grob-thick (ly:grob-property grob 'thickness 2))
1082 (width (* line-thick grob-thick))
1083 (x-ext (symmetric-interval (/ width 2)))
1084 (y-ext (cons point-min point-max))
1085 (line (ly:round-filled-box x-ext y-ext blot))
1086 (y-coord (ly:grob-relative-coordinate grob common Y)))
1088 (ly:stencil-translate-axis line (- y-coord) Y))
1091 (ly:grob-suicide! grob)
1094 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1095 ;; laissez-vibrer tie
1097 ;; needed so we can make laissez-vibrer a pure print
1099 (define-public (laissez-vibrer::print grob)
1100 (ly:tie::print grob))