- (draw-xo
- layout props string-count fret-range size restlist orientation)
- glyph-stencil))))
-
-(define (make-bezier-sandwich-list start stop base height thickness orientation)
- "Make the argument list for a bezier sandwich from
-@var{start} to @var{stop} with a baseline at @var{base}, a height of
-@var{height}, and a thickness of @var{thickness}. If @var{orientation} is
-@var{'normal}, @var{base} is a y coordinate, otherwise it's an x coordinate."
- (let* ((width (+ (- stop start) 1))
- (x1 (+ (* width thickness) start))
- (x2 (- stop (* width thickness)))
- (bottom-control-point-height
- (if (eq? orientation 'normal)
- (+ base (- height thickness))
- (- base (- height thickness))))
- (top-control-point-height
- (if (eq? orientation 'normal)
- (+ base height)
- (- base height))))
- ; order of bezier control 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.
- (if (eq? orientation 'normal)
- (list (cons x1 bottom-control-point-height)
- (cons x2 bottom-control-point-height)
- (cons stop base)
- (cons start base)
- (cons x2 top-control-point-height)
- (cons x1 top-control-point-height)
- (cons start base)
- (cons stop base))
- (list (cons bottom-control-point-height x1)
- (cons bottom-control-point-height x2)
- (cons base stop)
- (cons base start)
- (cons top-control-point-height x2)
- (cons top-control-point-height x1)
- (cons base start)
- (cons base stop)))))
-
-(define (draw-barre layout props string-count fret-range
- size finger-code dot-position dot-radius
- barre-list orientation)
- "Create barre indications for a fret diagram"
- (if (not (null? barre-list))
- (let* ((details (chain-assoc-get 'fret-diagram-details props '()))
- (string1 (caar barre-list))
- (string2 (cadar barre-list))
- (fret (caddar barre-list))
- (top-fret (cadr fret-range))
- (low-fret (car fret-range))
- (barre-type (assoc-get 'barre-type details 'curved))
- (scale-dot-radius (* size dot-radius))
- (barre-vertical-offset 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)))
- (dot-center-fret-coordinate (+ (- fret low-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))
- (bottom
- (+ dot-center-y (* barre-vertical-offset scale-dot-radius)))
- (left (* size (- string-count string1)))
- (right (* size (- string-count string2)))
- (bezier-thick 0.1)
- (bezier-height 0.5)
- (bezier-list
- (if (eq? orientation 'normal)
- (make-bezier-sandwich-list
- (* size barre-start-string-coordinate)
- (* size barre-end-string-coordinate)
- (* size (+ 2 (- top-fret
- (+ low-fret barre-fret-coordinate))))
- (* size bezier-height)
- (* size bezier-thick)
- orientation)
- (make-bezier-sandwich-list
- (* size barre-start-string-coordinate)
- (* size barre-end-string-coordinate)
- (* size barre-fret-coordinate)
- (* size bezier-height)
- (* size bezier-thick)
- orientation)))
- (barre-stencil
- (if (eq? barre-type 'straight)
- (if (eq? orientation 'normal)
- (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 'draw-line (* size dot-radius)
- (* size barre-fret-coordinate)
- (* size barre-start-string-coordinate)
- (* size barre-fret-coordinate)
- (* size barre-end-string-coordinate))
- (cons (- (* size barre-fret-coordinate)
- scale-dot-radius)
- (+ (* size barre-fret-coordinate)
- scale-dot-radius))
- (cons (* size barre-start-string-coordinate)
- (* size barre-end-string-coordinate))))
- (if (eq? orientation 'normal)
- (ly:make-stencil
- (list 'bezier-sandwich
- `(quote ,bezier-list)
- (* size bezier-thick))
- (cons left right)
- (cons bottom (+ bottom (* size bezier-height))))
- (ly:make-stencil
- (list 'bezier-sandwich
- `(quote ,bezier-list)
- (* size bezier-thick))
- (cons bottom (+ bottom (* size bezier-height)))
- (cons left right))))))
- (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 ))))
+ (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)))
+ (set! fret-diagram-stencil
+ (ly:stencil-add
+ fret-diagram-stencil
+ (ly:stencil-translate
+ xo-stencil
+ (stencil-coordinates
+ (- diagram-fret-top
+ xo-fret-offset
+ (* size xo-padding))
+ 0)))))) ; no string 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 '()))
+ (items (string-split definition-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))))
+ ((#\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 #\-)))
+ (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 (string->number (car this-list)))
+ output-list))
+ (set! output-list
+ (cons-fret
+ (list 'open (string->number (car this-list)))
+ 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