1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 1998--2012 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 ;; FIXME: NEED TO FIND A BETTER WAY TO HANDLE KIEVAN NOTATION
163 (define-public (note-head::calc-duration-log grob)
164 (let ((style (ly:grob-property grob 'style)))
165 (if (and (symbol? style) (string-match "kievan*" (symbol->string style)))
168 (ly:event-property (event-cause grob) 'duration)))
171 (ly:event-property (event-cause grob) 'duration))))))
173 (define-public (dots::calc-dot-count grob)
174 (ly:duration-dot-count
175 (ly:event-property (event-cause grob) 'duration)))
177 (define-public (dots::calc-staff-position grob)
178 (let* ((head (ly:grob-parent grob Y))
179 (log (ly:grob-property head 'duration-log)))
182 ((or (not (grob::has-interface head 'rest-interface))
183 (not (integer? log))) 0)
191 ;; Kept separate from note-head::calc-glyph-name to allow use by
192 ;; markup commands \note and \note-by-number
193 (define-public (select-head-glyph style log)
194 "Select a note head glyph string based on note head style @var{style}
195 and duration-log @var{log}."
197 ;; "default" style is directly handled in note-head.cc as a
198 ;; special case (HW says, mainly for performance reasons).
199 ;; Therefore, style "default" does not appear in this case
201 ((xcircle) "2xcircle")
202 ((harmonic) "0harmonic")
203 ((harmonic-black) "2harmonic")
204 ((harmonic-mixed) (if (<= log 1) "0harmonic"
207 ;; Oops, I actually would not call this "baroque", but, for
208 ;; backwards compatibility to 1.4, this is supposed to take
209 ;; brevis, longa and maxima from the neo-mensural font and all
210 ;; other note heads from the default font. -- jr
212 (string-append (number->string log) "neomensural")
213 (number->string log)))
215 ;; Like default, but brevis is drawn with double vertical lines
217 (string-append (number->string log) "double")
218 (number->string log)))
220 (string-append (number->string log) (symbol->string style)))
223 (string-append (number->string log) "mensural")
224 (string-append (number->string log) (symbol->string style))))
227 (string-append (number->string log) "blackmensural")
228 (string-append (number->string log) (symbol->string style))))
231 (string-append (number->string log) "semimensural")
232 (string-append (number->string log) "petrucci")))
234 (string-append (number->string log) (symbol->string style)))
236 (string-append (number->string log) "kievan"))
238 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
239 (symbol->string style)
240 (string-append (number->string (max 0 log))
241 (symbol->string style))))))
243 (define-public (note-head::calc-glyph-name grob)
244 (let* ((style (ly:grob-property grob 'style))
245 (log (if (string-match "kievan*" (symbol->string style))
246 (min 3 (ly:grob-property grob 'duration-log))
247 (min 2 (ly:grob-property grob 'duration-log)))))
248 (select-head-glyph style log)))
250 (define-public (note-head::brew-ez-stencil grob)
251 (let* ((log (ly:grob-property grob 'duration-log))
252 (pitch (ly:event-property (event-cause grob) 'pitch))
253 (pitch-index (ly:pitch-notename pitch))
254 (note-names (ly:grob-property grob 'note-names))
255 (pitch-string (if (and (vector? note-names)
256 (> (vector-length note-names) pitch-index))
257 (vector-ref note-names pitch-index)
260 (+ (modulo (+ pitch-index 2) 7)
261 (char->integer #\A))))))
262 (staff-space (ly:staff-symbol-staff-space grob))
263 (line-thickness (ly:staff-symbol-line-thickness grob))
264 (stem (ly:grob-object grob 'stem))
265 (stem-thickness (* (if (ly:grob? stem)
266 (ly:grob-property stem 'thickness)
269 (radius (/ (+ staff-space line-thickness) 2))
270 (letter (markup #:center-align #:vcenter pitch-string))
271 (filled-circle (markup #:draw-circle radius 0 #t)))
273 (ly:stencil-translate-axis
274 (grob-interpret-markup
279 (make-with-color-markup white letter))
283 (make-with-color-markup white (make-draw-circle-markup
284 (- radius stem-thickness) 0 #t)))
288 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
291 (define-public (make-rhythmic-location bar-num num den)
293 bar-num (ly:make-moment num den)))
295 (define-public (rhythmic-location? a)
298 (ly:moment? (cdr a))))
300 (define-public (make-graceless-rhythmic-location loc)
301 (make-rhythmic-location
303 (ly:moment-main-numerator (rhythmic-location-measure-position loc))
304 (ly:moment-main-denominator (rhythmic-location-measure-position loc))))
306 (define-public rhythmic-location-measure-position cdr)
307 (define-public rhythmic-location-bar-number car)
309 (define-public (rhythmic-location<? a b)
311 ((< (car a) (car b)) #t)
312 ((> (car a) (car b)) #f)
314 (ly:moment<? (cdr a) (cdr b)))))
316 (define-public (rhythmic-location<=? a b)
317 (not (rhythmic-location<? b a)))
318 (define-public (rhythmic-location>=? a b)
319 (rhythmic-location<? a b))
320 (define-public (rhythmic-location>? a b)
321 (rhythmic-location<? b a))
323 (define-public (rhythmic-location=? a b)
324 (and (rhythmic-location<=? a b)
325 (rhythmic-location<=? b a)))
327 (define-public (rhythmic-location->file-string a)
328 (ly:format "~a.~a.~a"
330 (ly:moment-main-numerator (cdr a))
331 (ly:moment-main-denominator (cdr a))))
333 (define-public (rhythmic-location->string a)
334 (ly:format "bar ~a ~a"
336 (ly:moment->string (cdr a))))
338 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
341 (define-public all-visible #(#t #t #t))
342 (define-public begin-of-line-invisible #(#t #t #f))
343 (define-public center-invisible #(#t #f #t))
344 (define-public end-of-line-invisible #(#f #t #t))
345 (define-public begin-of-line-visible #(#f #f #t))
346 (define-public center-visible #(#f #t #f))
347 (define-public end-of-line-visible #(#t #f #f))
348 (define-public all-invisible #(#f #f #f))
349 (define-public (inherit-x-parent-visibility grob)
350 (let ((parent (ly:grob-parent grob X)))
351 (ly:grob-property parent 'break-visibility all-invisible)))
352 (define-public (inherit-y-parent-visibility grob)
353 (let ((parent (ly:grob-parent grob X)))
354 (ly:grob-property parent 'break-visibility)))
357 (define-public spanbar-begin-of-line-invisible #(#t #f #f))
360 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
364 ;; How should a bar line behave at a break?
365 (define bar-glyph-alist
366 '((":|:" . (":|" . "|:"))
367 (":|.|:" . (":|" . "|:"))
368 (":|.:" . (":|" . "|:"))
369 ("||:" . ("||" . "|:"))
370 ("dashed" . ("dashed" . '()))
372 ("||:" . ("||" . "|:"))
374 ("|:" . ("|" . "|:"))
377 ;; hmm... should we end with a bar line here?
378 (".|" . ("|" . ".|"))
381 (".|." . (".|." . ()))
382 ("|.|" . ("|.|" . ()))
387 ("empty" . (() . ()))
388 ("brace" . (() . "brace"))
389 ("bracket" . (() . "bracket"))
395 (":|S" . (":|" . "S"))
396 (":|S." . (":|S" . ()))
397 ("S|:" . ("S" . "|:"))
398 (".S|:" . ("|" . "S|:"))
399 (":|S|:" . (":|" . "S|:"))
400 (":|S.|:" . (":|S" . "|:"))
403 ("kievan" . ("kievan" . ""))))
405 (define-public (bar-line::calc-glyph-name grob)
406 (let* ((glyph (ly:grob-property grob 'glyph))
407 (dir (ly:item-break-dir grob))
408 (result (assoc-get glyph bar-glyph-alist))
409 (glyph-name (if (= dir CENTER)
412 (string? (index-cell result dir)))
413 (index-cell result dir)
417 (define-public (bar-line::calc-break-visibility grob)
418 (let* ((glyph (ly:grob-property grob 'glyph))
419 (result (assoc-get glyph bar-glyph-alist)))
422 (vector (string? (car result)) #t (string? (cdr result)))
425 (define-public (shift-right-at-line-begin g)
426 "Shift an item to the right, but only at the start of the line."
427 (if (and (ly:item? g)
428 (equal? (ly:item-break-dir g) RIGHT))
429 (ly:grob-translate-axis! g 3.5 X)))
431 (define-public (pure-from-neighbor-interface::extra-spacing-height-at-beginning-of-line grob)
432 (if (= 1 (ly:item-break-dir grob))
433 (pure-from-neighbor-interface::extra-spacing-height grob)
436 (define-public (pure-from-neighbor-interface::extra-spacing-height grob)
437 (let* ((height (ly:grob-pure-height grob grob 0 10000000))
438 (from-neighbors (interval-union
440 (ly:axis-group-interface::pure-height
444 (coord-operation - from-neighbors height)))
446 (define-public (pure-from-neighbor-interface::account-for-span-bar grob)
447 (let* ((esh (pure-from-neighbor-interface::extra-spacing-height grob))
448 (hsb (ly:grob-property grob 'has-span-bar))
449 (ii (interval-intersection esh (cons -1.01 1.01))))
451 (cons (car (if (and (car hsb)
452 (ly:grob-property grob 'allow-span-bar))
454 (cdr (if (cdr hsb) esh ii)))
457 (define-public (pure-from-neighbor-interface::extra-spacing-height-including-staff grob)
458 (let ((esh (pure-from-neighbor-interface::extra-spacing-height grob))
459 (to-staff (coord-operation -
462 (ly:staff-symbol-staff-radius grob))
463 (ly:grob::stencil-height grob))))
464 (interval-union esh to-staff)))
467 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
470 (define-public (tuplet-number::calc-direction grob)
471 (ly:tuplet-bracket::calc-direction (ly:grob-object grob 'bracket)))
473 (define-public (tuplet-number::calc-denominator-text grob)
474 (number->string (ly:event-property (event-cause grob) 'denominator)))
476 (define-public (tuplet-number::calc-fraction-text grob)
477 (let ((ev (event-cause grob)))
480 (ly:event-property ev 'denominator)
481 (ly:event-property ev 'numerator))))
483 ;; a formatter function, which is simply a wrapper around an existing
484 ;; tuplet formatter function. It takes the value returned by the given
485 ;; function and appends a note of given length.
486 (define-public ((tuplet-number::append-note-wrapper function note) grob)
487 (let ((txt (if function (function grob) #f)))
490 (markup txt #:fontsize -5 #:note note UP)
491 (markup #:fontsize -5 #:note note UP))))
493 ;; Print a tuplet denominator with a different number than the one derived from
494 ;; the actual tuplet fraction
495 (define-public ((tuplet-number::non-default-tuplet-denominator-text denominator)
497 (number->string (if denominator
499 (ly:event-property (event-cause grob) 'denominator))))
501 ;; Print a tuplet fraction with different numbers than the ones derived from
502 ;; the actual tuplet fraction
503 (define-public ((tuplet-number::non-default-tuplet-fraction-text
504 denominator numerator) grob)
505 (let* ((ev (event-cause grob))
506 (den (if denominator denominator (ly:event-property ev 'denominator)))
507 (num (if numerator numerator (ly:event-property ev 'numerator))))
509 (format #f "~a:~a" den num)))
511 ;; Print a tuplet fraction with note durations appended to the numerator and the
513 (define-public ((tuplet-number::fraction-with-notes
514 denominatornote numeratornote) grob)
515 (let* ((ev (event-cause grob))
516 (denominator (ly:event-property ev 'denominator))
517 (numerator (ly:event-property ev 'numerator)))
519 ((tuplet-number::non-default-fraction-with-notes
520 denominator denominatornote numerator numeratornote) grob)))
522 ;; Print a tuplet fraction with note durations appended to the numerator and the
524 (define-public ((tuplet-number::non-default-fraction-with-notes
525 denominator denominatornote numerator numeratornote) grob)
526 (let* ((ev (event-cause grob))
527 (den (if denominator denominator (ly:event-property ev 'denominator)))
528 (num (if numerator numerator (ly:event-property ev 'numerator))))
530 (make-concat-markup (list
531 (make-simple-markup (format #f "~a" den))
532 (markup #:fontsize -5 #:note denominatornote UP)
533 (make-simple-markup " : ")
534 (make-simple-markup (format #f "~a" num))
535 (markup #:fontsize -5 #:note numeratornote UP)))))
538 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
541 (define-public (color? x)
544 (apply eq? #t (map number? x))
545 (apply eq? #t (map (lambda (y) (<= 0 y 1)) x))))
547 (define-public (rgb-color r g b) (list r g b))
550 (define-public black '(0.0 0.0 0.0))
551 (define-public white '(1.0 1.0 1.0))
552 (define-public red '(1.0 0.0 0.0))
553 (define-public green '(0.0 1.0 0.0))
554 (define-public blue '(0.0 0.0 1.0))
555 (define-public cyan '(0.0 1.0 1.0))
556 (define-public magenta '(1.0 0.0 1.0))
557 (define-public yellow '(1.0 1.0 0.0))
559 (define-public grey '(0.5 0.5 0.5))
560 (define-public darkred '(0.5 0.0 0.0))
561 (define-public darkgreen '(0.0 0.5 0.0))
562 (define-public darkblue '(0.0 0.0 0.5))
563 (define-public darkcyan '(0.0 0.5 0.5))
564 (define-public darkmagenta '(0.5 0.0 0.5))
565 (define-public darkyellow '(0.5 0.5 0.0))
568 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
571 (define-public (key-signature-interface::alteration-position step alter
573 ;; TODO: memoize - this is mostly constant.
575 ;; fes, ges, as and bes typeset in lower octave
576 (define FLAT_TOP_PITCH 2)
578 ;; ais and bis typeset in lower octave
579 (define SHARP_TOP_PITCH 4)
582 (+ (cdr step) (* (car step) 7) c0-position)
583 (let* ((from-bottom-pos (modulo (+ 4 49 c0-position) 7))
585 (c0 (- from-bottom-pos 4)))
589 (or (> p FLAT_TOP_PITCH) (> (+ p c0) 4)) (> (+ p c0) 1))
591 (or (> p SHARP_TOP_PITCH) (> (+ p c0) 5)) (> (+ p c0) 2)))
593 ;; Typeset below c_position
596 ;; Provide for the four cases in which there's a glitch
597 ;; it's a hack, but probably not worth
598 ;; the effort of finding a nicer solution.
601 ((and (= c0 2) (= p 3) (> alter 0))
603 ((and (= c0 -3) (= p -1) (> alter 0))
605 ((and (= c0 -4) (= p -1) (< alter 0))
607 ((and (= c0 -2) (= p -3) (< alter 0))
613 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
616 (define-public (numbered-footnotes int)
617 (markup #:tiny (number->string (+ 1 int))))
619 (define-public (symbol-footnotes int)
620 (define (helper symbols out idx n)
624 (string-append out (list-ref symbols idx))
627 (markup #:tiny (helper '("*" "†" "‡" "§" "¶")
630 (+ 1 (quotient int 5)))))
632 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
635 (define-public (accidental-interface::calc-alteration grob)
636 (ly:pitch-alteration (ly:event-property (event-cause grob) 'pitch)))
638 (define-public cancellation-glyph-name-alist
639 '((0 . "accidentals.natural")))
641 (define-public standard-alteration-glyph-name-alist
643 ;; ordered for optimal performance.
644 (0 . "accidentals.natural")
645 (-1/2 . "accidentals.flat")
646 (1/2 . "accidentals.sharp")
648 (1 . "accidentals.doublesharp")
649 (-1 . "accidentals.flatflat")
651 (3/4 . "accidentals.sharp.slashslash.stemstemstem")
652 (1/4 . "accidentals.sharp.slashslash.stem")
653 (-1/4 . "accidentals.mirroredflat")
654 (-3/4 . "accidentals.mirroredflat.flat")))
656 ;; FIXME: standard vs default, alteration-FOO vs FOO-alteration
657 (define-public alteration-default-glyph-name-alist
658 standard-alteration-glyph-name-alist)
660 (define-public makam-alteration-glyph-name-alist
661 '((1 . "accidentals.doublesharp")
662 (8/9 . "accidentals.sharp.slashslashslash.stemstem")
663 (5/9 . "accidentals.sharp.slashslashslash.stem")
664 (4/9 . "accidentals.sharp")
665 (1/9 . "accidentals.sharp.slashslash.stem")
666 (0 . "accidentals.natural")
667 (-1/9 . "accidentals.mirroredflat")
668 (-4/9 . "accidentals.flat.slash")
669 (-5/9 . "accidentals.flat")
670 (-8/9 . "accidentals.flat.slashslash")
671 (-1 . "accidentals.flatflat")))
673 (define-public alteration-hufnagel-glyph-name-alist
674 '((-1/2 . "accidentals.hufnagelM1")
675 (0 . "accidentals.vaticana0")
676 (1/2 . "accidentals.mensural1")))
678 (define-public alteration-medicaea-glyph-name-alist
679 '((-1/2 . "accidentals.medicaeaM1")
680 (0 . "accidentals.vaticana0")
681 (1/2 . "accidentals.mensural1")))
683 (define-public alteration-vaticana-glyph-name-alist
684 '((-1/2 . "accidentals.vaticanaM1")
685 (0 . "accidentals.vaticana0")
686 (1/2 . "accidentals.mensural1")))
688 (define-public alteration-mensural-glyph-name-alist
689 '((-1/2 . "accidentals.mensuralM1")
690 (0 . "accidentals.vaticana0")
691 (1/2 . "accidentals.mensural1")))
693 (define-public alteration-kievan-glyph-name-alist
694 '((-1/2 . "accidentals.kievanM1")
695 (1/2 . "accidentals.kievan1")))
697 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
698 ;; * Pitch Trill Heads
701 (define-public (parentheses-item::calc-parenthesis-stencils grob)
702 (let* ((font (ly:grob-default-font grob))
703 (lp (ly:font-get-glyph font "accidentals.leftparen"))
704 (rp (ly:font-get-glyph font "accidentals.rightparen")))
708 (define-public (parentheses-item::calc-angled-bracket-stencils grob)
709 (let* ((parent (ly:grob-parent grob Y))
710 (y-extent (ly:grob-extent parent parent Y))
711 (half-thickness 0.05) ; should it be a property?
712 (width 0.5) ; should it be a property?
713 (angularity 1.5) ; makes angle brackets
714 (white-padding 0.1) ; should it be a property?
715 (lp (ly:stencil-aligned-to
716 (ly:stencil-aligned-to
717 (make-parenthesis-stencil y-extent
724 (interval-widen (ly:stencil-extent lp X) white-padding))
725 (rp (ly:stencil-aligned-to
726 (ly:stencil-aligned-to
727 (make-parenthesis-stencil y-extent
734 (interval-widen (ly:stencil-extent rp X) white-padding)))
735 (set! lp (ly:make-stencil (ly:stencil-expr lp)
737 (ly:stencil-extent lp Y)))
738 (set! rp (ly:make-stencil (ly:stencil-expr rp)
740 (ly:stencil-extent rp Y)))
741 (list (stencil-whiteout lp)
742 (stencil-whiteout rp))))
744 (define (parenthesize-elements grob . rest)
745 (let* ((refp (if (null? rest)
748 (elts (ly:grob-object grob 'elements))
749 (x-ext (ly:relative-group-extent elts refp X))
750 (stencils (ly:grob-property grob 'stencils))
753 (padding (ly:grob-property grob 'padding 0.1)))
756 (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
757 (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))))
760 (define-public (parentheses-item::print me)
761 (let* ((elts (ly:grob-object me 'elements))
762 (y-ref (ly:grob-common-refpoint-of-array me elts Y))
763 (x-ref (ly:grob-common-refpoint-of-array me elts X))
764 (stencil (parenthesize-elements me x-ref))
765 (elt-y-ext (ly:relative-group-extent elts y-ref Y))
766 (y-center (interval-center elt-y-ext)))
768 (ly:stencil-translate
771 (- (ly:grob-relative-coordinate me x-ref X))
772 (- y-center (ly:grob-relative-coordinate me y-ref Y))))))
776 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
779 (define-public (chain-grob-member-functions grob value . funcs)
782 (set! value (func grob value)))
788 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
791 (define-public (bend::print spanner)
793 (< (abs (- a b)) 0.01))
795 (let* ((delta-y (* 0.5 (ly:grob-property spanner 'delta-position)))
796 (left-span (ly:spanner-bound spanner LEFT))
797 (dots (if (and (grob::has-interface left-span 'note-head-interface)
798 (ly:grob? (ly:grob-object left-span 'dot)))
799 (ly:grob-object left-span 'dot) #f))
801 (right-span (ly:spanner-bound spanner RIGHT))
802 (thickness (* (ly:grob-property spanner 'thickness)
803 (ly:output-def-lookup (ly:grob-layout spanner)
805 (padding (ly:grob-property spanner 'padding 0.5))
806 (common (ly:grob-common-refpoint right-span
807 (ly:grob-common-refpoint spanner
810 (common-y (ly:grob-common-refpoint spanner left-span Y))
811 (minimum-length (ly:grob-property spanner 'minimum-length 0.5))
815 (interval-end (ly:grob-robust-relative-extent
820 (ly:grob-relative-coordinate dots common-y Y)
821 (ly:grob-relative-coordinate spanner common-y Y)))
823 (ly:grob-robust-relative-extent dots common X))
824 ;; TODO: use real infinity constant.
826 (right-x (max (- (interval-start
827 (ly:grob-robust-relative-extent right-span common X))
829 (+ left-x minimum-length)))
830 (self-x (ly:grob-relative-coordinate spanner common X))
831 (dx (- right-x left-x))
832 (exp (list 'path thickness
840 ,dx ,(* 0.66 delta-y)
845 (cons (- left-x self-x) (- right-x self-x))
846 (cons (min 0 delta-y)
850 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
853 (define-public (grace-spacing::calc-shortest-duration grob)
854 (let* ((cols (ly:grob-object grob 'columns))
857 (ly:moment-sub (ly:grob-property
858 (ly:grob-array-ref cols (1+ idx)) 'when)
860 (ly:grob-array-ref cols idx) 'when))))
862 (moment-min (lambda (x y)
865 (if (ly:moment<? x y)
871 (fold moment-min #f (map get-difference
872 (iota (1- (ly:grob-array-length cols)))))))
875 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
878 (define-public (fingering::calc-text grob)
879 (let* ((event (event-cause grob))
880 (digit (ly:event-property event 'digit)))
882 (number->string digit 10)))
884 (define-public (string-number::calc-text grob)
885 (let ((digit (ly:event-property (event-cause grob) 'string-number)))
887 (number->string digit 10)))
889 (define-public (stroke-finger::calc-text grob)
890 (let* ((digit (ly:event-property (event-cause grob) 'digit))
891 (text (ly:event-property (event-cause grob) 'text)))
895 (vector-ref (ly:grob-property grob 'digit-names)
896 (1- (max (min 5 digit) 1))))))
899 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
902 (define-public (hairpin::calc-grow-direction grob)
903 (if (ly:in-event-class? (event-cause grob) 'decrescendo-event)
907 (define-public (dynamic-text-spanner::before-line-breaking grob)
908 "Monitor left bound of @code{DynamicTextSpanner} for absolute dynamics.
909 If found, ensure @code{DynamicText} does not collide with spanner text by
910 changing @code{'attach-dir} and @code{'padding}. Reads the
911 @code{'right-padding} property of @code{DynamicText} to fine tune space
912 between the two text elements."
913 (let ((left-bound (ly:spanner-bound grob LEFT)))
914 (if (grob::has-interface left-bound 'dynamic-text-interface)
915 (let* ((details (ly:grob-property grob 'bound-details))
916 (left-details (ly:assoc-get 'left details))
917 (my-padding (ly:assoc-get 'padding left-details))
918 (script-padding (ly:grob-property left-bound 'right-padding 0)))
920 (and (number? my-padding)
921 (ly:grob-set-nested-property! grob
922 '(bound-details left attach-dir)
924 (ly:grob-set-nested-property! grob
925 '(bound-details left padding)
926 (+ my-padding script-padding)))))))
929 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
932 (define-public (lyric-text::print grob)
933 "Allow interpretation of tildes as lyric tieing marks."
935 (let ((text (ly:grob-property grob 'text)))
937 (grob-interpret-markup grob (if (string? text)
938 (make-tied-lyric-markup text)
941 (define-public ((grob::calc-property-by-copy prop) grob)
942 (ly:event-property (event-cause grob) prop))
945 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
948 (define-public (fret-board::calc-stencil grob)
949 (grob-interpret-markup
951 (make-fret-diagram-verbose-markup
952 (ly:grob-property grob 'dot-placement-list))))
955 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
958 (define-public (script-interface::calc-x-offset grob)
959 (ly:grob-property grob 'positioning-done)
960 (let* ((shift (ly:grob-property grob 'toward-stem-shift 0.0))
962 (ly:self-alignment-interface::centered-on-x-parent grob))
963 (note-head-grob (ly:grob-parent grob X))
964 (stem-grob (ly:grob-object note-head-grob 'stem)))
966 (+ note-head-location
967 ;; If the property 'toward-stem-shift is defined and the script
968 ;; has the same direction as the stem, move the script accordingly.
969 ;; Since scripts can also be over skips, we need to check whether
970 ;; the grob has a stem at all.
971 (if (ly:grob? stem-grob)
972 (let ((dir1 (ly:grob-property grob 'direction))
973 (dir2 (ly:grob-property stem-grob 'direction)))
974 (if (equal? dir1 dir2)
975 (let* ((common-refp (ly:grob-common-refpoint grob stem-grob X))
977 (ly:grob-relative-coordinate stem-grob common-refp X)))
978 (* shift (- stem-location note-head-location)))
983 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
986 (define-public (system-start-text::print grob)
987 (let* ((left-bound (ly:spanner-bound grob LEFT))
988 (left-mom (ly:grob-property left-bound 'when))
989 (name (if (moment<=? left-mom ZERO-MOMENT)
990 (ly:grob-property grob 'long-text)
991 (ly:grob-property grob 'text))))
993 (if (and (markup? name)
994 (!= (ly:item-break-dir left-bound) CENTER))
996 (grob-interpret-markup grob name)
997 (ly:grob-suicide! grob))))
999 (define-public (system-start-text::calc-x-offset grob)
1000 (let* ((left-bound (ly:spanner-bound grob LEFT))
1001 (left-mom (ly:grob-property left-bound 'when))
1002 (layout (ly:grob-layout grob))
1003 (indent (ly:output-def-lookup layout
1004 (if (moment<=? left-mom ZERO-MOMENT)
1008 (system (ly:grob-system grob))
1009 (my-extent (ly:grob-extent grob system X))
1010 (elements (ly:grob-object system 'elements))
1011 (common (ly:grob-common-refpoint-of-array system elements X))
1012 (total-ext empty-interval)
1013 (align-x (ly:grob-property grob 'self-alignment-X 0))
1014 (padding (min 0 (- (interval-length my-extent) indent)))
1015 (right-padding (- padding
1016 (/ (* padding (1+ align-x)) 2))))
1018 ;; compensate for the variation in delimiter extents by
1019 ;; calculating an X-offset correction based on united extents
1020 ;; of all delimiters in this system
1021 (let unite-delims ((l (ly:grob-array-length elements)))
1023 (let ((elt (ly:grob-array-ref elements (1- l))))
1025 (if (grob::has-interface elt 'system-start-delimiter-interface)
1026 (let ((dims (ly:grob-extent elt common X)))
1027 (if (interval-sane? dims)
1028 (set! total-ext (interval-union total-ext dims)))))
1029 (unite-delims (1- l)))))
1032 (ly:side-position-interface::x-aligned-side grob)
1034 (- (interval-length total-ext)))))
1036 (define-public (system-start-text::calc-y-offset grob)
1038 (define (live-elements-list me)
1039 (let ((elements (ly:grob-object me 'elements)))
1041 (filter! grob::is-live?
1042 (ly:grob-array->list elements))))
1044 (let* ((left-bound (ly:spanner-bound grob LEFT))
1045 (live-elts (live-elements-list grob))
1046 (system (ly:grob-system grob))
1047 (extent empty-interval))
1049 (if (and (pair? live-elts)
1050 (interval-sane? (ly:grob-extent grob system Y)))
1051 (let get-extent ((lst live-elts))
1053 (let ((axis-group (car lst)))
1055 (if (and (ly:spanner? axis-group)
1056 (equal? (ly:spanner-bound axis-group LEFT)
1058 (set! extent (add-point extent
1059 (ly:grob-relative-coordinate
1060 axis-group system Y))))
1061 (get-extent (cdr lst)))))
1062 ;; no live axis group(s) for this instrument name -> remove from system
1063 (ly:grob-suicide! grob))
1066 (ly:self-alignment-interface::y-aligned-on-self grob)
1067 (interval-center extent))))
1070 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1073 (define-public (ambitus::print grob)
1074 (let ((heads (ly:grob-object grob 'note-heads)))
1076 (if (and (ly:grob-array? heads)
1077 (= (ly:grob-array-length heads) 2))
1078 (let* ((common (ly:grob-common-refpoint-of-array grob heads Y))
1079 (head-down (ly:grob-array-ref heads 0))
1080 (head-up (ly:grob-array-ref heads 1))
1081 (gap (ly:grob-property grob 'gap 0.35))
1082 (point-min (+ (interval-end (ly:grob-extent head-down common Y))
1084 (point-max (- (interval-start (ly:grob-extent head-up common Y))
1087 (if (< point-min point-max)
1088 (let* ((layout (ly:grob-layout grob))
1089 (line-thick (ly:output-def-lookup layout 'line-thickness))
1090 (blot (ly:output-def-lookup layout 'blot-diameter))
1091 (grob-thick (ly:grob-property grob 'thickness 2))
1092 (width (* line-thick grob-thick))
1093 (x-ext (symmetric-interval (/ width 2)))
1094 (y-ext (cons point-min point-max))
1095 (line (ly:round-filled-box x-ext y-ext blot))
1096 (y-coord (ly:grob-relative-coordinate grob common Y)))
1098 (ly:stencil-translate-axis line (- y-coord) Y))
1101 (ly:grob-suicide! grob)
1104 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1105 ;; laissez-vibrer tie
1107 ;; needed so we can make laissez-vibrer a pure print
1109 (define-public (laissez-vibrer::print grob)
1110 (ly:tie::print grob))