]> git.donarmstrong.com Git - lilypond.git/blob - scm/bass-figure.scm
* lily/font-interface.cc (get-font): take alist chain i.s.o. alist
[lilypond.git] / scm / bass-figure.scm
1 ;;;; figured bass support ...
2
3 ;;;; todo: make interfaces as 1st level objects in LilyPond.
4
5 (define (brew-one-figure grob fig-music)
6   "Brew a single column for a music figure"
7   (let* (
8          (mf (ly:get-font grob (cons  '((font-family . music))
9                                       Font_interface::get_property_alist_chain
10                                       )))
11          (nf (ly:get-font grob
12                           (cons  '((font-family . number))
13                                  Font_interface::get_property_alist_chain)))
14          (mol (ly:make-molecule  '() '(0 . 0) '(0 . 1.0)))
15          (fig  (ly:get-mus-property fig-music 'figure))
16          (acc  (ly:get-mus-property fig-music 'alteration))
17          )
18     
19     (if (number? fig)
20         (begin
21           (set! mol   (fontify-text nf (number->string fig)))
22           (ly:align-to! mol Y CENTER)
23         ))
24     
25     (if (number? acc)
26         (set! mol
27               (ly:combine-molecule-at-edge
28                mol 0 1 (ly:find-glyph-by-name mf (string-append "accidentals-" (number->string acc)))
29                0.2))
30         )
31     (if (ly:molecule? mol)
32         (ly:align-to! mol X CENTER)
33         )
34     mol))
35
36 (define (brew-bass-figure grob)
37   "Make a molecule for a Figured Bass grob"
38   (let* (
39          (figs (ly:get-grob-property grob 'causes ))
40          (mol (ly:make-molecule '() '(0 . 0) '(0 . 0)))
41          (padding (ly:get-grob-property grob 'padding))
42          (kerning (ly:get-grob-property grob 'kern))
43          (thickness (*
44                      (ly:get-paper-variable grob 'linethickness)
45                      (ly:get-grob-property grob 'thickness))
46                     )
47          )
48
49     (define (brew-complete-figure grob figs mol)
50       "recursive function: take some stuff from FIGS, and add it to MOL." 
51       (define (end-bracket? fig)
52         (eq? (ly:get-mus-property fig 'bracket-stop) #t)
53         )
54       
55       (if (null? figs)
56           mol
57           (if (eq? (ly:get-mus-property (car figs) 'bracket-start) #t)
58               (let* (
59                      (gather-todo (take-from-list-until figs '() end-bracket?))
60                      (unbr-mols
61                       (map
62                        (lambda (x) (brew-one-figure grob x))
63                        (reverse! (car gather-todo) '())))
64                      (br-mol (bracketify-molecule
65                               (stack-molecules Y UP kerning unbr-mols)
66                               Y thickness (* 2 padding) padding))
67                      )
68                 (brew-complete-figure
69                  grob (cdr gather-todo)
70                  (ly:combine-molecule-at-edge mol Y UP br-mol kerning)
71                  )
72                 )
73               (brew-complete-figure
74                grob (cdr figs)
75                (ly:combine-molecule-at-edge mol Y UP (brew-one-figure grob (car figs))
76                                             kerning))
77               )
78           ))
79
80     
81     (set! mol (brew-complete-figure grob (reverse figs) mol))
82     (ly:align-to! mol Y DOWN)
83     mol
84     ))
85
86
87 (ly:add-interface
88 'bass-figure-interface
89  "A bass figure, including bracket"
90  '(padding thickness ))