-@var{size}. "
- (let* ((fret-count (+ (- (cadr fret-range) (car fret-range)) 1))
- (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)))
-
-
-(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 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.6))
- (fret-count (+ (- (cadr fret-range) (car fret-range) 1)))
- (mypair (car dot-list))
- (restlist (cdr dot-list))
- (xpos (* size (- string-count (car mypair))))
-;TODO -- figure out what 4 is and get rid of it
-;UGH -- 4?
- (ypos (* size (+ 4 (- fret-count (cadr mypair) dot-position ))))
- (extent (cons (- scale-dot-radius) scale-dot-radius))
- (finger (caddr mypair))
- (finger (if (number? finger) (number->string finger) finger))
- (dotstencil (if (eq? dot-color 'white)
- (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* ((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))
- (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))
- ;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 dot-thickness restlist)
- labeled-dot-stencil))))
-
-(define (draw-xo layout props string-count fret-range size xo-list)
-"Put open and mute string indications on diagram, as contained in @var{xo-list}."
- (let* ((fret-count (+ (- (cadr fret-range) (car fret-range) 1)))
-; (xo-font-mag (* size (chain-assoc-get 'xo-font-magnification props 0.5)))
- (xo-font-mag (* size 0.5))
-; (xo-horizontal-offset (* size (chain-assoc-get 'xo-horizontal-offset props -0.35)))
- (xo-horizontal-offset (* size -0.35))
- (mypair (car xo-list))
- (restlist (cdr xo-list))
- (glyph-string (if (eq? (car mypair) 'mute) "X" "O"))
- (xpos (+ (* (- string-count (cadr mypair)) size) xo-horizontal-offset ))
- (glyph-stencil (ly:stencil-translate-axis
- (sans-serif-stencil layout props (* size xo-font-mag) glyph-string) xpos X)))
- (if (null? restlist)
- glyph-stencil
- (ly:stencil-add
- (draw-xo layout props string-count fret-range size restlist)
- glyph-stencil))))
-
-(define (make-bezier-sandwich-list left right bottom height thickness)
-" Make the argument list for a horizontal bezier sandwich from
-@var{left} to @var{right} with a bottom at @var{bottom}, a height of
-@var{height}, and a thickness of @var{thickness}."
- (let* ((width (+ (- right left) 1))
- (x1 (+ (* width thickness) left))
- (x2 (- right (* width thickness)))
- (bottom-control-point-height (+ bottom (- height thickness)))
- (top-control-point-height (+ bottom height)))
- ; order of 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.
- (list (cons x1 bottom-control-point-height) (cons x2 bottom-control-point-height) (cons right bottom) (cons left bottom)
- (cons x2 top-control-point-height) (cons x1 top-control-point-height) (cons left bottom) (cons right bottom))))
-
-(define (draw-barre layout props string-count fret-range size finger-code dot-position dot-radius barre-list)
- "Create barre indications for a fret diagram"
- (if (not (null? barre-list))
- (let* ((string1 (caar barre-list))
- (string2 (cadar barre-list))
- (fret (caddar barre-list))
- (barre-type (chain-assoc-get 'barre-type props 'curved))
- (scale-dot-radius (* size dot-radius))
- (barre-vertical-offset (chain-assoc-get 'barre-vertical-offset props 0.5))
- ;; 2 is 1 for empty fret at bottom of figure + 1 for interval (top-fret - fret + 1) -- not an arbitrary constant
- (dot-center-y (* size
- (- (+ 2 (- (cadr fret-range) fret)) dot-position)))
- (bottom (+ dot-center-y (* barre-vertical-offset scale-dot-radius)))
- (left (* size (- string-count string1)))
- (right (* size (- string-count string2)))
-;; (bezier-thick (chain-assoc-get 'bezier-thickness props 0.1))
- (bezier-thick 0.1)
-;; (bezier-height (chain-assoc-get 'bezier-height props 0.5))
- (bezier-height 0.5)
- (bezier-list (make-bezier-sandwich-list left right bottom (* size bezier-height) (* size bezier-thick)))
- (barre-stencil (if (eq? barre-type 'straight)
- (ly:make-stencil (list 'draw-line (* size dot-radius) left dot-center-y right dot-center-y)
- (cons left right)
- (cons (- dot-center-y scale-dot-radius) (+ dot-center-y scale-dot-radius)))
- (ly:make-stencil (list 'bezier-sandwich `(quote ,bezier-list) (* size bezier-thick))
- (cons left right)
- (cons bottom (+ bottom (* size bezier-height)))))))
- (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)))
- barre-stencil ))))
-
-(define (stepmag mag)
-"Calculate the font step necessary to get a desired magnification"
-(* 6 (/ (log mag) (log 2))))
-
-(define (label-fret layout props string-count fret-range size)
- "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.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))
- (fret-count (+ (- (cadr fret-range) (car fret-range)) 1))
- (label-text
- (cond
- ((equal? number-type 'roman-lower) (format #f "~(~:@r~)" base-fret))
- ((equal? number-type 'roman-upper) (format #f "~:@r" base-fret))
- ((equal? 'arabic number-type) (format #f "~d" base-fret))
- (else (format #f "~(~:@r~)" base-fret)))))
- (ly:stencil-translate-axis
- (sans-serif-stencil layout props (* size label-font-mag) label-text)
- (* size (+ fret-count label-vertical-offset)) Y)))
-
-(define-builtin-markup-command (fret-diagram-verbose layout props marking-list)
- (list?)
- "Make a fret diagram containing the symbols indicated in @var{marking-list}
-
+@var{size}. Orientation is given by @var{orientation}."
+ (define (helper x)
+ (if (null? (cdr x))
+ (fret-stencil (car x))
+ (ly:stencil-add
+ (fret-stencil (car x))
+ (helper (cdr x)))))
+
+ (let ((fret-list (iota (1+ my-fret-count))))
+ (helper fret-list)))
+
+ (define (fret-stencil fret)
+ "Make a stencil for @code{fret}, given the
+fret-diagram overall parameters."
+ (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
+ (* fret-distance size fret)
+ (- fret-half-thickness low-string-half-thickness)))
+ (end-coordinates
+ (stencil-coordinates
+ (* fret-distance size fret)
+ (* size string-distance (1- string-count)))))
+ (make-line-stencil
+ (* size th)
+ (car start-coordinates) (cdr start-coordinates)
+ (car end-coordinates) (cdr end-coordinates))))
+
+ (define (draw-barre barre-list)
+ "Create barre indications for a fret diagram"
+ (if (not (null? barre-list))
+ (let* ((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
+ barre-fret-coordinate
+ barre-start-string-coordinate
+ barre-end-string-coordinate
+ scale-dot-radius))
+ ((eq? barre-type 'curved)
+ (make-curved-barre-stencil
+ barre-fret-coordinate
+ barre-start-string-coordinate
+ barre-end-string-coordinate
+ scale-dot-radius)))))
+ (if (not (null? (cdr barre-list)))
+ (ly:stencil-add
+ barre-stencil
+ (draw-barre (cdr barre-list)))
+ barre-stencil ))))
+
+ (define (make-straight-barre-stencil
+ fret-coordinate
+ start-string-coordinate
+ end-string-coordinate
+ half-thickness)
+ "Create a straight barre stencil."
+ (let ((start-point
+ (stencil-coordinates
+ (* size fret-distance fret-coordinate)
+ (* size string-distance start-string-coordinate)))
+ (end-point
+ (stencil-coordinates
+ (* size fret-distance fret-coordinate)
+ (* size string-distance end-string-coordinate))))
+ (make-line-stencil
+ half-thickness
+ (car start-point)
+ (cdr start-point)
+ (car end-point)
+ (cdr end-point))))
+
+ (define (make-curved-barre-stencil
+ fret-coordinate
+ start-string-coordinate
+ end-string-coordinate
+ half-thickness)
+ "Create a curved barre stencil."
+ (let* ((bezier-thick 0.1)
+ (bezier-height 0.5)
+ (bezier-list
+ (make-bezier-sandwich-list
+ (* size string-distance start-string-coordinate)
+ (* size string-distance end-string-coordinate)
+ (* size fret-distance fret-coordinate)
+ (* size bezier-height)
+ (* size bezier-thick))))
+ (make-bezier-sandwich-stencil
+ bezier-list
+ (* size bezier-thick))))
+
+ (define (draw-dots dot-list)
+ "Make dots for fret diagram."
+
+ (let* ( (scale-dot-radius (* size dot-radius))
+ (scale-dot-thick (* size th))
+ (default-dot-color (assoc-get 'dot-color details))
+ (finger-label-padding 0.3)
+ (dot-label-font-mag
+ (* scale-dot-radius
+ (assoc-get 'dot-label-font-mag details 1.0)))
+ (string-label-font-mag
+ (* size
+ (assoc-get
+ 'string-label-font-mag details
+ (cond ((or (eq? orientation 'landscape)
+ (eq? orientation 'opposing-landscape))
+ 0.5)
+ (else 0.6)))))
+ (mypair (car dot-list))
+ (restlist (cdr dot-list))
+ (string (car mypair))
+ (fret (cadr mypair))
+ (fret-coordinate
+ (* size fret-distance (+ (1- fret) dot-position)))
+ (string-coordinate
+ (* size string-distance (- string-count string)))
+ (dot-coordinates
+ (stencil-coordinates fret-coordinate string-coordinate))
+ (extent (cons (- scale-dot-radius) scale-dot-radius))
+ (finger (caddr mypair))
+ (finger (if (number? finger) (number->string finger) finger))
+ (parenthesized
+ (if (not (null? (dot-is-parenthesized mypair)))
+ (dot-is-parenthesized mypair)
+ #f))
+ (parenthesis-color
+ (if (not (null? (default-paren-color mypair)))
+ (default-paren-color mypair)
+ #f))
+ (inverted
+ (if (not (null? (dot-is-inverted mypair)))
+ (dot-is-inverted mypair)
+ #f))
+ (dot-color-is-white?
+ (or inverted
+ (and (eq? default-dot-color 'white) (not inverted))))
+ (what-color
+ (x11-color
+ (cond ((and inverted
+ (not (dot-has-color mypair))
+ (not (eq? default-dot-color 'white)))
+ (or default-dot-color 'black))
+ (dot-color-is-white?
+ (or (dot-has-color mypair) 'black))
+ (else
+ (or (dot-has-color mypair)
+ default-dot-color
+ 'black)))))
+ (inverted-stil
+ (lambda (color)
+ (ly:stencil-add
+ (stencil-with-color
+ (make-circle-stencil
+ scale-dot-radius scale-dot-thick #t)
+ color)
+ (stencil-with-color
+ (make-circle-stencil
+ (- scale-dot-radius (* 0.5 scale-dot-thick))
+ 0 #t)
+ (x11-color 'white)))))
+ (dot-stencil
+ (if dot-color-is-white?
+ (inverted-stil what-color)
+ (stencil-with-color
+ (make-circle-stencil
+ scale-dot-radius scale-dot-thick #t)
+ what-color)))
+ (par-dot-stencil
+ (let ((paren-color
+ (if (and parenthesis-color
+ (not (eq? default-dot-color 'white)))
+ (x11-color (or default-dot-color 'black))
+ what-color)))
+ (stencil-with-color
+ (parenthesize-stencil
+ dot-stencil ;; stencil
+ (* size th 0.75) ;; half-thickness
+ (* 0.15 size) ;;width
+ 0 ;; angularity
+ paren-padding ;; padding
+ )
+ paren-color)))
+ (final-dot-stencil
+ (if parenthesized
+ par-dot-stencil
+ dot-stencil))
+ (positioned-dot
+ (ly:stencil-translate final-dot-stencil dot-coordinates))
+ (labeled-dot-stencil
+ (cond
+ ((or (eq? finger '())(eq? finger-code 'none))
+ positioned-dot)
+ ((eq? finger-code 'in-dot)
+ (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
+ (if dot-color-is-white?
+ (stencil-with-color
+ finger-label
+ what-color)
+ (stencil-with-color finger-label white)))
+ dot-coordinates)))
+ ((eq? finger-code 'below-string)
+ (let* ((label-stencil
+ (centered-stencil
+ (sans-serif-stencil
+ layout props string-label-font-mag
+ finger)))
+ (label-fret-offset
+ (stencil-fretboard-offset
+ label-stencil 'fret orientation))
+ (label-fret-coordinate
+ ;; (1) Move the below-string-finger-codes to the bottom
+ ;; edge of the string, i.e.
+ ;; (* (1+ my-fret-count) fret-distance)
+ ;; (2) add `finger-label-padding' (a hardcoded
+ ;; correction-value to get a bit default padding).
+ ;; TODO: make it a property?
+ ;; (3) scale this with `size'
+ ;; (4) add `label-fret-offset', to get the final
+ ;; padding
+ (+
+ (* size
+ (+ (* (1+ my-fret-count) fret-distance)
+ finger-label-padding))
+ label-fret-offset))
+ (label-string-coordinate string-coordinate)
+ (label-translation
+ (stencil-coordinates
+ label-fret-coordinate
+ label-string-coordinate)))
+ (ly:stencil-add
+ positioned-dot
+ (ly:stencil-translate
+ label-stencil
+ label-translation))))
+ (else ;unknown finger-code
+ positioned-dot))))
+ (if (null? restlist)
+ labeled-dot-stencil
+ (ly:stencil-add
+ (draw-dots restlist)
+ labeled-dot-stencil))))
+
+ (define (draw-thick-zero-fret)
+ "Draw a thick zeroth fret for a fret diagram whose base fret is 1."
+ (let* ((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-lowest-string-thickness))
+ (end-string-coordinate
+ (+ (* size string-distance (1- string-count)) half-thick))
+ (start-fret-coordinate half-thick)
+ (end-fret-coordinate (- half-thick top-fret-thick))
+ (lower-left
+ (stencil-coordinates
+ start-fret-coordinate start-string-coordinate))
+ (upper-right
+ (stencil-coordinates
+ end-fret-coordinate end-string-coordinate)))
+ (ly:round-filled-box
+ ;; Put limits in order, or else the intervals are considered empty
+ (ordered-cons (car lower-left) (car upper-right))
+ (ordered-cons (cdr lower-left) (cdr upper-right))
+ sth)))
+
+ (define (draw-xo xo-list)
+ "Put open and mute string indications on diagram, as contained in
+@var{xo-list}."
+ (let* ((xo-font-mag
+ (assoc-get 'xo-font-magnification details
+ (cond ((or (eq? orientation 'landscape)
+ (eq? orientation 'opposing-landscape))
+ 0.4)
+ (else 0.4))))
+ (mypair (car xo-list))
+ (restlist (cdr xo-list))
+ (glyph-string (if (eq? (car mypair) 'mute)
+ (assoc-get 'mute-string details "X")
+ (assoc-get 'open-string details "O")))
+ (glyph-string-coordinate
+ (* (- string-count (cadr mypair)) string-distance size))
+ (glyph-stencil
+ (centered-stencil
+ (sans-serif-stencil
+ layout props (* size xo-font-mag) glyph-string)))
+ (glyph-stencil-coordinates
+ (stencil-coordinates 0 glyph-string-coordinate))
+ (positioned-glyph
+ (ly:stencil-translate
+ glyph-stencil
+ glyph-stencil-coordinates)))
+ (if (null? restlist)
+ positioned-glyph
+ (ly:stencil-add
+ positioned-glyph
+ (draw-xo restlist)))))
+
+ (define (draw-capo fret)
+ "Draw a capo indicator across the full width of the fret-board
+at @var{fret}."
+ (let* ((capo-thick
+ (* size (assoc-get 'capo-thickness details 0.5)))
+ (half-thick (* capo-thick 0.5))
+ (last-string-position 0)
+ (first-string-position (* size (- string-count 1)))
+ (fret-position (* size (1- (+ dot-position fret))))
+ (start-point
+ (stencil-coordinates
+ (* fret-distance fret-position)
+ (* string-distance first-string-position)))
+ (end-point
+ (stencil-coordinates
+ (* fret-distance fret-position)
+ last-string-position)))
+ (make-line-stencil
+ capo-thick
+ (car start-point) (cdr start-point)
+ (car end-point) (cdr end-point))))
+
+ (define (label-fret fret-range)
+ "Label the base fret on a fret diagram"
+ (let* ((base-fret (car fret-range))
+ (label-font-mag (assoc-get 'fret-label-font-mag details 0.5))
+ (label-space (* 0.5 size))
+ (label-dir (assoc-get 'label-dir details RIGHT))
+ (label-vertical-offset
+ (assoc-get 'fret-label-vertical-offset details 0))
+ (label-horizontal-offset
+ (assoc-get 'fret-label-horizontal-offset details 0))
+ (number-type
+ (assoc-get 'number-type details 'roman-lower))
+ (label-text
+ (number-format number-type base-fret
+ (assoc-get 'fret-label-custom-format
+ details "~a")))
+ (label-stencil
+ (centered-stencil
+ (sans-serif-stencil
+ layout props (* size label-font-mag) label-text)))
+ (label-half-width
+ (stencil-fretboard-offset
+ label-stencil
+ 'string
+ orientation))
+ (label-outside-diagram
+ (+ label-space
+ (* size label-horizontal-offset)
+ label-half-width)))
+ (ly:stencil-translate
+ label-stencil
+ (stencil-coordinates
+ (* size fret-distance (1+ label-vertical-offset))
+ (if (eqv? label-dir LEFT)
+ (- label-outside-diagram)
+ (+ (* size string-distance (1- string-count))
+ label-outside-diagram))))))
+
+ ;; Here is the body of make-fret-diagram
+
+ (set! fret-diagram-stencil
+ (ly:stencil-add (draw-strings) (draw-frets)))
+ (if (and (not (null? barre-list))
+ (not (eq? 'none barre-type)))
+ (set! fret-diagram-stencil
+ (ly:stencil-add
+ (draw-barre barre-list)
+ fret-diagram-stencil)))
+ (if (not (null? dot-list))
+ (set! fret-diagram-stencil
+ (ly:stencil-add
+ fret-diagram-stencil
+ (draw-dots dot-list))))
+ (if (= (car fret-range) 1)
+ (set! fret-diagram-stencil
+ (ly:stencil-add
+ fret-diagram-stencil
+ (draw-thick-zero-fret))))
+ (if (not (null? xo-list))
+ (let* ((diagram-fret-top
+ (car (stencil-fretboard-extent
+ fret-diagram-stencil
+ 'fret
+ orientation)))
+ (xo-stencil (draw-xo xo-list))
+ (xo-fret-offset
+ (stencil-fretboard-offset
+ xo-stencil 'fret orientation))
+ (xo-stencil-offset
+ (stencil-coordinate-offset
+ (- diagram-fret-top
+ xo-fret-offset
+ (* size xo-padding))
+ 0)))
+ (set! fret-diagram-stencil
+ (ly:stencil-add
+ fret-diagram-stencil
+ (ly:stencil-translate
+ xo-stencil
+ xo-stencil-offset)))))
+ (if (> capo-fret 0)
+ (set! fret-diagram-stencil
+ (ly:stencil-add
+ fret-diagram-stencil
+ (draw-capo capo-fret))))
+ (if (> (car fret-range) 1)
+ (set! fret-diagram-stencil
+ (ly:stencil-add
+ fret-diagram-stencil
+ (label-fret fret-range))))
+ (ly:stencil-aligned-to fret-diagram-stencil X alignment)))
+
+(define (fret-parse-definition-string props definition-string)
+ "Parse a fret diagram string and return a pair containing:
+@var{props}, modified as necessary by the definition-string
+a fret-indication list with the appropriate values"
+ (let* ((fret-count 4)
+ (string-count 6)
+ (fret-range (cons 1 fret-count))
+ (barre-list '())
+ (dot-list '())
+ (xo-list '())
+ (output-list '())
+ (new-props '())
+ (details (merge-details 'fret-diagram-details props '()))
+ ;; 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)))
+ (case (car (string->list (substring test-string 0 1)))
+ ((#\s) (let ((size (get-numeric-from-key test-string)))
+ (set! props (prepend-alist-chain 'size size props))))
+ ((#\t) (let ((th (get-numeric-from-key test-string)))
+ (set! props (prepend-alist-chain 'thickness th props))))
+ ((#\f) (let* ((finger-code (get-numeric-from-key test-string))
+ (finger-id (case finger-code
+ ((0) 'none)
+ ((1) 'in-dot)
+ ((2) 'below-string))))
+ (set! details
+ (acons 'finger-code finger-id details))))
+ ((#\c) (set! output-list
+ (cons-fret
+ (cons
+ 'barre
+ (numerify
+ (string-split (substring test-string 2) #\-)))
+ output-list)))
+ ((#\h) (let ((fret-count (get-numeric-from-key test-string)))
+ (set! details
+ (acons 'fret-count fret-count details))))
+ ((#\w) (let ((string-count (get-numeric-from-key test-string)))
+ (set! details
+ (acons 'string-count string-count details))))
+ ((#\d) (let ((dot-size (get-numeric-from-key test-string)))
+ (set! details
+ (acons 'dot-radius dot-size details))))
+ ((#\p) (let ((dot-position (get-numeric-from-key test-string)))
+ (set! details
+ (acons 'dot-position dot-position details))))
+ (else
+ (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
+ (cons 'place-fret (numerify this-list))
+ output-list))
+ (if (equal? (cadr this-list) "x" )
+ (set! output-list
+ (cons-fret
+ (list 'mute fret-number)
+ output-list))
+ (set! output-list
+ (cons-fret
+ (list 'open fret-number)
+ output-list)))))))
+ (parse-item (cdr myitems)))))
+ ;; add the modified details
+ (set! props
+ (prepend-alist-chain 'fret-diagram-details details props))
+ `(,props . ,output-list))) ;ugh -- hard-coded spell -- procedure better
+
+(define-public
+ (fret-parse-terse-definition-string props definition-string)
+ "Parse a fret diagram string that uses terse syntax;
+return a pair containing:
+@var{props}, modified to include the string-count determined by the
+definition-string, and
+a fret-indication list with the appropriate values"
+ ;; TODO -- change syntax to fret\string-finger
+
+ (let* ((details (merge-details 'fret-diagram-details props '()))
+ (barre-start-list '())
+ (output-list '())
+ (new-props '())
+ (items (string-split definition-string #\;))
+ (string-count (- (length items) 1)))
+ (let parse-item ((myitems items))
+ (if (not (null? (cdr myitems)))
+ (let* ((test-string (car myitems))
+ (current-string (- (length myitems) 1))
+ (indicators (string-split test-string #\ )))
+ (let parse-indicators ((myindicators indicators))
+ (if (not (eq? '() myindicators))
+ (let* ((this-list (string-split (car myindicators) #\-))
+ (max-element-index (- (length this-list) 1))
+ (last-element
+ (car (list-tail this-list max-element-index)))
+ (fret
+ (if (string->number (car this-list))
+ (string->number (car this-list))
+ (car this-list))))
+ (if (equal? last-element "(")
+ (begin
+ (set! barre-start-list
+ (cons-fret (list current-string fret)
+ barre-start-list))
+ (set! this-list
+ (list-head this-list max-element-index))))
+ (if (equal? last-element ")")
+ (let* ((this-barre
+ (get-sub-list fret barre-start-list))
+ (insert-index (- (length this-barre) 1)))
+ (set! output-list
+ (cons-fret (cons* 'barre
+ (car this-barre)
+ current-string
+ (cdr this-barre))
+ output-list))
+ (set! this-list
+ (list-head this-list max-element-index))))
+ (if (number? fret)
+ (set!
+ output-list
+ (cons-fret (cons*
+ 'place-fret
+ current-string
+ (drop-paren (numerify this-list)))
+ output-list))
+ (if (equal? (car this-list) "x" )
+ (set!
+ output-list
+ (cons-fret
+ (list 'mute current-string)
+ output-list))
+ (set!
+ output-list
+ (cons-fret
+ (list 'open current-string)
+ output-list))))
+ (parse-indicators (cdr myindicators)))))
+ (parse-item (cdr myitems)))))
+ (set! details (acons 'string-count string-count details))
+ (set! props (prepend-alist-chain 'fret-diagram-details details props))
+ `(,props . ,output-list))) ; ugh -- hard coded; proc is better
+
+
+(define-markup-command
+ (fret-diagram-verbose layout props marking-list)
+ (pair?) ; argument type (list, but use pair? for speed)
+ #:category instrument-specific-markup ; markup type
+ #:properties ((align-dir -0.4) ; properties and defaults
+ (size 1.0)
+ (fret-diagram-details)
+ (thickness 0.5))
+ "Make a fret diagram containing the symbols indicated in @var{marking-list}.
+