]> git.donarmstrong.com Git - lilypond.git/blob - scm/output-lib.scm
Merge branch 'master' into lilypond/translation
[lilypond.git] / scm / output-lib.scm
1 ;;;; output-lib.scm -- implement Scheme output helper functions
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;; 
5 ;;;; (c) 1998--2007 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@xs4all.nl>
7
8
9
10
11 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12 ;; general
13 (define-public (grob::has-interface grob iface)
14   (memq iface (ly:grob-interfaces grob)))
15
16 (define-public (make-stencil-boxer thickness padding callback)
17
18   "Return function that adds a box around the grob passed as argument."
19   (lambda (grob)
20     
21     (box-stencil (callback grob) thickness padding)))
22
23 (define-public (make-stencil-circler thickness padding callback)
24   "Return function that adds a circle around the grob passed as argument."
25   
26   (lambda (grob) (circle-stencil (callback grob) thickness padding)))
27
28 (define-public (print-circled-text-callback grob)
29   (grob-interpret-markup grob (make-circle-markup
30                    (ly:grob-property grob 'text))
31              ))
32
33 (define-public (event-cause grob)
34   (let*
35       ((cause (ly:grob-property  grob 'cause)))
36     
37     (cond
38      ((ly:stream-event? cause) cause)
39      ((ly:grob? cause) (event-cause cause))
40      (else #f))))
41
42 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43 ;; tablature
44
45 ;; The TabNoteHead tablatureFormat callback.
46 ;; Compute the text grob-property
47 (define-public (fret-number-tablature-format string
48                                              context event)
49   (let*
50       ((tuning (ly:context-property context 'stringTunings))
51        (pitch (ly:event-property event 'pitch))
52        (is-harmonic (apply
53                      functional-or
54                      (map
55                       (lambda (ev)
56                         (eq? 'harmonic-event (ly:event-property ev 'class)))
57                       (ly:event-property event 'articulations)))))
58
59     
60     (make-whiteout-markup
61      (make-vcenter-markup
62       (format
63        "~a"
64        (- (ly:pitch-semitones pitch)
65           (list-ref tuning
66                     ;; remove 1 because list index starts at 0 and guitar string at 1. 
67                     (- string 1))))))
68     ))
69
70 ;; The 5-string banjo has got a extra string, the fifth (duh), wich
71 ;; starts at the fifth fret on the neck. Frets on the fifth string
72 ;; are referred to relative to the other frets:
73 ;;   the "first fret" on the fifth string is really the sixth fret
74 ;;   on the banjo neck.
75 ;; We solve this by defining a new fret-number-tablature function:
76 (define-public (fret-number-tablature-format-banjo string 
77                                              context event)
78   (let*
79       ((tuning (ly:context-property context 'stringTunings))
80        (pitch (ly:event-property event 'pitch))
81         )
82   (make-whiteout-markup
83    (make-vcenter-markup  
84     (let ((fret (- (ly:pitch-semitones pitch) (list-ref tuning (- string 1)))))
85       (number->string (cond
86                        ((and (> fret 0) (= string 5))
87                         (+ fret 5))
88                        (else fret))))))
89   ))
90
91
92 ; default tunings for common string instruments
93 (define-public guitar-tuning '(4 -1 -5 -10 -15 -20))
94 (define-public guitar-open-g-tuning '(2 -1 -5 -10 -17 -22))
95 (define-public bass-tuning '(-17 -22 -27 -32))
96 (define-public mandolin-tuning '(16 9 2 -5))
97
98 ;; tunings for 5-string banjo
99 (define-public banjo-open-g-tuning '(2 -1 -5 -10 7))
100 (define-public banjo-c-tuning '(2 -1 -5 -12 7))
101 (define-public banjo-modal-tuning '(2 0 -5 -10 7))
102 (define-public banjo-open-d-tuning '(2 -3 -6 -10 9))
103 (define-public banjo-open-dm-tuning '(2 -3 -6 -10 9))
104 ;; convert 5-string banjo tuning to 4-string by removing the 5th string
105 (define-public (four-string-banjo tuning)
106   (reverse (cdr (reverse tuning))))
107
108 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
109 ;; note heads
110
111
112 (define-public (stem::calc-duration-log grob)
113   (ly:duration-log
114    (ly:event-property (event-cause grob) 'duration)))
115
116 (define-public (note-head::calc-duration-log grob)
117   (min 2 
118        (ly:duration-log
119         (ly:event-property (event-cause grob) 'duration))))
120
121 (define-public (dots::calc-dot-count grob)
122   (ly:duration-dot-count
123    (ly:event-property (event-cause grob) 'duration)))
124
125 (define-public (dots::calc-staff-position grob)
126   (let*
127       ((head (ly:grob-parent grob Y))
128        (log (ly:grob-property head 'duration-log)))
129
130     (cond
131      ((or (not (grob::has-interface head 'rest-interface))
132          (not (integer? log))) 0)
133      ((= log 7) 4)
134      ((> log 4) 3)
135      ((= log 0) -1)
136      ((= log 1) 1)
137      ((= log -1) 1)
138      (else 0))))
139
140 (define (note-head::calc-tablature-stem-attachment grob)
141   (cons 0.0 1.35))
142
143
144
145 ;; silly, use alist? 
146 (define-public (note-head::calc-glyph-name grob)
147   (let*
148       ((style (ly:grob-property grob 'style))
149        (log (min 2 (ly:grob-property grob 'duration-log))))
150     
151     (case style
152       ;; "default" style is directly handled in note-head.cc as a
153       ;; special case (HW says, mainly for performance reasons).
154       ;; Therefore, style "default" does not appear in this case
155       ;; statement.  -- jr
156       ((xcircle) "2xcircle")
157       ((harmonic) "0harmonic")
158       ((harmonic-black) "2harmonic")
159       ((harmonic-mixed) (if (<= log 1) "0harmonic"
160                                        "2harmonic"))
161       ((baroque) 
162        ;; Oops, I actually would not call this "baroque", but, for
163        ;; backwards compatibility to 1.4, this is supposed to take
164        ;; brevis, longa and maxima from the neo-mensural font and all
165        ;; other note heads from the default font.  -- jr
166        (if (< log 0)
167            (string-append (number->string log) "neomensural")
168            (number->string log)))
169       ((mensural)
170        (string-append (number->string log) (symbol->string style)))
171       ((petrucci)
172        (if (< log 0)
173            (string-append (number->string log) "mensural")
174            (string-append (number->string log) (symbol->string style))))
175       ((neomensural)
176        (string-append (number->string log) (symbol->string style)))
177       (else
178        (if (string-match "vaticana*|hufnagel*|medicaea*" (symbol->string style))
179            (symbol->string style)
180            (string-append (number->string (max 0 log))
181                           (symbol->string style)))))))
182
183 ;; TODO junk completely?
184 (define (note-head-style->attachment-coordinates grob axis)
185   "Return pair (X . Y), containing multipliers for the note head
186 bounding box, where to attach the stem. e.g.: X==0 means horizontally
187 centered, X==1 is at the right, X == -1 is at the left."
188
189   '(1.0 . 0.0))
190
191
192 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
193 ;; bar numbers
194
195 (define-public ((every-nth-bar-number-visible n) barnum) (= 0 (modulo barnum n)))
196
197 (define-public ((modulo-bar-number-visible n m) barnum) (and (> barnum 1) (= m (modulo barnum n))))
198
199 (define-public ((set-bar-number-visibility n) tr)
200   (let* ((bn (ly:context-property tr 'currentBarNumber)))
201     (ly:context-set-property! tr 'barNumberVisibility (modulo-bar-number-visible n (modulo bn n)))))
202
203 (define-public (first-bar-number-invisible barnum) (> barnum 1))
204
205 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
206 ;; break visibility
207
208 (define-public begin-of-line-visible
209   #(#f #f #t))
210 (define-public end-of-line-visible
211   #(#t #f #f))
212 (define-public end-of-line-invisible
213   #(#f #t #t))
214 (define-public spanbar-begin-of-line-invisible
215   #(#t #f #f))
216 (define-public all-visible #(#t #t #t))
217 (define-public all-invisible #(#f #f #f))
218 (define-public begin-of-line-invisible
219   #(#t #t #f))
220 (define-public center-invisible #(#t #f #t))
221
222 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
223 ;; Bar lines.
224
225 ;;
226 ;; How should a  bar line behave at a break? 
227 (define bar-glyph-alist
228   '((":|:" . (":|" . "|:"))
229     ("||:" . ("||" . "|:"))
230     ("dashed" . ("dashed" . '())) 
231     ("|" . ("|" . ()))
232     ("||:" . ("||" . "|:"))
233     ("|s" . (() . "|"))
234     ("|:" . ("|" . "|:"))
235     ("|." . ("|." . ()))
236     
237     ;; hmm... should we end with a bar line here?
238     (".|" . ("|" . ".|"))
239     (":|" . (":|" . ()))
240     ("||" . ("||" . ()))
241     (".|." . (".|." . ()))
242     ("" . ("" . ""))
243     (":" . (":" . ""))
244     ("." . ("." . ()))
245     ("empty" . (() . ()))
246     ("brace" . (() . "brace"))
247     ("bracket" . (() . "bracket")) 
248     ))
249
250 (define-public (bar-line::calc-glyph-name grob)
251   (let* (
252          (glyph (ly:grob-property grob 'glyph))
253          (dir (ly:item-break-dir grob))
254          (result (assoc glyph  bar-glyph-alist))
255          (glyph-name (if (= dir CENTER)
256                          glyph
257                          (if (and result (string? (index-cell (cdr result) dir)))
258                              (index-cell (cdr result) dir)
259                              #f)))
260          )
261     glyph-name))
262
263 (define-public (bar-line::calc-break-visibility grob)
264   (let* ((glyph (ly:grob-property grob 'glyph))
265          (result (assoc glyph bar-glyph-alist)))
266     (if result
267         (vector (string? (cadr result)) #t (string? (cddr result)))
268         #(#f #f #f))))
269
270
271 (define-public (shift-right-at-line-begin g)
272   "Shift an item to the right, but only at the start of the line."
273   (if (and (ly:item? g)
274            (equal? (ly:item-break-dir g) RIGHT))
275       (ly:grob-translate-axis! g 3.5 X)))
276
277
278 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
279 ;; Tuplets
280
281 (define-public (tuplet-number::calc-denominator-text grob)
282   (number->string (ly:event-property (event-cause grob) 'denominator)))
283
284 (define-public (tuplet-number::calc-fraction-text grob)
285   (let*
286       ((ev (event-cause grob)))
287
288     (format "~a:~a" 
289             (ly:event-property ev 'denominator)
290             (ly:event-property ev 'numerator))))
291
292 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
293 ;; Color
294
295 (define-public color? list?)
296
297 ; predefined colors
298 (define-public black       '(0.0 0.0 0.0))
299 (define-public white       '(1.0 1.0 1.0))
300 (define-public red         '(1.0 0.0 0.0))
301 (define-public green       '(0.0 1.0 0.0))
302 (define-public blue        '(0.0 0.0 1.0))
303 (define-public cyan        '(0.0 1.0 1.0))
304 (define-public magenta     '(1.0 0.0 1.0))
305 (define-public yellow      '(1.0 1.0 0.0))
306
307 (define-public grey        '(0.5 0.5 0.5))
308 (define-public darkred     '(0.5 0.0 0.0))
309 (define-public darkgreen   '(0.0 0.5 0.0))
310 (define-public darkblue    '(0.0 0.0 0.5))
311 (define-public darkcyan    '(0.0 0.5 0.5))
312 (define-public darkmagenta '(0.5 0.0 0.5))
313 (define-public darkyellow  '(0.5 0.5 0.0))
314
315 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
316 ;; key signature
317
318
319 (define-public (key-signature-interface::alteration-position step alter c0-position)
320   ;; TODO: memoize - this is mostly constant.
321   
322   ;; fes, ges, as and bes typeset in lower octave
323   (define FLAT_TOP_PITCH 2)
324   
325   ;; ais and bis typeset in lower octave
326   (define SHARP_TOP_PITCH 4)
327
328   (if (pair? step)
329       (+ (cdr step) (* (car step) 7)  c0-position)
330       (let*
331           ((from-bottom-pos (modulo (+ 4 49 c0-position)  7))
332            (p step)
333            (c0 (- from-bottom-pos  4)))
334         
335         (if
336          (or (and (< alter 0) (or (> p FLAT_TOP_PITCH) (> (+ p c0) 4)) (> (+ p c0) 1))
337              (and (> alter 0) (or (> p SHARP_TOP_PITCH) (> (+ p c0) 5)) (> (+ p c0) 2))
338              )
339
340          ;; Typeset below c_position 
341          (set! p (- p 7)))
342
343         ;; Provide for the four cases in which there's a glitch
344         ;; it's a hack, but probably not worth
345         ;; the effort of finding a nicer solution.
346         ;; --dl. 
347         (cond
348          ((and (= c0 2) (= p 3) (> alter 0))
349           (set! p (- p 7)))
350          ((and (= c0 -3) (= p -1) (> alter 0))
351           (set! p (+ p 7)))
352          ((and (= c0 -4) (= p -1) (< alter 0))
353           (set! p (+ p 7)))
354          ((and (= c0 -2) (= p -3) (< alter 0))
355           (set! p (+ p 7))))
356
357         (+ c0 p))))
358
359
360 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
361 ;; accidentals
362
363 (define-public (accidental-interface::calc-alteration grob)
364   (ly:pitch-alteration  (ly:event-property (event-cause grob) 'pitch)))
365
366
367 (define-public cancellation-glyph-name-alist
368   '((0 . "accidentals.natural")))
369
370 (define-public standard-alteration-glyph-name-alist
371      '(
372        ;; ordered for optimal performance.
373        (0 . "accidentals.natural")
374        (-1/2 . "accidentals.flat")
375        (1/2 . "accidentals.sharp")
376
377        (1 . "accidentals.doublesharp")
378        (-1 . "accidentals.flatflat")
379        
380        (3/4 . "accidentals.sharp.slashslash.stemstemstem")
381        (1/4 . "accidentals.sharp.slashslash.stem")
382        (-1/4 . "accidentals.mirroredflat")
383        (-3/4 . "accidentals.mirroredflat.flat")
384        ))
385
386 ;; FIXME: standard vs default, alteration-FOO vs FOO-alteration
387 (define-public alteration-default-glyph-name-alist standard-alteration-glyph-name-alist)
388
389 (define-public makam-alteration-glyph-name-alist
390      '((1 . "accidentals.doublesharp")
391        (8/9 . "accidentals.sharp.slashslashslash.stemstem")
392        (5/9 . "accidentals.sharp.slashslashslash.stem")
393        (4/9 . "accidentals.sharp")
394        (1/9 . "accidentals.sharp.slashslash.stem")
395        (0 . "accidentals.natural")
396        (-1/9 . "accidentals.mirroredflat")
397        (-4/9 . "accidentals.flat.slash")
398        (-5/9 . "accidentals.flat")
399        (-8/9 . "accidentals.flat.slashslash")
400        (-1 . "accidentals.flatflat")
401        ))
402   
403 (define-public alteration-hufnagel-glyph-name-alist
404    '((-1/2 . "accidentals.hufnagel-1")
405      (0 . "accidentals.vaticana0")
406      (1/2 . "accidentals.mensural1")))
407
408 (define-public alteration-medicaea-glyph-name-alist
409    '((-1/2 . "accidentals.medicaea-1")
410      (0 . "accidentals.vaticana0")
411      (1/2 . "accidentals.mensural1")))
412
413 (define-public alteration-vaticana-glyph-name-alist
414    '((-1/2 . "accidentals.vaticana-1")
415      (0 . "accidentals.vaticana0")
416      (1/2 . "accidentals.mensural1")))
417
418 (define-public alteration-mensural-glyph-name-alist
419    '((-1/2 . "accidentals.mensural-1")
420      (0 . "accidentals.vaticana0")
421      (1/2 . "accidentals.mensural1")))
422
423
424 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
425 ;; * Pitch Trill Heads
426 ;; * Parentheses
427
428 (define-public (parentheses-item::calc-parenthesis-stencils grob)
429   (let* ((font (ly:grob-default-font grob))
430          (lp (ly:font-get-glyph font "accidentals.leftparen"))
431          (rp (ly:font-get-glyph font "accidentals.rightparen")))
432
433     (list lp rp)))
434
435
436 (define-public (grob-interpret-markup grob text)
437   (let*
438       ((layout (ly:grob-layout grob))
439        (defs (ly:output-def-lookup layout 'text-font-defaults))
440        (props (ly:grob-alist-chain grob defs)))
441
442     (ly:text-interface::interpret-markup
443      layout props text)))
444
445 (define-public (parentheses-item::calc-angled-bracket-stencils grob)
446   (let* (
447          (font (ly:grob-default-font grob))
448          (lp (ly:stencil-aligned-to (ly:stencil-aligned-to (grob-interpret-markup grob (ly:wide-char->utf-8 #x2329))
449                                                            Y CENTER)  X RIGHT))
450          (rp (ly:stencil-aligned-to (ly:stencil-aligned-to (grob-interpret-markup grob (ly:wide-char->utf-8 #x232A))
451                                                            Y CENTER) X LEFT))
452          )
453
454     (list (stencil-whiteout lp)
455           (stencil-whiteout rp))))
456
457 (define (parenthesize-elements grob . rest)
458   (let*
459       ((refp (if (null? rest)
460                  grob
461                  (car rest)))
462        (elts (ly:grob-object grob 'elements))
463        (x-ext (ly:relative-group-extent elts refp X))
464        (stencils (ly:grob-property grob 'stencils))
465        (lp (car stencils))
466        (rp (cadr stencils))
467        (padding (ly:grob-property grob 'padding 0.1)))
468     
469     (ly:stencil-add
470      (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
471      (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))
472   ))
473
474
475 (define (parentheses-item::print me)
476   (let*
477       ((elts (ly:grob-object me 'elements))
478        (y-ref (ly:grob-common-refpoint-of-array me elts Y))
479        (x-ref (ly:grob-common-refpoint-of-array me elts X))
480        (stencil (parenthesize-elements me x-ref))
481        (elt-y-ext  (ly:relative-group-extent elts y-ref Y))
482        (y-center (interval-center elt-y-ext)))
483
484     (ly:stencil-translate
485      stencil
486      (cons
487       (-
488        (ly:grob-relative-coordinate me x-ref X))
489       (-
490        y-center
491        (ly:grob-relative-coordinate me y-ref Y))))
492     ))
493
494
495
496 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
497 ;; 
498
499 (define-public (chain-grob-member-functions grob value . funcs)
500   (for-each
501    (lambda (func)
502      (set! value (func grob value)))
503    funcs)
504
505   value)
506
507 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
508 ;; falls/doits
509
510 (define-public (bend::print spanner)
511   (define (close  a b)
512     (< (abs (- a b)) 0.01))
513   
514   (let*
515       ((delta-y (* 0.5 (ly:grob-property spanner 'delta-position)))
516        (left-span (ly:spanner-bound spanner LEFT))
517        (dots (if (and (grob::has-interface left-span 'note-head-interface)
518                       (ly:grob? (ly:grob-object left-span 'dot)))
519                  (ly:grob-object left-span 'dot) #f))
520                  
521        (right-span (ly:spanner-bound spanner RIGHT))
522        (thickness (* (ly:grob-property spanner 'thickness)
523                      (ly:output-def-lookup (ly:grob-layout spanner)
524                                            'line-thickness)))
525        (padding (ly:grob-property spanner 'padding 0.5))
526        (common (ly:grob-common-refpoint right-span
527                                         (ly:grob-common-refpoint spanner
528                                                                  left-span X)
529                                         X))
530        (common-y (ly:grob-common-refpoint spanner left-span Y))
531        (left-x (+ padding
532                   (max (interval-end (ly:grob-robust-relative-extent
533                                       left-span common X))
534                         (if (and
535                              dots
536                              (close (ly:grob-relative-coordinate dots common-y Y)
537                                         (ly:grob-relative-coordinate spanner common-y Y)))
538                             (interval-end (ly:grob-robust-relative-extent dots common X))
539                             -10000) ;; TODO: use real infinity constant.
540                         )))
541        (right-x (- (interval-start
542                     (ly:grob-robust-relative-extent right-span common X))
543                    padding))
544        (self-x (ly:grob-relative-coordinate spanner common X))
545        (dx (- right-x left-x))
546        (exp (list 'path thickness 
547                   `(quote
548                     (rmoveto
549                      ,(- left-x self-x) 0
550
551                      rcurveto                
552                      ,(/ dx 3)
553                      0
554                      ,dx ,(* 0.66 delta-y)
555                      ,dx ,delta-y
556                      )))))
557
558     (ly:make-stencil
559      exp
560      (cons (- left-x self-x) (- right-x self-x))
561      (cons (min 0 delta-y)
562            (max 0 delta-y)))))
563
564 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
565 ;; grace spacing
566
567
568 (define-public (grace-spacing::calc-shortest-duration grob)
569   (let*
570      ((cols (ly:grob-object grob 'columns))
571       (get-difference
572        (lambda (idx)
573          (ly:moment-sub (ly:grob-property
574                          (ly:grob-array-ref cols (1+ idx)) 'when)
575                         (ly:grob-property
576                          (ly:grob-array-ref cols idx) 'when))))
577       
578       (moment-min (lambda (x y)
579                     (cond
580                      ((and x y)
581                       (if (ly:moment<? x y)
582                             x
583                             y))
584                      (x x)
585                      (y y)))))
586                      
587     (fold moment-min #f (map get-difference
588                              (iota (1- (ly:grob-array-length cols)))))))
589
590
591
592 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
593 ;; fingering
594
595 (define-public (fingering::calc-text grob)
596   (let*
597       ((event (event-cause grob))
598        (digit (ly:event-property event 'digit)))
599     
600     (if (> digit 5)
601         (ly:input-message (ly:event-property event 'origin)
602                           "Warning: Fingering notation for finger number ~a" digit))
603
604     (number->string digit 10)
605   ))
606
607 (define-public (string-number::calc-text grob)
608   (let*
609       ((digit (ly:event-property (event-cause  grob) 'string-number)))
610     
611     (number->string digit 10)
612   ))
613
614
615 (define-public (stroke-finger::calc-text grob)
616   (let*
617       ((digit (ly:event-property (event-cause grob) 'digit))
618        (text (ly:event-property (event-cause grob) 'text)))
619
620     (if (string? text)
621         text
622         (vector-ref (ly:grob-property grob 'digit-names)  (1- (max (min 5 digit) 1))))))
623
624 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
625 ;; dynamics
626 (define-public (hairpin::calc-grow-direction grob)
627   (if (eq? (ly:event-property (event-cause grob) 'class) 'decrescendo-event)
628       START
629       STOP
630       ))
631
632 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
633 ;; lyrics
634
635 (define-public (lyric-text::print grob)
636   "Allow interpretation of tildes as lyric tieing marks."
637   
638   (let*
639       ((text (ly:grob-property grob 'text)))
640
641     (grob-interpret-markup grob 
642                (if (string? text)
643                    (make-tied-lyric-markup text)
644                    text))))
645
646 (define-public ((grob::calc-property-by-copy prop) grob)
647   (ly:event-property (event-cause grob) prop))
648
649 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
650 ;; fret boards
651
652 (define (string-frets->description string-frets string-count)
653   (let*
654       ((desc (list->vector
655               (map (lambda (x) (list 'mute  (1+ x)))
656                    (iota string-count)))))
657        
658        (for-each (lambda (sf)
659                    (let*
660                        ((string (car sf))
661                         (fret (cadr sf))
662                         (finger (caddr sf)))
663
664                      
665                      (vector-set! desc (1- string)
666                                   (if (= 0 fret)
667                                       (list 'open string)
668                                       (if finger
669                                           (list 'place-fret string fret finger) 
670                                           (list 'place-fret string fret))
671                                           
672
673                                       ))
674                      ))
675                  string-frets)
676
677        (vector->list desc)))
678
679 (define-public (fret-board::calc-stencil grob)
680   (let* ((string-frets (ly:grob-property grob 'string-fret-finger-combinations))
681          (string-count (ly:grob-property grob 'string-count)))
682     
683     (grob-interpret-markup grob
684                            (make-fret-diagram-verbose-markup
685                             (string-frets->description string-frets string-count)))))
686
687 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
688 ;; scripts
689
690 (define-public (script-interface::calc-x-offset grob)
691   (ly:grob-property grob 'positioning-done)
692   (ly:self-alignment-interface::centered-on-x-parent grob))