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 text dur count context)
10 (let* ((hide_note (eq? #t (ly:context-property context 'tempoHideNote)))
11 (note-mark (if (and (not hide_note) (ly:duration? dur))
13 (make-note-by-number-markup (ly:duration-log dur)
14 (ly:duration-dot-count dur)
17 (note-markup (if (and note-mark (number? count) (> count 0) )
18 (make-concat-markup (list
19 (make-general-align-markup Y DOWN note-mark)
20 (make-simple-markup " ")
21 (make-simple-markup "=")
22 (make-simple-markup " ")
23 (make-simple-markup (number->string count))))
25 (text-markup (if (not (null? text))
26 (make-bold-markup text)
30 (make-line-markup (list text-markup
31 (make-concat-markup (list (make-simple-markup "(")
33 (make-simple-markup ")")))))
34 (make-line-markup (list text-markup))
37 (make-line-markup (list note-markup))
44 (define-public (format-mark-alphabet mark context)
45 (make-bold-markup (make-markalphabet-markup (1- mark))))
47 (define-public (format-mark-box-alphabet mark context)
48 (make-bold-markup (make-box-markup (make-markalphabet-markup (1- mark)))))
50 (define-public (format-mark-circle-alphabet mark context)
51 (make-bold-markup (make-circle-markup (make-markalphabet-markup (1- mark)))))
53 (define-public (format-mark-letters mark context)
54 (make-bold-markup (make-markletter-markup (1- mark))))
56 (define-public (format-mark-numbers mark context)
57 (make-bold-markup (number->string mark)))
59 (define-public (format-mark-barnumbers mark context)
60 (make-bold-markup (number->string (ly:context-property context 'currentBarNumber))))
62 (define-public (format-mark-box-letters mark context)
63 (make-bold-markup (make-box-markup (make-markletter-markup (1- mark)))))
65 (define-public (format-mark-circle-letters mark context)
66 (make-bold-markup (make-circle-markup (make-markletter-markup (1- mark)))))
68 (define-public (format-mark-box-numbers mark context)
69 (make-bold-markup (make-box-markup (number->string mark))))
71 (define-public (format-mark-circle-numbers mark context)
72 (make-bold-markup (make-circle-markup (number->string mark))))
74 (define-public (format-mark-box-barnumbers mark context)
75 (make-bold-markup (make-box-markup
76 (number->string (ly:context-property context 'currentBarNumber)))))
78 (define-public (format-mark-circle-barnumbers mark context)
79 (make-bold-markup (make-circle-markup
80 (number->string (ly:context-property context 'currentBarNumber)))))
83 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
85 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
87 (define-public (format-bass-figure figure event context)
88 (let* ((fig (ly:event-property event 'figure))
89 (fig-markup (if (number? figure)
91 ;; this is not very elegant, but center-aligning all digits
92 ;; is problematic with other markups, and shows problems
93 ;; in the (lack of) overshoot of feta alphabet glyphs.
96 (lambda (y) (make-translate-scaled-markup (cons -0.7 0) y))
100 ((eq? #t (ly:event-property event 'diminished))
101 (markup #:slashed-digit figure))
102 ((eq? #t (ly:event-property event 'augmented-slash))
103 (markup #:backslashed-digit figure))
104 (else (markup #:number (number->string figure 10)))))
107 (alt (ly:event-property event 'alteration))
111 #:general-align Y DOWN #:fontsize
112 (if (not (= alt DOUBLE-SHARP))
114 (alteration->text-accidental-markup alt))
117 (plus-markup (if (eq? #t (ly:event-property event 'augmented))
118 (markup #:number "+")
121 (alt-dir (ly:context-property context 'figuredBassAlterationDirection))
122 (plus-dir (ly:context-property context 'figuredBassPlusDirection))
125 (if (and (not fig-markup) alt-markup)
127 (set! fig-markup (markup #:left-align #:pad-around 0.3 alt-markup))
128 (set! alt-markup #f)))
131 ;; hmm, how to get figures centered between note, and
132 ;; lone accidentals too?
134 ;; (if (markup? fig-markup)
136 ;; fig-markup (markup #:translate (cons 1.0 0)
137 ;; #:hcenter fig-markup)))
141 (markup #:put-adjacent
143 (if (number? alt-dir)
146 #:pad-x 0.2 alt-markup
153 (markup #:put-adjacent
155 X (if (number? plus-dir)
158 #:pad-x 0.2 plus-markup)
161 (if (markup? fig-markup)
162 (markup #:fontsize -2 fig-markup)
167 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
170 (define-public (determine-frets context grob notes string-numbers)
171 (define (ensure-number a b)
176 ((tunings (ly:context-property context 'stringTunings))
177 (details (ly:grob-property grob 'fret-diagram-details))
178 (minimum-fret (ensure-number
179 (ly:context-property context 'minimumFret) 0))
180 (max-stretch (ensure-number
181 (ly:context-property context 'maximumFretStretch) 4))
182 (string-frets (determine-frets-mf notes string-numbers
183 minimum-fret max-stretch
186 (set! (ly:grob-property grob 'fret-diagram-details)
188 (acons 'string-count (length tunings) '())
189 (acons 'string-count (length tunings) details)))
190 (set! (ly:grob-property grob 'string-fret-finger-combinations) string-frets)))
192 (define-public (determine-frets-mf notes string-numbers
193 minimum-fret max-stretch
196 (define (calc-fret pitch string tuning)
197 (- (ly:pitch-semitones pitch) (list-ref tuning (1- string))))
199 (define (note-pitch a)
200 (ly:event-property a 'pitch))
202 (define (note-pitch<? a b)
203 (ly:pitch<? (note-pitch a)
206 (define (note-finger ev)
207 (let* ((articulations (ly:event-property ev 'articulations))
212 ((num (ly:event-property art 'digit)))
214 (if (and (eq? 'fingering-event (ly:event-property art 'class))
216 (set! finger-found num))))
221 (define (note-string ev)
222 (let* ((articulations (ly:event-property ev 'articulations))
227 ((num (ly:event-property art 'string-number)))
230 (set! string-found num))))
235 (define (del-string string)
238 (delete string free-strings))))
239 (define specified-frets '())
240 (define free-strings '())
242 (define (close-enough fret)
247 (map (lambda (specced-fret)
248 (> max-stretch (abs (- fret specced-fret))))
252 (define (string-qualifies string pitch)
254 ((fret (calc-fret pitch string tunings)))
256 (and (>= fret minimum-fret)
261 (define string-fret-fingering-tuples '())
262 (define (set-fret note string)
263 (set! string-fret-fingering-tuples
265 (calc-fret (ly:event-property note 'pitch)
268 string-fret-fingering-tuples))
273 (set! specified-frets
274 (filter identity (map
276 (if (note-string note)
277 (calc-fret (note-pitch note)
278 (note-string note) tunings)
283 (set! free-strings (map 1+ (iota (length tunings))))
285 (for-each (lambda (note)
286 (del-string (note-string note)))
292 (if (note-string note)
293 (set-fret note (note-string note))
295 ((string (find (lambda (string) (string-qualifies string
297 (reverse free-strings))))
299 (set-fret note string)
300 (ly:warning "No string for pitch ~a (given frets ~a)" (note-pitch note)
304 (sort notes note-pitch<?))
306 string-fret-fingering-tuples)