]> git.donarmstrong.com Git - lilypond.git/commitdiff
Add variable string thickness to fret-diagrams
authorCarl Sorensen <c_sorensen@byu.edu>
Sun, 11 Jan 2009 22:10:31 +0000 (15:10 -0700)
committerCarl Sorensen <c_sorensen@byu.edu>
Sun, 11 Jan 2009 22:10:31 +0000 (15:10 -0700)
Add string-thickness-factor to fret-diagram-details, which
allows varying the thickness of the strings in fret diagrams.

Also, fixed errors in regression tests for fret diagrams.

input/new/fret-diagrams-explained-and-developed.ly
input/regression/fret-diagrams-dots.ly
input/regression/fret-diagrams-fingering.ly
input/regression/fret-diagrams-fret-label.ly
input/regression/fret-diagrams-string-thickness.ly [new file with mode: 0644]
scm/define-grob-properties.scm
scm/fret-diagrams.scm

index b37fd5f8ad68b89964db21c1542819a429e5ce5d..971dd0e4e7c90591be09202c574e4bbaf8a609af 100644 (file)
@@ -123,6 +123,7 @@ and tweaking fret diagrams."
       \override #'(fret-diagram-details . (
                    (finger-code . below-string)
                    (dot-radius . 0.35)
+                   (string-thickness-factor . 0.3)
                    (dot-position . 0.5)
                    (fret-count . 3))) {
         \fret-diagram-terse #"x;x;o;2-1;3-2;2-3;"
index cf06e666ea585ca535bfd2b9c725e3b04e540ecb..a38d0b2218ec0e5ba7e6b1b2d120ba94988e4333 100644 (file)
@@ -29,7 +29,7 @@ size, and coloring.
                                      (place-fret 3 5 3)
                                      (place-fret 2 5 4)
                                      (place-fret 1 3 1)
-                                     (barre 5 1 1))}
+                                     (barre 5 1 3))}
 
      %% C major for guitar, verbose style
     \override TextScript #'fret-diagram-details 
@@ -41,7 +41,7 @@ size, and coloring.
                                      (place-fret 3 5 3)
                                      (place-fret 2 5 4)
                                      (place-fret 1 3 1)
-                                     (barre 5 1 1))}
+                                     (barre 5 1 3))}
 
      %% C major for guitar, verbose style
     \revert TextScript #'fret-diagram-details #'dot-radius
@@ -54,7 +54,7 @@ size, and coloring.
                                      (place-fret 3 5 3)
                                      (place-fret 2 5 4)
                                      (place-fret 1 3 1)
-                                     (barre 5 1 1))}
+                                     (barre 5 1 3))}
 
      %% C major for guitar,  verbose style
     \once \override TextScript #'fret-diagram-details 
@@ -66,7 +66,7 @@ size, and coloring.
                                      (place-fret 3 5 3)
                                      (place-fret 2 5 4)
                                      (place-fret 1 3 1)
-                                     (barre 5 1 1))}
+                                     (barre 5 1 3))}
 
  }
 >>
index bebd9a621739e426cdff62e0d09760dfbf013b99..5833e0b9983e84753d1c5fb96ebf88585973d551 100644 (file)
@@ -32,7 +32,7 @@ can be adjusted.
                                      (place-fret 3 5 3)
                                      (place-fret 2 5 4)
                                      (place-fret 1 3 1)
-                                     (barre 5 1 1))}
+                                     (barre 5 1 3))}
 
      %% C major for guitar,  verbose style
     \override TextScript #'fret-diagram-details 
@@ -44,7 +44,7 @@ can be adjusted.
                                      (place-fret 3 5 3)
                                      (place-fret 2 5 4)
                                      (place-fret 1 3 1)
-                                     (barre 5 1 1))}
+                                     (barre 5 1 3))}
 
      %% C major for guitar, verbose style
     \override TextScript #'fret-diagram-details
@@ -56,7 +56,7 @@ can be adjusted.
                                      (place-fret 3 5 3)
                                      (place-fret 2 5 4)
                                      (place-fret 1 3 1)
-                                     (barre 5 1 1))}
+                                     (barre 5 1 3))}
 
      %% C major for guitar, verbose style
     \once \override TextScript #'fret-diagram-details 
@@ -68,7 +68,7 @@ can be adjusted.
                                      (place-fret 3 5 3)
                                      (place-fret 2 5 4)
                                      (place-fret 1 3 1)
-                                     (barre 5 1 1))}
+                                     (barre 5 1 3))}
 
      %% C major for guitar,  verbose style
     \once \override TextScript #'fret-diagram-details 
@@ -80,7 +80,7 @@ can be adjusted.
                                      (place-fret 3 5 3)
                                      (place-fret 2 5 4)
                                      (place-fret 1 3 1)
-                                     (barre 5 1 1))}
+                                     (barre 5 1 3))}
 
  }
 >>
index dbe18f27b6ed7b0a829cdc3a99482962f59e6d9f..e45755c8f24dd31a32caa6025b9ff1f0e0660b9f 100644 (file)
@@ -28,7 +28,7 @@ size, and number type.
                                      (place-fret 3 5 3)
                                      (place-fret 2 5 4)
                                      (place-fret 1 3 1)
-                                     (barre 5 1 1))}
+                                     (barre 5 1 3))}
 
      %% C major for guitar, verbose style
     \override TextScript #'fret-diagram-details 
@@ -42,7 +42,7 @@ size, and number type.
                                      (place-fret 3 5 3)
                                      (place-fret 2 5 4)
                                      (place-fret 1 3 1)
-                                     (barre 5 1 1))}
+                                     (barre 5 1 3))}
 
      %% C major for guitar, verbose style
     \revert TextScript #'fret-diagram-details #'label-dir
@@ -59,7 +59,7 @@ size, and number type.
                                      (place-fret 3 5 3)
                                      (place-fret 2 5 4)
                                      (place-fret 1 3 1)
-                                     (barre 5 1 1))}
+                                     (barre 5 1 3))}
 
  }
 >>
diff --git a/input/regression/fret-diagrams-string-thickness.ly b/input/regression/fret-diagrams-string-thickness.ly
new file mode 100644 (file)
index 0000000..2a2d2b5
--- /dev/null
@@ -0,0 +1,58 @@
+\version "2.12.0"
+
+\header {
+  texidoc="
+String thickness can be changed, and diagrams can have variable
+string thickness.
+"
+}
+
+\layout { ragged-right = ##t }
+
+<<
+  \chords {
+    c1 |
+    c1 |
+    c1
+  }
+
+  \new Voice {
+    \textLengthOn
+     %% C major for guitar,  verbose style
+    c'1 ^\markup {
+            \fret-diagram-verbose #'((mute 6)
+                                     (place-fret 5 3 1)
+                                     (place-fret 4 5 2)
+                                     (place-fret 3 5 3)
+                                     (place-fret 2 5 4)
+                                     (place-fret 1 3 1)
+                                     (barre 5 1 3))}
+
+     %% C major for guitar,  verbose style
+    \once \override TextScript #'thickness = #1.5 
+    c'1 ^\markup {
+            \fret-diagram-verbose #'((mute 6)
+                                     (place-fret 5 3 1)
+                                     (place-fret 4 5 2)
+                                     (place-fret 3 5 3)
+                                     (place-fret 2 5 4)
+                                     (place-fret 1 3 1)
+                                     (barre 5 1 3))}
+
+     %% C major for guitar, verbose style
+    \once \override TextScript #'fret-diagram-details
+      #'string-thickness-factor = #0.3
+    c' ^\markup {
+            \fret-diagram-verbose #'((mute 6)
+                                     (place-fret 5 3 1)
+                                     (place-fret 4 5 2)
+                                     (place-fret 3 5 3)
+                                     (place-fret 2 5 4)
+                                     (place-fret 1 3 1)
+                                     (barre 5 1 3))}
+
+
+ }
+>>
+
+
index 302f26f1a7c2e473796c1716d44203879048cacf..3240912a1d79daf7d6bbf3202c37eb2842c41f69 100644 (file)
@@ -321,6 +321,10 @@ fingerings at the string, rather than in the dot.  Default value 0.6 for
 @code{normal} orientation, 0.5 for @code{landscape} and 
 @code{opposing-landscape}.
 @item
+@code{string-thickness-factor} -- Factor for changing thickness of each
+string in the fret diagram.  Thickness of string @code{k} is given by
+@code{thickness}*(1+@code{string-thickness-factor})^(k-1).  Default 0.
+@item
 @code{top-fret-thickness} -- The thickness of the top fret line, as a multiple
 of the standard thickness.   Default value 3.
 @item
index 7592ef37ef044d5b44aa52abcdd19edb5f6146fa..f18cf3e7d85f8d7d829eed312b5d2decc7d8b2c3 100644 (file)
@@ -9,6 +9,25 @@
 ;
 ;
     
+(define (string-x-extent start-point end-point)
+  "Return the x-extent of a string that goes from start-point
+to end-point."
+  (let ((x1 (car start-point))
+         (x2 (car end-point)))
+    (if (> x1 x2)
+        (cons x2 x1)
+        (cons x1 x2))))
+
+(define (string-y-extent start-point end-point)
+  "Return the y-extent of a string that goes from start-point
+to end-point."
+  (let ((y1 (cdr start-point))
+         (y2 (cdr end-point)))
+    (if (> y1 y2)
+        (cons y2 y1)
+        (cons y1 y2))))
+
+
 (define (cons-fret new-value old-list)
   "Put together a fret-list in the format desired by parse-string"
   (if (eq? old-list '())
@@ -187,6 +206,9 @@ system."
    (else
     (cons string-coordinate (- fret-coordinate)))))
  
+(define (string-thickness string thickness-factor)
+  (expt (1+ thickness-factor) (1- string)))
+  
 ;
 ;  Functions that create stencils used in the fret diagram
 ;
@@ -205,28 +227,35 @@ with magnification @var{mag} of the string @var{text}."
                         th thickness-factor size orientation)
  "Make a stencil for @code{string}, given the fret-diagram
 overall parameters."
-  (let* ((string-thickness (* th (expt (1+ thickness-factor) string)))
+  (let* ((string-coordinate (- string-count string))
+         (current-string-thickness 
+           (* th size (string-thickness string thickness-factor)))
+         (fret-half-thickness (* size th 0.5))
+         (half-string (* current-string-thickness 0.5))
          (start-coordinates
            (stencil-coordinates
-             0
-             (* size (1- string))
+             (- fret-half-thickness)
+             (- (* size string-coordinate) half-string)
              orientation))
          (end-coordinates
            (stencil-coordinates
-            (* size (1+ (fret-count fret-range)))
-            (* size (1- string))
+            (+ fret-half-thickness (* size (1+ (fret-count fret-range))))
+            (+ half-string (* size string-coordinate))
             orientation)))
-   (make-line-stencil
-      string-thickness
-      (car start-coordinates) (cdr start-coordinates)
-      (car end-coordinates) (cdr end-coordinates))))
-
-(define (fret-stencil fret fret-range string-count th size orientation)
+   (ly:round-filled-box (string-x-extent start-coordinates end-coordinates)
+                        (string-y-extent start-coordinates end-coordinates)
+                        (* th size))))
+   
+(define (fret-stencil fret string-count th 
+                      thickness-factor size orientation)
  "Make a stencil for @code{fret}, given the fret-diagram overall parameters."
- (let* ((start-coordinates 
+ (let* ((low-string-half-thickness 
+          (* 0.5 size th (string-thickness string-count thickness-factor)))
+        (fret-half-thickness (* 0.5 size th)) 
+        (start-coordinates 
          (stencil-coordinates
            (* size fret)
-           0
+           (- fret-half-thickness low-string-half-thickness)
            orientation))
         (end-coordinates
          (stencil-coordinates
@@ -234,7 +263,7 @@ overall parameters."
           (* size (1- string-count))
           orientation)))
   (make-line-stencil
-   th
+   (* size th)
    (car start-coordinates) (cdr start-coordinates)
    (car end-coordinates) (cdr end-coordinates))))
 
@@ -320,31 +349,35 @@ Line thickness is given by @var{th}, fret & string spacing by
   (let* ( (string-list (map 1+ (iota string-count))))
    (helper string-list)))
 
-(define (draw-fret-lines fret-count string-count th size orientation)
+(define (draw-fret-lines fret-count string-count th 
+                         thickness-factor size orientation)
   "Draw @var{fret-count} fret lines for a fret diagram
 with @var{string-count} strings.  Line thickness is given by @var{th},
 fret & string spacing by @var{size}. Orientation is given by @var{orientation}"
   (define (helper x)
      (if (null? (cdr x))
          (fret-stencil 
-          (car x) fret-count string-count th
+          (car x) string-count th thickness-factor
            size orientation)
          (ly:stencil-add 
            (fret-stencil 
-            (car x) fret-count string-count th
+            (car x) string-count th thickness-factor
             size orientation)
            (helper (cdr x)))))
 
-  (let* ((fret-list (iota (1+ fret-count))))
+  (let* ( (fret-list (iota (1+ fret-count))))
    (helper fret-list)))
 
-(define (draw-thick-zero-fret details string-count th size orientation)
+(define (draw-thick-zero-fret details string-count th 
+                              thickness-factor size orientation)
   "Draw a thick zeroth fret for a fret diagram whose base fret is 1."
   (let* ((sth (* th size))
+         (half-lowest-string-thickness 
+           (* 0.5 th (string-thickness string-count thickness-factor))) 
          (half-thick (* 0.5 sth))
          (top-fret-thick
            (* sth (assoc-get 'top-fret-thickness details 3.0)))
-         (start-string-coordinate (- half-thick))
+         (start-string-coordinate (- half-lowest-string-thickness))
          (end-string-coordinate (+ (* size (1- string-count)) half-thick))
          (start-fret-coordinate half-thick)
          (end-fret-coordinate (- half-thick top-fret-thick))
@@ -354,9 +387,10 @@ fret & string spacing by @var{size}. Orientation is given by @var{orientation}"
          (upper-right 
           (stencil-coordinates 
             end-fret-coordinate end-string-coordinate orientation)))
-   (make-filled-box-stencil 
+   (ly:round-filled-box 
      (cons (car lower-left) (car upper-right))
-     (cons (cdr lower-left) (cdr upper-right)))))
+     (cons (cdr lower-left) (cdr upper-right))
+     sth)))
   
 
 (define (draw-capo details string-count fret fret-count th size 
@@ -379,13 +413,15 @@ at @var{fret}."
      (car start-point) (cdr start-point)
      (car end-point) (cdr end-point))))
 
-(define (draw-frets fret-range string-count th size orientation)
+(define (draw-frets fret-range string-count th 
+                    thickness-factor size orientation)
   "Draw the fret 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}. Orientation is given by @var{orientation}."
   (let* ((my-fret-count (fret-count fret-range)))
-   (draw-fret-lines my-fret-count string-count th size orientation)))
+   (draw-fret-lines 
+     my-fret-count string-count th thickness-factor size orientation)))
 
 (define (draw-dots layout props string-count fret-count
                    size finger-code
@@ -514,38 +550,40 @@ Line thickness is given by @var{th}, fret & string spacing by
                     barre-list orientation)
   "Create barre indications for a fret diagram"
   (if (not (null? barre-list))
-      (let* ((details (merge-details 'fret-diagram-details props '()))
-             (string1 (caar barre-list))
-             (string2 (cadar barre-list))
-             (barre-fret (caddar barre-list))
-             (top-fret (cdr fret-range))
-             (low-fret (car fret-range))
-             (fret (1+ (- barre-fret low-fret)))
-             (barre-vertical-offset 0.5)
-             (dot-center-fret-coordinate (+ (1- fret) dot-position))
-             (barre-fret-coordinate
-              (+ dot-center-fret-coordinate
-                 (* (- barre-vertical-offset 0.5) dot-radius)))
-             (barre-start-string-coordinate (- string-count string1))
-             (barre-end-string-coordinate (- string-count string2))
-             (scale-dot-radius (* size dot-radius))
-             (barre-type (assoc-get 'barre-type details 'curved))
-             (barre-stencil
-               (cond 
-                 ((eq? barre-type 'straight)
-                  (make-straight-barre-stencil size scale-dot-radius 
-                     barre-fret-coordinate barre-start-string-coordinate
-                     barre-end-string-coordinate orientation))
-                 ((eq? barre-type 'curved)
-                  (make-curved-barre-stencil size scale-dot-radius
-                     barre-fret-coordinate barre-start-string-coordinate
-                     barre-end-string-coordinate orientation)))))
-(if (not (null? (cdr barre-list)))
-            (ly:stencil-add
-             barre-stencil
-             (draw-barre layout props string-count fret-range size finger-code
-                         dot-position dot-radius (cdr barre-list) orientation))
-            barre-stencil ))))
+    (let* ((details (merge-details 'fret-diagram-details props '()))
+           (string1 (caar barre-list))
+           (string2 (cadar barre-list))
+           (barre-fret (caddar barre-list))
+           (top-fret (cdr fret-range))
+           (low-fret (car fret-range))
+           (fret (1+ (- barre-fret low-fret)))
+           (barre-vertical-offset 0.5)
+           (dot-center-fret-coordinate (+ (1- fret) dot-position))
+           (barre-fret-coordinate
+             (+ dot-center-fret-coordinate
+                (* (- barre-vertical-offset 0.5) dot-radius)))
+           (barre-start-string-coordinate (- string-count string1))
+           (barre-end-string-coordinate (- string-count string2))
+           (scale-dot-radius (* size dot-radius))
+           (barre-type (assoc-get 'barre-type details 'curved))
+           (barre-stencil
+             (cond 
+               ((eq? barre-type 'straight)
+                (make-straight-barre-stencil 
+                  size scale-dot-radius 
+                  barre-fret-coordinate barre-start-string-coordinate
+                  barre-end-string-coordinate orientation))
+               ((eq? barre-type 'curved)
+                (make-curved-barre-stencil 
+                  size scale-dot-radius
+                  barre-fret-coordinate barre-start-string-coordinate
+                  barre-end-string-coordinate orientation)))))
+      (if (not (null? (cdr barre-list)))
+        (ly:stencil-add
+          barre-stencil
+          (draw-barre layout props string-count fret-range size finger-code
+                      dot-position dot-radius (cdr barre-list) orientation))
+        barre-stencil ))))
 
 (define (label-fret layout props string-count fret-range size orientation)
   "Label the base fret on a fret diagram"
@@ -691,7 +729,8 @@ Line thickness is given by @var{th}, fret & string spacing by
           (ly:stencil-add
            (draw-strings 
              string-count fret-range th thickness-factor size orientation)
-           (draw-frets fret-range string-count th size orientation))))
+           (draw-frets 
+             fret-range string-count th thickness-factor size orientation))))
     (if (and (not (null? barre-list))
              (not (eq? 'none barre-type)))
         (set! fret-diagram-stencil
@@ -712,7 +751,8 @@ Line thickness is given by @var{th}, fret & string spacing by
                   (ly:stencil-add
                      fret-diagram-stencil 
                      (draw-thick-zero-fret
-                     details string-count th size orientation))))
+                       details string-count th 
+                       thickness-factor size orientation))))
     (if (not (null? xo-list))
      (let* ((diagram-fret-top 
               (car (stencil-fretboard-extent