]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/fret-diagrams.scm
Doc - CG: Update information about git-cl
[lilypond.git] / scm / fret-diagrams.scm
index 74ab65fedd0788fb29e79e712a8d4afec45431f8..45db612b9658b054a4ecf9a845d87f3bf1be9f7a 100644 (file)
@@ -44,7 +44,15 @@ to end-point."
 
 (define (get-numeric-from-key keystring)
   "Get the numeric value from a key of the form k:val"
-  (string->number (substring keystring 2 (string-length keystring))))
+  (let* ((entry (substring keystring 2 (string-length keystring)))
+         (numeric-entry (string->number entry)))
+    ;; throw an error, if `entry' can't be transformed into a number
+    (if numeric-entry
+        numeric-entry
+        (ly:error
+          "Unhandled entry in fret-diagram \"~a\" in \"~a\""
+          entry
+          keystring))))
 
 (define (numerify mylist)
   "Convert string values to numeric or character"
@@ -109,11 +117,12 @@ to end-point."
                   (car this-list)
                 ;; fret
                   (- (second this-list) base-fret)
-                ;; finger
-                  (if (or (null? (cddr this-list))
-                        (not (number? (caddr this-list))))
-                      '()
-                      (third this-list))
+                ;; finger-number or markup
+                  (if (and (not (null? (cddr this-list)))
+                           (or (markup? (caddr this-list))
+                               (number? (caddr this-list))))
+                      (third this-list)
+                      '())
                 ;; inverted
                   (dot-is-inverted this-list)
                 ;; parenthesis
@@ -244,7 +253,11 @@ with magnification @var{mag} of the string @var{text}."
              ((or (eq? my-code 'open)(eq? my-code 'mute))
               (set! xo-list (cons* my-item xo-list)))
              ((eq? my-code 'barre)
-              (set! barre-list (cons* (cdr my-item) barre-list)))
+              (if (every number? (cdr my-item))
+                  (set! barre-list (cons* (cdr my-item) barre-list))
+                  (ly:error
+                    "barre-indications should contain only numbers: ~a"
+                    (cdr my-item))))
              ((eq? my-code 'capo)
               (set! capo-fret (cadr my-item)))
              ((eq? my-code 'place-fret)
@@ -260,12 +273,16 @@ with magnification @var{mag} of the string @var{text}."
               (if (> fretval maxfret) (set! maxfret fretval))
               (if (< fretval minfret) (set! minfret fretval))
               (updatemax (cdr fret-list)))))
+      ;; take frets of 'barre-settings into account
+      (if (not (null? barre-list))
+          (set! minfret (apply min minfret (map last barre-list))))
       (if (or (> maxfret my-fret-count) (> capo-fret 1))
           (set! fret-range
                 (cons minfret
                       (let ((upfret (- (+ minfret my-fret-count) 1)))
                         (if (> maxfret upfret) maxfret upfret)))))
-      (set! capo-fret (1+ (- capo-fret minfret)))
+      (if (not (zero? (apply min capo-fret (map cadr dot-list))))
+          (set! capo-fret (1+ (- capo-fret minfret))))
       ;; subtract fret from dots
       (set! dot-list (subtract-base-fret (- (car fret-range) 1) dot-list)))
     (acons 'fret-range fret-range
@@ -389,17 +406,17 @@ baseline at fret coordinate @var{base}, a height of
                bottom-control-point-height cp-right-width)))
 
         ;; order of bezier control points is:
-        ;;    left cp low, right cp low, right end low, left end low
-        ;;   right cp high, left cp high, left end high, right end high.
+        ;;   left cp low, left cp low, right cp low, right end low
+        ;;   right cp high, left cp high
 
-        (list left-lower-control-point
+        (list
+              left-end-point
+              left-lower-control-point
               right-lower-control-point
               right-end-point
-              left-end-point
+
               right-upper-control-point
-              left-upper-control-point
-              left-end-point
-              right-end-point)))
+              left-upper-control-point)))
 
     (define (draw-strings)
       "Draw the string lines for a fret diagram with
@@ -548,24 +565,10 @@ fret-diagram overall parameters."
                (* size end-string-coordinate)
                (* size fret-coordinate)
                (* size bezier-height)
-               (* size bezier-thick)))
-             (box-lower-left
-              (stencil-coordinates
-               (+ (* size fret-coordinate) half-thickness)
-               (- (* size start-string-coordinate) half-thickness)))
-             (box-upper-right
-              (stencil-coordinates
-               (- (* size fret-coordinate)
-                  (* size bezier-height)
-                  half-thickness)
-               (+ (* size end-string-coordinate) half-thickness)))
-             (x-extent (cons (car box-lower-left) (car box-upper-right)))
-             (y-extent (cons (cdr box-lower-left) (cdr box-upper-right))))
+               (* size bezier-thick))))
         (make-bezier-sandwich-stencil
          bezier-list
-         (* size bezier-thick)
-         x-extent
-         y-extent)))
+         (* size bezier-thick))))
 
     (define (draw-dots dot-list)
       "Make dots for fret diagram."
@@ -668,10 +671,37 @@ fret-diagram overall parameters."
                 ((or (eq? finger '())(eq? finger-code 'none))
                  positioned-dot)
                 ((eq? finger-code 'in-dot)
-                 (let ((finger-label
-                        (centered-stencil
-                         (sans-serif-stencil
-                          layout props dot-label-font-mag finger))))
+                 (let* ((finger-stil
+                          (if (not (null? finger))
+                              (sans-serif-stencil
+                                 layout props dot-label-font-mag finger)
+                              empty-stencil))
+                        (finger-stil-length
+                          (interval-length (ly:stencil-extent finger-stil X)))
+                        (finger-stil-height
+                          (interval-length (ly:stencil-extent finger-stil Y)))
+                        (dot-stencil-radius
+                          (/ (interval-length (ly:stencil-extent dot-stencil Y))
+                             2))
+                        (scale-factor
+                          (/ dot-stencil-radius
+                             ;; Calculate the radius of the circle through the
+                             ;; corners of the box containing the finger-stil.
+                             ;; Give it a little padding. The value, (* 2 th),
+                             ;; is my choice
+                             (+
+                               (sqrt
+                                  (+ (expt (/ finger-stil-length 2) 2)
+                                     (expt (/ finger-stil-height 2) 2)))
+                                (* 2 th))))
+                        (finger-label
+                         (centered-stencil
+                          (ly:stencil-scale
+                           (sans-serif-stencil
+                            layout props
+                            dot-label-font-mag
+                            finger)
+                           scale-factor scale-factor))))
                    (ly:stencil-translate
                     (ly:stencil-add
                      final-dot-stencil
@@ -892,7 +922,9 @@ a fret-indication list with the appropriate values"
          (output-list '())
          (new-props '())
          (details (merge-details 'fret-diagram-details props '()))
-         (items (string-split definition-string #\;)))
+         ;; remove whitespace-characters from definition-string
+         (cleared-string (remove-whitespace definition-string))
+         (items (string-split cleared-string #\;)))
     (let parse-item ((myitems items))
       (if (not (null? (cdr myitems)))
           (let ((test-string (car myitems)))
@@ -928,7 +960,15 @@ a fret-indication list with the appropriate values"
                        (set! details
                              (acons 'dot-position dot-position details))))
               (else
-               (let ((this-list (string-split test-string #\-)))
+               (let* ((this-list (string-split test-string #\-))
+                      (fret-number (string->number (car this-list))))
+                 ;; If none of the above applies, `fret-number' needs to be a
+                 ;; number. Throw an error, if not.
+                 (if (not fret-number)
+                   (ly:error
+                     "Unhandled entry in fret-diagrams \"~a\" in \"~a\""
+                     (car this-list)
+                     test-string))
                  (if (string->number (cadr this-list))
                      (set! output-list
                            (cons-fret
@@ -937,11 +977,11 @@ a fret-indication list with the appropriate values"
                      (if (equal? (cadr this-list) "x" )
                          (set! output-list
                                (cons-fret
-                                (list 'mute (string->number (car this-list)))
+                                (list 'mute fret-number)
                                 output-list))
                          (set! output-list
                                (cons-fret
-                                (list 'open (string->number (car this-list)))
+                                (list 'open fret-number)
                                 output-list)))))))
             (parse-item (cdr myitems)))))
     ;; add the modified details