diff options
author | Carl Sorensen <c_sorensen@byu.edu> | 2009-01-11 15:10:31 -0700 |
---|---|---|
committer | Carl Sorensen <c_sorensen@byu.edu> | 2009-01-11 15:10:31 -0700 |
commit | cb47f0d75cc88e34d5cb06fcfbf4104ce0780c90 (patch) | |
tree | b455b1b42f3d30b39e876ef8dc48af61024f1ec4 | |
parent | 90eb747c52a93e1293f3aa3254c204d2c39dbc31 (diff) |
Add variable string thickness to fret-diagrams
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.
-rw-r--r-- | input/new/fret-diagrams-explained-and-developed.ly | 1 | ||||
-rw-r--r-- | input/regression/fret-diagrams-dots.ly | 8 | ||||
-rw-r--r-- | input/regression/fret-diagrams-fingering.ly | 10 | ||||
-rw-r--r-- | input/regression/fret-diagrams-fret-label.ly | 6 | ||||
-rw-r--r-- | input/regression/fret-diagrams-string-thickness.ly | 58 | ||||
-rw-r--r-- | scm/define-grob-properties.scm | 4 | ||||
-rw-r--r-- | scm/fret-diagrams.scm | 156 |
7 files changed, 173 insertions, 70 deletions
diff --git a/input/new/fret-diagrams-explained-and-developed.ly b/input/new/fret-diagrams-explained-and-developed.ly index b37fd5f8ad..971dd0e4e7 100644 --- a/input/new/fret-diagrams-explained-and-developed.ly +++ b/input/new/fret-diagrams-explained-and-developed.ly @@ -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;" diff --git a/input/regression/fret-diagrams-dots.ly b/input/regression/fret-diagrams-dots.ly index cf06e666ea..a38d0b2218 100644 --- a/input/regression/fret-diagrams-dots.ly +++ b/input/regression/fret-diagrams-dots.ly @@ -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))} } >> diff --git a/input/regression/fret-diagrams-fingering.ly b/input/regression/fret-diagrams-fingering.ly index bebd9a6217..5833e0b998 100644 --- a/input/regression/fret-diagrams-fingering.ly +++ b/input/regression/fret-diagrams-fingering.ly @@ -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))} } >> diff --git a/input/regression/fret-diagrams-fret-label.ly b/input/regression/fret-diagrams-fret-label.ly index dbe18f27b6..e45755c8f2 100644 --- a/input/regression/fret-diagrams-fret-label.ly +++ b/input/regression/fret-diagrams-fret-label.ly @@ -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 index 0000000000..2a2d2b5928 --- /dev/null +++ b/input/regression/fret-diagrams-string-thickness.ly @@ -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))} + + + } +>> + + diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index 302f26f1a7..3240912a1d 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -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 diff --git a/scm/fret-diagrams.scm b/scm/fret-diagrams.scm index 7592ef37ef..f18cf3e7d8 100644 --- a/scm/fret-diagrams.scm +++ b/scm/fret-diagrams.scm @@ -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 |