]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/fret-diagrams.scm
Merge with master
[lilypond.git] / scm / fret-diagrams.scm
index e70a756a0e2d05f5cc0fd15c9f6ae4974d8a7e09..69194956f326c1810c1745c942e05103f1e461af 100644 (file)
@@ -2,7 +2,7 @@
 ;;;;
 ;;;;  source file of the GNU LilyPond music typesetter
 ;;;; 
-;;;; (c) 2004--2005 Carl D. Sorensen <c_sorensen@byu.edu>
+;;;; (c) 2004--2006 Carl D. Sorensen <c_sorensen@byu.edu>
 
 (define (fret-parse-marking-list marking-list fret-count)
    (let* ((fret-range (list 1 fret-count))
@@ -21,7 +21,8 @@
                      ((eq? my-code 'place-fret)
                         (set! dot-list (cons* (cdr my-item) dot-list))))
                  (parse-item (cdr mylist)))))
-               ; calculate fret-range
+      
+      ;; calculate fret-range
                (let ((maxfret 0) (minfret 99))
                     (let updatemax ((fret-list dot-list))
                         (if (null?  fret-list)
@@ -40,7 +41,9 @@
                (acons 'barre-list barre-list
                (acons 'dot-list dot-list
                (acons 'xo-list xo-list '()))))))
-   
+
+
+
 (define (subtract-base-fret base-fret dot-list)
 "Subtract @var{base-fret} from every fret in @var{dot-list}"  
   (if (null? dot-list)
@@ -58,16 +61,6 @@ with magnification @varr{mag} of the string @var{text}."
                    (prepend-alist-chain  'font-family 'sans props))))
         (interpret-markup layout my-props text)))
 
-(define (sans-serif-stencil-white layout props mag text)
-"create a stencil with white text in sans-serif font based on
-@var{layout} and @var{props} with magnification @varr{mag} of the
-string @var{text}."
-  (let* ((text-stencil (sans-serif-stencil layout props mag text))
-         (x-extent  (ly:stencil-extent text-stencil X))
-         (y-extent  (ly:stencil-extent text-stencil Y))
-         (c  `(white-text ,(* 2 mag) ,text))) ;urg -- workaround for using ps font
-    (ly:make-stencil c  x-extent y-extent)))  ;urg -- extent is not from ps font, but we hope it's close
-
 
 (define (draw-strings string-count fret-range th size)
 "Draw the strings (vertical lines) for a fret diagram with
@@ -87,44 +80,44 @@ Line thickness is given by @var{th}, fret & string spacing by
         (ly:stencil-combine-at-edge
          (draw-strings (- string-count 1) fret-range th size) X RIGHT
          string-stencil
-         gap 0))))
+         gap))))
 
 (define (draw-fret-lines fret-count string-count th size)
- "Draw @var{fret-count} frets (horizontal lines) for a fret diagram
 "Draw @var{fret-count} frets (horizontal lines) for a fret diagram
 with @var{string-count} strings.  Line thickness is given by @var{th},
 fret & string spacing by @var{size}. "
-   (let* ((fret-length (* (- string-count 1) size))
-          (sth (* size th))
-          (half-thickness (* sth 0.5))
-          (gap (- size sth))
-          (fret-line (ly:make-stencil (list 'draw-line sth half-thickness size (- fret-length half-thickness) size)
-                          (cons 0 fret-length)
-                          (cons (- size half-thickness) (+  size half-thickness)))))
-       (if (= fret-count 1)
-         fret-line
-         (ly:stencil-combine-at-edge fret-line Y UP
-          (draw-fret-lines (- fret-count 1) string-count th size)
-          gap 0))))
-          
+  (let* ((fret-length (* (- string-count 1) size))
+        (sth (* size th))
+        (half-thickness (* sth 0.5))
+        (gap (- size sth))
+        (fret-line (ly:make-stencil (list 'draw-line sth half-thickness size (- fret-length half-thickness) size)
+                                    (cons 0 fret-length)
+                                    (cons (- size half-thickness) (+  size half-thickness)))))
+    (if (= fret-count 1)
+       fret-line
+       (ly:stencil-combine-at-edge fret-line Y UP
+                                   (draw-fret-lines (- fret-count 1) string-count th size)
+                                   gap))))
+
 (define (draw-thick-top-fret props string-count th size)
- "Draw a thick top fret for a fret diagram whose base fret is not 1."
-   (let* ((sth (* th size))
-;          (top-fret-thick (* sth (chain-assoc-get 'top-fret-thickness props 3.0)))
-          (top-fret-thick (* sth 3.0))
-;          (top-half-thick (* top-fret-thick 0.5))
-          (half-thick (* sth 0.5))
-          (x1 half-thick)
-          (x2 (+ half-thick (* size (- string-count 1))))
-          (y1 (- half-thick))
-          (y2 (+ top-fret-thick half-thick))
-          (x-extent (cons (- x1) x2))
-          (y-extent (cons 0 y2)))
-          (ly:make-stencil (list 'round-filled-box x1 x2 y1 y2 sth)
-                            x-extent y-extent)))           
 "Draw a thick top fret for a fret diagram whose base fret is not 1."
+  (let* ((sth (* th size))
+                                       ;          (top-fret-thick (* sth (chain-assoc-get 'top-fret-thickness props 3.0)))
+        (top-fret-thick (* sth 3.0))
+                                       ;          (top-half-thick (* top-fret-thick 0.5))
+        (half-thick (* sth 0.5))
+        (x1 half-thick)
+        (x2 (+ half-thick (* size (- string-count 1))))
+        (y1 (- half-thick))
+        (y2 (+ top-fret-thick half-thick))
+        (x-extent (cons (- x1) x2))
+        (y-extent (cons 0 y2)))
+    (ly:make-stencil (list 'round-filled-box x1 x2 y1 y2 sth)
+                    x-extent y-extent)))           
+
+
 (define (draw-frets layout props fret-range string-count th size)
- "Draw the frets (horizontal lines) for a fret diagram with
 "Draw the frets (horizontal lines) for a fret diagram with
 @var{string-count} strings and frets as indicated in @var{fret-range}.
 Line thickness is given by @var{th}, fret & string spacing by
 @var{size}. "
@@ -132,26 +125,29 @@ Line thickness is given by @var{th}, fret & string spacing by
          (fret-length (* (- string-count 1) size))
          (half-thickness (* th 0.5))
          (base-fret (car fret-range)))
-       (ly:stencil-combine-at-edge
-          (draw-fret-lines fret-count string-count th size) Y UP
-             (if (= base-fret 1)
-                 (draw-thick-top-fret props string-count th size)
-                 (draw-fret-lines 1 string-count th size)) 
-                 (- size th) 0))) 
-                 
+    (ly:stencil-combine-at-edge
+     (draw-fret-lines fret-count string-count th size) Y UP
+     (if (= base-fret 1)
+        (draw-thick-top-fret props string-count th size)
+        (draw-fret-lines 1 string-count th size)) 
+     (- size th)))) 
 
-(define (draw-dots layout props string-count fret-range size finger-code dot-position dot-radius dot-list)
+
+(define (draw-dots layout props string-count fret-range size finger-code 
+                    dot-position dot-radius dot-thickness dot-list)
   "Make dots for fret diagram."
+
   (let* ((scale-dot-radius (* size dot-radius))
+         (scale-dot-thick (* size dot-thickness))
          (dot-color (chain-assoc-get 'dot-color props 'black))
 ;         (finger-xoffset (chain-assoc-get 'finger-xoffset props -0.25))
 ;         (finger-yoffset (chain-assoc-get 'finger-yoffset props (- size)))
          (finger-xoffset -0.25)
-         (finger-yoffset (- size))
+         (finger-yoffset (- (* size 0.5)))
 ;         (dot-label-font-mag (* scale-dot-radius (chain-assoc-get 'dot-label-font-mag props 1.0)))
          (dot-label-font-mag scale-dot-radius)
 ;         (string-label-font-mag (* size (chain-assoc-get 'label-font-mag props 0.7)))
-         (string-label-font-mag (* size 0.7))
+         (string-label-font-mag (* size 0.6))
          (fret-count (+ (- (cadr fret-range) (car fret-range) 1)))
          (mypair (car dot-list))
          (restlist (cdr dot-list))
@@ -163,46 +159,51 @@ Line thickness is given by @var{th}, fret & string spacing by
          (finger (caddr mypair))
          (finger (if (number? finger) (number->string finger) finger))
          (dotstencil  (if (eq? dot-color 'white)
-                          (begin
-                          (ly:make-stencil (list 'white-dot 0 0 scale-dot-radius) extent extent))
-                          (ly:make-stencil (list 'dot 0 0 scale-dot-radius ) extent extent)))
-         (positioned-dot (ly:stencil-translate-axis
-                           (ly:stencil-translate-axis dotstencil xpos X)
-                           ypos Y))
+                          (ly:stencil-add 
+                              (make-circle-stencil scale-dot-radius scale-dot-thick #t)
+                              (ly:stencil-in-color
+                                    (make-circle-stencil 
+                                        (- scale-dot-radius (* 0.5 scale-dot-thick)) 0  #t)
+                                    1 1 1))
+                          (make-circle-stencil scale-dot-radius scale-dot-thick #t))) 
+         (positioned-dot (begin
+                           ;(display dotstencil)
+                           (ly:stencil-translate-axis
+                             (ly:stencil-translate-axis dotstencil xpos X)
+                           ypos Y)))
+
          (labeled-dot-stencil 
                  (if (or (eq? finger '())(eq? finger-code 'none))
                      positioned-dot
-                 (if (eq? finger-code 'in-dot)
-                    (let*  ((dot-proc (if (eq? dot-color 'white) 'white-dot 'dot)))
-                     (ly:stencil-add 
-                        (ly:stencil-translate-axis 
-                          (ly:stencil-translate-axis 
-                              (if (eq? dot-color 'white)
-                              (centered-stencil (sans-serif-stencil layout props dot-label-font-mag finger))
-                              (centered-stencil (sans-serif-stencil-white layout props 
-                                                 dot-label-font-mag  finger)))
-                               xpos X)
-                              ypos Y)
-                        (ly:stencil-translate-axis
-                           (ly:stencil-translate-axis 
-                              (ly:make-stencil (list dot-proc 0 0 scale-dot-radius) extent extent)
+                     (if (eq? finger-code 'in-dot)
+                         (let*  ((finger-label (centered-stencil 
+                                           (sans-serif-stencil layout props
+                                                  dot-label-font-mag finger))))
+                         (ly:stencil-translate-axis 
+                            (ly:stencil-translate-axis 
+                             (ly:stencil-add 
+                                dotstencil
+                                (if (eq? dot-color 'white)
+                                     finger-label
+                                     (ly:stencil-in-color finger-label 1 1 1))) 
                                xpos X)
-                           ypos Y)))
+                              ypos Y))
                  (if (eq? finger-code 'below-string) 
                      (ly:stencil-add 
                          positioned-dot
                          (ly:stencil-translate-axis 
                              (ly:stencil-translate-axis 
                                  (centered-stencil (sans-serif-stencil layout props 
-                                                        string-label-font-mag finger)) xpos  X)
-                             (* size finger-yoffset) Y))
+                                                        string-label-font-mag finger))
+                              xpos  X)
+                          (* size finger-yoffset) Y))
                      ;unknown finger-code
                      positioned-dot)))))
     (if (null? restlist) 
         labeled-dot-stencil
         (ly:stencil-add 
             (draw-dots layout props string-count fret-range size finger-code 
-                          dot-position dot-radius restlist)
+                          dot-position dot-radius dot-thickness restlist)
             labeled-dot-stencil))))
 
 (define (draw-xo layout props string-count fret-range size xo-list) 
@@ -270,7 +271,6 @@ Line thickness is given by @var{th}, fret & string spacing by
                  (draw-barre layout props string-count fret-range size finger-code 
                       dot-position dot-radius (cdr barre-list)))
             barre-stencil ))))
-
   
 (define (stepmag mag)
 "Calculate the font step necessary to get a desired magnification"
@@ -280,7 +280,7 @@ Line thickness is given by @var{th}, fret & string spacing by
    "Label the base fret on a fret diagram"
    (let* ((base-fret (car fret-range))
 ;          (label-font-mag (chain-assoc-get 'label-font-mag props 0.7))
-          (label-font-mag 0.7)
+          (label-font-mag 0.5)
 ;          (label-vertical-offset (chain-assoc-get 'fret-label-vertical-offset props -0.2))
           (label-vertical-offset -0.2)
          (number-type (chain-assoc-get 'number-type props 'roman-lower))
@@ -295,14 +295,14 @@ Line thickness is given by @var{th}, fret & string spacing by
            (sans-serif-stencil layout props (* size label-font-mag) label-text) 
                        (* size (+ fret-count label-vertical-offset)) Y)))
  
-(def-markup-command (fret-diagram-verbose layout props marking-list)
+(define-builtin-markup-command (fret-diagram-verbose layout props marking-list)
   (list?)
   "Make a fret diagram containing the symbols indicated in @var{marking-list}
   
   For example,
   
 @example
-   \\markup \\fret-diagram #'((mute 6) (mute 5) (open 4)
+   \\markup \\fret-diagram-verbose #'((mute 6) (mute 5) (open 4)
         (place-fret 3 2) (place-fret 2 3) (place-fret 1 2))
 @end example 
   
@@ -330,6 +330,9 @@ changed by setting the value of the variable @var{dot-color}.  If the
 variable @var{finger-code}.  There is no limit to the number of fret
 indications per string.
 
+
+
+
 @end table
 "
    (make-fret-diagram layout props marking-list))
@@ -351,13 +354,13 @@ indications per string.
          (default-dot-position (if (eq? finger-code 'in-dot) (- 0.95 default-dot-radius) 0.6))  ; move up to make room for bigger if labeled
          (dot-radius (chain-assoc-get 'dot-radius props default-dot-radius))  ; needed for both draw-dots and draw-barre
          (dot-position (chain-assoc-get 'dot-position props default-dot-position)) ; needed for both draw-dots and draw-barre
-         (th (* (ly:output-def-lookup layout 'linethickness)
+         (th (* (ly:output-def-lookup layout 'line-thickness)
                 (chain-assoc-get 'thickness props 0.5))) ; needed for both draw-frets and draw-strings
                 
          (alignment (chain-assoc-get 'align-dir props -0.4)) ; needed only here
 ;         (xo-padding (* th (chain-assoc-get 'padding props 2))) ; needed only here
-         (label-space 0.25)
-         (xo-padding (* th 2))
+         (label-space (* 0.25 size))
+         (xo-padding (* th size 5))
          (label-dir (chain-assoc-get 'label-dir props RIGHT))
          (parameters (fret-parse-marking-list marking-list fret-count))
          (dot-list (cdr (assoc 'dot-list parameters)))
@@ -374,21 +377,21 @@ indications per string.
                                     fret-diagram-stencil)))
          (if (not (null? dot-list))
              (set! fret-diagram-stencil (ly:stencil-add
+                                    fret-diagram-stencil
                                     (draw-dots layout props string-count fret-range size finger-code 
-                                          dot-position dot-radius dot-list)
-                                    fret-diagram-stencil)))
+                                          dot-position dot-radius th dot-list))))
          (if (not (null? xo-list))
              (set! fret-diagram-stencil (ly:stencil-combine-at-edge
                                     fret-diagram-stencil Y UP
-                                    (draw-xo layout props string-count fret-range size xo-list) xo-padding 0)))
+                                    (draw-xo layout props string-count fret-range size xo-list) xo-padding)))
          (if (> (car fret-range) 1) 
              (set! fret-diagram-stencil
                    (ly:stencil-combine-at-edge fret-diagram-stencil X label-dir
-                                              (label-fret layout props string-count fret-range size) label-space 0)))
+                                              (label-fret layout props string-count fret-range size) label-space)))
          (ly:stencil-aligned-to fret-diagram-stencil X alignment)
         ))
          
-(def-markup-command (fret-diagram layout props definition-string)
+(define-builtin-markup-command (fret-diagram layout props definition-string)
   (string?)
   "  
 Example
@@ -519,7 +522,7 @@ Note:  There is no limit to the number of fret indications per string.
                 (cons* numeric-value (numerify (cdr mylist)))
                 (cons* (car (string->list (car mylist))) (numerify (cdr mylist)))))))
            
-(def-markup-command (fret-diagram-terse layout props definition-string)
+(define-builtin-markup-command (fret-diagram-terse layout props definition-string)
   (string?)
   "Make a fret diagram markup using terse string-based syntax.