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