]> git.donarmstrong.com Git - lilypond.git/blob - scm/output-lib.scm
Merge commit 'origin' into beamlets2
[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--2008 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 ;; percent repeat counters
207
208 (define-public ((every-nth-repeat-count-visible n) count context) (= 0 (modulo count n)))
209
210 (define-public (all-repeat-counts-visible count context) #t)
211
212 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
213 ;; break visibility
214
215 (define-public all-visible             #(#t #t #t))
216 (define-public begin-of-line-invisible #(#t #t #f))
217 (define-public center-invisible        #(#t #f #t))
218 (define-public end-of-line-invisible   #(#f #t #t))
219 (define-public begin-of-line-visible   #(#f #f #t))
220 (define-public center-visible          #(#f #t #f))
221 (define-public end-of-line-visible     #(#t #f #f))
222 (define-public all-invisible           #(#f #f #f))
223
224 (define-public spanbar-begin-of-line-invisible
225   #(#t #f #f))
226
227 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
228 ;; Bar lines.
229
230 ;;
231 ;; How should a  bar line behave at a break? 
232 (define bar-glyph-alist
233   '((":|:" . (":|" . "|:"))
234     (":|.|:" . (":|" . "|:"))
235     (":|.:" . (":|" . "|:"))
236     ("||:" . ("||" . "|:"))
237     ("dashed" . ("dashed" . '())) 
238     ("|" . ("|" . ()))
239     ("||:" . ("||" . "|:"))
240     ("|s" . (() . "|"))
241     ("|:" . ("|" . "|:"))
242     ("|." . ("|." . ()))
243     
244     ;; hmm... should we end with a bar line here?
245     (".|" . ("|" . ".|"))
246     (":|" . (":|" . ()))
247     ("||" . ("||" . ()))
248     (".|." . (".|." . ()))
249     ("|.|" . ("|.|" . ()))
250     ("" . ("" . ""))
251     (":" . (":" . ""))
252     ("." . ("." . ()))
253     ("'" . ("'" . ()))
254     ("empty" . (() . ()))
255     ("brace" . (() . "brace"))
256     ("bracket" . (() . "bracket")) 
257     ))
258
259 (define-public (bar-line::calc-glyph-name grob)
260   (let* (
261          (glyph (ly:grob-property grob 'glyph))
262          (dir (ly:item-break-dir grob))
263          (result (assoc glyph  bar-glyph-alist))
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     glyph-name))
271
272 (define-public (bar-line::calc-break-visibility grob)
273   (let* ((glyph (ly:grob-property grob 'glyph))
274          (result (assoc glyph bar-glyph-alist)))
275     (if result
276         (vector (string? (cadr result)) #t (string? (cddr result)))
277         #(#f #f #f))))
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 (define-public (rgb-color r g b) (list r g b))
306
307 ; predefined colors
308 (define-public black       '(0.0 0.0 0.0))
309 (define-public white       '(1.0 1.0 1.0))
310 (define-public red         '(1.0 0.0 0.0))
311 (define-public green       '(0.0 1.0 0.0))
312 (define-public blue        '(0.0 0.0 1.0))
313 (define-public cyan        '(0.0 1.0 1.0))
314 (define-public magenta     '(1.0 0.0 1.0))
315 (define-public yellow      '(1.0 1.0 0.0))
316
317 (define-public grey        '(0.5 0.5 0.5))
318 (define-public darkred     '(0.5 0.0 0.0))
319 (define-public darkgreen   '(0.0 0.5 0.0))
320 (define-public darkblue    '(0.0 0.0 0.5))
321 (define-public darkcyan    '(0.0 0.5 0.5))
322 (define-public darkmagenta '(0.5 0.0 0.5))
323 (define-public darkyellow  '(0.5 0.5 0.0))
324
325 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
326 ;; key signature
327
328
329 (define-public (key-signature-interface::alteration-position step alter c0-position)
330   ;; TODO: memoize - this is mostly constant.
331   
332   ;; fes, ges, as and bes typeset in lower octave
333   (define FLAT_TOP_PITCH 2)
334   
335   ;; ais and bis typeset in lower octave
336   (define SHARP_TOP_PITCH 4)
337
338   (if (pair? step)
339       (+ (cdr step) (* (car step) 7)  c0-position)
340       (let*
341           ((from-bottom-pos (modulo (+ 4 49 c0-position)  7))
342            (p step)
343            (c0 (- from-bottom-pos  4)))
344         
345         (if
346          (or (and (< alter 0) (or (> p FLAT_TOP_PITCH) (> (+ p c0) 4)) (> (+ p c0) 1))
347              (and (> alter 0) (or (> p SHARP_TOP_PITCH) (> (+ p c0) 5)) (> (+ p c0) 2))
348              )
349
350          ;; Typeset below c_position 
351          (set! p (- p 7)))
352
353         ;; Provide for the four cases in which there's a glitch
354         ;; it's a hack, but probably not worth
355         ;; the effort of finding a nicer solution.
356         ;; --dl. 
357         (cond
358          ((and (= c0 2) (= p 3) (> alter 0))
359           (set! p (- p 7)))
360          ((and (= c0 -3) (= p -1) (> alter 0))
361           (set! p (+ p 7)))
362          ((and (= c0 -4) (= p -1) (< alter 0))
363           (set! p (+ p 7)))
364          ((and (= c0 -2) (= p -3) (< alter 0))
365           (set! p (+ p 7))))
366
367         (+ c0 p))))
368
369
370 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
371 ;; accidentals
372
373 (define-public (accidental-interface::calc-alteration grob)
374   (ly:pitch-alteration  (ly:event-property (event-cause grob) 'pitch)))
375
376
377 (define-public cancellation-glyph-name-alist
378   '((0 . "accidentals.natural")))
379
380 (define-public standard-alteration-glyph-name-alist
381      '(
382        ;; ordered for optimal performance.
383        (0 . "accidentals.natural")
384        (-1/2 . "accidentals.flat")
385        (1/2 . "accidentals.sharp")
386
387        (1 . "accidentals.doublesharp")
388        (-1 . "accidentals.flatflat")
389        
390        (3/4 . "accidentals.sharp.slashslash.stemstemstem")
391        (1/4 . "accidentals.sharp.slashslash.stem")
392        (-1/4 . "accidentals.mirroredflat")
393        (-3/4 . "accidentals.mirroredflat.flat")
394        ))
395
396 ;; FIXME: standard vs default, alteration-FOO vs FOO-alteration
397 (define-public alteration-default-glyph-name-alist standard-alteration-glyph-name-alist)
398
399 (define-public makam-alteration-glyph-name-alist
400      '((1 . "accidentals.doublesharp")
401        (8/9 . "accidentals.sharp.slashslashslash.stemstem")
402        (5/9 . "accidentals.sharp.slashslashslash.stem")
403        (4/9 . "accidentals.sharp")
404        (1/9 . "accidentals.sharp.slashslash.stem")
405        (0 . "accidentals.natural")
406        (-1/9 . "accidentals.mirroredflat")
407        (-4/9 . "accidentals.flat.slash")
408        (-5/9 . "accidentals.flat")
409        (-8/9 . "accidentals.flat.slashslash")
410        (-1 . "accidentals.flatflat")
411        ))
412   
413 (define-public alteration-hufnagel-glyph-name-alist
414    '((-1/2 . "accidentals.hufnagelM1")
415      (0 . "accidentals.vaticana0")
416      (1/2 . "accidentals.mensural1")))
417
418 (define-public alteration-medicaea-glyph-name-alist
419    '((-1/2 . "accidentals.medicaeaM1")
420      (0 . "accidentals.vaticana0")
421      (1/2 . "accidentals.mensural1")))
422
423 (define-public alteration-vaticana-glyph-name-alist
424    '((-1/2 . "accidentals.vaticanaM1")
425      (0 . "accidentals.vaticana0")
426      (1/2 . "accidentals.mensural1")))
427
428 (define-public alteration-mensural-glyph-name-alist
429    '((-1/2 . "accidentals.mensuralM1")
430      (0 . "accidentals.vaticana0")
431      (1/2 . "accidentals.mensural1")))
432
433
434 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
435 ;; * Pitch Trill Heads
436 ;; * Parentheses
437
438 (define-public (parentheses-item::calc-parenthesis-stencils grob)
439   (let* ((font (ly:grob-default-font grob))
440          (lp (ly:font-get-glyph font "accidentals.leftparen"))
441          (rp (ly:font-get-glyph font "accidentals.rightparen")))
442
443     (list lp rp)))
444
445
446 (define-public (grob-interpret-markup grob text)
447   (let*
448       ((layout (ly:grob-layout grob))
449        (defs (ly:output-def-lookup layout 'text-font-defaults))
450        (props (ly:grob-alist-chain grob defs)))
451
452     (ly:text-interface::interpret-markup
453      layout props text)))
454
455 (define-public (parentheses-item::calc-angled-bracket-stencils grob)
456   (let* (
457          (font (ly:grob-default-font grob))
458          (lp (ly:stencil-aligned-to (ly:stencil-aligned-to (grob-interpret-markup grob (ly:wide-char->utf-8 #x2329))
459                                                            Y CENTER)  X RIGHT))
460          (rp (ly:stencil-aligned-to (ly:stencil-aligned-to (grob-interpret-markup grob (ly:wide-char->utf-8 #x232A))
461                                                            Y CENTER) X LEFT))
462          )
463
464     (list (stencil-whiteout lp)
465           (stencil-whiteout rp))))
466
467 (define (parenthesize-elements grob . rest)
468   (let*
469       ((refp (if (null? rest)
470                  grob
471                  (car rest)))
472        (elts (ly:grob-object grob 'elements))
473        (x-ext (ly:relative-group-extent elts refp X))
474        (stencils (ly:grob-property grob 'stencils))
475        (lp (car stencils))
476        (rp (cadr stencils))
477        (padding (ly:grob-property grob 'padding 0.1)))
478     
479     (ly:stencil-add
480      (ly:stencil-translate-axis lp (- (car x-ext) padding) X)
481      (ly:stencil-translate-axis rp (+ (cdr x-ext) padding) X))
482   ))
483
484
485 (define (parentheses-item::print me)
486   (let*
487       ((elts (ly:grob-object me 'elements))
488        (y-ref (ly:grob-common-refpoint-of-array me elts Y))
489        (x-ref (ly:grob-common-refpoint-of-array me elts X))
490        (stencil (parenthesize-elements me x-ref))
491        (elt-y-ext  (ly:relative-group-extent elts y-ref Y))
492        (y-center (interval-center elt-y-ext)))
493
494     (ly:stencil-translate
495      stencil
496      (cons
497       (-
498        (ly:grob-relative-coordinate me x-ref X))
499       (-
500        y-center
501        (ly:grob-relative-coordinate me y-ref Y))))
502     ))
503
504
505
506 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
507 ;; 
508
509 (define-public (chain-grob-member-functions grob value . funcs)
510   (for-each
511    (lambda (func)
512      (set! value (func grob value)))
513    funcs)
514
515   value)
516
517 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
518 ;; falls/doits
519
520 (define-public (bend::print spanner)
521   (define (close  a b)
522     (< (abs (- a b)) 0.01))
523   
524   (let*
525       ((delta-y (* 0.5 (ly:grob-property spanner 'delta-position)))
526        (left-span (ly:spanner-bound spanner LEFT))
527        (dots (if (and (grob::has-interface left-span 'note-head-interface)
528                       (ly:grob? (ly:grob-object left-span 'dot)))
529                  (ly:grob-object left-span 'dot) #f))
530                  
531        (right-span (ly:spanner-bound spanner RIGHT))
532        (thickness (* (ly:grob-property spanner 'thickness)
533                      (ly:output-def-lookup (ly:grob-layout spanner)
534                                            'line-thickness)))
535        (padding (ly:grob-property spanner 'padding 0.5))
536        (common (ly:grob-common-refpoint right-span
537                                         (ly:grob-common-refpoint spanner
538                                                                  left-span X)
539                                         X))
540        (common-y (ly:grob-common-refpoint spanner left-span Y))
541        (left-x (+ padding
542                   (max (interval-end (ly:grob-robust-relative-extent
543                                       left-span common X))
544                         (if (and
545                              dots
546                              (close (ly:grob-relative-coordinate dots common-y Y)
547                                         (ly:grob-relative-coordinate spanner common-y Y)))
548                             (interval-end (ly:grob-robust-relative-extent dots common X))
549                             -10000) ;; TODO: use real infinity constant.
550                         )))
551        (right-x (- (interval-start
552                     (ly:grob-robust-relative-extent right-span common X))
553                    padding))
554        (self-x (ly:grob-relative-coordinate spanner common X))
555        (dx (- right-x left-x))
556        (exp (list 'path thickness 
557                   `(quote
558                     (rmoveto
559                      ,(- left-x self-x) 0
560
561                      rcurveto                
562                      ,(/ dx 3)
563                      0
564                      ,dx ,(* 0.66 delta-y)
565                      ,dx ,delta-y
566                      )))))
567
568     (ly:make-stencil
569      exp
570      (cons (- left-x self-x) (- right-x self-x))
571      (cons (min 0 delta-y)
572            (max 0 delta-y)))))
573
574 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
575 ;; grace spacing
576
577
578 (define-public (grace-spacing::calc-shortest-duration grob)
579   (let*
580      ((cols (ly:grob-object grob 'columns))
581       (get-difference
582        (lambda (idx)
583          (ly:moment-sub (ly:grob-property
584                          (ly:grob-array-ref cols (1+ idx)) 'when)
585                         (ly:grob-property
586                          (ly:grob-array-ref cols idx) 'when))))
587       
588       (moment-min (lambda (x y)
589                     (cond
590                      ((and x y)
591                       (if (ly:moment<? x y)
592                             x
593                             y))
594                      (x x)
595                      (y y)))))
596                      
597     (fold moment-min #f (map get-difference
598                              (iota (1- (ly:grob-array-length cols)))))))
599
600
601
602 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
603 ;; fingering
604
605 (define-public (fingering::calc-text grob)
606   (let*
607       ((event (event-cause grob))
608        (digit (ly:event-property event 'digit)))
609     
610     (if (> digit 5)
611         (ly:input-message (ly:event-property event 'origin)
612                           "Warning: Fingering notation for finger number ~a" digit))
613
614     (number->string digit 10)
615   ))
616
617 (define-public (string-number::calc-text grob)
618   (let*
619       ((digit (ly:event-property (event-cause  grob) 'string-number)))
620     
621     (number->string digit 10)
622   ))
623
624
625 (define-public (stroke-finger::calc-text grob)
626   (let*
627       ((digit (ly:event-property (event-cause grob) 'digit))
628        (text (ly:event-property (event-cause grob) 'text)))
629
630     (if (string? text)
631         text
632         (vector-ref (ly:grob-property grob 'digit-names)  (1- (max (min 5 digit) 1))))))
633
634 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
635 ;; dynamics
636 (define-public (hairpin::calc-grow-direction grob)
637   (if (eq? (ly:event-property (event-cause grob) 'class) 'decrescendo-event)
638       START
639       STOP
640       ))
641
642 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
643 ;; lyrics
644
645 (define-public (lyric-text::print grob)
646   "Allow interpretation of tildes as lyric tieing marks."
647   
648   (let*
649       ((text (ly:grob-property grob 'text)))
650
651     (grob-interpret-markup grob 
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-public (fret-board::calc-stencil grob)
663     (grob-interpret-markup 
664       grob
665       (make-fret-diagram-verbose-markup
666         (ly:grob-property grob 'dot-placement-list))))
667
668 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
669 ;; scripts
670
671 (define-public (script-interface::calc-x-offset grob)
672   (ly:grob-property grob 'positioning-done)
673   (let* ((shift (ly:grob-property grob 'toward-stem-shift 0.0))
674          (note-head-location (ly:self-alignment-interface::centered-on-x-parent grob))
675          (note-head-grob (ly:grob-parent grob X))
676          (stem-grob (ly:grob-object note-head-grob 'stem)))
677     (+ note-head-location
678        ;; If the property 'toward-stem-shift is defined and the script has the
679        ;; same direction as the stem, move the script accordingly. Since scripts can
680        ;; also be over skips, we need to check whether the grob has a stem at all.
681        (if (ly:grob? stem-grob)
682            (let ((dir1 (ly:grob-property grob 'direction))
683                  (dir2 (ly:grob-property stem-grob 'direction)))
684              (if (equal? dir1 dir2)
685                  (let* ((common-refp (ly:grob-common-refpoint grob stem-grob X))
686                         (stem-location (ly:grob-relative-coordinate stem-grob common-refp X)))
687                    (* shift (- stem-location
688                                note-head-location)))
689                  0.0))
690            0.0))))