]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/translation-functions.scm
Merge branch 'master' into nested-bookparts
[lilypond.git] / scm / translation-functions.scm
index 667b0e267900dc0042ebfa784da767d1698ee2fe..0f4e4ce31a2ce2c2604037b8665fd7aeab2cbfb8 100644 (file)
     ;;    (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
 ;; 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
      (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))
                           
               )))