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 (make-stencil-boxer thickness padding callback)
30 "Return function that adds a box around the grob passed as argument."
32 (box-stencil (callback grob) thickness padding)))
34 (define-public (make-stencil-circler thickness padding callback)
35 "Return function that adds a circle around the grob passed as argument."
37 (circle-stencil (callback grob) thickness padding)))
39 (define-public (print-circled-text-callback grob)
40 (grob-interpret-markup grob (make-circle-markup
41 (ly:grob-property grob 'text))))
43 (define-public (event-cause grob)
44 (let ((cause (ly:grob-property grob 'cause)))
47 ((ly:stream-event? cause) cause)
48 ((ly:grob? cause) (event-cause cause))
51 (define-public (grob-interpret-markup grob text)
52 (let* ((layout (ly:grob-layout grob))
53 (defs (ly:output-def-lookup layout 'text-font-defaults))
54 (props (ly:grob-alist-chain grob defs)))
56 (ly:text-interface::interpret-markup layout props text)))
59 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
62 (define-public (stem::calc-duration-log grob)
64 (ly:event-property (event-cause grob) 'duration)))
66 (define-public (note-head::calc-duration-log grob)
69 (ly:event-property (event-cause grob) 'duration))))
71 (define-public (dots::calc-dot-count grob)
72 (ly:duration-dot-count
73 (ly:event-property (event-cause grob) 'duration)))
75 (define-public (dots::calc-staff-position grob)
76 (let* ((head (ly:grob-parent grob Y))
77 (log (ly:grob-property head 'duration-log)))
80 ((or (not (grob::has-interface head 'rest-interface))
81 (not (integer? log))) 0)
89 ;; Kept separate from note-head::calc-glyph-name to allow use by
90 ;; markup commands \note and \note-by-number
91 (define-public (select-head-glyph style log)
92 "Select a note head glyph string based on note head style @var{style}
93 and duration-log @var{log}."
95 ;; "default" style is directly handled in note-head.cc as a
96 ;; special case (HW says, mainly for performance reasons).
97 ;; Therefore, style "default" does not appear in this case
99 ((xcircle) "2xcircle")
100 ((harmonic) "0harmonic")
101 ((harmonic-black) "2harmonic")
102 ((harmonic-mixed) (if (<= log 1) "0harmonic"
105 ;; Oops, I actually would not call this "baroque", but, for
106 ;; backwards compatibility to 1.4, this is supposed to take
107 ;; brevis, longa and maxima from the neo-mensural font and all
108 ;; other note heads from the default font. -- jr
110 (string-append (number->string log) "neomensural")
111 (number->string log)))
113 ;; Like default, but brevis is drawn with double vertical lines
115 (string-append (number->string log) "double")
116 (number->string log)))
118 (string-append (number->string log) (symbol->string style)))
121 (string-append (number->string log) "mensural")
122 (string-append (number->string log) (symbol->string style))))
124 (string-append (number->string log) (symbol->string style)))
126 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
127 (symbol->string style)
128 (string-append (number->string (max 0 log))
129 (symbol->string style))))))
131 (define-public (note-head::calc-glyph-name grob)
132 (let ((style (ly:grob-property grob 'style))
133 (log (min 2 (ly:grob-property grob 'duration-log))))
135 (select-head-glyph style log)))
137 (define-public (note-head::brew-ez-stencil grob)
138 (let* ((log (ly:grob-property grob 'duration-log))
139 (pitch (ly:event-property (event-cause grob) 'pitch))
140 (pitch-index (ly:pitch-notename pitch))
141 (note-names (ly:grob-property grob 'note-names))
142 (pitch-string (if (and (vector? note-names)
143 (> (vector-length note-names) pitch-index))
144 (vector-ref note-names pitch-index)
147 (+ (modulo (+ pitch-index 2) 7)
148 (char->integer #\A))))))
149 (staff-space (ly:staff-symbol-staff-space grob))
150 (line-thickness (ly:staff-symbol-line-thickness grob))
151 (stem (ly:grob-object grob 'stem))
152 (stem-thickness (* (if (ly:grob? stem)
153 (ly:grob-property stem 'thickness)
156 (radius (/ (+ staff-space line-thickness) 2))
157 (letter (markup #:center-align #:vcenter pitch-string))
158 (filled-circle (markup #:draw-circle radius 0 #t)))
160 (ly:stencil-translate-axis
161 (grob-interpret-markup
166 (make-with-color-markup white letter))
170 (make-with-color-markup white (make-draw-circle-markup
171 (- radius stem-thickness) 0 #t)))
175 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
178 (define-public (make-rhythmic-location bar-num num den)
180 bar-num (ly:make-moment num den)))
182 (define-public (rhythmic-location? a)
185 (ly:moment? (cdr a))))
187 (define-public (make-graceless-rhythmic-location loc)
188 (make-rhythmic-location
190 (ly:moment-main-numerator (rhythmic-location-measure-position loc))
191 (ly:moment-main-denominator (rhythmic-location-measure-position loc))))
193 (define-public rhythmic-location-measure-position cdr)
194 (define-public rhythmic-location-bar-number car)
196 (define-public (rhythmic-location<? a b)
198 ((< (car a) (car b)) #t)
199 ((> (car a) (car b)) #f)
201 (ly:moment<? (cdr a) (cdr b)))))
203 (define-public (rhythmic-location<=? a b)
204 (not (rhythmic-location<? b a)))
205 (define-public (rhythmic-location>=? a b)
206 (rhythmic-location<? a b))
207 (define-public (rhythmic-location>? a b)
208 (rhythmic-location<? b a))
210 (define-public (rhythmic-location=? a b)
211 (and (rhythmic-location<=? a b)
212 (rhythmic-location<=? b a)))
214 (define-public (rhythmic-location->file-string a)
215 (ly:format "~a.~a.~a"
217 (ly:moment-main-numerator (cdr a))
218 (ly:moment-main-denominator (cdr a))))
220 (define-public (rhythmic-location->string a)
221 (ly:format "bar ~a ~a"
223 (ly:moment->string (cdr a))))
225 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
228 (define-public all-visible #(#t #t #t))
229 (define-public begin-of-line-invisible #(#t #t #f))
230 (define-public center-invisible #(#t #f #t))
231 (define-public end-of-line-invisible #(#f #t #t))
232 (define-public begin-of-line-visible #(#f #f #t))
233 (define-public center-visible #(#f #t #f))
234 (define-public end-of-line-visible #(#t #f #f))
235 (define-public all-invisible #(#f #f #f))
236 (define-public (inherit-x-parent-visibility grob)
237 (let ((parent (ly:grob-parent grob X)))
238 (ly:grob-property parent 'break-visibility all-invisible)))
241 (define-public spanbar-begin-of-line-invisible #(#t #f #f))
244 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
248 ;; How should a bar line behave at a break?
249 (define bar-glyph-alist
250 '((":|:" . (":|" . "|:"))
251 (":|.|:" . (":|" . "|:"))
252 (":|.:" . (":|" . "|:"))
253 ("||:" . ("||" . "|:"))
254 ("dashed" . ("dashed" . '()))
256 ("||:" . ("||" . "|:"))
258 ("|:" . ("|" . "|:"))
261 ;; hmm... should we end with a bar line here?
262 (".|" . ("|" . ".|"))
265 (".|." . (".|." . ()))
266 ("|.|" . ("|.|" . ()))
271 ("empty" . (() . ()))
272 ("brace" . (() . "brace"))
273 ("bracket" . (() . "bracket"))
279 (":|S" . (":|" . "S"))
280 (":|S." . (":|S" . ()))
281 ("S|:" . ("S" . "|:"))
282 (".S|:" . ("|" . "S|:"))
283 (":|S|:" . (":|" . "S|:"))
284 (":|S.|:" . (":|S" . "|:"))))
286 (define-public (bar-line::calc-glyph-name grob)
287 (let* ((glyph (ly:grob-property grob 'glyph))
288 (dir (ly:item-break-dir grob))
289 (result (assoc-get glyph bar-glyph-alist))
290 (glyph-name (if (= dir CENTER)
293 (string? (index-cell result dir)))
294 (index-cell result dir)
298 (define-public (bar-line::calc-break-visibility grob)
299 (let* ((glyph (ly:grob-property grob 'glyph))
300 (result (assoc-get glyph bar-glyph-alist)))
303 (vector (string? (car result)) #t (string? (cdr result)))
306 (define-public (shift-right-at-line-begin g)
307 "Shift an item to the right, but only at the start of the line."
308 (if (and (ly:item? g)
309 (equal? (ly:item-break-dir g) RIGHT))
310 (ly:grob-translate-axis! g 3.5 X)))
313 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
316 (define-public (tuplet-number::calc-denominator-text grob)
317 (number->string (ly:event-property (event-cause grob) 'denominator)))
319 (define-public (tuplet-number::calc-fraction-text grob)
320 (let ((ev (event-cause grob)))
323 (ly:event-property ev 'denominator)
324 (ly:event-property ev 'numerator))))
326 ;; a formatter function, which is simply a wrapper around an existing
327 ;; tuplet formatter function. It takes the value returned by the given
328 ;; function and appends a note of given length.
329 (define-public ((tuplet-number::append-note-wrapper function note) grob)
330 (let ((txt (if function (function grob) #f)))
333 (markup txt #:fontsize -5 #:note note UP)
334 (markup #:fontsize -5 #:note note UP))))
336 ;; Print a tuplet denominator with a different number than the one derived from
337 ;; the actual tuplet fraction
338 (define-public ((tuplet-number::non-default-tuplet-denominator-text denominator)
340 (number->string (if denominator
342 (ly:event-property (event-cause grob) 'denominator))))
344 ;; Print a tuplet fraction with different numbers than the ones derived from
345 ;; the actual tuplet fraction
346 (define-public ((tuplet-number::non-default-tuplet-fraction-text
347 denominator numerator) grob)
348 (let* ((ev (event-cause grob))
349 (den (if denominator denominator (ly:event-property ev 'denominator)))
350 (num (if numerator numerator (ly:event-property ev 'numerator))))
352 (format "~a:~a" den num)))
354 ;; Print a tuplet fraction with note durations appended to the numerator and the
356 (define-public ((tuplet-number::fraction-with-notes
357 denominatornote numeratornote) grob)
358 (let* ((ev (event-cause grob))
359 (denominator (ly:event-property ev 'denominator))
360 (numerator (ly:event-property ev 'numerator)))
362 ((tuplet-number::non-default-fraction-with-notes
363 denominator denominatornote numerator numeratornote) grob)))
365 ;; Print a tuplet fraction with note durations appended to the numerator and the
367 (define-public ((tuplet-number::non-default-fraction-with-notes
368 denominator denominatornote numerator numeratornote) grob)
369 (let* ((ev (event-cause grob))
370 (den (if denominator denominator (ly:event-property ev 'denominator)))
371 (num (if numerator numerator (ly:event-property ev 'numerator))))
373 (make-concat-markup (list
374 (make-simple-markup (format "~a" den))
375 (markup #:fontsize -5 #:note denominatornote UP)
376 (make-simple-markup " : ")
377 (make-simple-markup (format "~a" num))
378 (markup #:fontsize -5 #:note numeratornote UP)))))
381 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
384 (define-public (color? x)
387 (apply eq? #t (map number? x))
388 (apply eq? #t (map (lambda (y) (<= 0 y 1)) x))))
390 (define-public (rgb-color r g b) (list r g b))
393 (define-public black '(0.0 0.0 0.0))
394 (define-public white '(1.0 1.0 1.0))
395 (define-public red '(1.0 0.0 0.0))
396 (define-public green '(0.0 1.0 0.0))
397 (define-public blue '(0.0 0.0 1.0))
398 (define-public cyan '(0.0 1.0 1.0))
399 (define-public magenta '(1.0 0.0 1.0))
400 (define-public yellow '(1.0 1.0 0.0))
402 (define-public grey '(0.5 0.5 0.5))
403 (define-public darkred '(0.5 0.0 0.0))
404 (define-public darkgreen '(0.0 0.5 0.0))
405 (define-public darkblue '(0.0 0.0 0.5))
406 (define-public darkcyan '(0.0 0.5 0.5))
407 (define-public darkmagenta '(0.5 0.0 0.5))
408 (define-public darkyellow '(0.5 0.5 0.0))
411 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
414 (define-public (key-signature-interface::alteration-position step alter
416 ;; TODO: memoize - this is mostly constant.
418 ;; fes, ges, as and bes typeset in lower octave
419 (define FLAT_TOP_PITCH 2)
421 ;; ais and bis typeset in lower octave
422 (define SHARP_TOP_PITCH 4)
425 (+ (cdr step) (* (car step) 7) c0-position)
426 (let* ((from-bottom-pos (modulo (+ 4 49 c0-position) 7))
428 (c0 (- from-bottom-pos 4)))
432 (or (> p FLAT_TOP_PITCH) (> (+ p c0) 4)) (> (+ p c0) 1))
434 (or (> p SHARP_TOP_PITCH) (> (+ p c0) 5)) (> (+ p c0) 2)))
436 ;; Typeset below c_position
439 ;; Provide for the four cases in which there's a glitch
440 ;; it's a hack, but probably not worth
441 ;; the effort of finding a nicer solution.
444 ((and (= c0 2) (= p 3) (> alter 0))
446 ((and (= c0 -3) (= p -1) (> alter 0))
448 ((and (= c0 -4) (= p -1) (< alter 0))
450 ((and (= c0 -2) (= p -3) (< alter 0))
456 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
459 (define-public (accidental-interface::calc-alteration grob)
460 (ly:pitch-alteration (ly:event-property (event-cause grob) 'pitch)))
462 (define-public cancellation-glyph-name-alist
463 '((0 . "accidentals.natural")))
465 (define-public standard-alteration-glyph-name-alist
467 ;; ordered for optimal performance.
468 (0 . "accidentals.natural")
469 (-1/2 . "accidentals.flat")
470 (1/2 . "accidentals.sharp")
472 (1 . "accidentals.doublesharp")
473 (-1 . "accidentals.flatflat")
475 (3/4 . "accidentals.sharp.slashslash.stemstemstem")
476 (1/4 . "accidentals.sharp.slashslash.stem")
477 (-1/4 . "accidentals.mirroredflat")
478 (-3/4 . "accidentals.mirroredflat.flat")))
480 ;; FIXME: standard vs default, alteration-FOO vs FOO-alteration
481 (define-public alteration-default-glyph-name-alist
482 standard-alteration-glyph-name-alist)
484 (define-public makam-alteration-glyph-name-alist
485 '((1 . "accidentals.doublesharp")
486 (8/9 . "accidentals.sharp.slashslashslash.stemstem")
487 (5/9 . "accidentals.sharp.slashslashslash.stem")
488 (4/9 . "accidentals.sharp")
489 (1/9 . "accidentals.sharp.slashslash.stem")
490 (0 . "accidentals.natural")
491 (-1/9 . "accidentals.mirroredflat")
492 (-4/9 . "accidentals.flat.slash")
493 (-5/9 . "accidentals.flat")
494 (-8/9 . "accidentals.flat.slashslash")
495 (-1 . "accidentals.flatflat")))
497 (define-public alteration-hufnagel-glyph-name-alist
498 '((-1/2 . "accidentals.hufnagelM1")
499 (0 . "accidentals.vaticana0")
500 (1/2 . "accidentals.mensural1")))
502 (define-public alteration-medicaea-glyph-name-alist
503 '((-1/2 . "accidentals.medicaeaM1")
504 (0 . "accidentals.vaticana0")
505 (1/2 . "accidentals.mensural1")))
507 (define-public alteration-vaticana-glyph-name-alist
508 '((-1/2 . "accidentals.vaticanaM1")
509 (0 . "accidentals.vaticana0")
510 (1/2 . "accidentals.mensural1")))
512 (define-public alteration-mensural-glyph-name-alist
513 '((-1/2 . "accidentals.mensuralM1")
514 (0 . "accidentals.vaticana0")
515 (1/2 . "accidentals.mensural1")))
518 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
519 ;; * Pitch Trill Heads
522 (define-public (parentheses-item::calc-parenthesis-stencils grob)
523 (let* ((font (ly:grob-default-font grob))
524 (lp (ly:font-get-glyph font "accidentals.leftparen"))
525 (rp (ly:font-get-glyph font "accidentals.rightparen")))
529 (define-public (parentheses-item::calc-angled-bracket-stencils grob)
530 (let* ((parent (ly:grob-parent grob Y))
531 (y-extent (ly:grob-extent parent parent Y))
532 (half-thickness 0.05) ; should it be a property?
533 (width 0.5) ; should it be a property?
534 (angularity 1.5) ; makes angle brackets
535 (white-padding 0.1) ; should it be a property?
536 (lp (ly:stencil-aligned-to
537 (ly:stencil-aligned-to
538 (make-parenthesis-stencil y-extent
545 (interval-widen (ly:stencil-extent lp X) white-padding))
546 (rp (ly:stencil-aligned-to
547 (ly:stencil-aligned-to
548 (make-parenthesis-stencil y-extent
555 (interval-widen (ly:stencil-extent rp X) white-padding)))
556 (set! lp (ly:make-stencil (ly:stencil-expr lp)
558 (ly:stencil-extent lp Y)))
559 (set! rp (ly:make-stencil (ly:stencil-expr rp)
561 (ly:stencil-extent rp Y)))
562 (list (stencil-whiteout lp)
563 (stencil-whiteout rp))))
565 (define (parenthesize-elements grob . rest)
566 (let* ((refp (if (null? rest)
569 (elts (ly:grob-object grob 'elements))
570 (x-ext (ly:relative-group-extent elts refp X))
571 (stencils (ly:grob-property grob 'stencils))
574 (padding (ly:grob-property grob 'padding 0.1)))
577 (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
578 (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))))
581 (define (parentheses-item::print me)
582 (let* ((elts (ly:grob-object me 'elements))
583 (y-ref (ly:grob-common-refpoint-of-array me elts Y))
584 (x-ref (ly:grob-common-refpoint-of-array me elts X))
585 (stencil (parenthesize-elements me x-ref))
586 (elt-y-ext (ly:relative-group-extent elts y-ref Y))
587 (y-center (interval-center elt-y-ext)))
589 (ly:stencil-translate
592 (- (ly:grob-relative-coordinate me x-ref X))
593 (- y-center (ly:grob-relative-coordinate me y-ref Y))))))
597 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
600 (define-public (chain-grob-member-functions grob value . funcs)
603 (set! value (func grob value)))
609 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
612 (define-public (bend::print spanner)
614 (< (abs (- a b)) 0.01))
616 (let* ((delta-y (* 0.5 (ly:grob-property spanner 'delta-position)))
617 (left-span (ly:spanner-bound spanner LEFT))
618 (dots (if (and (grob::has-interface left-span 'note-head-interface)
619 (ly:grob? (ly:grob-object left-span 'dot)))
620 (ly:grob-object left-span 'dot) #f))
622 (right-span (ly:spanner-bound spanner RIGHT))
623 (thickness (* (ly:grob-property spanner 'thickness)
624 (ly:output-def-lookup (ly:grob-layout spanner)
626 (padding (ly:grob-property spanner 'padding 0.5))
627 (common (ly:grob-common-refpoint right-span
628 (ly:grob-common-refpoint spanner
631 (common-y (ly:grob-common-refpoint spanner left-span Y))
632 (minimum-length (ly:grob-property spanner 'minimum-length 0.5))
636 (interval-end (ly:grob-robust-relative-extent
641 (ly:grob-relative-coordinate dots common-y Y)
642 (ly:grob-relative-coordinate spanner common-y Y)))
644 (ly:grob-robust-relative-extent dots common X))
645 ;; TODO: use real infinity constant.
647 (right-x (max (- (interval-start
648 (ly:grob-robust-relative-extent right-span common X))
650 (+ left-x minimum-length)))
651 (self-x (ly:grob-relative-coordinate spanner common X))
652 (dx (- right-x left-x))
653 (exp (list 'path thickness
661 ,dx ,(* 0.66 delta-y)
666 (cons (- left-x self-x) (- right-x self-x))
667 (cons (min 0 delta-y)
671 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
674 (define-public (grace-spacing::calc-shortest-duration grob)
675 (let* ((cols (ly:grob-object grob 'columns))
678 (ly:moment-sub (ly:grob-property
679 (ly:grob-array-ref cols (1+ idx)) 'when)
681 (ly:grob-array-ref cols idx) 'when))))
683 (moment-min (lambda (x y)
686 (if (ly:moment<? x y)
692 (fold moment-min #f (map get-difference
693 (iota (1- (ly:grob-array-length cols)))))))
696 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
699 (define-public (fingering::calc-text grob)
700 (let* ((event (event-cause grob))
701 (digit (ly:event-property event 'digit)))
704 (ly:input-message (ly:event-property event 'origin)
705 "Warning: Fingering notation for finger number ~a"
708 (number->string digit 10)))
710 (define-public (string-number::calc-text grob)
711 (let ((digit (ly:event-property (event-cause grob) 'string-number)))
713 (number->string digit 10)))
715 (define-public (stroke-finger::calc-text grob)
716 (let* ((digit (ly:event-property (event-cause grob) 'digit))
717 (text (ly:event-property (event-cause grob) 'text)))
721 (vector-ref (ly:grob-property grob 'digit-names)
722 (1- (max (min 5 digit) 1))))))
725 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
728 (define-public (hairpin::calc-grow-direction grob)
729 (if (eq? (ly:event-property (event-cause grob) 'class) 'decrescendo-event)
733 (define-public (dynamic-text-spanner::before-line-breaking grob)
734 "Monitor left bound of @code{DynamicTextSpanner} for absolute dynamics.
735 If found, ensure @code{DynamicText} does not collide with spanner text by
736 changing @code{'attach-dir} and @code{'padding}. Reads the
737 @code{'right-padding} property of @code{DynamicText} to fine tune space
738 between the two text elements."
739 (let ((left-bound (ly:spanner-bound grob LEFT)))
740 (if (grob::has-interface left-bound 'dynamic-text-interface)
741 (let* ((details (ly:grob-property grob 'bound-details))
742 (left-details (ly:assoc-get 'left details))
743 (my-padding (ly:assoc-get 'padding left-details))
744 (script-padding (ly:grob-property left-bound 'right-padding 0)))
746 (and (number? my-padding)
747 (ly:grob-set-nested-property! grob
748 '(bound-details left attach-dir)
750 (ly:grob-set-nested-property! grob
751 '(bound-details left padding)
752 (+ my-padding script-padding)))))))
755 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
758 (define-public (lyric-text::print grob)
759 "Allow interpretation of tildes as lyric tieing marks."
761 (let ((text (ly:grob-property grob 'text)))
763 (grob-interpret-markup grob (if (string? text)
764 (make-tied-lyric-markup text)
767 (define-public ((grob::calc-property-by-copy prop) grob)
768 (ly:event-property (event-cause grob) prop))
771 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
774 (define-public (fret-board::calc-stencil grob)
775 (grob-interpret-markup
777 (make-fret-diagram-verbose-markup
778 (ly:grob-property grob 'dot-placement-list))))
781 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
784 (define-public (script-interface::calc-x-offset grob)
785 (ly:grob-property grob 'positioning-done)
786 (let* ((shift (ly:grob-property grob 'toward-stem-shift 0.0))
788 (ly:self-alignment-interface::centered-on-x-parent grob))
789 (note-head-grob (ly:grob-parent grob X))
790 (stem-grob (ly:grob-object note-head-grob 'stem)))
792 (+ note-head-location
793 ;; If the property 'toward-stem-shift is defined and the script
794 ;; has the same direction as the stem, move the script accordingly.
795 ;; Since scripts can also be over skips, we need to check whether
796 ;; the grob has a stem at all.
797 (if (ly:grob? stem-grob)
798 (let ((dir1 (ly:grob-property grob 'direction))
799 (dir2 (ly:grob-property stem-grob 'direction)))
800 (if (equal? dir1 dir2)
801 (let* ((common-refp (ly:grob-common-refpoint grob stem-grob X))
803 (ly:grob-relative-coordinate stem-grob common-refp X)))
804 (* shift (- stem-location note-head-location)))
809 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
812 (define-public (system-start-text::print grob)
813 (let* ((left-bound (ly:spanner-bound grob LEFT))
814 (left-mom (ly:grob-property left-bound 'when))
815 (name (if (moment<=? left-mom ZERO-MOMENT)
816 (ly:grob-property grob 'long-text)
817 (ly:grob-property grob 'text))))
819 (if (and (markup? name)
820 (!= (ly:item-break-dir left-bound) CENTER))
822 (grob-interpret-markup grob name)
823 (ly:grob-suicide! grob))))
825 (define-public (system-start-text::calc-x-offset grob)
826 (let* ((left-bound (ly:spanner-bound grob LEFT))
827 (left-mom (ly:grob-property left-bound 'when))
828 (layout (ly:grob-layout grob))
829 (indent (ly:output-def-lookup layout
830 (if (moment<=? left-mom ZERO-MOMENT)
834 (system (ly:grob-system grob))
835 (my-extent (ly:grob-extent grob system X))
836 (elements (ly:grob-object system 'elements))
837 (common (ly:grob-common-refpoint-of-array system elements X))
838 (total-ext empty-interval)
839 (align-x (ly:grob-property grob 'self-alignment-X 0))
840 (padding (min 0 (- (interval-length my-extent) indent)))
841 (right-padding (- padding
842 (/ (* padding (1+ align-x)) 2))))
844 ;; compensate for the variation in delimiter extents by
845 ;; calculating an X-offset correction based on united extents
846 ;; of all delimiters in this system
847 (let unite-delims ((l (ly:grob-array-length elements)))
849 (let ((elt (ly:grob-array-ref elements (1- l))))
851 (if (grob::has-interface elt 'system-start-delimiter-interface)
852 (let ((dims (ly:grob-extent elt common X)))
853 (if (interval-sane? dims)
854 (set! total-ext (interval-union total-ext dims)))))
855 (unite-delims (1- l)))))
858 (ly:side-position-interface::x-aligned-side grob)
860 (- (interval-length total-ext)))))
862 (define-public (system-start-text::calc-y-offset grob)
864 (define (live-elements-list me)
865 (let ((elements (ly:grob-object me 'elements)))
867 (filter! grob::is-live?
868 (ly:grob-array->list elements))))
870 (let* ((left-bound (ly:spanner-bound grob LEFT))
871 (live-elts (live-elements-list grob))
872 (system (ly:grob-system grob))
873 (extent empty-interval))
875 (if (and (pair? live-elts)
876 (interval-sane? (ly:grob-extent grob system Y)))
877 (let get-extent ((lst live-elts))
879 (let ((axis-group (car lst)))
881 (if (and (ly:spanner? axis-group)
882 (equal? (ly:spanner-bound axis-group LEFT)
884 (set! extent (add-point extent
885 (ly:grob-relative-coordinate
886 axis-group system Y))))
887 (get-extent (cdr lst)))))
888 ;; no live axis group(s) for this instrument name -> remove from system
889 (ly:grob-suicide! grob))
892 (ly:self-alignment-interface::y-aligned-on-self grob)
893 (interval-center extent))))
896 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
899 (define-public (ambitus::print grob)
900 (let ((heads (ly:grob-object grob 'note-heads)))
902 (if (and (ly:grob-array? heads)
903 (= (ly:grob-array-length heads) 2))
904 (let* ((common (ly:grob-common-refpoint-of-array grob heads Y))
905 (head-down (ly:grob-array-ref heads 0))
906 (head-up (ly:grob-array-ref heads 1))
907 (gap (ly:grob-property grob 'gap 0.35))
908 (point-min (+ (interval-end (ly:grob-extent head-down common Y))
910 (point-max (- (interval-start (ly:grob-extent head-up common Y))
913 (if (< point-min point-max)
914 (let* ((layout (ly:grob-layout grob))
915 (line-thick (ly:output-def-lookup layout 'line-thickness))
916 (blot (ly:output-def-lookup layout 'blot-diameter))
917 (grob-thick (ly:grob-property grob 'thickness 2))
918 (width (* line-thick grob-thick))
919 (x-ext (symmetric-interval (/ width 2)))
920 (y-ext (cons point-min point-max))
921 (line (ly:round-filled-box x-ext y-ext blot))
922 (y-coord (ly:grob-relative-coordinate grob common Y)))
924 (ly:stencil-translate-axis line (- y-coord) Y))
927 (ly:grob-suicide! grob)
930 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
931 ;; laissez-vibrer tie
933 ;; needed so we can make laissez-vibrer a pure print
935 (define-public (laissez-vibrer::print grob)
936 (ly:tie::print grob))