1 ;;;; translation-functions.scm --
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 ;;;; Jan Nieuwenhuizen <janneke@gnu.org>
9 (define-public (format-metronome-markup dur count context)
10 (let* ((note-mark (make-smaller-markup
11 (make-note-by-number-markup (ly:duration-log dur)
12 (ly:duration-dot-count dur)
16 (make-general-align-markup Y DOWN note-mark)
17 (make-simple-markup "=")
18 (make-simple-markup (number->string count))))))
20 (define-public (format-mark-alphabet mark context)
21 (make-bold-markup (make-markalphabet-markup (1- mark))))
23 (define-public (format-mark-box-alphabet mark context)
24 (make-bold-markup (make-box-markup (make-markalphabet-markup (1- mark)))))
26 (define-public (format-mark-circle-alphabet mark context)
27 (make-bold-markup (make-circle-markup (make-markalphabet-markup (1- mark)))))
29 (define-public (format-mark-letters mark context)
30 (make-bold-markup (make-markletter-markup (1- mark))))
32 (define-public (format-mark-numbers mark context)
33 (make-bold-markup (number->string mark)))
35 (define-public (format-mark-barnumbers mark context)
36 (make-bold-markup (number->string (ly:context-property context 'currentBarNumber))))
38 (define-public (format-mark-box-letters mark context)
39 (make-bold-markup (make-box-markup (make-markletter-markup (1- mark)))))
41 (define-public (format-mark-circle-letters mark context)
42 (make-bold-markup (make-circle-markup (make-markletter-markup (1- mark)))))
44 (define-public (format-mark-box-numbers mark context)
45 (make-bold-markup (make-box-markup (number->string mark))))
47 (define-public (format-mark-circle-numbers mark context)
48 (make-bold-markup (make-circle-markup (number->string mark))))
50 (define-public (format-mark-box-barnumbers mark context)
51 (make-bold-markup (make-box-markup
52 (number->string (ly:context-property context 'currentBarNumber)))))
54 (define-public (format-mark-circle-barnumbers mark context)
55 (make-bold-markup (make-circle-markup
56 (number->string (ly:context-property context 'currentBarNumber)))))
59 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
61 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
63 (define-public (format-bass-figure figure event context)
64 (let* ((fig (ly:event-property event 'figure))
65 (fig-markup (if (number? figure)
67 ;; this is not very elegant, but center-aligning all digits
68 ;; is problematic with other markups, and shows problems
69 ;; in the (lack of) overshoot of feta alphabet glyphs.
72 (lambda (y) (make-translate-scaled-markup (cons -0.7 0) y))
75 (if (eq? #t (ly:event-property event 'diminished))
76 (markup #:slashed-digit figure)
77 (markup #:number (number->string figure 10))))
80 (alt (ly:event-property event 'alteration))
84 #:general-align Y DOWN #:fontsize
85 (if (not (= alt DOUBLE-SHARP))
87 (alteration->text-accidental-markup alt))
90 (plus-markup (if (eq? #t (ly:event-property event 'augmented))
94 (alt-dir (ly:context-property context 'figuredBassAlterationDirection))
95 (plus-dir (ly:context-property context 'figuredBassPlusDirection))
98 (if (and (not fig-markup) alt-markup)
100 (set! fig-markup (markup #:left-align #:pad-around 0.3 alt-markup))
101 (set! alt-markup #f)))
104 ;; hmm, how to get figures centered between note, and
105 ;; lone accidentals too?
107 ;; (if (markup? fig-markup)
109 ;; fig-markup (markup #:translate (cons 1.0 0)
110 ;; #:hcenter fig-markup)))
114 (markup #:put-adjacent
116 (if (number? alt-dir)
119 #:pad-x 0.2 alt-markup
126 (markup #:put-adjacent
128 X (if (number? plus-dir)
131 #:pad-x 0.2 plus-markup)
134 (if (markup? fig-markup)
135 (markup #:fontsize -2 fig-markup)
140 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
143 (define-public (determine-frets context grob notes string-numbers)
144 (define (ensure-number a b)
149 ((tunings (ly:context-property context 'stringTunings))
150 (minimum-fret (ensure-number
151 (ly:context-property context 'minimumFret) 0))
152 (max-stretch (ensure-number
153 (ly:context-property context 'maximumFretStretch) 4))
154 (string-frets (determine-frets-mf notes string-numbers
155 minimum-fret max-stretch
159 (set! (ly:grob-property grob 'string-count) (length tunings))
160 (set! (ly:grob-property grob 'string-fret-finger-combinations) string-frets)
164 (define-public (determine-frets-mf notes string-numbers
165 minimum-fret max-stretch
168 (define (calc-fret pitch string tuning)
169 (- (ly:pitch-semitones pitch) (list-ref tuning (1- string))))
171 (define (note-pitch a)
172 (ly:event-property a 'pitch))
174 (define (note-pitch<? a b)
175 (ly:pitch<? (note-pitch a)
178 (define (note-finger ev)
179 (let* ((articulations (ly:event-property ev 'articulations))
184 ((num (ly:event-property art 'digit)))
186 (if (and (eq? 'fingering-event (ly:event-property art 'class))
188 (set! finger-found num))))
193 (define (note-string ev)
194 (let* ((articulations (ly:event-property ev 'articulations))
199 ((num (ly:event-property art 'string-number)))
202 (set! string-found num))))
207 (define (del-string string)
210 (delete string free-strings))))
211 (define specified-frets '())
212 (define free-strings '())
214 (define (close-enough fret)
219 (map (lambda (specced-fret)
220 (> max-stretch (abs (- fret specced-fret))))
224 (define (string-qualifies string pitch)
226 ((fret (calc-fret pitch string tunings)))
228 (and (>= fret minimum-fret)
233 (define string-fret-fingering-tuples '())
234 (define (set-fret note string)
235 (set! string-fret-fingering-tuples
237 (calc-fret (ly:event-property note 'pitch)
240 string-fret-fingering-tuples))
245 (set! specified-frets
246 (filter identity (map
248 (if (note-string note)
249 (calc-fret (note-pitch note)
250 (note-string note) tunings)
255 (set! free-strings (map 1+ (iota (length tunings))))
257 (for-each (lambda (note)
258 (del-string (note-string note)))
264 (if (note-string note)
265 (set-fret note (note-string note))
267 ((string (find (lambda (string) (string-qualifies string
269 (reverse free-strings))))
271 (set-fret note string)
272 (ly:warning "No string for pitch ~a (given frets ~a)" (note-pitch note)
276 (sort notes note-pitch<?))
278 string-fret-fingering-tuples)