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 (define-public (grob::unpure-Y-extent-from-stencil pure-function)
62 "The unpure height will come from a stencil whereas the pure
63 height will come from @code{pure-function}."
64 (ly:make-unpure-pure-container ly:grob::stencil-height pure-function))
66 (define-public grob::unpure-horizontal-skylines-from-stencil
67 (ly:make-unpure-pure-container
68 ly:grob::horizontal-skylines-from-stencil
69 ly:grob::pure-simple-horizontal-skylines-from-extents))
71 (define-public grob::always-horizontal-skylines-from-stencil
72 (ly:make-unpure-pure-container
73 ly:grob::horizontal-skylines-from-stencil))
75 (define-public grob::unpure-vertical-skylines-from-stencil
76 (ly:make-unpure-pure-container
77 ly:grob::vertical-skylines-from-stencil
78 ly:grob::pure-simple-vertical-skylines-from-extents))
80 (define-public grob::always-vertical-skylines-from-stencil
81 (ly:make-unpure-pure-container
82 ly:grob::vertical-skylines-from-stencil))
84 (define-public grob::always-vertical-skylines-from-element-stencils
85 (ly:make-unpure-pure-container
86 ly:grob::vertical-skylines-from-element-stencils
87 ly:grob::pure-vertical-skylines-from-element-stencils))
89 (define-public grob::always-horizontal-skylines-from-element-stencils
90 (ly:make-unpure-pure-container
91 ly:grob::horizontal-skylines-from-element-stencils
92 ly:grob::pure-horizontal-skylines-from-element-stencils))
94 ;; Using this as a callback for a grob's Y-extent promises
95 ;; that the grob's stencil does not depend on line-spacing.
96 ;; We use this promise to figure the space required by Clefs
97 ;; and such at the note-spacing stage.
99 (define-public grob::always-Y-extent-from-stencil
100 (ly:make-unpure-pure-container ly:grob::stencil-height))
102 (define-public (layout-line-thickness grob)
103 "Get the line thickness of the @var{grob}'s corresponding layout."
104 (let* ((layout (ly:grob-layout grob))
105 (line-thickness (ly:output-def-lookup layout 'line-thickness)))
109 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
112 ;; even though kievan noteheads do not have stems, their
113 ;; invisible stems help with beam placement
114 ;; this assures that invisible stems for kievan notes are aligned
115 ;; to the center of kievan noteheads. that is thus where the beams'
116 ;; x extrema will fall
117 (define-public (stem::kievan-offset-callback grob)
118 (let* ((note-heads (ly:grob-object grob 'note-heads))
119 (note-heads-grobs (if (not (null? note-heads))
120 (ly:grob-array->list note-heads)
122 (first-note-head (if (not (null? note-heads-grobs))
123 (car note-heads-grobs)
125 (note-head-w (if (not (null? first-note-head))
126 (ly:grob-extent first-note-head first-note-head X)
128 (interval-center note-head-w)))
131 ;; sets position of beams for Kievan notation
132 (define-public (beam::get-kievan-positions grob)
133 (let* ((stems (ly:grob-object grob 'stems))
134 (stems-grobs (if (not (null? stems))
135 (ly:grob-array->list stems)
137 (first-stem (if (not (null? stems-grobs))
140 (note-heads (if (not (null? first-stem))
141 (ly:grob-object first-stem 'note-heads)
143 (note-heads-grobs (if (not (null? note-heads))
144 (ly:grob-array->list note-heads)
146 (first-note-head (if (not (null? note-heads-grobs))
147 (car note-heads-grobs)
149 (next-stem (if (not (null? stems))
152 (next-note-heads (if (not (null? next-stem))
153 (ly:grob-object next-stem 'note-heads)
155 (next-note-heads-grobs (if (not (null? next-note-heads))
156 (ly:grob-array->list next-note-heads)
158 (next-note-head (if (not (null? next-note-heads-grobs))
159 (car next-note-heads-grobs)
161 (left-pos (ly:grob-property first-note-head 'Y-offset))
162 (right-pos (ly:grob-property next-note-head 'Y-offset))
163 (direction (ly:grob-property grob 'direction))
164 (first-nh-height (ly:grob::stencil-height first-note-head))
165 (next-nh-height (ly:grob::stencil-height next-note-head))
166 (left-height (if (= direction DOWN)
167 (+ (car first-nh-height) 0.75)
168 (- (cdr first-nh-height) 0.75)))
169 (right-height (if (= direction DOWN)
170 (+ (car next-nh-height) 0.75)
171 (- (cdr next-nh-height) 0.75))))
172 (cons (+ left-pos left-height) (+ right-pos right-height))))
174 (define-public (beam::get-kievan-quantized-positions grob)
175 (let* ((pos (ly:grob-property grob 'positions))
176 (stems (ly:grob-object grob 'stems))
177 (stems-grobs (if (not (null? stems))
178 (ly:grob-array->list stems)
182 (ly:grob-set-property! g 'stem-begin-position 0)
183 (ly:grob-set-property! g 'length 0))
187 ;; calculates each slope of a broken beam individually
188 (define-public (beam::place-broken-parts-individually grob)
189 (ly:beam::quanting grob '(+inf.0 . -inf.0) #f))
191 ;; calculates the slope of a beam as a single unit,
192 ;; even if it is broken. this assures that the beam
193 ;; will pick up where it left off after a line break
194 (define-public (beam::align-with-broken-parts grob)
195 (ly:beam::quanting grob '(+inf.0 . -inf.0) #t))
197 ;; uses the broken beam style from edition peters combines the
198 ;; values of place-broken-parts-individually and align-with-broken-parts above,
199 ;; favoring place-broken-parts-individually when the beam naturally has a steeper
200 ;; incline and align-with-broken-parts when the beam is flat
201 (define-public (beam::slope-like-broken-parts grob)
203 (/ (- (cdr y) (car y)) (- (cdr x) (car x))))
204 (let* ((quant1 (ly:beam::quanting grob '(+inf.0 . -inf.0) #t))
205 (original (ly:grob-original grob))
206 (siblings (if (ly:grob? original)
207 (ly:spanner-broken-into original)
211 (let* ((quant2 (ly:beam::quanting grob '(+inf.0 . -inf.0) #f))
212 (x-span (ly:grob-property grob 'X-positions))
213 (slope1 (slope quant1 x-span))
214 (slope2 (slope quant2 x-span))
215 (quant2 (if (not (= (sign slope1) (sign slope2)))
218 (factor (/ (atan (abs slope1)) PI-OVER-TWO))
221 (+ (* (x quant1) (- 1 factor))
222 (* (x quant2) factor)))
224 (ly:beam::quanting grob base #f)))))
226 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
229 (define-public (script-or-side-position-cross-staff g)
231 (ly:script-interface::calc-cross-staff g)
232 (ly:side-position-interface::calc-cross-staff g)))
235 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
236 ;; side-position stuff
238 (define-public (only-if-beamed g)
239 (any (lambda (x) (ly:grob? (ly:grob-object x 'beam)))
240 (ly:grob-array->list (ly:grob-object g 'side-support-elements))))
242 (define-public side-position-interface::y-aligned-side
243 (ly:make-unpure-pure-container
244 ly:side-position-interface::y-aligned-side
245 ly:side-position-interface::pure-y-aligned-side))
247 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
248 ;; self-alignment stuff
250 (define-public self-alignment-interface::y-aligned-on-self
251 (ly:make-unpure-pure-container
252 ly:self-alignment-interface::y-aligned-on-self
253 ly:self-alignment-interface::pure-y-aligned-on-self))
255 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
258 (define staff-symbol-referencer::callback
259 (ly:make-unpure-pure-container ly:staff-symbol-referencer::callback))
261 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
264 (define-public (stem::calc-duration-log grob)
266 (ly:event-property (event-cause grob) 'duration)))
268 (define (stem-stub::do-calculations grob)
269 (and (ly:grob-property (ly:grob-parent grob X) 'cross-staff)
270 (not (ly:grob-property (ly:grob-parent grob X) 'transparent))))
272 (define-public (stem-stub::pure-height grob beg end)
273 (if (stem-stub::do-calculations grob)
277 (define-public (stem-stub::width grob)
278 (if (stem-stub::do-calculations grob)
279 (grob::x-parent-width grob)
282 (define-public (stem-stub::extra-spacing-height grob)
283 (if (stem-stub::do-calculations grob)
284 (let* ((dad (ly:grob-parent grob X))
285 (refp (ly:grob-common-refpoint grob dad Y))
286 (stem_ph (ly:grob-pure-height dad refp 0 INFINITY-INT))
287 (my_ph (ly:grob-pure-height grob refp 0 INFINITY-INT))
288 ;; only account for distance if stem is on different staff than stub
289 (dist (if (grob::has-interface refp 'hara-kiri-group-spanner-interface)
291 (- (car my_ph) (car stem_ph)))))
292 (if (interval-empty? (interval-intersection stem_ph my_ph)) #f (coord-translate stem_ph dist)))
295 (define-public (note-head::calc-kievan-duration-log grob)
298 (ly:event-property (event-cause grob) 'duration))))
300 (define-public (note-head::calc-duration-log grob)
303 (ly:event-property (event-cause grob) 'duration))))
305 (define-public (dots::calc-dot-count grob)
306 (ly:duration-dot-count
307 (ly:event-property (event-cause grob) 'duration)))
309 (define-public (dots::calc-staff-position grob)
310 (let* ((head (ly:grob-parent grob Y))
311 (log (ly:grob-property head 'duration-log)))
314 ((or (not (grob::has-interface head 'rest-interface))
315 (not (integer? log))) 0)
323 ;; Kept separate from note-head::calc-glyph-name to allow use by
324 ;; markup commands \note and \note-by-number
325 (define-public (select-head-glyph style log)
326 "Select a note head glyph string based on note head style @var{style}
327 and duration-log @var{log}."
329 ;; "default" style is directly handled in note-head.cc as a
330 ;; special case (HW says, mainly for performance reasons).
331 ;; Therefore, style "default" does not appear in this case
333 ((xcircle) "2xcircle")
334 ((harmonic) "0harmonic")
335 ((harmonic-black) "2harmonic")
336 ((harmonic-mixed) (if (<= log 1) "0harmonic"
339 ;; Oops, I actually would not call this "baroque", but, for
340 ;; backwards compatibility to 1.4, this is supposed to take
341 ;; brevis, longa and maxima from the neo-mensural font and all
342 ;; other note heads from the default font. -- jr
344 (string-append (number->string log) "neomensural")
345 (number->string log)))
347 ;; Like default, but brevis is drawn with double vertical lines
349 (string-append (number->string log) "double")
350 (number->string log)))
352 (string-append (number->string log) (symbol->string style)))
355 (string-append (number->string log) "mensural")
356 (string-append (number->string log) (symbol->string style))))
359 (string-append (number->string log) "blackmensural")
360 (string-append (number->string log) (symbol->string style))))
363 (string-append (number->string log) "semimensural")
364 (string-append (number->string log) "petrucci")))
366 (string-append (number->string log) (symbol->string style)))
368 (string-append (number->string log) "kievan"))
370 (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
371 (symbol->string style)
372 (string-append (number->string (max 0 log))
373 (symbol->string style))))))
375 (define-public (note-head::calc-glyph-name grob)
376 (let* ((style (ly:grob-property grob 'style))
377 (log (if (string-match "kievan*" (symbol->string style))
378 (min 3 (ly:grob-property grob 'duration-log))
379 (min 2 (ly:grob-property grob 'duration-log)))))
380 (select-head-glyph style log)))
382 (define-public (note-head::brew-ez-stencil grob)
383 (let* ((log (ly:grob-property grob 'duration-log))
384 (pitch (ly:event-property (event-cause grob) 'pitch))
385 (pitch-index (ly:pitch-notename pitch))
386 (note-names (ly:grob-property grob 'note-names))
387 (pitch-string (if (and (vector? note-names)
388 (> (vector-length note-names) pitch-index))
389 (vector-ref note-names pitch-index)
392 (+ (modulo (+ pitch-index 2) 7)
393 (char->integer #\A))))))
394 (staff-space (ly:staff-symbol-staff-space grob))
395 (line-thickness (ly:staff-symbol-line-thickness grob))
396 (stem (ly:grob-object grob 'stem))
397 (stem-thickness (* (if (ly:grob? stem)
398 (ly:grob-property stem 'thickness)
401 (radius (/ (+ staff-space line-thickness) 2))
402 (letter (markup #:center-align #:vcenter pitch-string))
403 (filled-circle (markup #:draw-circle radius 0 #t)))
405 (ly:stencil-translate-axis
406 (grob-interpret-markup
411 (make-with-color-markup white letter))
415 (make-with-color-markup white (make-draw-circle-markup
416 (- radius stem-thickness) 0 #t)))
420 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
423 (define-public (make-rhythmic-location bar-num num den)
425 bar-num (ly:make-moment num den)))
427 (define-public (rhythmic-location? a)
430 (ly:moment? (cdr a))))
432 (define-public (make-graceless-rhythmic-location loc)
433 (make-rhythmic-location
435 (ly:moment-main-numerator (rhythmic-location-measure-position loc))
436 (ly:moment-main-denominator (rhythmic-location-measure-position loc))))
438 (define-public rhythmic-location-measure-position cdr)
439 (define-public rhythmic-location-bar-number car)
441 (define-public (rhythmic-location<? a b)
443 ((< (car a) (car b)) #t)
444 ((> (car a) (car b)) #f)
446 (ly:moment<? (cdr a) (cdr b)))))
448 (define-public (rhythmic-location<=? a b)
449 (not (rhythmic-location<? b a)))
450 (define-public (rhythmic-location>=? a b)
451 (not (rhythmic-location<? a b)))
452 (define-public (rhythmic-location>? a b)
453 (rhythmic-location<? b a))
455 (define-public (rhythmic-location=? a b)
456 (and (rhythmic-location<=? a b)
457 (rhythmic-location<=? b a)))
459 (define-public (rhythmic-location->file-string a)
460 (ly:format "~a.~a.~a"
462 (ly:moment-main-numerator (cdr a))
463 (ly:moment-main-denominator (cdr a))))
465 (define-public (rhythmic-location->string a)
466 (ly:format "bar ~a ~a"
468 (ly:moment->string (cdr a))))
470 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
473 (define-public all-visible #(#t #t #t))
474 (define-public begin-of-line-invisible #(#t #t #f))
475 (define-public center-invisible #(#t #f #t))
476 (define-public end-of-line-invisible #(#f #t #t))
477 (define-public begin-of-line-visible #(#f #f #t))
478 (define-public center-visible #(#f #t #f))
479 (define-public end-of-line-visible #(#t #f #f))
480 (define-public all-invisible #(#f #f #f))
482 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
483 ;; neighbor-interface routines
486 (define-public (shift-right-at-line-begin g)
487 "Shift an item to the right, but only at the start of the line."
488 (if (and (ly:item? g)
489 (equal? (ly:item-break-dir g) RIGHT))
490 (ly:grob-translate-axis! g 3.5 X)))
492 (define-public (pure-from-neighbor-interface::extra-spacing-height-at-beginning-of-line grob)
493 (if (= 1 (ly:item-break-dir grob))
494 (pure-from-neighbor-interface::extra-spacing-height grob)
497 (define-public (pure-from-neighbor-interface::extra-spacing-height grob)
498 (let* ((height (ly:grob-pure-height grob grob 0 INFINITY-INT))
499 (from-neighbors (interval-union
501 (ly:axis-group-interface::pure-height
505 (coord-operation - from-neighbors height)))
507 ;; If there are neighbors, we place the height at their midpoint
508 ;; to avoid protrusion of this pure height out of the vertical
509 ;; axis group on either side. This will minimize the impact of the
510 ;; grob on pure minimum translations.
512 ;; TODO - there is a double call to axis-group-interface::pure-height
513 ;; here and then in the extra-spacing-height function above. Can/should this
514 ;; be rolled into one?
515 (define-public (pure-from-neighbor-interface::pure-height grob beg end)
516 (let* ((height (ly:axis-group-interface::pure-height
520 (c (interval-center height)))
521 (if (interval-empty? height) empty-interval (cons c c))))
523 ;; Minimizes the impact of the height on vertical spacing while allowing
524 ;; it to appear in horizontal skylines of paper columns if necessary.
525 (define-public pure-from-neighbor-interface::height-if-pure
526 (ly:make-unpure-pure-container #f pure-from-neighbor-interface::pure-height))
528 (define-public (pure-from-neighbor-interface::account-for-span-bar grob)
529 (let* ((esh (pure-from-neighbor-interface::extra-spacing-height grob))
530 (hsb (ly:grob-property grob 'has-span-bar))
531 (ii (interval-intersection esh (cons -1.01 1.01))))
533 (cons (car (if (and (car hsb)
534 (ly:grob-property grob 'allow-span-bar))
536 (cdr (if (cdr hsb) esh ii)))
539 (define-public (pure-from-neighbor-interface::extra-spacing-height-including-staff grob)
540 (let ((esh (pure-from-neighbor-interface::extra-spacing-height grob))
541 (to-staff (coord-operation -
544 (ly:staff-symbol-staff-radius grob))
545 (ly:grob::stencil-height grob))))
546 (interval-union esh to-staff)))
549 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
552 (define-public (tuplet-number::calc-direction grob)
553 (ly:tuplet-bracket::calc-direction (ly:grob-object grob 'bracket)))
555 (define-public (tuplet-number::calc-denominator-text grob)
556 (number->string (ly:event-property (event-cause grob) 'denominator)))
558 (define-public (tuplet-number::calc-fraction-text grob)
559 (let ((ev (event-cause grob)))
562 (ly:event-property ev 'denominator)
563 (ly:event-property ev 'numerator))))
565 ;; a formatter function, which is simply a wrapper around an existing
566 ;; tuplet formatter function. It takes the value returned by the given
567 ;; function and appends a note of given length.
568 (define-public ((tuplet-number::append-note-wrapper function note) grob)
569 (let ((txt (if function (function grob) #f)))
572 (markup txt #:fontsize -5 #:note note UP)
573 (markup #:fontsize -5 #:note note UP))))
575 ;; Print a tuplet denominator with a different number than the one derived from
576 ;; the actual tuplet fraction
577 (define-public ((tuplet-number::non-default-tuplet-denominator-text denominator)
579 (number->string (if denominator
581 (ly:event-property (event-cause grob) 'denominator))))
583 ;; Print a tuplet fraction with different numbers than the ones derived from
584 ;; the actual tuplet fraction
585 (define-public ((tuplet-number::non-default-tuplet-fraction-text
586 denominator numerator) grob)
587 (let* ((ev (event-cause grob))
588 (den (if denominator denominator (ly:event-property ev 'denominator)))
589 (num (if numerator numerator (ly:event-property ev 'numerator))))
591 (format #f "~a:~a" den num)))
593 ;; Print a tuplet fraction with note durations appended to the numerator and the
595 (define-public ((tuplet-number::fraction-with-notes
596 denominatornote numeratornote) grob)
597 (let* ((ev (event-cause grob))
598 (denominator (ly:event-property ev 'denominator))
599 (numerator (ly:event-property ev 'numerator)))
601 ((tuplet-number::non-default-fraction-with-notes
602 denominator denominatornote numerator numeratornote) grob)))
604 ;; Print a tuplet fraction with note durations appended to the numerator and the
606 (define-public ((tuplet-number::non-default-fraction-with-notes
607 denominator denominatornote numerator numeratornote) grob)
608 (let* ((ev (event-cause grob))
609 (den (if denominator denominator (ly:event-property ev 'denominator)))
610 (num (if numerator numerator (ly:event-property ev 'numerator))))
612 (make-concat-markup (list
613 (make-simple-markup (format #f "~a" den))
614 (markup #:fontsize -5 #:note denominatornote UP)
615 (make-simple-markup " : ")
616 (make-simple-markup (format #f "~a" num))
617 (markup #:fontsize -5 #:note numeratornote UP)))))
620 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
623 (define-public (color? x)
626 (apply eq? #t (map number? x))
627 (apply eq? #t (map (lambda (y) (<= 0 y 1)) x))))
629 (define-public (rgb-color r g b) (list r g b))
632 (define-public black '(0.0 0.0 0.0))
633 (define-public white '(1.0 1.0 1.0))
634 (define-public red '(1.0 0.0 0.0))
635 (define-public green '(0.0 1.0 0.0))
636 (define-public blue '(0.0 0.0 1.0))
637 (define-public cyan '(0.0 1.0 1.0))
638 (define-public magenta '(1.0 0.0 1.0))
639 (define-public yellow '(1.0 1.0 0.0))
641 (define-public grey '(0.5 0.5 0.5))
642 (define-public darkred '(0.5 0.0 0.0))
643 (define-public darkgreen '(0.0 0.5 0.0))
644 (define-public darkblue '(0.0 0.0 0.5))
645 (define-public darkcyan '(0.0 0.5 0.5))
646 (define-public darkmagenta '(0.5 0.0 0.5))
647 (define-public darkyellow '(0.5 0.5 0.0))
650 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
653 (define-public (key-signature-interface::alteration-positions
654 entry c0-position grob)
655 (let ((step (car entry))
658 (list (+ (cdr step) (* (car step) 7) c0-position))
659 (let* ((c-position (modulo c0-position 7))
662 ;; See (flat|sharp)-positions in define-grob-properties.scm
663 (ly:grob-property grob 'flat-positions '(3))
664 (ly:grob-property grob 'sharp-positions '(3))))
665 (p (list-ref positions
666 (if (< c-position (length positions))
668 (max-position (if (pair? p) (cdr p) p))
669 (min-position (if (pair? p) (car p) (- max-position 6)))
670 (first-position (+ (modulo (- (+ c-position step)
674 (define (prepend x l) (if (> x max-position)
676 (prepend (+ x 7) (cons x l))))
677 (prepend first-position '())))))
679 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
682 (define-public (numbered-footnotes int)
683 (markup #:tiny (number->string (+ 1 int))))
685 (define-public (symbol-footnotes int)
686 (define (helper symbols out idx n)
690 (string-append out (list-ref symbols idx))
693 (markup #:tiny (helper '("*" "†" "‡" "§" "¶")
696 (+ 1 (quotient int 5)))))
698 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
701 (define-public (accidental-interface::calc-alteration grob)
702 (ly:pitch-alteration (ly:event-property (event-cause grob) 'pitch)))
704 (define-public (accidental-interface::glyph-name grob)
705 (assoc-get (ly:grob-property grob 'alteration)
706 standard-alteration-glyph-name-alist))
708 (define-public accidental-interface::height
709 (ly:make-unpure-pure-container
710 ly:accidental-interface::height
711 ly:accidental-interface::pure-height))
713 (define-public cancellation-glyph-name-alist
714 '((0 . "accidentals.natural")))
716 (define-public standard-alteration-glyph-name-alist
718 ;; ordered for optimal performance.
719 (0 . "accidentals.natural")
720 (-1/2 . "accidentals.flat")
721 (1/2 . "accidentals.sharp")
723 (1 . "accidentals.doublesharp")
724 (-1 . "accidentals.flatflat")
726 (3/4 . "accidentals.sharp.slashslash.stemstemstem")
727 (1/4 . "accidentals.sharp.slashslash.stem")
728 (-1/4 . "accidentals.mirroredflat")
729 (-3/4 . "accidentals.mirroredflat.flat")))
731 ;; FIXME: standard vs default, alteration-FOO vs FOO-alteration
732 (define-public alteration-default-glyph-name-alist
733 standard-alteration-glyph-name-alist)
735 (define-public makam-alteration-glyph-name-alist
736 '((1 . "accidentals.doublesharp")
737 (8/9 . "accidentals.sharp.slashslashslash.stemstem")
738 (5/9 . "accidentals.sharp.slashslashslash.stem")
739 (4/9 . "accidentals.sharp")
740 (1/9 . "accidentals.sharp.slashslash.stem")
741 (0 . "accidentals.natural")
742 (-1/9 . "accidentals.mirroredflat")
743 (-4/9 . "accidentals.flat.slash")
744 (-5/9 . "accidentals.flat")
745 (-8/9 . "accidentals.flat.slashslash")
746 (-1 . "accidentals.flatflat")))
748 (define-public alteration-hufnagel-glyph-name-alist
749 '((-1/2 . "accidentals.hufnagelM1")
750 (0 . "accidentals.vaticana0")
751 (1/2 . "accidentals.mensural1")))
753 (define-public alteration-medicaea-glyph-name-alist
754 '((-1/2 . "accidentals.medicaeaM1")
755 (0 . "accidentals.vaticana0")
756 (1/2 . "accidentals.mensural1")))
758 (define-public alteration-vaticana-glyph-name-alist
759 '((-1/2 . "accidentals.vaticanaM1")
760 (0 . "accidentals.vaticana0")
761 (1/2 . "accidentals.mensural1")))
763 (define-public alteration-mensural-glyph-name-alist
764 '((-1/2 . "accidentals.mensuralM1")
765 (0 . "accidentals.vaticana0")
766 (1/2 . "accidentals.mensural1")))
768 (define-public alteration-kievan-glyph-name-alist
769 '((-1/2 . "accidentals.kievanM1")
770 (1/2 . "accidentals.kievan1")))
772 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
773 ;; * Pitch Trill Heads
776 (define-public (parentheses-item::calc-parenthesis-stencils grob)
777 (let* ((font (ly:grob-default-font grob))
778 (lp (ly:font-get-glyph font "accidentals.leftparen"))
779 (rp (ly:font-get-glyph font "accidentals.rightparen")))
783 (define-public (parentheses-item::calc-angled-bracket-stencils grob)
784 (let* ((parent (ly:grob-parent grob Y))
785 (y-extent (ly:grob-extent parent parent Y))
786 (half-thickness 0.05) ; should it be a property?
787 (width 0.5) ; should it be a property?
788 (angularity 1.5) ; makes angle brackets
789 (white-padding 0.1) ; should it be a property?
790 (lp (ly:stencil-aligned-to
791 (ly:stencil-aligned-to
792 (make-parenthesis-stencil y-extent
799 (interval-widen (ly:stencil-extent lp X) white-padding))
800 (rp (ly:stencil-aligned-to
801 (ly:stencil-aligned-to
802 (make-parenthesis-stencil y-extent
809 (interval-widen (ly:stencil-extent rp X) white-padding)))
810 (set! lp (ly:make-stencil (ly:stencil-expr lp)
812 (ly:stencil-extent lp Y)))
813 (set! rp (ly:make-stencil (ly:stencil-expr rp)
815 (ly:stencil-extent rp Y)))
816 (list (stencil-whiteout lp)
817 (stencil-whiteout rp))))
819 (define (parenthesize-elements grob . rest)
820 (let* ((refp (if (null? rest)
823 (elts (ly:grob-object grob 'elements))
824 (x-ext (ly:relative-group-extent elts refp X))
825 (stencils (ly:grob-property grob 'stencils))
828 (padding (ly:grob-property grob 'padding 0.1)))
831 (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
832 (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))))
835 (define-public (parentheses-item::print me)
836 (let* ((elts (ly:grob-object me 'elements))
837 (y-ref (ly:grob-common-refpoint-of-array me elts Y))
838 (x-ref (ly:grob-common-refpoint-of-array me elts X))
839 (stencil (parenthesize-elements me x-ref))
840 (elt-y-ext (ly:relative-group-extent elts y-ref Y))
841 (y-center (interval-center elt-y-ext)))
843 (ly:stencil-translate
846 (- (ly:grob-relative-coordinate me x-ref X))
847 (- y-center (ly:grob-relative-coordinate me y-ref Y))))))
850 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
853 (define-public (pure-chain-offset-callback grob start end prev-offset)
854 "Sometimes, a chained offset callback is unpure and there is
855 no way to write a pure function that estimates its behavior.
856 In this case, we use a pure equivalent that will simply pass
857 the previous calculated offset value."
860 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
863 (define-public (chain-grob-member-functions grob value . funcs)
866 (set! value (func grob value)))
872 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
875 (define-public (bend::print spanner)
877 (< (abs (- a b)) 0.01))
879 (let* ((delta-y (* 0.5 (ly:grob-property spanner 'delta-position)))
880 (left-span (ly:spanner-bound spanner LEFT))
881 (dots (if (and (grob::has-interface left-span 'note-head-interface)
882 (ly:grob? (ly:grob-object left-span 'dot)))
883 (ly:grob-object left-span 'dot) #f))
885 (right-span (ly:spanner-bound spanner RIGHT))
886 (thickness (* (ly:grob-property spanner 'thickness)
887 (ly:output-def-lookup (ly:grob-layout spanner)
889 (padding (ly:grob-property spanner 'padding 0.5))
890 (common (ly:grob-common-refpoint right-span
891 (ly:grob-common-refpoint spanner
894 (common-y (ly:grob-common-refpoint spanner left-span Y))
895 (minimum-length (ly:grob-property spanner 'minimum-length 0.5))
899 (interval-end (ly:grob-robust-relative-extent
904 (ly:grob-relative-coordinate dots common-y Y)
905 (ly:grob-relative-coordinate spanner common-y Y)))
907 (ly:grob-robust-relative-extent dots common X))
909 (right-x (max (- (interval-start
910 (ly:grob-robust-relative-extent right-span common X))
912 (+ left-x minimum-length)))
913 (self-x (ly:grob-relative-coordinate spanner common X))
914 (dx (- right-x left-x))
915 (exp (list 'path thickness
923 ,dx ,(* 0.66 delta-y)
928 (cons (- left-x self-x) (- right-x self-x))
929 (cons (min 0 delta-y)
933 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
936 (define-public (grace-spacing::calc-shortest-duration grob)
937 (let* ((cols (ly:grob-object grob 'columns))
940 (ly:moment-sub (ly:grob-property
941 (ly:grob-array-ref cols (1+ idx)) 'when)
943 (ly:grob-array-ref cols idx) 'when))))
945 (moment-min (lambda (x y)
948 (if (ly:moment<? x y)
954 (fold moment-min #f (map get-difference
955 (iota (1- (ly:grob-array-length cols)))))))
958 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
961 (define-public (fingering::calc-text grob)
962 (let ((event (event-cause grob)))
963 (or (ly:event-property event 'text #f)
964 (number->string (ly:event-property event 'digit) 10))))
966 (define-public (string-number::calc-text grob)
967 (let ((event (event-cause grob)))
968 (or (ly:event-property event 'text #f)
969 (number->string (ly:event-property event 'string-number) 10))))
971 (define-public (stroke-finger::calc-text grob)
972 (let ((event (event-cause grob)))
973 (or (ly:event-property event 'text #f)
974 (vector-ref (ly:grob-property grob 'digit-names)
976 (min 5 (ly:event-property event 'digit))))))))
979 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
982 (define-public (hairpin::calc-grow-direction grob)
983 (if (ly:in-event-class? (event-cause grob) 'decrescendo-event)
987 (define-public (dynamic-text-spanner::before-line-breaking grob)
988 "Monitor left bound of @code{DynamicTextSpanner} for absolute dynamics.
989 If found, ensure @code{DynamicText} does not collide with spanner text by
990 changing @code{'attach-dir} and @code{'padding}. Reads the
991 @code{'right-padding} property of @code{DynamicText} to fine tune space
992 between the two text elements."
993 (let ((left-bound (ly:spanner-bound grob LEFT)))
994 (if (grob::has-interface left-bound 'dynamic-text-interface)
995 (let* ((details (ly:grob-property grob 'bound-details))
996 (left-details (ly:assoc-get 'left details))
997 (my-padding (ly:assoc-get 'padding left-details))
998 (script-padding (ly:grob-property left-bound 'right-padding 0)))
1000 (and (number? my-padding)
1001 (ly:grob-set-nested-property! grob
1002 '(bound-details left attach-dir)
1004 (ly:grob-set-nested-property! grob
1005 '(bound-details left padding)
1006 (+ my-padding script-padding)))))))
1008 (define-public ((elbowed-hairpin coords mirrored?) grob)
1009 "Create hairpin based on a list of @var{coords} in @code{(cons x y)}
1010 form. @code{x} is the portion of the width consumed for a given line
1011 and @code{y} is the portion of the height. For example,
1012 @code{'((0.3 . 0.7) (0.8 . 0.9) (1.0 . 1.0))} means that at the point
1013 where the hairpin has consumed 30% of its width, it must
1014 be at 70% of its height. Once it is to 80% width, it
1015 must be at 90% height. It finishes at
1016 100% width and 100% height. @var{mirrored?} indicates if the hairpin
1017 is mirrored over the Y-axis or if just the upper part is drawn.
1018 Returns a function that accepts a hairpin grob as an argument
1019 and draws the stencil based on its coordinates.
1020 @lilypond[verbatim,quote]
1021 #(define simple-hairpin
1022 (elbowed-hairpin '((1.0 . 1.0)) #t))
1025 \\override Hairpin #'stencil = #simple-hairpin
1030 (define (pair-to-list pair)
1031 (list (car pair) (cdr pair)))
1032 (define (normalize-coords goods x y)
1035 (cons (* x (car coord)) (* y (cdr coord))))
1037 (define (my-c-p-s points thick decresc?)
1038 (make-connected-path-stencil
1041 (if decresc? -1.0 1.0)
1045 ; outer let to trigger suicide
1046 (let ((sten (ly:hairpin::print grob)))
1047 (if (grob::is-live? grob)
1048 (let* ((decresc? (eq? (ly:grob-property grob 'grow-direction) LEFT))
1049 (thick (ly:grob-property grob 'thickness 0.1))
1050 (thick (* thick (layout-line-thickness grob)))
1051 (xex (ly:stencil-extent sten X))
1052 (lenx (interval-length xex))
1053 (yex (ly:stencil-extent sten Y))
1054 (leny (interval-length yex))
1055 (xtrans (+ (car xex) (if decresc? lenx 0)))
1057 (uplist (map pair-to-list
1058 (normalize-coords coords lenx (/ leny 2))))
1059 (downlist (map pair-to-list
1060 (normalize-coords coords lenx (/ leny -2)))))
1061 (ly:stencil-translate
1063 (my-c-p-s uplist thick decresc?)
1064 (if mirrored? (my-c-p-s downlist thick decresc?) empty-stencil))
1065 (cons xtrans ytrans)))
1068 (define-public flared-hairpin
1069 (elbowed-hairpin '((0.95 . 0.4) (1.0 . 1.0)) #t))
1071 (define-public constante-hairpin
1072 (elbowed-hairpin '((1.0 . 0.0) (1.0 . 1.0)) #f))
1074 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1077 (define-public (lyric-text::print grob)
1078 "Allow interpretation of tildes as lyric tieing marks."
1080 (let ((text (ly:grob-property grob 'text)))
1082 (grob-interpret-markup grob (if (string? text)
1083 (make-tied-lyric-markup text)
1086 (define-public ((grob::calc-property-by-copy prop) grob)
1087 (ly:event-property (event-cause grob) prop))
1089 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1090 ;; general inheritance
1092 (define-public ((grob::inherit-parent-property axis property . default) grob)
1093 "@var{grob} callback generator for inheriting a @var{property} from
1094 an @var{axis} parent, defaulting to @var{default} if there is no
1095 parent or the parent has no setting."
1096 (let ((parent (ly:grob-parent grob axis)))
1099 (apply ly:grob-property parent property default))
1100 ((pair? default) (car default))
1103 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1106 (define-public (fret-board::calc-stencil grob)
1107 (grob-interpret-markup
1109 (make-fret-diagram-verbose-markup
1110 (ly:grob-property grob 'dot-placement-list))))
1113 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1116 (define-public slur::height
1117 (ly:make-unpure-pure-container
1119 ly:slur::pure-height))
1121 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1124 (define-public (script-interface::calc-x-offset grob)
1125 (ly:grob-property grob 'positioning-done)
1126 (let* ((shift (ly:grob-property grob 'toward-stem-shift 0.0))
1128 (ly:self-alignment-interface::centered-on-x-parent grob))
1129 (note-head-grob (ly:grob-parent grob X))
1130 (stem-grob (ly:grob-object note-head-grob 'stem)))
1132 (+ note-head-location
1133 ;; If the property 'toward-stem-shift is defined and the script
1134 ;; has the same direction as the stem, move the script accordingly.
1135 ;; Since scripts can also be over skips, we need to check whether
1136 ;; the grob has a stem at all.
1137 (if (ly:grob? stem-grob)
1138 (let ((dir1 (ly:grob-property grob 'direction))
1139 (dir2 (ly:grob-property stem-grob 'direction)))
1140 (if (equal? dir1 dir2)
1141 (let* ((common-refp (ly:grob-common-refpoint grob stem-grob X))
1143 (ly:grob-relative-coordinate stem-grob common-refp X)))
1144 (* shift (- stem-location note-head-location)))
1149 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1152 (define-public (system-start-text::print grob)
1153 (let* ((left-bound (ly:spanner-bound grob LEFT))
1154 (left-mom (ly:grob-property left-bound 'when))
1155 (name (if (moment<=? left-mom ZERO-MOMENT)
1156 (ly:grob-property grob 'long-text)
1157 (ly:grob-property grob 'text))))
1159 (if (and (markup? name)
1160 (!= (ly:item-break-dir left-bound) CENTER))
1162 (grob-interpret-markup grob name)
1163 (ly:grob-suicide! grob))))
1165 (define-public (system-start-text::calc-x-offset grob)
1166 (let* ((left-bound (ly:spanner-bound grob LEFT))
1167 (left-mom (ly:grob-property left-bound 'when))
1168 (layout (ly:grob-layout grob))
1169 (indent (ly:output-def-lookup layout
1170 (if (moment<=? left-mom ZERO-MOMENT)
1174 (system (ly:grob-system grob))
1175 (my-extent (ly:grob-extent grob system X))
1176 (elements (ly:grob-object system 'elements))
1177 (common (ly:grob-common-refpoint-of-array system elements X))
1178 (total-ext empty-interval)
1179 (align-x (ly:grob-property grob 'self-alignment-X 0))
1180 (padding (min 0 (- (interval-length my-extent) indent)))
1181 (right-padding (- padding
1182 (/ (* padding (1+ align-x)) 2))))
1184 ;; compensate for the variation in delimiter extents by
1185 ;; calculating an X-offset correction based on united extents
1186 ;; of all delimiters in this system
1187 (let unite-delims ((l (ly:grob-array-length elements)))
1189 (let ((elt (ly:grob-array-ref elements (1- l))))
1191 (if (grob::has-interface elt 'system-start-delimiter-interface)
1192 (let ((dims (ly:grob-extent elt common X)))
1193 (if (interval-sane? dims)
1194 (set! total-ext (interval-union total-ext dims)))))
1195 (unite-delims (1- l)))))
1198 (ly:side-position-interface::x-aligned-side grob)
1200 (- (interval-length total-ext)))))
1202 (define-public (system-start-text::calc-y-offset grob)
1204 (define (live-elements-list me)
1205 (let ((elements (ly:grob-object me 'elements)))
1207 (filter! grob::is-live?
1208 (ly:grob-array->list elements))))
1210 (let* ((left-bound (ly:spanner-bound grob LEFT))
1211 (live-elts (live-elements-list grob))
1212 (system (ly:grob-system grob))
1213 (extent empty-interval))
1215 (if (and (pair? live-elts)
1216 (interval-sane? (ly:grob-extent grob system Y)))
1217 (let get-extent ((lst live-elts))
1219 (let ((axis-group (car lst)))
1221 (if (and (ly:spanner? axis-group)
1222 (equal? (ly:spanner-bound axis-group LEFT)
1224 (set! extent (add-point extent
1225 (ly:grob-relative-coordinate
1226 axis-group system Y))))
1227 (get-extent (cdr lst)))))
1228 ;; no live axis group(s) for this instrument name -> remove from system
1229 (ly:grob-suicide! grob))
1232 (ly:self-alignment-interface::y-aligned-on-self grob)
1233 (interval-center extent))))
1236 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1237 ;; axis group interface
1239 (define-public axis-group-interface::height
1240 (ly:make-unpure-pure-container
1241 ly:axis-group-interface::height
1242 ly:axis-group-interface::pure-height))
1244 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1247 (define-public (ambitus::print grob)
1248 (let ((heads (ly:grob-object grob 'note-heads)))
1250 (if (and (ly:grob-array? heads)
1251 (= (ly:grob-array-length heads) 2))
1252 (let* ((common (ly:grob-common-refpoint-of-array grob heads Y))
1253 (head-down (ly:grob-array-ref heads 0))
1254 (head-up (ly:grob-array-ref heads 1))
1255 (gap (ly:grob-property grob 'gap 0.35))
1256 (point-min (+ (interval-end (ly:grob-extent head-down common Y))
1258 (point-max (- (interval-start (ly:grob-extent head-up common Y))
1261 (if (< point-min point-max)
1262 (let* ((layout (ly:grob-layout grob))
1263 (line-thick (ly:output-def-lookup layout 'line-thickness))
1264 (blot (ly:output-def-lookup layout 'blot-diameter))
1265 (grob-thick (ly:grob-property grob 'thickness 2))
1266 (width (* line-thick grob-thick))
1267 (x-ext (symmetric-interval (/ width 2)))
1268 (y-ext (cons point-min point-max))
1269 (line (ly:round-filled-box x-ext y-ext blot))
1270 (y-coord (ly:grob-relative-coordinate grob common Y)))
1272 (ly:stencil-translate-axis line (- y-coord) Y))
1275 (ly:grob-suicide! grob)
1278 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1279 ;; laissez-vibrer tie
1281 ;; needed so we can make laissez-vibrer a pure print
1283 (define-public (laissez-vibrer::print grob)
1284 (ly:tie::print grob))
1286 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1289 (define-public (volta-bracket-interface::pure-height grob start end)
1290 (let ((edge-height (ly:grob-property grob 'edge-height)))
1291 (if (number-pair? edge-height)
1292 (let ((smaller (min (car edge-height) (cdr edge-height)))
1293 (larger (max (car edge-height) (cdr edge-height))))
1294 (interval-union '(0 . 0) (cons smaller larger)))