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 ;; even though kievan noteheads do not have stems, their
65 ;; invisible stems help with beam placement
66 ;; this assures that invisible stems for kievan notes are aligned
67 ;; to the center of kievan noteheads. that is thus where the beams'
68 ;; x extrema will fall
69 (define-public (stem::kievan-offset-callback grob)
70 (let* ((note-heads (ly:grob-object grob 'note-heads))
71 (note-heads-grobs (if (not (null? note-heads))
72 (ly:grob-array->list note-heads)
74 (first-note-head (if (not (null? note-heads-grobs))
75 (car note-heads-grobs)
77 (note-head-w (if (not (null? first-note-head))
78 (ly:grob-extent first-note-head first-note-head X)
80 (interval-center note-head-w)))
83 ;; sets position of beams for Kievan notation
84 (define-public (beam::get-kievan-positions grob)
85 (let* ((stems (ly:grob-object grob 'stems))
86 (stems-grobs (if (not (null? stems))
87 (ly:grob-array->list stems)
89 (first-stem (if (not (null? stems-grobs))
92 (note-heads (if (not (null? first-stem))
93 (ly:grob-object first-stem 'note-heads)
95 (note-heads-grobs (if (not (null? note-heads))
96 (ly:grob-array->list note-heads)
98 (first-note-head (if (not (null? note-heads-grobs))
99 (car note-heads-grobs)
101 (next-stem (if (not (null? stems))
104 (next-note-heads (if (not (null? next-stem))
105 (ly:grob-object next-stem 'note-heads)
107 (next-note-heads-grobs (if (not (null? next-note-heads))
108 (ly:grob-array->list next-note-heads)
110 (next-note-head (if (not (null? next-note-heads-grobs))
111 (car next-note-heads-grobs)
113 (left-pos (ly:grob-property first-note-head 'Y-offset))
114 (right-pos (ly:grob-property next-note-head 'Y-offset))
115 (direction (ly:grob-property grob 'direction))
116 (first-nh-height (ly:grob::stencil-height first-note-head))
117 (next-nh-height (ly:grob::stencil-height next-note-head))
118 (left-height (if (= direction DOWN)
119 (+ (car first-nh-height) 0.75)
120 (- (cdr first-nh-height) 0.75)))
121 (right-height (if (= direction DOWN)
122 (+ (car next-nh-height) 0.75)
123 (- (cdr next-nh-height) 0.75))))
124 (cons (+ left-pos left-height) (+ right-pos right-height))))
126 (define-public (beam::get-kievan-quantized-positions grob)
127 (let* ((pos (ly:grob-property grob 'positions))
128 (stems (ly:grob-object grob 'stems))
129 (stems-grobs (if (not (null? stems))
130 (ly:grob-array->list stems)
134 (ly:grob-set-property! g 'stem-begin-position 0)
135 (ly:grob-set-property! g 'length 0))
139 ;; calculates each slope of a broken beam individually
140 (define-public (beam::place-broken-parts-individually grob)
141 (ly:beam::quanting grob '(+inf.0 . -inf.0) #f))
143 ;; calculates the slope of a beam as a single unit,
144 ;; even if it is broken. this assures that the beam
145 ;; will pick up where it left off after a line break
146 (define-public (beam::align-with-broken-parts grob)
147 (ly:beam::quanting grob '(+inf.0 . -inf.0) #t))
149 ;; uses the broken beam style from edition peters combines the
150 ;; values of place-broken-parts-individually and align-with-broken-parts above,
151 ;; favoring place-broken-parts-individually when the beam naturally has a steeper
152 ;; incline and align-with-broken-parts when the beam is flat
153 (define-public (beam::slope-like-broken-parts grob)
155 (/ (- (cdr y) (car y)) (- (cdr x) (car x))))
156 (let* ((quant1 (ly:beam::quanting grob '(+inf.0 . -inf.0) #t))
157 (original (ly:grob-original grob))
158 (siblings (if (ly:grob? original)
159 (ly:spanner-broken-into original)
163 (let* ((quant2 (ly:beam::quanting grob '(+inf.0 . -inf.0) #f))
164 (x-span (ly:grob-property grob 'X-positions))
165 (slope1 (slope quant1 x-span))
166 (slope2 (slope quant2 x-span))
167 (quant2 (if (not (= (sign slope1) (sign slope2)))
170 (factor (/ (atan (abs slope1)) PI-OVER-TWO))
173 (+ (* (x quant1) (- 1 factor))
174 (* (x quant2) factor)))
176 (ly:beam::quanting grob base #f)))))
178 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
181 (define-public (script-or-side-position-cross-staff g)
183 (ly:script-interface::calc-cross-staff g)
184 (ly:side-position-interface::calc-cross-staff g)))
187 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
188 ;; side-position stuff
190 (define-public (only-if-beamed g)
191 (any (lambda (x) (ly:grob? (ly:grob-object x 'beam)))
192 (ly:grob-array->list (ly:grob-object g 'side-support-elements))))
194 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
197 (define-public (stem::calc-duration-log grob)
199 (ly:event-property (event-cause grob) 'duration)))
201 (define (stem-stub::do-calculations grob)
202 (and (ly:grob-property (ly:grob-parent grob X) 'cross-staff)
203 (not (ly:grob-property (ly:grob-parent grob X) 'transparent))))
205 (define-public (stem-stub::pure-height grob beg end)
206 (if (stem-stub::do-calculations grob)
210 (define-public (stem-stub::width grob)
211 (if (stem-stub::do-calculations grob)
212 (grob::x-parent-width grob)
215 (define-public (stem-stub::extra-spacing-height grob)
216 (if (stem-stub::do-calculations grob)
217 (let* ((dad (ly:grob-parent grob X))
218 (refp (ly:grob-common-refpoint grob dad Y))
219 (stem_ph (ly:grob-pure-height dad refp 0 1000000))
220 (my_ph (ly:grob-pure-height grob refp 0 1000000))
221 ;; only account for distance if stem is on different staff than stub
222 (dist (if (grob::has-interface refp 'hara-kiri-group-spanner-interface)
224 (- (car my_ph) (car stem_ph)))))
225 (if (interval-empty? (interval-intersection stem_ph my_ph)) #f (coord-translate stem_ph dist)))
228 (define-public (note-head::calc-kievan-duration-log grob)
231 (ly:event-property (event-cause grob) 'duration))))
233 (define-public (note-head::calc-duration-log grob)
236 (ly:event-property (event-cause grob) 'duration))))
238 (define-public (dots::calc-dot-count grob)
239 (ly:duration-dot-count
240 (ly:event-property (event-cause grob) 'duration)))
242 (define-public (dots::calc-staff-position grob)
243 (let* ((head (ly:grob-parent grob Y))
244 (log (ly:grob-property head 'duration-log)))
247 ((or (not (grob::has-interface head 'rest-interface))
248 (not (integer? log))) 0)
256 ;; Kept separate from note-head::calc-glyph-name to allow use by
257 ;; markup commands \note and \note-by-number
258 (define-public (select-head-glyph style log)
259 "Select a note head glyph string based on note head style @var{style}
260 and duration-log @var{log}."
262 ;; "default" style is directly handled in note-head.cc as a
263 ;; special case (HW says, mainly for performance reasons).
264 ;; Therefore, style "default" does not appear in this case
266 ((xcircle) "2xcircle")
267 ((harmonic) "0harmonic")
268 ((harmonic-black) "2harmonic")
269 ((harmonic-mixed) (if (<= log 1) "0harmonic"
272 ;; Oops, I actually would not call this "baroque", but, for
273 ;; backwards compatibility to 1.4, this is supposed to take
274 ;; brevis, longa and maxima from the neo-mensural font and all
275 ;; other note heads from the default font. -- jr
277 (string-append (number->string log) "neomensural")
278 (number->string log)))
280 ;; Like default, but brevis is drawn with double vertical lines
282 (string-append (number->string log) "double")
283 (number->string log)))
285 (string-append (number->string log) (symbol->string style)))
288 (string-append (number->string log) "mensural")
289 (string-append (number->string log) (symbol->string style))))
292 (string-append (number->string log) "blackmensural")
293 (string-append (number->string log) (symbol->string style))))
296 (string-append (number->string log) "semimensural")
297 (string-append (number->string log) "petrucci")))
299 (string-append (number->string log) (symbol->string style)))
301 (string-append (number->string log) "kievan"))
303 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
304 (symbol->string style)
305 (string-append (number->string (max 0 log))
306 (symbol->string style))))))
308 (define-public (note-head::calc-glyph-name grob)
309 (let* ((style (ly:grob-property grob 'style))
310 (log (if (string-match "kievan*" (symbol->string style))
311 (min 3 (ly:grob-property grob 'duration-log))
312 (min 2 (ly:grob-property grob 'duration-log)))))
313 (select-head-glyph style log)))
315 (define-public (note-head::brew-ez-stencil grob)
316 (let* ((log (ly:grob-property grob 'duration-log))
317 (pitch (ly:event-property (event-cause grob) 'pitch))
318 (pitch-index (ly:pitch-notename pitch))
319 (note-names (ly:grob-property grob 'note-names))
320 (pitch-string (if (and (vector? note-names)
321 (> (vector-length note-names) pitch-index))
322 (vector-ref note-names pitch-index)
325 (+ (modulo (+ pitch-index 2) 7)
326 (char->integer #\A))))))
327 (staff-space (ly:staff-symbol-staff-space grob))
328 (line-thickness (ly:staff-symbol-line-thickness grob))
329 (stem (ly:grob-object grob 'stem))
330 (stem-thickness (* (if (ly:grob? stem)
331 (ly:grob-property stem 'thickness)
334 (radius (/ (+ staff-space line-thickness) 2))
335 (letter (markup #:center-align #:vcenter pitch-string))
336 (filled-circle (markup #:draw-circle radius 0 #t)))
338 (ly:stencil-translate-axis
339 (grob-interpret-markup
344 (make-with-color-markup white letter))
348 (make-with-color-markup white (make-draw-circle-markup
349 (- radius stem-thickness) 0 #t)))
353 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
356 (define-public (make-rhythmic-location bar-num num den)
358 bar-num (ly:make-moment num den)))
360 (define-public (rhythmic-location? a)
363 (ly:moment? (cdr a))))
365 (define-public (make-graceless-rhythmic-location loc)
366 (make-rhythmic-location
368 (ly:moment-main-numerator (rhythmic-location-measure-position loc))
369 (ly:moment-main-denominator (rhythmic-location-measure-position loc))))
371 (define-public rhythmic-location-measure-position cdr)
372 (define-public rhythmic-location-bar-number car)
374 (define-public (rhythmic-location<? a b)
376 ((< (car a) (car b)) #t)
377 ((> (car a) (car b)) #f)
379 (ly:moment<? (cdr a) (cdr b)))))
381 (define-public (rhythmic-location<=? a b)
382 (not (rhythmic-location<? b a)))
383 (define-public (rhythmic-location>=? a b)
384 (not (rhythmic-location<? a b)))
385 (define-public (rhythmic-location>? a b)
386 (rhythmic-location<? b a))
388 (define-public (rhythmic-location=? a b)
389 (and (rhythmic-location<=? a b)
390 (rhythmic-location<=? b a)))
392 (define-public (rhythmic-location->file-string a)
393 (ly:format "~a.~a.~a"
395 (ly:moment-main-numerator (cdr a))
396 (ly:moment-main-denominator (cdr a))))
398 (define-public (rhythmic-location->string a)
399 (ly:format "bar ~a ~a"
401 (ly:moment->string (cdr a))))
403 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
406 (define-public all-visible #(#t #t #t))
407 (define-public begin-of-line-invisible #(#t #t #f))
408 (define-public center-invisible #(#t #f #t))
409 (define-public end-of-line-invisible #(#f #t #t))
410 (define-public begin-of-line-visible #(#f #f #t))
411 (define-public center-visible #(#f #t #f))
412 (define-public end-of-line-visible #(#t #f #f))
413 (define-public all-invisible #(#f #f #f))
414 (define-public (inherit-x-parent-visibility grob)
415 (let ((parent (ly:grob-parent grob X)))
416 (ly:grob-property parent 'break-visibility all-invisible)))
417 (define-public (inherit-y-parent-visibility grob)
418 (let ((parent (ly:grob-parent grob X)))
419 (ly:grob-property parent 'break-visibility)))
422 (define-public spanbar-begin-of-line-invisible #(#t #f #f))
425 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
426 ;; neighbor-interface routines
429 (define-public (shift-right-at-line-begin g)
430 "Shift an item to the right, but only at the start of the line."
431 (if (and (ly:item? g)
432 (equal? (ly:item-break-dir g) RIGHT))
433 (ly:grob-translate-axis! g 3.5 X)))
435 (define-public (pure-from-neighbor-interface::extra-spacing-height-at-beginning-of-line grob)
436 (if (= 1 (ly:item-break-dir grob))
437 (pure-from-neighbor-interface::extra-spacing-height grob)
440 (define-public (pure-from-neighbor-interface::extra-spacing-height grob)
441 (let* ((height (ly:grob-pure-height grob grob 0 10000000))
442 (from-neighbors (interval-union
444 (ly:axis-group-interface::pure-height
448 (coord-operation - from-neighbors height)))
450 (define-public (pure-from-neighbor-interface::account-for-span-bar grob)
451 (let* ((esh (pure-from-neighbor-interface::extra-spacing-height grob))
452 (hsb (ly:grob-property grob 'has-span-bar))
453 (ii (interval-intersection esh (cons -1.01 1.01))))
455 (cons (car (if (and (car hsb)
456 (ly:grob-property grob 'allow-span-bar))
458 (cdr (if (cdr hsb) esh ii)))
461 (define-public (pure-from-neighbor-interface::extra-spacing-height-including-staff grob)
462 (let ((esh (pure-from-neighbor-interface::extra-spacing-height grob))
463 (to-staff (coord-operation -
466 (ly:staff-symbol-staff-radius grob))
467 (ly:grob::stencil-height grob))))
468 (interval-union esh to-staff)))
471 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
474 (define-public (tuplet-number::calc-direction grob)
475 (ly:tuplet-bracket::calc-direction (ly:grob-object grob 'bracket)))
477 (define-public (tuplet-number::calc-denominator-text grob)
478 (number->string (ly:event-property (event-cause grob) 'denominator)))
480 (define-public (tuplet-number::calc-fraction-text grob)
481 (let ((ev (event-cause grob)))
484 (ly:event-property ev 'denominator)
485 (ly:event-property ev 'numerator))))
487 ;; a formatter function, which is simply a wrapper around an existing
488 ;; tuplet formatter function. It takes the value returned by the given
489 ;; function and appends a note of given length.
490 (define-public ((tuplet-number::append-note-wrapper function note) grob)
491 (let ((txt (if function (function grob) #f)))
494 (markup txt #:fontsize -5 #:note note UP)
495 (markup #:fontsize -5 #:note note UP))))
497 ;; Print a tuplet denominator with a different number than the one derived from
498 ;; the actual tuplet fraction
499 (define-public ((tuplet-number::non-default-tuplet-denominator-text denominator)
501 (number->string (if denominator
503 (ly:event-property (event-cause grob) 'denominator))))
505 ;; Print a tuplet fraction with different numbers than the ones derived from
506 ;; the actual tuplet fraction
507 (define-public ((tuplet-number::non-default-tuplet-fraction-text
508 denominator numerator) grob)
509 (let* ((ev (event-cause grob))
510 (den (if denominator denominator (ly:event-property ev 'denominator)))
511 (num (if numerator numerator (ly:event-property ev 'numerator))))
513 (format #f "~a:~a" den num)))
515 ;; Print a tuplet fraction with note durations appended to the numerator and the
517 (define-public ((tuplet-number::fraction-with-notes
518 denominatornote numeratornote) grob)
519 (let* ((ev (event-cause grob))
520 (denominator (ly:event-property ev 'denominator))
521 (numerator (ly:event-property ev 'numerator)))
523 ((tuplet-number::non-default-fraction-with-notes
524 denominator denominatornote numerator numeratornote) grob)))
526 ;; Print a tuplet fraction with note durations appended to the numerator and the
528 (define-public ((tuplet-number::non-default-fraction-with-notes
529 denominator denominatornote numerator numeratornote) grob)
530 (let* ((ev (event-cause grob))
531 (den (if denominator denominator (ly:event-property ev 'denominator)))
532 (num (if numerator numerator (ly:event-property ev 'numerator))))
534 (make-concat-markup (list
535 (make-simple-markup (format #f "~a" den))
536 (markup #:fontsize -5 #:note denominatornote UP)
537 (make-simple-markup " : ")
538 (make-simple-markup (format #f "~a" num))
539 (markup #:fontsize -5 #:note numeratornote UP)))))
542 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
545 (define-public (color? x)
548 (apply eq? #t (map number? x))
549 (apply eq? #t (map (lambda (y) (<= 0 y 1)) x))))
551 (define-public (rgb-color r g b) (list r g b))
554 (define-public black '(0.0 0.0 0.0))
555 (define-public white '(1.0 1.0 1.0))
556 (define-public red '(1.0 0.0 0.0))
557 (define-public green '(0.0 1.0 0.0))
558 (define-public blue '(0.0 0.0 1.0))
559 (define-public cyan '(0.0 1.0 1.0))
560 (define-public magenta '(1.0 0.0 1.0))
561 (define-public yellow '(1.0 1.0 0.0))
563 (define-public grey '(0.5 0.5 0.5))
564 (define-public darkred '(0.5 0.0 0.0))
565 (define-public darkgreen '(0.0 0.5 0.0))
566 (define-public darkblue '(0.0 0.0 0.5))
567 (define-public darkcyan '(0.0 0.5 0.5))
568 (define-public darkmagenta '(0.5 0.0 0.5))
569 (define-public darkyellow '(0.5 0.5 0.0))
572 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
575 (define-public (key-signature-interface::alteration-positions
576 entry c0-position grob)
577 (let ((step (car entry))
580 (list (+ (cdr step) (* (car step) 7) c0-position))
581 (let* ((c-position (modulo c0-position 7))
584 ;; See (flat|sharp)-positions in define-grob-properties.scm
585 (ly:grob-property grob 'flat-positions '(3))
586 (ly:grob-property grob 'sharp-positions '(3))))
587 (p (list-ref positions
588 (if (< c-position (length positions))
590 (max-position (if (pair? p) (cdr p) p))
591 (min-position (if (pair? p) (car p) (- max-position 6)))
592 (first-position (+ (modulo (- (+ c-position step)
596 (define (prepend x l) (if (> x max-position)
598 (prepend (+ x 7) (cons x l))))
599 (prepend first-position '())))))
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 (accidental-interface::glyph-name grob)
627 (assoc-get (ly:grob-property grob 'alteration)
628 standard-alteration-glyph-name-alist))
630 (define-public cancellation-glyph-name-alist
631 '((0 . "accidentals.natural")))
633 (define-public standard-alteration-glyph-name-alist
635 ;; ordered for optimal performance.
636 (0 . "accidentals.natural")
637 (-1/2 . "accidentals.flat")
638 (1/2 . "accidentals.sharp")
640 (1 . "accidentals.doublesharp")
641 (-1 . "accidentals.flatflat")
643 (3/4 . "accidentals.sharp.slashslash.stemstemstem")
644 (1/4 . "accidentals.sharp.slashslash.stem")
645 (-1/4 . "accidentals.mirroredflat")
646 (-3/4 . "accidentals.mirroredflat.flat")))
648 ;; FIXME: standard vs default, alteration-FOO vs FOO-alteration
649 (define-public alteration-default-glyph-name-alist
650 standard-alteration-glyph-name-alist)
652 (define-public makam-alteration-glyph-name-alist
653 '((1 . "accidentals.doublesharp")
654 (8/9 . "accidentals.sharp.slashslashslash.stemstem")
655 (5/9 . "accidentals.sharp.slashslashslash.stem")
656 (4/9 . "accidentals.sharp")
657 (1/9 . "accidentals.sharp.slashslash.stem")
658 (0 . "accidentals.natural")
659 (-1/9 . "accidentals.mirroredflat")
660 (-4/9 . "accidentals.flat.slash")
661 (-5/9 . "accidentals.flat")
662 (-8/9 . "accidentals.flat.slashslash")
663 (-1 . "accidentals.flatflat")))
665 (define-public alteration-hufnagel-glyph-name-alist
666 '((-1/2 . "accidentals.hufnagelM1")
667 (0 . "accidentals.vaticana0")
668 (1/2 . "accidentals.mensural1")))
670 (define-public alteration-medicaea-glyph-name-alist
671 '((-1/2 . "accidentals.medicaeaM1")
672 (0 . "accidentals.vaticana0")
673 (1/2 . "accidentals.mensural1")))
675 (define-public alteration-vaticana-glyph-name-alist
676 '((-1/2 . "accidentals.vaticanaM1")
677 (0 . "accidentals.vaticana0")
678 (1/2 . "accidentals.mensural1")))
680 (define-public alteration-mensural-glyph-name-alist
681 '((-1/2 . "accidentals.mensuralM1")
682 (0 . "accidentals.vaticana0")
683 (1/2 . "accidentals.mensural1")))
685 (define-public alteration-kievan-glyph-name-alist
686 '((-1/2 . "accidentals.kievanM1")
687 (1/2 . "accidentals.kievan1")))
689 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
690 ;; * Pitch Trill Heads
693 (define-public (parentheses-item::calc-parenthesis-stencils grob)
694 (let* ((font (ly:grob-default-font grob))
695 (lp (ly:font-get-glyph font "accidentals.leftparen"))
696 (rp (ly:font-get-glyph font "accidentals.rightparen")))
700 (define-public (parentheses-item::calc-angled-bracket-stencils grob)
701 (let* ((parent (ly:grob-parent grob Y))
702 (y-extent (ly:grob-extent parent parent Y))
703 (half-thickness 0.05) ; should it be a property?
704 (width 0.5) ; should it be a property?
705 (angularity 1.5) ; makes angle brackets
706 (white-padding 0.1) ; should it be a property?
707 (lp (ly:stencil-aligned-to
708 (ly:stencil-aligned-to
709 (make-parenthesis-stencil y-extent
716 (interval-widen (ly:stencil-extent lp X) white-padding))
717 (rp (ly:stencil-aligned-to
718 (ly:stencil-aligned-to
719 (make-parenthesis-stencil y-extent
726 (interval-widen (ly:stencil-extent rp X) white-padding)))
727 (set! lp (ly:make-stencil (ly:stencil-expr lp)
729 (ly:stencil-extent lp Y)))
730 (set! rp (ly:make-stencil (ly:stencil-expr rp)
732 (ly:stencil-extent rp Y)))
733 (list (stencil-whiteout lp)
734 (stencil-whiteout rp))))
736 (define (parenthesize-elements grob . rest)
737 (let* ((refp (if (null? rest)
740 (elts (ly:grob-object grob 'elements))
741 (x-ext (ly:relative-group-extent elts refp X))
742 (stencils (ly:grob-property grob 'stencils))
745 (padding (ly:grob-property grob 'padding 0.1)))
748 (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
749 (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))))
752 (define-public (parentheses-item::print me)
753 (let* ((elts (ly:grob-object me 'elements))
754 (y-ref (ly:grob-common-refpoint-of-array me elts Y))
755 (x-ref (ly:grob-common-refpoint-of-array me elts X))
756 (stencil (parenthesize-elements me x-ref))
757 (elt-y-ext (ly:relative-group-extent elts y-ref Y))
758 (y-center (interval-center elt-y-ext)))
760 (ly:stencil-translate
763 (- (ly:grob-relative-coordinate me x-ref X))
764 (- y-center (ly:grob-relative-coordinate me y-ref Y))))))
768 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
771 (define-public (chain-grob-member-functions grob value . funcs)
774 (set! value (func grob value)))
780 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
783 (define-public (bend::print spanner)
785 (< (abs (- a b)) 0.01))
787 (let* ((delta-y (* 0.5 (ly:grob-property spanner 'delta-position)))
788 (left-span (ly:spanner-bound spanner LEFT))
789 (dots (if (and (grob::has-interface left-span 'note-head-interface)
790 (ly:grob? (ly:grob-object left-span 'dot)))
791 (ly:grob-object left-span 'dot) #f))
793 (right-span (ly:spanner-bound spanner RIGHT))
794 (thickness (* (ly:grob-property spanner 'thickness)
795 (ly:output-def-lookup (ly:grob-layout spanner)
797 (padding (ly:grob-property spanner 'padding 0.5))
798 (common (ly:grob-common-refpoint right-span
799 (ly:grob-common-refpoint spanner
802 (common-y (ly:grob-common-refpoint spanner left-span Y))
803 (minimum-length (ly:grob-property spanner 'minimum-length 0.5))
807 (interval-end (ly:grob-robust-relative-extent
812 (ly:grob-relative-coordinate dots common-y Y)
813 (ly:grob-relative-coordinate spanner common-y Y)))
815 (ly:grob-robust-relative-extent dots common X))
816 ;; TODO: use real infinity constant.
818 (right-x (max (- (interval-start
819 (ly:grob-robust-relative-extent right-span common X))
821 (+ left-x minimum-length)))
822 (self-x (ly:grob-relative-coordinate spanner common X))
823 (dx (- right-x left-x))
824 (exp (list 'path thickness
832 ,dx ,(* 0.66 delta-y)
837 (cons (- left-x self-x) (- right-x self-x))
838 (cons (min 0 delta-y)
842 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
845 (define-public (grace-spacing::calc-shortest-duration grob)
846 (let* ((cols (ly:grob-object grob 'columns))
849 (ly:moment-sub (ly:grob-property
850 (ly:grob-array-ref cols (1+ idx)) 'when)
852 (ly:grob-array-ref cols idx) 'when))))
854 (moment-min (lambda (x y)
857 (if (ly:moment<? x y)
863 (fold moment-min #f (map get-difference
864 (iota (1- (ly:grob-array-length cols)))))))
867 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
870 (define-public (fingering::calc-text grob)
871 (let ((event (event-cause grob)))
872 (or (ly:event-property event 'text #f)
873 (number->string (ly:event-property event 'digit) 10))))
875 (define-public (string-number::calc-text grob)
876 (let ((event (event-cause grob)))
877 (or (ly:event-property event 'text #f)
878 (number->string (ly:event-property event 'string-number) 10))))
880 (define-public (stroke-finger::calc-text grob)
881 (let ((event (event-cause grob)))
882 (or (ly:event-property event 'text #f)
883 (vector-ref (ly:grob-property grob 'digit-names)
885 (min 5 (ly:event-property event 'digit))))))))
888 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
891 (define-public (hairpin::calc-grow-direction grob)
892 (if (ly:in-event-class? (event-cause grob) 'decrescendo-event)
896 (define-public (dynamic-text-spanner::before-line-breaking grob)
897 "Monitor left bound of @code{DynamicTextSpanner} for absolute dynamics.
898 If found, ensure @code{DynamicText} does not collide with spanner text by
899 changing @code{'attach-dir} and @code{'padding}. Reads the
900 @code{'right-padding} property of @code{DynamicText} to fine tune space
901 between the two text elements."
902 (let ((left-bound (ly:spanner-bound grob LEFT)))
903 (if (grob::has-interface left-bound 'dynamic-text-interface)
904 (let* ((details (ly:grob-property grob 'bound-details))
905 (left-details (ly:assoc-get 'left details))
906 (my-padding (ly:assoc-get 'padding left-details))
907 (script-padding (ly:grob-property left-bound 'right-padding 0)))
909 (and (number? my-padding)
910 (ly:grob-set-nested-property! grob
911 '(bound-details left attach-dir)
913 (ly:grob-set-nested-property! grob
914 '(bound-details left padding)
915 (+ my-padding script-padding)))))))
918 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
921 (define-public (lyric-text::print grob)
922 "Allow interpretation of tildes as lyric tieing marks."
924 (let ((text (ly:grob-property grob 'text)))
926 (grob-interpret-markup grob (if (string? text)
927 (make-tied-lyric-markup text)
930 (define-public ((grob::calc-property-by-copy prop) grob)
931 (ly:event-property (event-cause grob) prop))
933 (define-public ((grob::calc-property-by-non-event-cause prop) grob)
934 (ly:grob-property (non-event-cause grob) prop))
937 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
940 (define-public (fret-board::calc-stencil grob)
941 (grob-interpret-markup
943 (make-fret-diagram-verbose-markup
944 (ly:grob-property grob 'dot-placement-list))))
947 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
950 (define-public (script-interface::calc-x-offset grob)
951 (ly:grob-property grob 'positioning-done)
952 (let* ((shift (ly:grob-property grob 'toward-stem-shift 0.0))
954 (ly:self-alignment-interface::centered-on-x-parent grob))
955 (note-head-grob (ly:grob-parent grob X))
956 (stem-grob (ly:grob-object note-head-grob 'stem)))
958 (+ note-head-location
959 ;; If the property 'toward-stem-shift is defined and the script
960 ;; has the same direction as the stem, move the script accordingly.
961 ;; Since scripts can also be over skips, we need to check whether
962 ;; the grob has a stem at all.
963 (if (ly:grob? stem-grob)
964 (let ((dir1 (ly:grob-property grob 'direction))
965 (dir2 (ly:grob-property stem-grob 'direction)))
966 (if (equal? dir1 dir2)
967 (let* ((common-refp (ly:grob-common-refpoint grob stem-grob X))
969 (ly:grob-relative-coordinate stem-grob common-refp X)))
970 (* shift (- stem-location note-head-location)))
975 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
978 (define-public (system-start-text::print grob)
979 (let* ((left-bound (ly:spanner-bound grob LEFT))
980 (left-mom (ly:grob-property left-bound 'when))
981 (name (if (moment<=? left-mom ZERO-MOMENT)
982 (ly:grob-property grob 'long-text)
983 (ly:grob-property grob 'text))))
985 (if (and (markup? name)
986 (!= (ly:item-break-dir left-bound) CENTER))
988 (grob-interpret-markup grob name)
989 (ly:grob-suicide! grob))))
991 (define-public (system-start-text::calc-x-offset grob)
992 (let* ((left-bound (ly:spanner-bound grob LEFT))
993 (left-mom (ly:grob-property left-bound 'when))
994 (layout (ly:grob-layout grob))
995 (indent (ly:output-def-lookup layout
996 (if (moment<=? left-mom ZERO-MOMENT)
1000 (system (ly:grob-system grob))
1001 (my-extent (ly:grob-extent grob system X))
1002 (elements (ly:grob-object system 'elements))
1003 (common (ly:grob-common-refpoint-of-array system elements X))
1004 (total-ext empty-interval)
1005 (align-x (ly:grob-property grob 'self-alignment-X 0))
1006 (padding (min 0 (- (interval-length my-extent) indent)))
1007 (right-padding (- padding
1008 (/ (* padding (1+ align-x)) 2))))
1010 ;; compensate for the variation in delimiter extents by
1011 ;; calculating an X-offset correction based on united extents
1012 ;; of all delimiters in this system
1013 (let unite-delims ((l (ly:grob-array-length elements)))
1015 (let ((elt (ly:grob-array-ref elements (1- l))))
1017 (if (grob::has-interface elt 'system-start-delimiter-interface)
1018 (let ((dims (ly:grob-extent elt common X)))
1019 (if (interval-sane? dims)
1020 (set! total-ext (interval-union total-ext dims)))))
1021 (unite-delims (1- l)))))
1024 (ly:side-position-interface::x-aligned-side grob)
1026 (- (interval-length total-ext)))))
1028 (define-public (system-start-text::calc-y-offset grob)
1030 (define (live-elements-list me)
1031 (let ((elements (ly:grob-object me 'elements)))
1033 (filter! grob::is-live?
1034 (ly:grob-array->list elements))))
1036 (let* ((left-bound (ly:spanner-bound grob LEFT))
1037 (live-elts (live-elements-list grob))
1038 (system (ly:grob-system grob))
1039 (extent empty-interval))
1041 (if (and (pair? live-elts)
1042 (interval-sane? (ly:grob-extent grob system Y)))
1043 (let get-extent ((lst live-elts))
1045 (let ((axis-group (car lst)))
1047 (if (and (ly:spanner? axis-group)
1048 (equal? (ly:spanner-bound axis-group LEFT)
1050 (set! extent (add-point extent
1051 (ly:grob-relative-coordinate
1052 axis-group system Y))))
1053 (get-extent (cdr lst)))))
1054 ;; no live axis group(s) for this instrument name -> remove from system
1055 (ly:grob-suicide! grob))
1058 (ly:self-alignment-interface::y-aligned-on-self grob)
1059 (interval-center extent))))
1062 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1065 (define-public (ambitus::print grob)
1066 (let ((heads (ly:grob-object grob 'note-heads)))
1068 (if (and (ly:grob-array? heads)
1069 (= (ly:grob-array-length heads) 2))
1070 (let* ((common (ly:grob-common-refpoint-of-array grob heads Y))
1071 (head-down (ly:grob-array-ref heads 0))
1072 (head-up (ly:grob-array-ref heads 1))
1073 (gap (ly:grob-property grob 'gap 0.35))
1074 (point-min (+ (interval-end (ly:grob-extent head-down common Y))
1076 (point-max (- (interval-start (ly:grob-extent head-up common Y))
1079 (if (< point-min point-max)
1080 (let* ((layout (ly:grob-layout grob))
1081 (line-thick (ly:output-def-lookup layout 'line-thickness))
1082 (blot (ly:output-def-lookup layout 'blot-diameter))
1083 (grob-thick (ly:grob-property grob 'thickness 2))
1084 (width (* line-thick grob-thick))
1085 (x-ext (symmetric-interval (/ width 2)))
1086 (y-ext (cons point-min point-max))
1087 (line (ly:round-filled-box x-ext y-ext blot))
1088 (y-coord (ly:grob-relative-coordinate grob common Y)))
1090 (ly:stencil-translate-axis line (- y-coord) Y))
1093 (ly:grob-suicide! grob)
1096 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1097 ;; laissez-vibrer tie
1099 ;; needed so we can make laissez-vibrer a pure print
1101 (define-public (laissez-vibrer::print grob)
1102 (ly:tie::print grob))