1 ;;;; translation-functions.scm --
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2009 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 (metronome-markup text dur count hide-note)))
13 (define-public (metronome-markup text dur count hide-note)
14 (let* ((note-mark (if (and (not hide-note) (ly:duration? dur))
16 (make-note-by-number-markup (ly:duration-log dur)
17 (ly:duration-dot-count dur)
20 (note-markup (if (and (not hide-note) (number? count) (> count 0) )
21 (make-concat-markup (list
22 (make-general-align-markup Y DOWN note-mark)
23 (make-simple-markup " ")
24 (make-simple-markup "=")
25 (make-simple-markup " ")
26 (make-simple-markup (number->string count))))
28 (text-markup (if (not (null? text))
29 (make-bold-markup text)
32 (if (and note-markup (not hide-note))
33 (make-line-markup (list text-markup
34 (make-concat-markup (list (make-simple-markup "(")
36 (make-simple-markup ")")))))
37 (make-line-markup (list text-markup)))
39 (make-line-markup (list note-markup))
40 (make-null-markup)))))
42 (define-public (format-mark-alphabet mark context)
43 (make-bold-markup (make-markalphabet-markup (1- mark))))
45 (define-public (format-mark-box-alphabet mark context)
46 (make-bold-markup (make-box-markup (make-markalphabet-markup (1- mark)))))
48 (define-public (format-mark-circle-alphabet mark context)
49 (make-bold-markup (make-circle-markup (make-markalphabet-markup (1- mark)))))
51 (define-public (format-mark-letters mark context)
52 (make-bold-markup (make-markletter-markup (1- mark))))
54 (define-public (format-mark-numbers mark context)
55 (make-bold-markup (number->string mark)))
57 (define-public (format-mark-barnumbers mark context)
58 (make-bold-markup (number->string (ly:context-property context 'currentBarNumber))))
60 (define-public (format-mark-box-letters mark context)
61 (make-bold-markup (make-box-markup (make-markletter-markup (1- mark)))))
63 (define-public (format-mark-circle-letters mark context)
64 (make-bold-markup (make-circle-markup (make-markletter-markup (1- mark)))))
66 (define-public (format-mark-box-numbers mark context)
67 (make-bold-markup (make-box-markup (number->string mark))))
69 (define-public (format-mark-circle-numbers mark context)
70 (make-bold-markup (make-circle-markup (number->string mark))))
72 (define-public (format-mark-box-barnumbers mark context)
73 (make-bold-markup (make-box-markup
74 (number->string (ly:context-property context 'currentBarNumber)))))
76 (define-public (format-mark-circle-barnumbers mark context)
77 (make-bold-markup (make-circle-markup
78 (number->string (ly:context-property context 'currentBarNumber)))))
81 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
83 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
85 (define-public (format-bass-figure figure event context)
86 (let* ((fig (ly:event-property event 'figure))
87 (fig-markup (if (number? figure)
89 ;; this is not very elegant, but center-aligning all digits
90 ;; is problematic with other markups, and shows problems
91 ;; in the (lack of) overshoot of feta alphabet glyphs.
94 (lambda (y) (make-translate-scaled-markup (cons -0.7 0) y))
98 ((eq? #t (ly:event-property event 'diminished))
99 (markup #:slashed-digit figure))
100 ((eq? #t (ly:event-property event 'augmented-slash))
101 (markup #:backslashed-digit figure))
102 (else (markup #:number (number->string figure 10)))))
105 (alt (ly:event-property event 'alteration))
109 #:general-align Y DOWN #:fontsize
110 (if (not (= alt DOUBLE-SHARP))
112 (alteration->text-accidental-markup alt))
115 (plus-markup (if (eq? #t (ly:event-property event 'augmented))
116 (markup #:number "+")
119 (alt-dir (ly:context-property context 'figuredBassAlterationDirection))
120 (plus-dir (ly:context-property context 'figuredBassPlusDirection))
123 (if (and (not fig-markup) alt-markup)
125 (set! fig-markup (markup #:left-align #:pad-around 0.3 alt-markup))
126 (set! alt-markup #f)))
129 ;; hmm, how to get figures centered between note, and
130 ;; lone accidentals too?
132 ;; (if (markup? fig-markup)
134 ;; fig-markup (markup #:translate (cons 1.0 0)
135 ;; #:center-align fig-markup)))
139 (markup #:put-adjacent
140 X (if (number? alt-dir)
144 #:pad-x 0.2 alt-markup
151 (markup #:put-adjacent
152 X (if (number? plus-dir)
156 #:pad-x 0.2 plus-markup)
159 (if (markup? fig-markup)
160 (markup #:fontsize -2 fig-markup)
165 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
168 (define-public (determine-frets context grob notes string-numbers)
170 (define (ensure-number a b)
175 (define (string-frets->dot-placement string-frets string-count)
178 (map (lambda (x) (list 'mute (1+ x)))
179 (iota string-count)))))
181 (for-each (lambda (sf)
192 (list 'place-fret string fret finger)
193 (list 'place-fret string fret))
197 (vector->list desc)))
201 ((tunings (ly:context-property context 'stringTunings))
202 (my-string-count (length tunings))
203 (details (ly:grob-property grob 'fret-diagram-details))
205 (ly:context-property context 'predefinedDiagramTable))
206 (minimum-fret (ensure-number
207 (ly:context-property context 'minimumFret) 0))
208 (max-stretch (ensure-number
209 (ly:context-property context 'maximumFretStretch) 4))
210 (string-frets (determine-frets-mf notes string-numbers
211 minimum-fret max-stretch
213 (pitches (map (lambda (x) (ly:event-property x 'pitch)) notes)))
215 (set! (ly:grob-property grob 'fret-diagram-details)
218 (acons 'string-count (length tunings) '())
219 (acons 'string-count (length tunings) details)))
220 (set! (ly:grob-property grob 'dot-placement-list)
225 (cons tunings pitches))))
227 (cdr hash-handle) ;found default diagram
228 (string-frets->dot-placement
229 string-frets my-string-count)))
230 (string-frets->dot-placement string-frets my-string-count)))))
232 (define-public (determine-frets-mf notes string-numbers
233 minimum-fret max-stretch
236 (define (calc-fret pitch string tuning)
237 (- (ly:pitch-semitones pitch) (list-ref tuning (1- string))))
239 (define (note-pitch a)
240 (ly:event-property a 'pitch))
242 (define (note-pitch>? a b)
243 (ly:pitch<? (note-pitch b)
246 (define (note-finger ev)
247 (let* ((articulations (ly:event-property ev 'articulations))
252 ((num (ly:event-property art 'digit)))
254 (if (and (eq? 'fingering-event (ly:event-property art 'class))
256 (set! finger-found num))))
261 (define (note-string ev)
262 (let* ((articulations (ly:event-property ev 'articulations))
267 ((num (ly:event-property art 'string-number)))
270 (set! string-found num))))
275 (define (del-string string)
278 (delete string free-strings))))
279 (define specified-frets '())
280 (define free-strings '())
282 (define (close-enough fret)
287 (map (lambda (specced-fret)
288 (> max-stretch (abs (- fret specced-fret))))
292 (define (string-qualifies string pitch)
294 ((fret (calc-fret pitch string tunings)))
296 (and (>= fret minimum-fret)
301 (define string-fret-fingering-tuples '())
302 (define (set-fret note string)
303 (set! string-fret-fingering-tuples
305 (calc-fret (ly:event-property note 'pitch)
308 string-fret-fingering-tuples))
313 (set! specified-frets
314 (filter identity (map
316 (if (note-string note)
317 (calc-fret (note-pitch note)
318 (note-string note) tunings)
323 (set! free-strings (map 1+ (iota (length tunings))))
325 (for-each (lambda (note)
326 (del-string (note-string note)))
332 (if (note-string note)
333 (set-fret note (note-string note))
335 ((fit-string (find (lambda (string)
336 (string-qualifies string (note-pitch note)))
339 (set-fret note fit-string)
340 (ly:warning "No string for pitch ~a (given frets ~a)"
345 (sort notes note-pitch>?))
347 string-fret-fingering-tuples)