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 (not hide-note) (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)
29 (if (and note-markup (not hide-note))
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)))
36 (make-line-markup (list note-markup))
37 (make-null-markup)))))
39 (define-public (format-mark-alphabet mark context)
40 (make-bold-markup (make-markalphabet-markup (1- mark))))
42 (define-public (format-mark-box-alphabet mark context)
43 (make-bold-markup (make-box-markup (make-markalphabet-markup (1- mark)))))
45 (define-public (format-mark-circle-alphabet mark context)
46 (make-bold-markup (make-circle-markup (make-markalphabet-markup (1- mark)))))
48 (define-public (format-mark-letters mark context)
49 (make-bold-markup (make-markletter-markup (1- mark))))
51 (define-public (format-mark-numbers mark context)
52 (make-bold-markup (number->string mark)))
54 (define-public (format-mark-barnumbers mark context)
55 (make-bold-markup (number->string (ly:context-property context 'currentBarNumber))))
57 (define-public (format-mark-box-letters mark context)
58 (make-bold-markup (make-box-markup (make-markletter-markup (1- mark)))))
60 (define-public (format-mark-circle-letters mark context)
61 (make-bold-markup (make-circle-markup (make-markletter-markup (1- mark)))))
63 (define-public (format-mark-box-numbers mark context)
64 (make-bold-markup (make-box-markup (number->string mark))))
66 (define-public (format-mark-circle-numbers mark context)
67 (make-bold-markup (make-circle-markup (number->string mark))))
69 (define-public (format-mark-box-barnumbers mark context)
70 (make-bold-markup (make-box-markup
71 (number->string (ly:context-property context 'currentBarNumber)))))
73 (define-public (format-mark-circle-barnumbers mark context)
74 (make-bold-markup (make-circle-markup
75 (number->string (ly:context-property context 'currentBarNumber)))))
78 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
80 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
82 (define-public (format-bass-figure figure event context)
83 (let* ((fig (ly:event-property event 'figure))
84 (fig-markup (if (number? figure)
86 ;; this is not very elegant, but center-aligning all digits
87 ;; is problematic with other markups, and shows problems
88 ;; in the (lack of) overshoot of feta alphabet glyphs.
91 (lambda (y) (make-translate-scaled-markup (cons -0.7 0) y))
95 ((eq? #t (ly:event-property event 'diminished))
96 (markup #:slashed-digit figure))
97 ((eq? #t (ly:event-property event 'augmented-slash))
98 (markup #:backslashed-digit figure))
99 (else (markup #:number (number->string figure 10)))))
102 (alt (ly:event-property event 'alteration))
106 #:general-align Y DOWN #:fontsize
107 (if (not (= alt DOUBLE-SHARP))
109 (alteration->text-accidental-markup alt))
112 (plus-markup (if (eq? #t (ly:event-property event 'augmented))
113 (markup #:number "+")
116 (alt-dir (ly:context-property context 'figuredBassAlterationDirection))
117 (plus-dir (ly:context-property context 'figuredBassPlusDirection))
120 (if (and (not fig-markup) alt-markup)
122 (set! fig-markup (markup #:left-align #:pad-around 0.3 alt-markup))
123 (set! alt-markup #f)))
126 ;; hmm, how to get figures centered between note, and
127 ;; lone accidentals too?
129 ;; (if (markup? fig-markup)
131 ;; fig-markup (markup #:translate (cons 1.0 0)
132 ;; #:center-align fig-markup)))
136 (markup #:put-adjacent
137 X (if (number? alt-dir)
141 #:pad-x 0.2 alt-markup
148 (markup #:put-adjacent
149 X (if (number? plus-dir)
153 #:pad-x 0.2 plus-markup)
156 (if (markup? fig-markup)
157 (markup #:fontsize -2 fig-markup)
162 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
165 (define-public (determine-frets context grob notes string-numbers)
167 (define (ensure-number a b)
172 (define (string-frets->dot-placement string-frets string-count)
175 (map (lambda (x) (list 'mute (1+ x)))
176 (iota string-count)))))
178 (for-each (lambda (sf)
189 (list 'place-fret string fret finger)
190 (list 'place-fret string fret))
194 (vector->list desc)))
198 ((tunings (ly:context-property context 'stringTunings))
199 (my-string-count (length tunings))
200 (details (ly:grob-property grob 'fret-diagram-details))
202 (ly:context-property context 'predefinedDiagramTable))
203 (minimum-fret (ensure-number
204 (ly:context-property context 'minimumFret) 0))
205 (max-stretch (ensure-number
206 (ly:context-property context 'maximumFretStretch) 4))
207 (string-frets (determine-frets-mf notes string-numbers
208 minimum-fret max-stretch
210 (pitches (map (lambda (x) (ly:event-property x 'pitch)) notes)))
212 (set! (ly:grob-property grob 'fret-diagram-details)
215 (acons 'string-count (length tunings) '())
216 (acons 'string-count (length tunings) details)))
217 (set! (ly:grob-property grob 'dot-placement-list)
222 (cons tunings pitches))))
224 (cdr hash-handle) ;found default diagram
225 (string-frets->dot-placement
226 string-frets my-string-count)))
227 (string-frets->dot-placement string-frets my-string-count)))))
229 (define-public (determine-frets-mf notes string-numbers
230 minimum-fret max-stretch
233 (define (calc-fret pitch string tuning)
234 (- (ly:pitch-semitones pitch) (list-ref tuning (1- string))))
236 (define (note-pitch a)
237 (ly:event-property a 'pitch))
239 (define (note-pitch>? a b)
240 (ly:pitch<? (note-pitch b)
243 (define (note-finger ev)
244 (let* ((articulations (ly:event-property ev 'articulations))
249 ((num (ly:event-property art 'digit)))
251 (if (and (eq? 'fingering-event (ly:event-property art 'class))
253 (set! finger-found num))))
258 (define (note-string ev)
259 (let* ((articulations (ly:event-property ev 'articulations))
264 ((num (ly:event-property art 'string-number)))
267 (set! string-found num))))
272 (define (del-string string)
275 (delete string free-strings))))
276 (define specified-frets '())
277 (define free-strings '())
279 (define (close-enough fret)
284 (map (lambda (specced-fret)
285 (> max-stretch (abs (- fret specced-fret))))
289 (define (string-qualifies string pitch)
291 ((fret (calc-fret pitch string tunings)))
293 (and (>= fret minimum-fret)
298 (define string-fret-fingering-tuples '())
299 (define (set-fret note string)
300 (set! string-fret-fingering-tuples
302 (calc-fret (ly:event-property note 'pitch)
305 string-fret-fingering-tuples))
310 (set! specified-frets
311 (filter identity (map
313 (if (note-string note)
314 (calc-fret (note-pitch note)
315 (note-string note) tunings)
320 (set! free-strings (map 1+ (iota (length tunings))))
322 (for-each (lambda (note)
323 (del-string (note-string note)))
329 (if (note-string note)
330 (set-fret note (note-string note))
332 ((fit-string (find (lambda (string)
333 (string-qualifies string (note-pitch note)))
336 (set-fret note fit-string)
337 (ly:warning "No string for pitch ~a (given frets ~a)"
342 (sort notes note-pitch>?))
344 string-fret-fingering-tuples)