X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scm%2Ftranslation-functions.scm;h=366f44fa3baf095b706501c6a21d045f985b2b85;hb=2f996385b21b9d5006c7369c2c496ccbee001e97;hp=96a5c7ec27b2c7f1bab4268337b5a3127e3984e8;hpb=abbdb46061be5c0a0682059d1f86bf3e44ca5cf3;p=lilypond.git diff --git a/scm/translation-functions.scm b/scm/translation-functions.scm index 96a5c7ec27..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 @@ -137,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