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