X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scm%2Ftranslation-functions.scm;h=3767a18be2be9de99549f3541ef00ea2b494dd66;hb=5c14a087ca6cbd665fd631452b7b1283ba0387c3;hp=0367a007ae5d512bcf3dc11a41d34f6ed1e91b83;hpb=376cb0a3769e8616d131d8fab30a22eab83cfb0e;p=lilypond.git diff --git a/scm/translation-functions.scm b/scm/translation-functions.scm index 0367a007ae..3767a18be2 100644 --- a/scm/translation-functions.scm +++ b/scm/translation-functions.scm @@ -7,39 +7,34 @@ ;; metronome marks (define-public (format-metronome-markup text dur count context) - (let* ((hide_note (eq? #t (ly:context-property context 'tempoHideNote))) - (note-mark (if (and (not hide_note) (ly:duration? dur)) + (let* ((hide-note (eq? #t (ly:context-property context 'tempoHideNote))) + (note-mark (if (and (not hide-note) (ly:duration? dur)) (make-smaller-markup (make-note-by-number-markup (ly:duration-log dur) (ly:duration-dot-count dur) 1)) - #f)) - (note-markup (if (and note-mark (number? count) (> count 0) ) + (make-null-markup))) + (note-markup (if (and (not hide-note) (number? count) (> count 0) ) (make-concat-markup (list (make-general-align-markup Y DOWN note-mark) (make-simple-markup " ") (make-simple-markup "=") (make-simple-markup " ") (make-simple-markup (number->string count)))) - #f)) + #f)) (text-markup (if (not (null? text)) (make-bold-markup text) #f))) (if text-markup - (if note-markup + (if (and note-markup (not hide-note)) (make-line-markup (list text-markup (make-concat-markup (list (make-simple-markup "(") note-markup (make-simple-markup ")"))))) - (make-line-markup (list text-markup)) - ) + (make-line-markup (list text-markup))) (if note-markup (make-line-markup (list note-markup)) - #f - ) - ) - ) -) + (make-null-markup))))) (define-public (format-mark-alphabet mark context) (make-bold-markup (make-markalphabet-markup (1- mark)))) @@ -134,15 +129,15 @@ ;; (if (markup? fig-markup) ;; (set! ;; fig-markup (markup #:translate (cons 1.0 0) - ;; #:hcenter fig-markup))) + ;; #:center-align fig-markup))) (if alt-markup (set! fig-markup (markup #:put-adjacent - fig-markup X - (if (number? alt-dir) - alt-dir - LEFT) + X (if (number? alt-dir) + alt-dir + LEFT) + fig-markup #:pad-x 0.2 alt-markup ))) @@ -151,10 +146,10 @@ (set! fig-markup (if fig-markup (markup #:put-adjacent - fig-markup X (if (number? plus-dir) plus-dir LEFT) + fig-markup #:pad-x 0.2 plus-markup) plus-markup))) @@ -168,26 +163,68 @@ ;; fret diagrams (define-public (determine-frets context grob notes string-numbers) + (define (ensure-number a b) (if (number? a) a b)) -(let* + + (define (string-frets->dot-placement string-frets string-count) + (let* + ((desc (list->vector + (map (lambda (x) (list 'mute (1+ x))) + (iota string-count))))) + + (for-each (lambda (sf) + (let* + ((string (car sf)) + (fret (cadr sf)) + (finger (caddr sf))) + + (vector-set! + desc (1- string) + (if (= 0 fret) + (list 'open string) + (if finger + (list 'place-fret string fret finger) + (list 'place-fret string fret)) + )) + )) + string-frets) + (vector->list desc))) + +;; body. + (let* ((tunings (ly:context-property context 'stringTunings)) + (my-string-count (length tunings)) (details (ly:grob-property grob 'fret-diagram-details)) + (predefined-frets + (ly:context-property context 'predefinedDiagramTable)) (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))) + tunings)) + (pitches (map (lambda (x) (ly:event-property x 'pitch)) notes))) + + (set! (ly:grob-property grob 'fret-diagram-details) - (set! (ly:grob-property grob 'fret-diagram-details) (if (null? details) (acons 'string-count (length tunings) '()) (acons 'string-count (length tunings) details))) - (set! (ly:grob-property grob 'string-fret-finger-combinations) string-frets))) + (set! (ly:grob-property grob 'dot-placement-list) + (if predefined-frets + (let ((hash-handle + (hash-get-handle + predefined-frets + (cons tunings pitches)))) + (if hash-handle + (cdr hash-handle) ;found default diagram + (string-frets->dot-placement + string-frets my-string-count))) + (string-frets->dot-placement string-frets my-string-count))))) (define-public (determine-frets-mf notes string-numbers minimum-fret max-stretch @@ -292,12 +329,13 @@ (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) + ((fit-string (find (lambda (string) + (string-qualifies string (note-pitch note))) + free-strings))) + (if fit-string + (set-fret note fit-string) + (ly:warning "No string for pitch ~a (given frets ~a)" + (note-pitch note) specified-frets)) )))