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