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)))
199 (define (get-predefined-fretboard predefined-fret-table tuning pitches)
200 ; (_i "Search through @var{predefined-fret-table} looking for a predefined
201 ;fretboard with a key of @var{(tuning . pitches)}. The search will check
202 ;both up and down an octave in order to accomodate transposition of the
204 (define (get-fretboard key)
206 (hash-get-handle predefined-fret-table key)))
208 (cdr hash-handle) ; return table entry
211 (let ((test-fretboard (get-fretboard (cons tuning pitches))))
212 (if (not (null? test-fretboard))
214 (let ((test-fretboard
216 (cons tuning (map (lambda (x) (shift-octave x 1)) pitches)))))
217 (if (not (null? test-fretboard))
220 (cons tuning (map (lambda (x) (shift-octave x -1)) pitches))))))))
224 ((tunings (ly:context-property context 'stringTunings))
225 (my-string-count (length tunings))
226 (details (ly:grob-property grob 'fret-diagram-details))
228 (ly:context-property context 'predefinedDiagramTable))
229 (minimum-fret (ensure-number
230 (ly:context-property context 'minimumFret) 0))
231 (max-stretch (ensure-number
232 (ly:context-property context 'maximumFretStretch) 4))
233 (string-frets (determine-frets-mf notes string-numbers
234 minimum-fret max-stretch
236 (pitches (map (lambda (x) (ly:event-property x 'pitch)) notes)))
238 (set! (ly:grob-property grob 'fret-diagram-details)
241 (acons 'string-count (length tunings) '())
242 (acons 'string-count (length tunings) details)))
243 (set! (ly:grob-property grob 'dot-placement-list)
245 (let ((predefined-fretboard
246 (get-predefined-fretboard
250 (if (null? predefined-fretboard)
251 (string-frets->dot-placement
252 string-frets my-string-count) ;no predefined diagram
253 predefined-fretboard)) ;found default diagram
254 (string-frets->dot-placement string-frets my-string-count)))))
256 (define-public (determine-frets-mf notes string-numbers
257 minimum-fret max-stretch
260 (define (calc-fret pitch string tuning)
261 (- (ly:pitch-semitones pitch) (list-ref tuning (1- string))))
263 (define (note-pitch a)
264 (ly:event-property a 'pitch))
266 (define (note-pitch>? a b)
267 (ly:pitch<? (note-pitch b)
270 (define (note-finger ev)
271 (let* ((articulations (ly:event-property ev 'articulations))
276 ((num (ly:event-property art 'digit)))
278 (if (and (eq? 'fingering-event (ly:event-property art 'class))
280 (set! finger-found num))))
285 (define (note-string ev)
286 (let* ((articulations (ly:event-property ev 'articulations))
291 ((num (ly:event-property art 'string-number)))
294 (set! string-found num))))
299 (define (del-string string)
302 (delete string free-strings))))
303 (define specified-frets '())
304 (define free-strings '())
306 (define (close-enough fret)
311 (map (lambda (specced-fret)
312 (> max-stretch (abs (- fret specced-fret))))
316 (define (string-qualifies string pitch)
318 ((fret (calc-fret pitch string tunings)))
320 (and (>= fret minimum-fret)
325 (define string-fret-fingering-tuples '())
326 (define (set-fret note string)
327 (set! string-fret-fingering-tuples
329 (calc-fret (ly:event-property note 'pitch)
332 string-fret-fingering-tuples))
337 (set! specified-frets
338 (filter identity (map
340 (if (note-string note)
341 (calc-fret (note-pitch note)
342 (note-string note) tunings)
347 (set! free-strings (map 1+ (iota (length tunings))))
349 (for-each (lambda (note)
350 (del-string (note-string note)))
356 (if (note-string note)
357 (set-fret note (note-string note))
359 ((fit-string (find (lambda (string)
360 (string-qualifies string (note-pitch note)))
363 (set-fret note fit-string)
364 (ly:warning "No string for pitch ~a (given frets ~a)"
369 (sort notes note-pitch>?))
371 string-fret-fingering-tuples)