;;;;
;;;; source file of the GNU LilyPond music typesetter
;;;;
-;;;; (c) 2004 Carl D. Sorensen <c_sorensen@byu.edu>
-
-(define ly:paper-lookup ly:output-def-lookup) ; compat for 2.3, remove when using 2.2
-(define fontify-text-white fontify-text) ; temporary until fontify-text-white works properly (see draw-dots for usage)
-
-;;TODO -- Change font interface from name, magnification to family, weight, size
-; Right now, using the desired interface gives an error, so we use name, magnification
+;;;; (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))
((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)
(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)
(third this-list)))
(subtract-base-fret base-fret (cdr dot-list))))))
+(define (sans-serif-stencil layout props mag text)
+"create a stencil in sans-serif font based on @var{layout} and @var{props}
+with magnification @varr{mag} of the string @var{text}."
+ (let* ((my-props (prepend-alist-chain 'font-size (stepmag mag)
+ (prepend-alist-chain 'font-family 'sans props))))
+ (interpret-markup layout my-props text)))
+
+
(define (draw-strings string-count fret-range th size)
-"Draw the strings (vertical 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}. "
+"Draw the strings (vertical 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}. "
(let* ((fret-count (+ (- (cadr fret-range) (car fret-range)) 1))
(sl (* (+ fret-count 1) size))
(sth (* size th))
(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 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))))
-
+ "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))))
+
(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-half-thick (* top-fret-thick 0.5))
- (half-thick (* sth 0.5))
- (x1 half-thick)
- (x2 (+ half-thick (* size (- string-count 1))))
- (y1 0)
- (y2 top-fret-thick)
- (x-extent (cons (- x1) x2))
- (y-extent (cons 0 y2)))
- (ly:make-stencil (list 'round-filled-box x1 x2 y1 y2 th)
- x-extent y-extent)))
-
-
-(define (draw-frets paper props fret-range string-count th size)
- "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}. "
- (let* ((top-fret-thick (* th (chain-assoc-get 'top-fret-thickness props 3.0)))
- (fret-count (+ (- (cadr fret-range) (car fret-range)) 1))
+ "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
+@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}. "
+ (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)))
-
+ (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 (centered-text-stencil procedure font text)
-"Create a centered text stencil of @var{text} in font @var{font} using stencil creation procedure @var{procedure}"
-;UGH -- version check is necessary because 2.3 is not available on cygwin, so CDS development
-; needs 2.2 compatible ly:stencil-align-to!
-; Once 2.3 is built on cygwin, version check can go (fret-diagrams.scm is not part of dist for 2.2)
-(let* ((text-stencil (procedure font text)))
- (if (= (cadr (ly:version)) 3)
- (begin
- (ly:stencil-align-to! text-stencil Y 0)
- (ly:stencil-align-to! text-stencil X 0)
- text-stencil)
- (ly:stencil-align-to (ly:stencil-align-to text-stencil X 0) Y 0))))
-
-(define (draw-dots paper props string-count fret-range size finger-code dot-circle-font-mag 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."
-;TODO -- move away from name,magnification font spec to family, size
-; Note -- family, size doesn't work with fontify-text procedure; need to fix that before we can make the switch
+
(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)))
-;part of deprecated font interface
- (label-font-name (chain-assoc-get 'label-font-name props "cmss8"))
- (white-dot-font-mag (* scale-dot-radius (chain-assoc-get 'white-dot-font-mag props 1.8)))
- (dot-label-font-mag (* scale-dot-radius (chain-assoc-get 'dot-label-font-mag props 1.2)))
- (string-label-font-mag (* size (chain-assoc-get 'string-label-font-mag props 0.6)))
+; (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))
(extent (cons (- scale-dot-radius) scale-dot-radius))
(finger (caddr mypair))
(finger (if (number? finger) (number->string finger) finger))
-; desired font interface
- (string-label-font (ly:paper-get-font paper `(((font-family . sans)(font-encoding . latin1)(font-series . medium) (font-shape . upright)
- (font-size . ,(stepmag (* size string-label-font-mag)))))))
-; deprecated font interface
-; (string-label-font (ly:paper-get-font paper `(((font-magnification . ,string-label-font-mag)
-; (font-name . ,label-font-name)))))
-; desired font interface
- (dot-label-font (ly:paper-get-font paper `(((font-family . sans)(font-encoding . latin1)(font-series . medium) (font-shape . upright)
- (font-size . ,(stepmag (* size dot-label-font-mag)))))))
-; deprecated font interface
-; (dot-label-font (ly:paper-get-text-font paper `(((font-magnification . ,dot-label-font-mag)
-; (font-name . ,label-font-name)))))
-; desired font interface
- (dot-circle-font (ly:paper-get-font paper `(((font-family . sans)(font-encoding . latin1)(font-series . medium) (font-shape . upright)
- (font-size . ,(stepmag (* size dot-circle-font-mag)))))))
-; deprecated font interface
-; (dot-circle-font (ly:paper-get-font paper `(((font-magnification . ,dot-circle-font-mag)
-; (font-name . ,label-font-name)))))
-; deprecated font interface
- (white-dot-font (ly:paper-get-font paper `(((font-magnification . ,white-dot-font-mag)
- (font-name . ,label-font-name)))))
(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))
- (text-proc (if (eq? dot-color 'white) fontify-text fontify-text-white)))
- (ly:stencil-add
- (ly:stencil-translate-axis
- (ly:stencil-translate-axis
- (centered-text-stencil text-proc dot-label-font 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-text-stencil fontify-text string-label-font finger) xpos X)
- (* size finger-yoffset) Y))
+ (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 paper props string-count fret-range size finger-code dot-circle-font-mag
- dot-position dot-radius restlist)
+ (draw-dots layout props string-count fret-range size finger-code
+ dot-position dot-radius dot-thickness restlist)
labeled-dot-stencil))))
-(define (draw-xo paper props string-count fret-range size xo-list)
+(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}."
-;TODO -- Move away from name,mag font spec to family, size
(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-name (chain-assoc-get 'xo-font-name props "cmss8"))
- (xo-horizontal-offset (* size (chain-assoc-get 'xo-horizontal-offset props -0.35)))
-; desired font interface
-; (font (ly:paper-get-font paper `(((font-family . sans)(font-series . medium) (font-shape . upright)
-; (font-size . ,(stepmag (* size xo-font-mag)))))))
-; deprecated font interface
- (font (ly:paper-get-font paper `(((font-magnification . ,xo-font-mag)
- (font-name . ,xo-font-name)))))
+; (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 (fontify-text font glyph-string) xpos X)))
+ (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 paper props string-count fret-range size restlist)
+ (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}."
+" 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)))
(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 paper props string-count fret-range size finger-code dot-circle-font-mag dot-position dot-radius barre-list)
+(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))
+ (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
- (bottom (+ (* size (- (+ 2 (- (cadr fret-range) fret))dot-position) ) (* size barre-vertical-offset dot-radius)))
+ ;; 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-height (chain-assoc-get 'bezier-height props 0.5))
+;; (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)))
- (sandwich-stencil (ly:make-stencil (list 'bezier-sandwich `(quote ,bezier-list) (* size bezier-thick) )
- (cons 0 right)
- (cons 0 (+ bottom (* size bezier-height))))))
+ (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 sandwich-stencil
- (draw-barre paper props string-count fret-range size finger-code dot-circle-font-mag
+ (ly:stencil-add barre-stencil
+ (draw-barre layout props string-count fret-range size finger-code
dot-position dot-radius (cdr barre-list)))
- sandwich-stencil ))))
-
+ barre-stencil ))))
(define (stepmag mag)
"Calculate the font step necessary to get a desired magnification"
(* 6 (/ (log mag) (log 2))))
-(define (label-fret paper props string-count fret-range size)
+(define (label-fret layout props string-count fret-range size)
"Label the base fret on a fret diagram"
-;TODO -- move away from name,magnification font spec to family, size
(let* ((base-fret (car fret-range))
- (label-font-mag (chain-assoc-get 'fret-label-font-magnification props 0.7))
-; (label-horizontal-offset (chain-assoc-get 'fret-label-horizontal-offset props -0.5))
- (label-vertical-offset (chain-assoc-get 'fret-label-vertical-offset props -0.2))
+; (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))
-; desired font interface
-; (font (ly:paper-get-font paper `(((font-family . sans)(font-series . medium) (font-shape . upright)
-; (font-size . ,(stepmag (* size label-font-mag))))))))
-; deprecated font interface
- (font (ly:paper-get-font paper `(((font-magnification . ,label-font-mag)
- (font-name . "cmss8"))))))
- (ly:stencil-translate-axis (fontify-text font (format #f "~(~:@r~)" base-fret))
+ (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)))
-(def-markup-command (fret-diagram-verbose paper props marking-list)
+(define-builtin-markup-command (fret-diagram-verbose layout props marking-list)
(list?)
-;TODO -- put table in doc string
"Make a fret diagram containing the symbols indicated in @var{marking-list}
- Syntax: \\fret-diagram marking-list
-
For example,
@example
- \\markup \\fret-diagram #'((mute 6) (mute 5) (open 4) (place-fret 3 2) (place-fret 2 3) (place-fret 1 2))
+ \\markup \\fret-diagram-verbose #'((mute 6) (mute 5) (open 4)
+ (place-fret 3 2) (place-fret 2 3) (place-fret 1 2))
@end example
will produce a standard D chord diagram without fingering indications.
Place a barre indicator (much like a tie) from string @var{start-string}to string @var{end-string} at fret @var{fret-number}
@item (place-fret string-number fret-number finger-value)
-Place a fret playing indication on string @var{string-number} at fret @var{fret-number} with an optional
-fingering label @var{finger-value}. By default, the fret playing indicator is a solid dot. This can be
-changed by setting the value of the variable @var{dot-color}. If the @var{finger}
-part of the place-fret element is present, @var{finger-value} will be displayed according to the setting of the variable
-@var{finger-code}. There is no limit to the number of fret indications per string.
+
+Place a fret playing indication on string @var{string-number} at fret
+@var{fret-number} with an optional fingering label @var{finger-value}.
+By default, the fret playing indicator is a solid dot. This can be
+changed by setting the value of the variable @var{dot-color}. If the
+@var{finger} part of the place-fret element is present,
+@var{finger-value} will be displayed according to the setting of the
+variable @var{finger-code}. There is no limit to the number of fret
+indications per string.
+
+
+
+
@end table
"
- (make-fret-diagram paper props marking-list))
+ (make-fret-diagram layout props marking-list))
-(define (make-fret-diagram paper props marking-list)
+(define (make-fret-diagram layout props marking-list)
" Make a fret diagram markup"
(let* (
; note: here we get items from props that are needed in this routine, or that are needed in more than one
;TODO -- adjust padding for fret label? it appears to be too close to dots
(string-count (chain-assoc-get 'string-count props 6)) ; needed for everything
(fret-count (chain-assoc-get 'fret-count props 4)) ; needed for everything
- (dot-position (chain-assoc-get 'dot-position props 0.6)) ; needed for both draw-dots and draw-barre
- (dot-radius (chain-assoc-get 'dot-radius props 0.25)) ; needed for both draw-dots and draw-barre
(finger-code (chain-assoc-get 'finger-code props 'none)) ; needed for both draw-dots and draw-barre
- (dot-circle-font-mag (* size (chain-assoc-get 'dot-circle-font-mag props .75))) ; needed for both draw-dots and draw-barre
- (th (* (ly:paper-lookup paper 'linethickness)
+ (default-dot-radius (if (eq? finger-code 'in-dot) 0.425 0.25)) ; bigger dots if labeled
+ (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 'line-thickness)
(chain-assoc-get 'thickness props 0.5))) ; needed for both draw-frets and draw-strings
- (alignment (chain-assoc-get 'alignment props -0.4)) ; needed only here
- (xo-padding (* th (chain-assoc-get 'xo-padding props 2))) ; needed only here
-
+ (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 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)))
(xo-list (cdr (assoc 'xo-list parameters)))
(barre-list (cdr (assoc 'barre-list parameters)))
(fret-diagram-stencil (ly:stencil-add
(draw-strings string-count fret-range th size)
- (draw-frets paper props fret-range string-count th size))))
+ (draw-frets layout props fret-range string-count th size))))
(if (not (null? barre-list))
(set! fret-diagram-stencil (ly:stencil-add
- (draw-barre paper props string-count fret-range size finger-code dot-circle-font-mag
+ (draw-barre layout props string-count fret-range size finger-code
dot-position dot-radius barre-list)
fret-diagram-stencil)))
(if (not (null? dot-list))
(set! fret-diagram-stencil (ly:stencil-add
- (draw-dots paper props string-count fret-range size finger-code dot-circle-font-mag
- dot-position dot-radius dot-list)
- fret-diagram-stencil)))
+ fret-diagram-stencil
+ (draw-dots layout props string-count fret-range size finger-code
+ 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 paper 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 RIGHT
- (label-fret paper props string-count fret-range size) 0 0)))
- (ly:stencil-align-to! fret-diagram-stencil X alignment)
- 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)))
+ (ly:stencil-aligned-to fret-diagram-stencil X alignment)
+ ))
-(def-markup-command (fret-diagram paper props definition-string)
+(define-builtin-markup-command (fret-diagram layout props definition-string)
(string?)
-;TODO -- put table in doc string
- "Syntax: \\fret-diagram definition-string
-
-eg: \\markup \\fret-diagram #\"s:0.75;6-x;5-x;4-o;3-2;2-3;1-2;\"
+ "
+Example
+
+@example
+ \\markup \\fret-diagram #\"s:0.75;6-x;5-x;4-o;3-2;2-3;1-2;\"
+@end example
for fret spacing 3/4 of staff space, D chord diagram
@end itemize
"
-; (define new-props (acons 'size size '()))
-; (set! props (cons new-props props))
(let ((definition-list (fret-parse-definition-string props definition-string)))
- (make-fret-diagram paper (car definition-list) (cdr definition-list))))
+ (make-fret-diagram layout (car definition-list) (cdr definition-list))))
(define (fret-parse-definition-string props definition-string)
"parse a fret diagram string and return a pair containing:
a fret-indication list with the appropriate values"
(let* ((fret-count 4)
(string-count 6)
- ; (thickness 0.05)
- ; (finger-code 0)
- ; (dot-size 0.25)
- ; (dot-position 0.6)
(fret-range (list 1 fret-count))
(barre-list '())
(dot-list '())
(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) )))
+ (string->number (substring keystring 2 (string-length keystring))))
(define (numerify mylist)
"Convert string values to numeric or character"
(cons* numeric-value (numerify (cdr mylist)))
(cons* (car (string->list (car mylist))) (numerify (cdr mylist)))))))
-(def-markup-command (fret-diagram-terse paper props definition-string)
+(define-builtin-markup-command (fret-diagram-terse layout props definition-string)
(string?)
-;TODO -- put table in doc string
"Make a fret diagram markup using terse string-based syntax.
-Syntax: \\fret-diagram-terse definition-string
-
-eg: \\markup \\fret-diagram #\"x;x;o;2;3;2;\" for a D chord diagram.
+Example
+@example
+ \\markup \\fret-diagram-terse #\"x;x;o;2;3;2;\"
+@end example
+for a D chord diagram.
Syntax rules for @var{definition-string}:
@itemize @bullet
@end itemize"
;TODO -- change syntax to fret\string-finger
(let ((definition-list (fret-parse-terse-definition-string props definition-string)))
- (make-fret-diagram paper (car definition-list) (cdr definition-list))))
+ (make-fret-diagram layout (car definition-list) (cdr definition-list))))
(define (fret-parse-terse-definition-string props definition-string)
"parse a fret diagram string that uses terse syntax; return a pair containing:
props, modified to include the string-count determined by the definition-string
a fret-indication list with the appropriate values"
;TODO -- change syntax to fret\string-finger
-;TODO -- fix bug that doesn't allow multiple indications per string
(let* ((barre-start-list '())
(output-list '())
(new-props '())
(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 "(") ; here I add ) to balance parentheses for my editor
+ (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 ")") ; here I add ( to balance parentheses for my editor
+ (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))