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