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