X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scm%2Ftranslation-functions.scm;h=366f44fa3baf095b706501c6a21d045f985b2b85;hb=28abc8a557d3083286fd1592e1a14c360bea7ab1;hp=998d05e836226e00d69e945c120560c0692d06a5;hpb=715153c6137c0a16a1e08ffe03e6937f03c1bf3f;p=lilypond.git diff --git a/scm/translation-functions.scm b/scm/translation-functions.scm index 998d05e836..366f44fa3b 100644 --- a/scm/translation-functions.scm +++ b/scm/translation-functions.scm @@ -2,7 +2,7 @@ ;;;; ;;;; source file of the GNU LilyPond music typesetter ;;;; -;;;; (c) 1998--2006 Han-Wen Nienhuys +;;;; (c) 1998--2007 Han-Wen Nienhuys ;;;; Jan Nieuwenhuizen ;; metronome marks @@ -60,9 +60,8 @@ ;; Bass figures. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(define-public (format-bass-figure figure stream-event context) - (let* ((event (ly:event-property stream-event 'music-cause )) - (fig (ly:music-property event 'figure)) +(define-public (format-bass-figure figure event context) + (let* ((fig (ly:event-property event 'figure)) (fig-markup (if (number? figure) ;; this is not very elegant, but center-aligning all digits @@ -73,12 +72,12 @@ (lambda (y) (make-translate-scaled-markup (cons -0.7 0) y)) identity) - (if (eq? #t (ly:music-property event 'diminished)) + (if (eq? #t (ly:event-property event 'diminished)) (markup #:slashed-digit figure) (markup #:number (number->string figure 10)))) #f )) - (alt (ly:music-property event 'alteration)) + (alt (ly:event-property event 'alteration)) (alt-markup (if (number? alt) (markup @@ -88,7 +87,7 @@ (alteration->text-accidental-markup alt)) #f)) - (plus-markup (if (eq? #t (ly:music-property event 'augmented)) + (plus-markup (if (eq? #t (ly:event-property event 'augmented)) (markup #:number "+") #f)) @@ -138,3 +137,142 @@ )) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; fret diagrams + +(define-public (determine-frets context grob notes string-numbers) + (define (ensure-number a b) + (if (number? a) + a + b)) +(let* + ((tunings (ly:context-property context 'stringTunings)) + (minimum-fret (ensure-number + (ly:context-property context 'minimumFret) 0)) + (max-stretch (ensure-number + (ly:context-property context 'maximumFretStretch) 4)) + (string-frets (determine-frets-mf notes string-numbers + minimum-fret max-stretch + tunings))) + + + (set! (ly:grob-property grob 'string-count) (length tunings)) + (set! (ly:grob-property grob 'string-fret-finger-combinations) string-frets) + + )) + +(define-public (determine-frets-mf notes string-numbers + minimum-fret max-stretch + tunings) + + (define (calc-fret pitch string tuning) + (- (ly:pitch-semitones pitch) (list-ref tuning (1- string)))) + + (define (note-pitch a) + (ly:event-property a 'pitch)) + + (define (note-pitch max-stretch (abs (- fret specced-fret)))) + specified-frets) + )) + + (define (string-qualifies string pitch) + (let* + ((fret (calc-fret pitch string tunings))) + + (and (>= fret minimum-fret) + (close-enough fret)) + + )) + + (define string-fret-fingering-tuples '()) + (define (set-fret note string) + (set! string-fret-fingering-tuples + (cons (list string + (calc-fret (ly:event-property note 'pitch) + string tunings) + (note-finger note)) + string-fret-fingering-tuples)) + (del-string string)) + + + ;;; body. + (set! specified-frets + (filter identity (map + (lambda (note) + (if (note-string note) + (calc-fret (note-pitch note) + (note-string note) tunings) + #f)) + notes))) + + + (set! free-strings (map 1+ (iota (length tunings)))) + + (for-each (lambda (note) + (del-string (note-string note))) + notes) + + + (for-each + (lambda (note) + (if (note-string note) + (set-fret note (note-string note)) + (let* + ((string (find (lambda (string) (string-qualifies string + (note-pitch note))) + (reverse free-strings)))) + (if string + (set-fret note string) + (ly:warning "No string for pitch ~a (given frets ~a)" (note-pitch note) + specified-frets)) + + ))) + (sort notes note-pitch