]> git.donarmstrong.com Git - lilypond.git/blob - scm/translation-functions.scm
* scm/translation-functions.scm (format-bass-figure): inspect stream-event.
[lilypond.git] / scm / translation-functions.scm
1 ;;;; translation-functions.scm --
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;; 
5 ;;;; (c) 1998--2006 Han-Wen Nienhuys <hanwen@cs.uu.nl>
6 ;;;;                 Jan Nieuwenhuizen <janneke@gnu.org>
7
8 ;; metronome marks
9 (define-public (format-metronome-markup event context)
10   (let* ((dur (ly:music-property event 'tempo-unit))
11        (count (ly:music-property event 'metronome-count))
12        (note-mark (make-smaller-markup
13                    (make-note-by-number-markup (ly:duration-log dur)
14                                                (ly:duration-dot-count dur)
15                                                1))))  
16     (make-line-markup
17      (list
18       (make-general-align-markup Y DOWN note-mark)
19       (make-simple-markup  "=")
20       (make-simple-markup (number->string count))))))
21
22 (define-public (format-mark-alphabet mark context)
23   (make-bold-markup (make-markalphabet-markup (1- mark))))
24
25 (define-public (format-mark-box-alphabet mark context)
26   (make-bold-markup (make-box-markup (make-markalphabet-markup (1- mark)))))
27
28 (define-public (format-mark-circle-alphabet mark context)
29   (make-bold-markup (make-circle-markup (make-markalphabet-markup (1- mark)))))
30
31 (define-public (format-mark-letters mark context)
32   (make-bold-markup (make-markletter-markup (1- mark))))
33
34 (define-public (format-mark-numbers mark context)
35   (make-bold-markup (number->string mark)))
36
37 (define-public (format-mark-barnumbers mark context)
38   (make-bold-markup (number->string (ly:context-property context 'currentBarNumber))))
39
40 (define-public (format-mark-box-letters mark context)
41   (make-bold-markup (make-box-markup (make-markletter-markup (1- mark)))))
42
43 (define-public (format-mark-circle-letters mark context)
44   (make-bold-markup (make-circle-markup (make-markletter-markup (1- mark)))))
45
46 (define-public (format-mark-box-numbers mark context)
47   (make-bold-markup (make-box-markup (number->string mark))))
48
49 (define-public (format-mark-circle-numbers mark context)
50   (make-bold-markup (make-circle-markup (number->string mark))))
51
52 (define-public (format-mark-box-barnumbers mark context)
53   (make-bold-markup (make-box-markup
54     (number->string (ly:context-property context 'currentBarNumber)))))
55
56 (define-public (format-mark-circle-barnumbers mark context)
57   (make-bold-markup (make-circle-markup
58     (number->string (ly:context-property context 'currentBarNumber)))))
59
60
61 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
62 ;; Bass figures.
63 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
64
65 (define-public (format-bass-figure figure stream-event context)
66   (let* ((event (ly:event-property stream-event 'music-cause ))
67          (fig (ly:music-property event 'figure))
68          (fig-markup (if (number? figure)
69
70                          ;; this is not very elegant, but center-aligning all digits
71                          ;; is problematic with other markups, and shows problems
72                          ;; in the (lack of) overshoot of feta alphabet glyphs.
73                          
74                          ((if (<= 10 figure)
75                               (lambda (y) (make-translate-scaled-markup (cons -0.7 0) y))
76                               identity)
77
78                           (if (eq? #t (ly:music-property event 'diminished))
79                               (markup #:slashed-digit figure)
80                               (markup #:number (number->string figure 10))))
81                          #f
82                          ))
83          (alt (ly:music-property event 'alteration))
84          (alt-markup
85           (if (number? alt)
86               (markup
87                #:general-align Y DOWN #:fontsize
88                (if (not (= alt DOUBLE-SHARP))
89                    -2 2)
90                (alteration->text-accidental-markup alt))
91               
92               #f))
93          (plus-markup (if (eq? #t (ly:music-property event 'augmented))
94                           (markup #:number "+")
95                           #f))
96
97          (alt-dir (ly:context-property context 'figuredBassAlterationDirection))
98          (plus-dir (ly:context-property context 'figuredBassPlusDirection))
99          )
100
101     (if (and (not fig-markup) alt-markup)
102         (begin
103           (set! fig-markup (markup #:left-align #:pad-around 0.3 alt-markup))
104           (set! alt-markup #f)))
105
106
107     ;; hmm, how to get figures centered between note, and
108     ;; lone accidentals too?
109     
110     ;;    (if (markup? fig-markup)
111     ;;  (set!
112     ;;   fig-markup (markup #:translate (cons 1.0 0)
113     ;;                      #:hcenter fig-markup)))
114
115     (if alt-markup
116         (set! fig-markup
117               (markup #:put-adjacent
118                       fig-markup X
119                       (if (number? alt-dir)
120                           alt-dir
121                           LEFT)
122                       #:pad-x 0.2 alt-markup
123                       )))
124
125     
126     (if plus-markup
127         (set! fig-markup
128               (if fig-markup
129                   (markup #:put-adjacent
130                           fig-markup
131                           X (if (number? plus-dir)
132                                 plus-dir
133                                 LEFT)
134                           #:pad-x 0.2 plus-markup)
135                   plus-markup)))
136     
137     (if (markup? fig-markup)
138         (markup #:fontsize -2 fig-markup)
139         empty-markup)
140
141     ))
142