]> git.donarmstrong.com Git - lilypond.git/blob - scm/output-lib.scm
Uses only unpure-pure containers to articulate unpure-pure relationships (issue 3199)
[lilypond.git] / scm / output-lib.scm
1 ;;;; This file is part of LilyPond, the GNU music typesetter.
2 ;;;;
3 ;;;; Copyright (C) 1998--2012 Jan Nieuwenhuizen <janneke@gnu.org>
4 ;;;; Han-Wen Nienhuys <hanwen@xs4all.nl>
5 ;;;;
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.
10 ;;;;
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.
15 ;;;;
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/>.
18
19
20 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
21 ;; general
22
23 (define-public (grob::has-interface grob iface)
24   (memq iface (ly:grob-interfaces grob)))
25
26 (define-public (grob::is-live? grob)
27   (pair? (ly:grob-basic-properties grob)))
28
29 (define-public (grob::x-parent-width grob)
30   (ly:grob-property (ly:grob-parent grob X) 'X-extent))
31
32 (define-public (make-stencil-boxer thickness padding callback)
33   "Return function that adds a box around the grob passed as argument."
34   (lambda (grob)
35     (box-stencil (callback grob) thickness padding)))
36
37 (define-public (make-stencil-circler thickness padding callback)
38   "Return function that adds a circle around the grob passed as argument."
39   (lambda (grob)
40     (circle-stencil (callback grob) thickness padding)))
41
42 (define-public (print-circled-text-callback grob)
43   (grob-interpret-markup grob (make-circle-markup
44                                (ly:grob-property grob 'text))))
45
46 (define-public (event-cause grob)
47   (let ((cause (ly:grob-property  grob 'cause)))
48
49     (cond
50      ((ly:stream-event? cause) cause)
51      ((ly:grob? cause) (event-cause cause))
52      (else #f))))
53
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)))
58
59     (ly:text-interface::interpret-markup layout props text)))
60
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))
65
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))
70
71 (define-public grob::always-horizontal-skylines-from-stencil
72   (ly:make-unpure-pure-container
73     ly:grob::horizontal-skylines-from-stencil))
74
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))
79
80 (define-public grob::always-vertical-skylines-from-stencil
81   (ly:make-unpure-pure-container
82     ly:grob::vertical-skylines-from-stencil))
83
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))
88
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))
93
94 ;; Sometimes, in horizontal spacing, we want grobs to block other grobs.
95 ;; They thus need to have a non-empty height.  We give them a point height
96 ;; so that, minimally, they block grobs directly to the right of them.
97 ;; Often this is complimented by an extra-spacing-height.
98 ;; We don't, however, want these grobs to factor into vertical spacing
99 ;; decisions, so we make their unpure height #f.
100
101 ;; Using this as a callback for a grob's Y-extent promises
102 ;; that the grob's stencil does not depend on line-spacing.
103 ;; We use this promise to figure the space required by Clefs
104 ;; and such at the note-spacing stage.
105
106 (define-public grob::always-Y-extent-from-stencil
107   (ly:make-unpure-pure-container ly:grob::stencil-height))
108
109 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
110 ;; beam slope
111
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)
121                                '()))
122          (first-note-head (if (not (null? note-heads-grobs))
123                               (car note-heads-grobs)
124                               '()))
125          (note-head-w (if (not (null? first-note-head))
126                           (ly:grob-extent first-note-head first-note-head X)
127                           '(0 . 0))))
128     (interval-center note-head-w)))
129
130
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)
136                           '()))
137          (first-stem (if (not (null? stems-grobs))
138                          (car stems-grobs)
139                          '()))
140          (note-heads (if (not (null? first-stem))
141                          (ly:grob-object first-stem 'note-heads)
142                          '()))
143          (note-heads-grobs (if (not (null? note-heads))
144                                (ly:grob-array->list note-heads)
145                                '()))
146          (first-note-head (if (not (null? note-heads-grobs))
147                               (car note-heads-grobs)
148                               '()))
149          (next-stem (if (not (null? stems))
150                         (cadr stems-grobs)
151                         '()))
152          (next-note-heads (if (not (null? next-stem))
153                               (ly:grob-object next-stem 'note-heads)
154                               '()))
155          (next-note-heads-grobs (if (not (null? next-note-heads))
156                                     (ly:grob-array->list next-note-heads)
157                                     '()))
158          (next-note-head (if (not (null? next-note-heads-grobs))
159                              (car next-note-heads-grobs)
160                              '()))
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))))
173
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)
179                           '())))
180     (for-each
181       (lambda (g)
182         (ly:grob-set-property! g 'stem-begin-position 0)
183         (ly:grob-set-property! g 'length 0))
184       stems-grobs)
185     pos))
186
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))
190
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))
196
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)
202   (define (slope y x)
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)
208                        '())))
209     (if (null? siblings)
210         quant1
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)))
216                            '(0 . 0)
217                            quant2))
218                (factor (/ (atan (abs slope1)) PI-OVER-TWO))
219                (base (cons-map
220                        (lambda (x)
221                          (+ (* (x quant1) (- 1 factor))
222                             (* (x quant2) factor)))
223                        (cons car cdr))))
224           (ly:beam::quanting grob base #f)))))
225
226 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
227 ;; cross-staff stuff
228
229 (define-public (script-or-side-position-cross-staff g)
230   (or
231    (ly:script-interface::calc-cross-staff g)
232    (ly:side-position-interface::calc-cross-staff g)))
233
234
235 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
236 ;; side-position stuff
237
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))))
241
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))
246
247 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
248 ;; self-alignment stuff
249
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))
254
255 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
256 ;; staff symbol
257
258 (define staff-symbol-referencer::callback
259   (ly:make-unpure-pure-container ly:staff-symbol-referencer::callback))
260
261 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
262 ;; note heads
263
264 (define-public (stem::calc-duration-log grob)
265   (ly:duration-log
266    (ly:event-property (event-cause grob) 'duration)))
267
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))))
271
272 (define-public (stem-stub::pure-height grob beg end)
273   (if (stem-stub::do-calculations grob)
274       '(0 . 0)
275       '(+inf.0 . -inf.0)))
276
277 (define-public (stem-stub::width grob)
278   (if (stem-stub::do-calculations grob)
279       (grob::x-parent-width grob)
280       '(+inf.0 . -inf.0)))
281
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 1000000))
287              (my_ph (ly:grob-pure-height grob refp 0 1000000))
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)
290                        0
291                        (- (car my_ph) (car stem_ph)))))
292         (if (interval-empty? (interval-intersection stem_ph my_ph)) #f (coord-translate stem_ph dist)))
293       #f))
294
295 (define-public (note-head::calc-kievan-duration-log grob)
296   (min 3
297        (ly:duration-log
298          (ly:event-property (event-cause grob) 'duration))))
299
300 (define-public (note-head::calc-duration-log grob)
301   (min 2
302        (ly:duration-log
303          (ly:event-property (event-cause grob) 'duration))))
304
305 (define-public (dots::calc-dot-count grob)
306   (ly:duration-dot-count
307    (ly:event-property (event-cause grob) 'duration)))
308
309 (define-public (dots::calc-staff-position grob)
310   (let* ((head (ly:grob-parent grob Y))
311          (log (ly:grob-property head 'duration-log)))
312
313     (cond
314      ((or (not (grob::has-interface head 'rest-interface))
315           (not (integer? log))) 0)
316      ((= log 7) 4)
317      ((> log 4) 3)
318      ((= log 0) -1)
319      ((= log 1) 1)
320      ((= log -1) 1)
321      (else 0))))
322
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}."
328   (case style
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
332     ;; statement.  -- jr
333     ((xcircle) "2xcircle")
334     ((harmonic) "0harmonic")
335     ((harmonic-black) "2harmonic")
336     ((harmonic-mixed) (if (<= log 1) "0harmonic"
337                           "2harmonic"))
338     ((baroque)
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
343      (if (< log 0)
344          (string-append (number->string log) "neomensural")
345          (number->string log)))
346     ((altdefault)
347      ;; Like default, but brevis is drawn with double vertical lines
348      (if (= log -1)
349          (string-append (number->string log) "double")
350          (number->string log)))
351     ((mensural)
352      (string-append (number->string log) (symbol->string style)))
353     ((petrucci)
354      (if (< log 0)
355          (string-append (number->string log) "mensural")
356          (string-append (number->string log) (symbol->string style))))
357     ((blackpetrucci)
358      (if (< log 0)
359          (string-append (number->string log) "blackmensural")
360          (string-append (number->string log) (symbol->string style))))
361     ((semipetrucci)
362      (if (< log 0)
363          (string-append (number->string log) "semimensural")
364          (string-append (number->string log) "petrucci")))
365     ((neomensural)
366      (string-append (number->string log) (symbol->string style)))
367     ((kievan)
368      (string-append (number->string log) "kievan"))
369     (else
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))))))
374
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)))
381
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)
390                            (string
391                             (integer->char
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)
399                                 1.3)
400                             line-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)))
404
405     (ly:stencil-translate-axis
406      (grob-interpret-markup
407       grob
408       (if (>= log 2)
409           (make-combine-markup
410            filled-circle
411            (make-with-color-markup white letter))
412           (make-combine-markup
413            (make-combine-markup
414             filled-circle
415             (make-with-color-markup white (make-draw-circle-markup
416                                            (- radius stem-thickness) 0 #t)))
417            letter)))
418      radius X)))
419
420 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
421 ;; clipping
422
423 (define-public (make-rhythmic-location bar-num num den)
424   (cons
425    bar-num (ly:make-moment num den)))
426
427 (define-public (rhythmic-location? a)
428   (and (pair? a)
429        (integer? (car a))
430        (ly:moment? (cdr a))))
431
432 (define-public (make-graceless-rhythmic-location loc)
433   (make-rhythmic-location
434    (car loc)
435    (ly:moment-main-numerator (rhythmic-location-measure-position loc))
436    (ly:moment-main-denominator (rhythmic-location-measure-position loc))))
437
438 (define-public rhythmic-location-measure-position cdr)
439 (define-public rhythmic-location-bar-number car)
440
441 (define-public (rhythmic-location<? a b)
442   (cond
443    ((< (car a) (car b)) #t)
444    ((> (car a) (car b)) #f)
445    (else
446     (ly:moment<? (cdr a) (cdr b)))))
447
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))
454
455 (define-public (rhythmic-location=? a b)
456   (and (rhythmic-location<=? a b)
457        (rhythmic-location<=? b a)))
458
459 (define-public (rhythmic-location->file-string a)
460   (ly:format "~a.~a.~a"
461              (car a)
462              (ly:moment-main-numerator (cdr a))
463              (ly:moment-main-denominator (cdr a))))
464
465 (define-public (rhythmic-location->string a)
466   (ly:format "bar ~a ~a"
467              (car a)
468              (ly:moment->string (cdr a))))
469
470 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
471 ;; break visibility
472
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))
481 (define-public (inherit-x-parent-visibility grob)
482   (let ((parent (ly:grob-parent grob X)))
483     (ly:grob-property parent 'break-visibility all-invisible)))
484 (define-public (inherit-y-parent-visibility grob)
485   (let ((parent (ly:grob-parent grob X)))
486     (ly:grob-property parent 'break-visibility)))
487
488
489 (define-public spanbar-begin-of-line-invisible #(#t #f #f))
490
491
492 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
493 ;; neighbor-interface routines
494
495
496 (define-public (shift-right-at-line-begin g)
497   "Shift an item to the right, but only at the start of the line."
498   (if (and (ly:item? g)
499            (equal? (ly:item-break-dir g) RIGHT))
500       (ly:grob-translate-axis! g 3.5 X)))
501
502 (define-public (pure-from-neighbor-interface::extra-spacing-height-at-beginning-of-line grob)
503   (if (= 1 (ly:item-break-dir grob))
504       (pure-from-neighbor-interface::extra-spacing-height grob)
505       (cons -0.1 0.1)))
506
507 (define-public (pure-from-neighbor-interface::extra-spacing-height grob)
508   (let* ((height (ly:grob-pure-height grob grob 0 10000000))
509          (from-neighbors (interval-union
510                             height
511                             (ly:axis-group-interface::pure-height
512                               grob
513                               0
514                               10000000))))
515     (coord-operation - from-neighbors height)))
516
517 ;; If there are neighbors, we place the height at their midpoint
518 ;; to avoid protrusion of this pure height out of the vertical
519 ;; axis group on either side.  This will minimize the impact of the
520 ;; grob on pure minimum translations.
521
522 ;; TODO - there is a double call to axis-group-interface::pure-height
523 ;; here and then in the extra-spacing-height function above. Can/should this
524 ;; be rolled into one?
525 (define-public (pure-from-neighbor-interface::pure-height grob beg end)
526   (let* ((height (ly:axis-group-interface::pure-height
527                   grob
528                   0
529                   10000000))
530          (c (interval-center height)))
531     (if (interval-empty? height) empty-interval (cons c c))))
532
533 ;; Minimizes the impact of the height on vertical spacing while allowing
534 ;; it to appear in horizontal skylines of paper columns if necessary.
535 (define-public pure-from-neighbor-interface::unobtrusive-height
536   (ly:make-unpure-pure-container #f pure-from-neighbor-interface::pure-height))
537
538 (define-public (pure-from-neighbor-interface::account-for-span-bar grob)
539   (let* ((esh (pure-from-neighbor-interface::extra-spacing-height grob))
540          (hsb (ly:grob-property grob 'has-span-bar))
541          (ii (interval-intersection esh (cons -1.01 1.01))))
542     (if (pair? hsb)
543         (cons (car (if (and (car hsb)
544                        (ly:grob-property grob 'allow-span-bar))
545                        esh ii))
546               (cdr (if (cdr hsb) esh ii)))
547         ii)))
548
549 (define-public (pure-from-neighbor-interface::extra-spacing-height-including-staff grob)
550   (let ((esh (pure-from-neighbor-interface::extra-spacing-height grob))
551         (to-staff (coord-operation -
552                                    (interval-widen
553                                      '(0 . 0)
554                                      (ly:staff-symbol-staff-radius grob))
555                                    (ly:grob::stencil-height grob))))
556     (interval-union esh to-staff)))
557
558
559 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
560 ;; Tuplets
561
562 (define-public (tuplet-number::calc-direction grob)
563   (ly:tuplet-bracket::calc-direction (ly:grob-object grob 'bracket)))
564
565 (define-public (tuplet-number::calc-denominator-text grob)
566   (number->string (ly:event-property (event-cause grob) 'denominator)))
567
568 (define-public (tuplet-number::calc-fraction-text grob)
569   (let ((ev (event-cause grob)))
570
571     (format #f "~a:~a"
572             (ly:event-property ev 'denominator)
573             (ly:event-property ev 'numerator))))
574
575 ;; a formatter function, which is simply a wrapper around an existing
576 ;; tuplet formatter function. It takes the value returned by the given
577 ;; function and appends a note of given length.
578 (define-public ((tuplet-number::append-note-wrapper function note) grob)
579   (let ((txt (if function (function grob) #f)))
580
581     (if txt
582         (markup txt #:fontsize -5 #:note note UP)
583         (markup #:fontsize -5 #:note note UP))))
584
585 ;; Print a tuplet denominator with a different number than the one derived from
586 ;; the actual tuplet fraction
587 (define-public ((tuplet-number::non-default-tuplet-denominator-text denominator)
588                 grob)
589   (number->string (if denominator
590                       denominator
591                       (ly:event-property (event-cause grob) 'denominator))))
592
593 ;; Print a tuplet fraction with different numbers than the ones derived from
594 ;; the actual tuplet fraction
595 (define-public ((tuplet-number::non-default-tuplet-fraction-text
596                  denominator numerator) grob)
597   (let* ((ev (event-cause grob))
598          (den (if denominator denominator (ly:event-property ev 'denominator)))
599          (num (if numerator numerator (ly:event-property ev 'numerator))))
600
601     (format #f "~a:~a" den num)))
602
603 ;; Print a tuplet fraction with note durations appended to the numerator and the
604 ;; denominator
605 (define-public ((tuplet-number::fraction-with-notes
606                  denominatornote numeratornote) grob)
607   (let* ((ev (event-cause grob))
608          (denominator (ly:event-property ev 'denominator))
609          (numerator (ly:event-property ev 'numerator)))
610
611     ((tuplet-number::non-default-fraction-with-notes
612       denominator denominatornote numerator numeratornote) grob)))
613
614 ;; Print a tuplet fraction with note durations appended to the numerator and the
615 ;; denominator
616 (define-public ((tuplet-number::non-default-fraction-with-notes
617                  denominator denominatornote numerator numeratornote) grob)
618   (let* ((ev (event-cause grob))
619          (den (if denominator denominator (ly:event-property ev 'denominator)))
620          (num (if numerator numerator (ly:event-property ev 'numerator))))
621
622     (make-concat-markup (list
623                          (make-simple-markup (format #f "~a" den))
624                          (markup #:fontsize -5 #:note denominatornote UP)
625                          (make-simple-markup " : ")
626                          (make-simple-markup (format #f "~a" num))
627                          (markup #:fontsize -5 #:note numeratornote UP)))))
628
629
630 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
631 ;; Color
632
633 (define-public (color? x)
634   (and (list? x)
635        (= 3 (length x))
636        (apply eq? #t (map number? x))
637        (apply eq? #t (map (lambda (y) (<= 0 y 1)) x))))
638
639 (define-public (rgb-color r g b) (list r g b))
640
641 ; predefined colors
642 (define-public black       '(0.0 0.0 0.0))
643 (define-public white       '(1.0 1.0 1.0))
644 (define-public red         '(1.0 0.0 0.0))
645 (define-public green       '(0.0 1.0 0.0))
646 (define-public blue        '(0.0 0.0 1.0))
647 (define-public cyan        '(0.0 1.0 1.0))
648 (define-public magenta     '(1.0 0.0 1.0))
649 (define-public yellow      '(1.0 1.0 0.0))
650
651 (define-public grey        '(0.5 0.5 0.5))
652 (define-public darkred     '(0.5 0.0 0.0))
653 (define-public darkgreen   '(0.0 0.5 0.0))
654 (define-public darkblue    '(0.0 0.0 0.5))
655 (define-public darkcyan    '(0.0 0.5 0.5))
656 (define-public darkmagenta '(0.5 0.0 0.5))
657 (define-public darkyellow  '(0.5 0.5 0.0))
658
659
660 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
661 ;; key signature
662
663 (define-public (key-signature-interface::alteration-positions
664                 entry c0-position grob)
665   (let ((step (car entry))
666         (alter (cdr entry)))
667     (if (pair? step)
668         (list (+ (cdr step) (* (car step) 7) c0-position))
669         (let* ((c-position (modulo c0-position 7))
670                (positions
671                 (if (< alter 0)
672                     ;; See (flat|sharp)-positions in define-grob-properties.scm
673                     (ly:grob-property grob 'flat-positions '(3))
674                     (ly:grob-property grob 'sharp-positions '(3))))
675                (p (list-ref positions
676                             (if (< c-position (length positions))
677                                 c-position 0)))
678                (max-position (if (pair? p) (cdr p) p))
679                (min-position (if (pair? p) (car p) (- max-position 6)))
680                (first-position (+ (modulo (- (+ c-position step)
681                                              min-position)
682                                           7)
683                                   min-position)))
684           (define (prepend x l) (if (> x max-position)
685                                     l
686                                     (prepend (+ x 7) (cons x l))))
687           (prepend first-position '())))))
688
689 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
690 ;; annotations
691
692 (define-public (numbered-footnotes int)
693   (markup #:tiny (number->string (+ 1 int))))
694
695 (define-public (symbol-footnotes int)
696   (define (helper symbols out idx n)
697     (if (< n 1)
698         out
699         (helper symbols
700                 (string-append out (list-ref symbols idx))
701                 idx
702                 (- n 1))))
703   (markup #:tiny (helper '("*" "†" "‡" "§" "¶")
704                           ""
705                           (remainder int 5)
706                           (+ 1 (quotient int 5)))))
707
708 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
709 ;; accidentals
710
711 (define-public (accidental-interface::calc-alteration grob)
712   (ly:pitch-alteration (ly:event-property (event-cause grob) 'pitch)))
713
714 (define-public (accidental-interface::glyph-name grob)
715   (assoc-get (ly:grob-property grob 'alteration)
716              standard-alteration-glyph-name-alist))
717
718 (define-public accidental-interface::height
719   (ly:make-unpure-pure-container
720     ly:accidental-interface::height
721     ly:accidental-interface::pure-height))
722
723 (define-public cancellation-glyph-name-alist
724   '((0 . "accidentals.natural")))
725
726 (define-public standard-alteration-glyph-name-alist
727   '(
728     ;; ordered for optimal performance.
729     (0 . "accidentals.natural")
730     (-1/2 . "accidentals.flat")
731     (1/2 . "accidentals.sharp")
732
733     (1 . "accidentals.doublesharp")
734     (-1 . "accidentals.flatflat")
735
736     (3/4 . "accidentals.sharp.slashslash.stemstemstem")
737     (1/4 . "accidentals.sharp.slashslash.stem")
738     (-1/4 . "accidentals.mirroredflat")
739     (-3/4 . "accidentals.mirroredflat.flat")))
740
741 ;; FIXME: standard vs default, alteration-FOO vs FOO-alteration
742 (define-public alteration-default-glyph-name-alist
743   standard-alteration-glyph-name-alist)
744
745 (define-public makam-alteration-glyph-name-alist
746   '((1 . "accidentals.doublesharp")
747     (8/9 . "accidentals.sharp.slashslashslash.stemstem")
748     (5/9 . "accidentals.sharp.slashslashslash.stem")
749     (4/9 . "accidentals.sharp")
750     (1/9 . "accidentals.sharp.slashslash.stem")
751     (0 . "accidentals.natural")
752     (-1/9 . "accidentals.mirroredflat")
753     (-4/9 . "accidentals.flat.slash")
754     (-5/9 . "accidentals.flat")
755     (-8/9 . "accidentals.flat.slashslash")
756     (-1 . "accidentals.flatflat")))
757
758 (define-public alteration-hufnagel-glyph-name-alist
759   '((-1/2 . "accidentals.hufnagelM1")
760     (0 . "accidentals.vaticana0")
761     (1/2 . "accidentals.mensural1")))
762
763 (define-public alteration-medicaea-glyph-name-alist
764   '((-1/2 . "accidentals.medicaeaM1")
765     (0 . "accidentals.vaticana0")
766     (1/2 . "accidentals.mensural1")))
767
768 (define-public alteration-vaticana-glyph-name-alist
769   '((-1/2 . "accidentals.vaticanaM1")
770     (0 . "accidentals.vaticana0")
771     (1/2 . "accidentals.mensural1")))
772
773 (define-public alteration-mensural-glyph-name-alist
774   '((-1/2 . "accidentals.mensuralM1")
775     (0 . "accidentals.vaticana0")
776     (1/2 . "accidentals.mensural1")))
777
778 (define-public alteration-kievan-glyph-name-alist
779  '((-1/2 . "accidentals.kievanM1")
780    (1/2 . "accidentals.kievan1")))
781
782 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
783 ;; * Pitch Trill Heads
784 ;; * Parentheses
785
786 (define-public (parentheses-item::calc-parenthesis-stencils grob)
787   (let* ((font (ly:grob-default-font grob))
788          (lp (ly:font-get-glyph font "accidentals.leftparen"))
789          (rp (ly:font-get-glyph font "accidentals.rightparen")))
790
791     (list lp rp)))
792
793 (define-public (parentheses-item::calc-angled-bracket-stencils grob)
794   (let* ((parent (ly:grob-parent grob Y))
795          (y-extent (ly:grob-extent parent parent Y))
796          (half-thickness 0.05) ; should it be a property?
797          (width 0.5) ; should it be a property?
798          (angularity 1.5)  ; makes angle brackets
799          (white-padding 0.1) ; should it be a property?
800          (lp (ly:stencil-aligned-to
801                  (ly:stencil-aligned-to
802                    (make-parenthesis-stencil y-extent
803                                              half-thickness
804                                              (- width)
805                                              angularity)
806                    Y CENTER)
807                  X RIGHT))
808          (lp-x-extent
809            (interval-widen (ly:stencil-extent lp X) white-padding))
810          (rp (ly:stencil-aligned-to
811                  (ly:stencil-aligned-to
812                    (make-parenthesis-stencil y-extent
813                                              half-thickness
814                                              width
815                                              angularity)
816                    Y CENTER)
817                  X LEFT))
818           (rp-x-extent
819             (interval-widen (ly:stencil-extent rp X) white-padding)))
820     (set! lp (ly:make-stencil (ly:stencil-expr lp)
821                               lp-x-extent
822                               (ly:stencil-extent lp Y)))
823     (set! rp (ly:make-stencil (ly:stencil-expr rp)
824                               rp-x-extent
825                               (ly:stencil-extent rp Y)))
826     (list (stencil-whiteout lp)
827           (stencil-whiteout rp))))
828
829 (define (parenthesize-elements grob . rest)
830   (let* ((refp (if (null? rest)
831                    grob
832                    (car rest)))
833          (elts (ly:grob-object grob 'elements))
834          (x-ext (ly:relative-group-extent elts refp X))
835          (stencils (ly:grob-property grob 'stencils))
836          (lp (car stencils))
837          (rp (cadr stencils))
838          (padding (ly:grob-property grob 'padding 0.1)))
839
840     (ly:stencil-add
841      (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
842      (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))))
843
844
845 (define-public (parentheses-item::print me)
846   (let* ((elts (ly:grob-object me 'elements))
847          (y-ref (ly:grob-common-refpoint-of-array me elts Y))
848          (x-ref (ly:grob-common-refpoint-of-array me elts X))
849          (stencil (parenthesize-elements me x-ref))
850          (elt-y-ext (ly:relative-group-extent elts y-ref Y))
851          (y-center (interval-center elt-y-ext)))
852
853     (ly:stencil-translate
854      stencil
855      (cons
856       (- (ly:grob-relative-coordinate me x-ref X))
857       (- y-center (ly:grob-relative-coordinate me y-ref Y))))))
858
859
860 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
861 ;; offset callbacks
862
863 (define-public (pure-chain-offset-callback grob start end prev-offset)
864   "Sometimes, a chained offset callback is unpure and there is
865    no way to write a pure function that estimates its behavior.
866    In this case, we use a pure equivalent that will simply pass
867    the previous calculated offset value."
868   prev-offset)
869
870 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
871 ;;
872
873 (define-public (chain-grob-member-functions grob value . funcs)
874   (for-each
875    (lambda (func)
876      (set! value (func grob value)))
877    funcs)
878
879   value)
880
881
882 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
883 ;; falls/doits
884
885 (define-public (bend::print spanner)
886   (define (close  a b)
887     (< (abs (- a b)) 0.01))
888
889   (let* ((delta-y (* 0.5 (ly:grob-property spanner 'delta-position)))
890          (left-span (ly:spanner-bound spanner LEFT))
891          (dots (if (and (grob::has-interface left-span 'note-head-interface)
892                         (ly:grob? (ly:grob-object left-span 'dot)))
893                    (ly:grob-object left-span 'dot) #f))
894
895          (right-span (ly:spanner-bound spanner RIGHT))
896          (thickness (* (ly:grob-property spanner 'thickness)
897                        (ly:output-def-lookup (ly:grob-layout spanner)
898                                              'line-thickness)))
899          (padding (ly:grob-property spanner 'padding 0.5))
900          (common (ly:grob-common-refpoint right-span
901                                           (ly:grob-common-refpoint spanner
902                                                                    left-span X)
903                                           X))
904          (common-y (ly:grob-common-refpoint spanner left-span Y))
905          (minimum-length (ly:grob-property spanner 'minimum-length 0.5))
906
907          (left-x (+ padding
908                     (max
909                      (interval-end (ly:grob-robust-relative-extent
910                                     left-span common X))
911                      (if
912                       (and dots
913                            (close
914                             (ly:grob-relative-coordinate dots common-y Y)
915                             (ly:grob-relative-coordinate spanner common-y Y)))
916                       (interval-end
917                        (ly:grob-robust-relative-extent dots common X))
918                       ;; TODO: use real infinity constant.
919                       -10000))))
920          (right-x (max (- (interval-start
921                            (ly:grob-robust-relative-extent right-span common X))
922                           padding)
923                        (+ left-x minimum-length)))
924          (self-x (ly:grob-relative-coordinate spanner common X))
925          (dx (- right-x left-x))
926          (exp (list 'path thickness
927                     `(quote
928                       (rmoveto
929                        ,(- left-x self-x) 0
930
931                        rcurveto
932                        ,(/ dx 3)
933                        0
934                        ,dx ,(* 0.66 delta-y)
935                        ,dx ,delta-y)))))
936
937     (ly:make-stencil
938      exp
939      (cons (- left-x self-x) (- right-x self-x))
940      (cons (min 0 delta-y)
941            (max 0 delta-y)))))
942
943
944 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
945 ;; grace spacing
946
947 (define-public (grace-spacing::calc-shortest-duration grob)
948   (let* ((cols (ly:grob-object grob 'columns))
949          (get-difference
950           (lambda (idx)
951             (ly:moment-sub (ly:grob-property
952                             (ly:grob-array-ref cols (1+ idx)) 'when)
953                            (ly:grob-property
954                             (ly:grob-array-ref cols idx) 'when))))
955
956          (moment-min (lambda (x y)
957                        (cond
958                         ((and x y)
959                          (if (ly:moment<? x y)
960                              x
961                              y))
962                         (x x)
963                         (y y)))))
964
965     (fold moment-min #f (map get-difference
966                              (iota (1- (ly:grob-array-length cols)))))))
967
968
969 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
970 ;; fingering
971
972 (define-public (fingering::calc-text grob)
973   (let ((event (event-cause grob)))
974     (or (ly:event-property event 'text #f)
975         (number->string (ly:event-property event 'digit) 10))))
976
977 (define-public (string-number::calc-text grob)
978   (let ((event (event-cause grob)))
979     (or (ly:event-property event 'text #f)
980         (number->string (ly:event-property event 'string-number) 10))))
981
982 (define-public (stroke-finger::calc-text grob)
983   (let ((event (event-cause grob)))
984     (or (ly:event-property event 'text #f)
985         (vector-ref (ly:grob-property grob 'digit-names)
986                     (1- (max 1
987                              (min 5 (ly:event-property event 'digit))))))))
988
989
990 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
991 ;; dynamics
992
993 (define-public (hairpin::calc-grow-direction grob)
994   (if (ly:in-event-class? (event-cause grob) 'decrescendo-event)
995       START
996       STOP))
997
998 (define-public (dynamic-text-spanner::before-line-breaking grob)
999   "Monitor left bound of @code{DynamicTextSpanner} for absolute dynamics.
1000 If found, ensure @code{DynamicText} does not collide with spanner text by
1001 changing @code{'attach-dir} and @code{'padding}.  Reads the
1002 @code{'right-padding} property of @code{DynamicText} to fine tune space
1003 between the two text elements."
1004   (let ((left-bound (ly:spanner-bound grob LEFT)))
1005     (if (grob::has-interface left-bound 'dynamic-text-interface)
1006         (let* ((details (ly:grob-property grob 'bound-details))
1007                (left-details (ly:assoc-get 'left details))
1008                (my-padding (ly:assoc-get 'padding left-details))
1009                (script-padding (ly:grob-property left-bound 'right-padding 0)))
1010
1011           (and (number? my-padding)
1012                (ly:grob-set-nested-property! grob
1013                                              '(bound-details left attach-dir)
1014                                              RIGHT)
1015                (ly:grob-set-nested-property! grob
1016                                              '(bound-details left padding)
1017                                              (+ my-padding script-padding)))))))
1018
1019
1020 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1021 ;; lyrics
1022
1023 (define-public (lyric-text::print grob)
1024   "Allow interpretation of tildes as lyric tieing marks."
1025
1026   (let ((text (ly:grob-property grob 'text)))
1027
1028     (grob-interpret-markup grob (if (string? text)
1029                                     (make-tied-lyric-markup text)
1030                                     text))))
1031
1032 (define-public ((grob::calc-property-by-copy prop) grob)
1033   (ly:event-property (event-cause grob) prop))
1034
1035 (define-public ((grob::calc-property-by-non-event-cause prop) grob)
1036   (ly:grob-property (non-event-cause grob) prop))
1037
1038
1039 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1040 ;; fret boards
1041
1042 (define-public (fret-board::calc-stencil grob)
1043   (grob-interpret-markup
1044    grob
1045    (make-fret-diagram-verbose-markup
1046     (ly:grob-property grob 'dot-placement-list))))
1047
1048
1049 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1050 ;; slurs
1051
1052 (define-public slur::height
1053   (ly:make-unpure-pure-container
1054     ly:slur::height
1055     ly:slur::pure-height))
1056
1057 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1058 ;; scripts
1059
1060 (define-public (script-interface::calc-x-offset grob)
1061   (ly:grob-property grob 'positioning-done)
1062   (let* ((shift (ly:grob-property grob 'toward-stem-shift 0.0))
1063          (note-head-location
1064           (ly:self-alignment-interface::centered-on-x-parent grob))
1065          (note-head-grob (ly:grob-parent grob X))
1066          (stem-grob (ly:grob-object note-head-grob 'stem)))
1067
1068     (+ note-head-location
1069        ;; If the property 'toward-stem-shift is defined and the script
1070        ;; has the same direction as the stem, move the script accordingly.
1071        ;; Since scripts can also be over skips, we need to check whether
1072        ;; the grob has a stem at all.
1073        (if (ly:grob? stem-grob)
1074            (let ((dir1 (ly:grob-property grob 'direction))
1075                  (dir2 (ly:grob-property stem-grob 'direction)))
1076              (if (equal? dir1 dir2)
1077                  (let* ((common-refp (ly:grob-common-refpoint grob stem-grob X))
1078                         (stem-location
1079                          (ly:grob-relative-coordinate stem-grob common-refp X)))
1080                    (* shift (- stem-location note-head-location)))
1081                  0.0))
1082            0.0))))
1083
1084
1085 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1086 ;; instrument names
1087
1088 (define-public (system-start-text::print grob)
1089   (let* ((left-bound (ly:spanner-bound grob LEFT))
1090          (left-mom (ly:grob-property left-bound 'when))
1091          (name (if (moment<=? left-mom ZERO-MOMENT)
1092                    (ly:grob-property grob 'long-text)
1093                    (ly:grob-property grob 'text))))
1094
1095     (if (and (markup? name)
1096              (!= (ly:item-break-dir left-bound) CENTER))
1097
1098         (grob-interpret-markup grob name)
1099         (ly:grob-suicide! grob))))
1100
1101 (define-public (system-start-text::calc-x-offset grob)
1102   (let* ((left-bound (ly:spanner-bound grob LEFT))
1103          (left-mom (ly:grob-property left-bound 'when))
1104          (layout (ly:grob-layout grob))
1105          (indent (ly:output-def-lookup layout
1106                                        (if (moment<=? left-mom ZERO-MOMENT)
1107                                            'indent
1108                                            'short-indent)
1109                                        0.0))
1110          (system (ly:grob-system grob))
1111          (my-extent (ly:grob-extent grob system X))
1112          (elements (ly:grob-object system 'elements))
1113          (common (ly:grob-common-refpoint-of-array system elements X))
1114          (total-ext empty-interval)
1115          (align-x (ly:grob-property grob 'self-alignment-X 0))
1116          (padding (min 0 (- (interval-length my-extent) indent)))
1117          (right-padding (- padding
1118                            (/ (* padding (1+ align-x)) 2))))
1119
1120     ;; compensate for the variation in delimiter extents by
1121     ;; calculating an X-offset correction based on united extents
1122     ;; of all delimiters in this system
1123     (let unite-delims ((l (ly:grob-array-length elements)))
1124       (if (> l 0)
1125           (let ((elt (ly:grob-array-ref elements (1- l))))
1126
1127             (if (grob::has-interface elt 'system-start-delimiter-interface)
1128                 (let ((dims (ly:grob-extent elt common X)))
1129                   (if (interval-sane? dims)
1130                       (set! total-ext (interval-union total-ext dims)))))
1131             (unite-delims (1- l)))))
1132
1133     (+
1134      (ly:side-position-interface::x-aligned-side grob)
1135      right-padding
1136      (- (interval-length total-ext)))))
1137
1138 (define-public (system-start-text::calc-y-offset grob)
1139
1140   (define (live-elements-list me)
1141     (let ((elements (ly:grob-object me 'elements)))
1142
1143       (filter! grob::is-live?
1144                (ly:grob-array->list elements))))
1145
1146   (let* ((left-bound (ly:spanner-bound grob LEFT))
1147          (live-elts (live-elements-list grob))
1148          (system (ly:grob-system grob))
1149          (extent empty-interval))
1150
1151     (if (and (pair? live-elts)
1152              (interval-sane? (ly:grob-extent grob system Y)))
1153         (let get-extent ((lst live-elts))
1154           (if (pair? lst)
1155               (let ((axis-group (car lst)))
1156
1157                 (if (and (ly:spanner? axis-group)
1158                          (equal? (ly:spanner-bound axis-group LEFT)
1159                                  left-bound))
1160                     (set! extent (add-point extent
1161                                             (ly:grob-relative-coordinate
1162                                              axis-group system Y))))
1163                 (get-extent (cdr lst)))))
1164         ;; no live axis group(s) for this instrument name -> remove from system
1165         (ly:grob-suicide! grob))
1166
1167     (+
1168      (ly:self-alignment-interface::y-aligned-on-self grob)
1169      (interval-center extent))))
1170
1171
1172 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1173 ;; axis group interface
1174
1175 (define-public axis-group-interface::height
1176   (ly:make-unpure-pure-container
1177     ly:axis-group-interface::height
1178     ly:axis-group-interface::pure-height))
1179
1180 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1181 ;; ambitus
1182
1183 (define-public (ambitus::print grob)
1184   (let ((heads (ly:grob-object grob 'note-heads)))
1185
1186     (if (and (ly:grob-array? heads)
1187              (= (ly:grob-array-length heads) 2))
1188         (let* ((common (ly:grob-common-refpoint-of-array grob heads Y))
1189                (head-down (ly:grob-array-ref heads 0))
1190                (head-up (ly:grob-array-ref heads 1))
1191                (gap (ly:grob-property grob 'gap 0.35))
1192                (point-min (+ (interval-end (ly:grob-extent head-down common Y))
1193                              gap))
1194                (point-max (- (interval-start (ly:grob-extent head-up common Y))
1195                              gap)))
1196
1197           (if (< point-min point-max)
1198               (let* ((layout (ly:grob-layout grob))
1199                      (line-thick (ly:output-def-lookup layout 'line-thickness))
1200                      (blot (ly:output-def-lookup layout 'blot-diameter))
1201                      (grob-thick (ly:grob-property grob 'thickness 2))
1202                      (width (* line-thick grob-thick))
1203                      (x-ext (symmetric-interval (/ width 2)))
1204                      (y-ext (cons point-min point-max))
1205                      (line (ly:round-filled-box x-ext y-ext blot))
1206                      (y-coord (ly:grob-relative-coordinate grob common Y)))
1207
1208                 (ly:stencil-translate-axis line (- y-coord) Y))
1209               empty-stencil))
1210         (begin
1211           (ly:grob-suicide! grob)
1212           (list)))))
1213
1214 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1215 ;;  laissez-vibrer tie
1216 ;;
1217 ;;  needed so we can make laissez-vibrer a pure print
1218 ;;
1219 (define-public (laissez-vibrer::print grob)
1220  (ly:tie::print grob))
1221
1222 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1223 ;; volta-bracket
1224
1225 (define-public (volta-bracket-interface::pure-height grob start end)
1226   (let ((edge-height (ly:grob-property grob 'edge-height)))
1227     (if (number-pair? edge-height)
1228         (let ((smaller (min (car edge-height) (cdr edge-height)))
1229               (larger (max (car edge-height) (cdr edge-height))))
1230           (interval-union '(0 . 0) (cons smaller larger)))
1231         '(0 . 0))))