1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2004--2011 Carl D. Sorensen <c_sorensen@byu.edu>
5 ;;;; LilyPond is free software: you can redistribute it and/or modify
6 ;;;; it under the terms of the GNU General Public License as published by
7 ;;;; the Free Software Foundation, either version 3 of the License, or
8 ;;;; (at your option) any later version.
10 ;;;; LilyPond is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;;;; GNU General Public License for more details.
15 ;;;; You should have received a copy of the GNU General Public License
16 ;;;; along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
23 (define (string-x-extent start-point end-point)
24 "Return the x-extent of a string that goes from start-point
26 (let ((x1 (car start-point))
32 (define (string-y-extent start-point end-point)
33 "Return the y-extent of a string that goes from start-point
35 (let ((y1 (cdr start-point))
42 (define (cons-fret new-value old-list)
43 "Put together a fret-list in the format desired by parse-string"
44 (if (eq? old-list '())
46 (cons* new-value old-list)))
48 (define (get-numeric-from-key keystring)
49 "Get the numeric value from a key of the form k:val"
50 (string->number (substring keystring 2 (string-length keystring))))
52 (define (numerify mylist)
53 "Convert string values to numeric or character"
56 (let ((numeric-value (string->number (car mylist))))
58 (cons* numeric-value (numerify (cdr mylist)))
59 (cons* (car (string->list (car mylist)))
60 (numerify (cdr mylist)))))))
63 "Calculate the font step necessary to get a desired magnification"
64 (* 6 (/ (log mag) (log 2))))
66 (define (fret-count fret-range)
67 "Calculate the fret count for the diagram given the range of frets in the diagram."
68 (1+ (- (cdr fret-range) (car fret-range))))
70 (define (subtract-base-fret base-fret dot-list)
71 "Subtract @var{base-fret} from every fret in @var{dot-list}"
74 (let ((this-list (car dot-list)))
79 (- (second this-list) base-fret)
81 (if (null? (cddr this-list))
85 (if (or (null? (cddr this-list))
86 (null? (cdddr this-list)))
89 (subtract-base-fret base-fret (cdr dot-list))))))
91 (define (drop-paren item-list)
92 "Drop a final parentheses from a fret indication list
93 @code{item-list} resulting from a terse string specification of barre."
94 (if (> (length item-list) 0)
95 (let* ((max-index (- (length item-list) 1))
96 (last-element (car (list-tail item-list max-index))))
97 (if (or (equal? last-element ")") (equal? last-element "("))
98 (list-head item-list max-index)
102 (define (get-sub-list value master-list)
103 "Get a sub-list whose cadr is equal to @var{value} from @var{master-list}"
104 (if (eq? master-list '())
106 (let ((sublist (car master-list)))
107 (if (equal? (cadr sublist) value)
109 (get-sub-list value (cdr master-list))))))
111 (define (merge-details key alist-list . default)
112 "Return @code{alist-list} entries for @code{key}, in one combined alist.
113 There can be two @code{alist-list} entries for a given key. The first
114 comes from the override-markup function, the second comes
115 from property settings during a regular override.
116 This is necessary because some details can be set in one
117 place, while others are set in the other. Both details
118 lists must be merged into a single alist.
119 Return @code{default} (optional, else #f) if not
122 (define (helper key alist-list default)
123 (if (null? alist-list)
125 (let* ((entry (assoc-get key (car alist-list))))
127 (append entry (chain-assoc-get key (cdr alist-list) '()))
128 (helper key (cdr alist-list) default)))))
130 (helper key alist-list
131 (if (pair? default) (car default) #f)))
134 ; Conversions between fret/string coordinate system and x-y coordinate
137 ; Fret coordinates are measured down the fretboard from the nut,
140 ; String coordinates are measured from the lowest string, starting at 0.
142 ; The x-y origin is at the intersection of the nut and the lowest string.
144 ; X coordinates are positive to the right.
145 ; Y coordinates are positive up.
148 (define (negate-extent extent)
149 "Return the extent in an axis opposite to the axis of @code{extent}."
150 (cons (- (cdr extent)) (- (car extent))))
152 (define (stencil-fretboard-extent stencil fretboard-axis orientation)
153 "Return the extent of @code{stencil} in the @code{fretboard-axis}
155 (if (eq? fretboard-axis 'fret)
156 (cond ((eq? orientation 'landscape)
157 (ly:stencil-extent stencil X))
158 ((eq? orientation 'opposing-landscape)
159 (negate-extent (ly:stencil-extent stencil X)))
161 (negate-extent (ly:stencil-extent stencil Y))))
162 ; else -- eq? fretboard-axis 'string
163 (cond ((eq? orientation 'landscape)
164 (ly:stencil-extent stencil Y))
165 ((eq? orientation 'opposing-landscape)
166 (negate-extent (ly:stencil-extent stencil Y)))
168 (ly:stencil-extent stencil Y)))))
171 (define (stencil-fretboard-offset stencil fretboard-axis orientation)
172 "Return a the stencil coordinates of the center of @code{stencil}
173 in the @code{fretboard-axis} direction."
174 (* 0.5 (interval-length
175 (stencil-fretboard-extent stencil fretboard-axis orientation))))
178 (define (string-thickness string thickness-factor)
179 (expt (1+ thickness-factor) (1- string)))
182 ; Functions that create stencils used in the fret diagram
185 (define (sans-serif-stencil layout props mag text)
186 "Create a stencil in sans-serif font based on @var{layout} and @var{props}
187 with magnification @var{mag} of the string @var{text}."
190 'font-size (stepmag mag)
191 (prepend-alist-chain 'font-family 'sans props))))
192 (interpret-markup layout my-props text)))
196 ;; markup commands and associated functions
201 (define (fret-parse-marking-list marking-list my-fret-count)
202 "Parse a fret-diagram-verbose marking list into component sublists"
203 (let* ((fret-range (cons 1 my-fret-count))
209 (let parse-item ((mylist marking-list))
210 (if (not (null? mylist))
211 (let* ((my-item (car mylist)) (my-code (car my-item)))
213 ((or (eq? my-code 'open)(eq? my-code 'mute))
214 (set! xo-list (cons* my-item xo-list)))
215 ((eq? my-code 'barre)
216 (set! barre-list (cons* (cdr my-item) barre-list)))
218 (set! capo-fret (cadr my-item)))
219 ((eq? my-code 'place-fret)
220 (set! dot-list (cons* (cdr my-item) dot-list))))
221 (parse-item (cdr mylist)))))
222 ;; calculate fret-range
224 (minfret (if (> capo-fret 0) capo-fret 99)))
225 (let updatemax ((fret-list dot-list)) ;CHANGE THIS TO HELPER FUNCTION?
226 (if (null? fret-list)
228 (let ((fretval (second (car fret-list))))
229 (if (> fretval maxfret) (set! maxfret fretval))
230 (if (< fretval minfret) (set! minfret fretval))
231 (updatemax (cdr fret-list)))))
232 (if (> maxfret my-fret-count)
235 (let ((upfret (- (+ minfret my-fret-count) 1)))
236 (if (> maxfret upfret) maxfret upfret)))))
237 (set! capo-fret (1+ (- capo-fret minfret)))
238 ; subtract fret from dots
239 (set! dot-list (subtract-base-fret (- (car fret-range) 1) dot-list)))
240 (acons 'fret-range fret-range
241 (acons 'barre-list barre-list
242 (acons 'dot-list dot-list
243 (acons 'xo-list xo-list
244 (acons 'capo-fret capo-fret '())))))))
246 (define (make-fret-diagram layout props marking-list)
247 "Make a fret diagram markup"
249 ; note: here we get items from props that are needed in this routine,
250 ; or that are needed in more than one of the procedures
251 ; called from this routine. If they're only used in one of the
252 ; sub-procedure, they're obtained in that procedure
253 (size (chain-assoc-get 'size props 1.0)) ; needed for everything
254 ;TODO -- get string-count directly from length of stringTunings;
255 ; from FretBoard engraver, but not from markup call
256 (details (merge-details 'fret-diagram-details props '()))
258 (assoc-get 'string-count details 6)) ; needed for everything
260 (assoc-get 'fret-count details 4)) ; needed for everything
262 (assoc-get 'orientation details 'normal)) ; needed for everything
265 'finger-code details 'none)) ; needed for draw-dots and draw-barre
267 (if (eq? finger-code 'in-dot) 0.425 0.25)) ; bigger dots if labeled
268 (default-dot-position
269 (if (eq? finger-code 'in-dot)
270 (- 0.95 default-dot-radius)
271 0.6)) ; move up to make room for bigger dot if labeled
274 'dot-radius details default-dot-radius)) ; needed for draw-dots
278 'dot-position details default-dot-position)) ; needed for
279 ; draw-dots and draw-barre
281 (* (ly:output-def-lookup layout 'line-thickness)
282 (chain-assoc-get 'thickness props 0.5))) ; needed for draw-frets
285 (thickness-factor (assoc-get 'string-thickness-factor details 0))
287 (chain-assoc-get 'align-dir props -0.4)) ; needed only here
288 (xo-padding (assoc-get 'xo-padding details 0.2)) ; needed only here
289 (parameters (fret-parse-marking-list marking-list my-fret-count))
290 (capo-fret (assoc-get 'capo-fret parameters 0))
291 (dot-list (assoc-get 'dot-list parameters))
292 (xo-list (assoc-get 'xo-list parameters))
293 (fret-range (assoc-get 'fret-range parameters))
294 (my-fret-count (fret-count fret-range))
295 (barre-list (assoc-get 'barre-list parameters))
297 (assoc-get 'barre-type details 'curved))
298 (fret-diagram-stencil '()))
300 ;; Here are the fret diagram helper functions that depend on the
301 ;; fret diagram parameters. The functions are here because the
302 ;; diagram parameters are part of the lexical scope here.
304 (define (stencil-coordinates fret-coordinate string-coordinate)
305 "Return a pair @code{(x-coordinate . y-coordinate)}
306 in stencil coordinate system."
308 ((eq? orientation 'landscape)
309 (cons fret-coordinate
310 (- string-coordinate (1- string-count))))
311 ((eq? orientation 'opposing-landscape)
312 (cons (- fret-coordinate) (- string-coordinate)))
314 (cons string-coordinate (- fret-coordinate)))))
316 (define (stencil-coordinate-offset fret-offset string-offset)
317 "Return a pair @code{(x-offset . y-offset)}
318 for translation in stencil coordinate system."
320 ((eq? orientation 'landscape)
321 (cons fret-offset (- string-offset)))
322 ((eq? orientation 'opposing-landscape)
323 (cons (- fret-offset) string-offset))
325 (cons string-offset (- fret-offset)))))
329 (define (make-bezier-sandwich-list start stop base height
331 "Make the argument list for a bezier sandwich from
332 string coordinate @var{start} to string-coordinate @var{stop} with a
333 baseline at fret coordinate @var{base}, a height of
334 @var{height}, and a half thickness of @var{half-thickness}."
335 (let* ((width (+ (- stop start) 1))
336 (cp-left-width (+ (* width half-thickness) start))
337 (cp-right-width (- stop (* width half-thickness)))
338 (bottom-control-point-height
339 (- base (- height half-thickness)))
340 (top-control-point-height
343 (stencil-coordinates base start))
345 (stencil-coordinates base stop))
346 (left-upper-control-point
348 top-control-point-height cp-left-width))
349 (left-lower-control-point
351 bottom-control-point-height cp-left-width))
352 (right-upper-control-point
354 top-control-point-height cp-right-width))
355 (right-lower-control-point
357 bottom-control-point-height cp-right-width)))
358 ; order of bezier control points is:
359 ; left cp low, right cp low, right end low, left end low
360 ; right cp high, left cp high, left end high, right end high.
362 (list left-lower-control-point
363 right-lower-control-point
366 right-upper-control-point
367 left-upper-control-point
371 (define (draw-strings)
372 "Draw the string lines for a fret diagram with
373 @var{string-count} strings and frets as indicated in @var{fret-range}.
374 Line thickness is given by @var{th}, fret & string spacing by
375 @var{size}. Orientation is determined by @var{orientation}."
379 (string-stencil (car x))
381 (string-stencil (car x))
384 (let* ( (string-list (map 1+ (iota string-count))))
385 (helper string-list)))
387 (define (string-stencil string)
388 "Make a stencil for @code{string}, given the fret-diagram
390 (let* ((string-coordinate (- string-count string))
391 (current-string-thickness
392 (* th size (string-thickness string thickness-factor)))
393 (fret-half-thickness (* size th 0.5))
394 (half-string (* current-string-thickness 0.5))
397 (- fret-half-thickness)
398 (- (* size string-coordinate) half-string)))
401 (+ fret-half-thickness (* size (1+ (fret-count fret-range))))
402 (+ half-string (* size string-coordinate)))))
404 (string-x-extent start-coordinates end-coordinates)
405 (string-y-extent start-coordinates end-coordinates)
409 "Draw the fret lines for a fret diagram with
410 @var{string-count} strings and frets as indicated in @var{fret-range}.
411 Line thickness is given by @var{th}, fret & string spacing by
412 @var{size}. Orientation is given by @var{orientation}."
415 (fret-stencil (car x))
417 (fret-stencil (car x))
420 (let ((fret-list (iota (1+ my-fret-count))))
423 (define (fret-stencil fret)
424 "Make a stencil for @code{fret}, given the
425 fret-diagram overall parameters."
426 (let* ((low-string-half-thickness
430 (string-thickness string-count thickness-factor)))
431 (fret-half-thickness (* 0.5 size th))
435 (- fret-half-thickness low-string-half-thickness)))
439 (* size (1- string-count)))))
442 (car start-coordinates) (cdr start-coordinates)
443 (car end-coordinates) (cdr end-coordinates))))
445 (define (draw-barre barre-list)
446 "Create barre indications for a fret diagram"
447 (if (not (null? barre-list))
448 (let* ((string1 (caar barre-list))
449 (string2 (cadar barre-list))
450 (barre-fret (caddar barre-list))
451 (top-fret (cdr fret-range))
452 (low-fret (car fret-range))
453 (fret (1+ (- barre-fret low-fret)))
454 (barre-vertical-offset 0.5)
455 (dot-center-fret-coordinate (+ (1- fret) dot-position))
456 (barre-fret-coordinate
457 (+ dot-center-fret-coordinate
458 (* (- barre-vertical-offset 0.5) dot-radius)))
459 (barre-start-string-coordinate (- string-count string1))
460 (barre-end-string-coordinate (- string-count string2))
461 (scale-dot-radius (* size dot-radius))
462 (barre-type (assoc-get 'barre-type details 'curved))
465 ((eq? barre-type 'straight)
466 (make-straight-barre-stencil
467 barre-fret-coordinate
468 barre-start-string-coordinate
469 barre-end-string-coordinate
471 ((eq? barre-type 'curved)
472 (make-curved-barre-stencil
473 barre-fret-coordinate
474 barre-start-string-coordinate
475 barre-end-string-coordinate
476 scale-dot-radius)))))
477 (if (not (null? (cdr barre-list)))
480 (draw-barre (cdr barre-list)))
483 (define (make-straight-barre-stencil
485 start-string-coordinate
486 end-string-coordinate
488 "Create a straight barre stencil."
491 (* size fret-coordinate)
492 (* size start-string-coordinate)))
495 (* size fret-coordinate)
496 (* size end-string-coordinate))))
504 (define (make-curved-barre-stencil
506 start-string-coordinate
507 end-string-coordinate
509 "Create a curved barre stencil."
510 (let* ((bezier-thick 0.1)
513 (make-bezier-sandwich-list
514 (* size start-string-coordinate)
515 (* size end-string-coordinate)
516 (* size fret-coordinate)
517 (* size bezier-height)
518 (* size bezier-thick)))
521 (+ (* size fret-coordinate) half-thickness)
522 (- (* size start-string-coordinate) half-thickness)))
525 (- (* size fret-coordinate)
526 (* size bezier-height)
528 (+ (* size end-string-coordinate) half-thickness)))
529 (x-extent (cons (car box-lower-left) (car box-upper-right)))
530 (y-extent (cons (cdr box-lower-left) (cdr box-upper-right))))
532 (list 'bezier-sandwich
533 `(quote ,bezier-list)
534 (* size bezier-thick))
538 (define (draw-dots dot-list)
539 "Make dots for fret diagram."
541 (let* ( (scale-dot-radius (* size dot-radius))
542 (scale-dot-thick (* size th))
543 (default-dot-color (assoc-get 'dot-color details 'black))
544 (finger-label-padding 0.3)
547 (assoc-get 'dot-label-font-mag details 1.0)))
548 (string-label-font-mag
551 'string-label-font-mag details
552 (cond ((or (eq? orientation 'landscape)
553 (eq? orientation 'opposing-landscape))
556 (mypair (car dot-list))
557 (restlist (cdr dot-list))
558 (string (car mypair))
560 (fret-coordinate (* size (+ (1- fret) dot-position)))
561 (string-coordinate (* size (- string-count string)))
563 (stencil-coordinates fret-coordinate string-coordinate))
564 (extent (cons (- scale-dot-radius) scale-dot-radius))
565 (finger (caddr mypair))
566 (finger (if (number? finger) (number->string finger) finger))
567 (inverted-color (eq? 'inverted (cadddr mypair)))
568 (dot-color (if (or (and (eq? default-dot-color 'black) inverted-color)
569 (and (eq? default-dot-color 'white) (not inverted-color)))
572 (dot-stencil (if (eq? dot-color 'white)
575 scale-dot-radius scale-dot-thick #t)
578 (- scale-dot-radius (* 0.5 scale-dot-thick))
582 scale-dot-radius scale-dot-thick #t)))
584 (ly:stencil-translate dot-stencil dot-coordinates))
587 ((or (eq? finger '())(eq? finger-code 'none))
589 ((eq? finger-code 'in-dot)
593 layout props dot-label-font-mag finger))))
594 (ly:stencil-translate
597 (if (eq? dot-color 'white)
599 (ly:stencil-in-color finger-label 1 1 1)))
601 ((eq? finger-code 'below-string)
602 (let* ((label-stencil
605 layout props string-label-font-mag
608 (stencil-fretboard-offset
609 label-stencil 'fret orientation))
610 (label-fret-coordinate
612 (+ 1 my-fret-count finger-label-padding))
614 (label-string-coordinate string-coordinate)
617 label-fret-coordinate
618 label-string-coordinate)))
621 (ly:stencil-translate
623 label-translation))))
624 (else ;unknown finger-code
630 labeled-dot-stencil))))
632 (define (draw-thick-zero-fret)
633 "Draw a thick zeroth fret for a fret diagram whose base fret is 1."
634 (let* ((half-lowest-string-thickness
635 (* 0.5 th (string-thickness string-count thickness-factor)))
636 (half-thick (* 0.5 sth))
638 (* sth (assoc-get 'top-fret-thickness details 3.0)))
639 (start-string-coordinate (- half-lowest-string-thickness))
640 (end-string-coordinate (+ (* size (1- string-count)) half-thick))
641 (start-fret-coordinate half-thick)
642 (end-fret-coordinate (- half-thick top-fret-thick))
645 start-fret-coordinate start-string-coordinate))
648 end-fret-coordinate end-string-coordinate)))
650 (cons (car lower-left) (car upper-right))
651 (cons (cdr lower-left) (cdr upper-right))
654 (define (draw-xo xo-list)
655 "Put open and mute string indications on diagram, as contained in
658 (assoc-get 'xo-font-magnification details
659 (cond ((or (eq? orientation 'landscape)
660 (eq? orientation 'opposing-landscape))
663 (mypair (car xo-list))
664 (restlist (cdr xo-list))
665 (glyph-string (if (eq? (car mypair) 'mute)
666 (assoc-get 'mute-string details "X")
667 (assoc-get 'open-string details "O")))
668 (glyph-string-coordinate (* (- string-count (cadr mypair)) size))
672 layout props (* size xo-font-mag) glyph-string)))
673 (glyph-stencil-coordinates
674 (stencil-coordinates 0 glyph-string-coordinate))
676 (ly:stencil-translate
678 glyph-stencil-coordinates)))
683 (draw-xo restlist)))))
685 (define (draw-capo fret)
686 "Draw a capo indicator across the full width of the fret-board
689 (* size (assoc-get 'capo-thickness details 0.5)))
690 (half-thick (* capo-thick 0.5))
691 (last-string-position 0)
692 (first-string-position (* size (- string-count 1)))
693 (fret-position ( * size (1- (+ dot-position fret))))
697 first-string-position))
701 last-string-position)))
704 (car start-point) (cdr start-point)
705 (car end-point) (cdr end-point))))
707 (define (label-fret fret-range)
708 "Label the base fret on a fret diagram"
709 (let* ((base-fret (car fret-range))
710 (label-font-mag (assoc-get 'fret-label-font-mag details 0.5))
711 (label-space (* 0.5 size))
712 (label-dir (assoc-get 'label-dir details RIGHT))
713 (label-vertical-offset
714 (assoc-get 'fret-label-vertical-offset details 0))
716 (assoc-get 'number-type details 'roman-lower))
719 ((equal? number-type 'roman-lower)
720 (fancy-format #f "~(~@r~)" base-fret))
721 ((equal? number-type 'roman-upper)
722 (fancy-format #f "~@r" base-fret))
723 ((equal? 'arabic number-type)
724 (fancy-format #f "~d" base-fret))
725 ((equal? 'custom number-type)
727 (assoc-get 'fret-label-custom-format
730 (else (fancy-format #f "~(~@r~)" base-fret))))
734 layout props (* size label-font-mag) label-text)))
736 (stencil-fretboard-offset
740 (label-outside-diagram (+ label-space label-half-width)))
741 (ly:stencil-translate
744 (* size (+ 1.0 label-vertical-offset))
745 (if (eq? label-dir LEFT)
746 (- label-outside-diagram)
747 (+ (* size (1- string-count)) label-outside-diagram))))))
750 ; Here is the body of make-fret-diagram
753 (set! fret-diagram-stencil
754 (ly:stencil-add (draw-strings) (draw-frets)))
755 (if (and (not (null? barre-list))
756 (not (eq? 'none barre-type)))
757 (set! fret-diagram-stencil
759 (draw-barre barre-list)
760 fret-diagram-stencil)))
761 (if (not (null? dot-list))
762 (set! fret-diagram-stencil
765 (draw-dots dot-list))))
766 (if (= (car fret-range) 1)
767 (set! fret-diagram-stencil
770 (draw-thick-zero-fret))))
771 (if (not (null? xo-list))
772 (let* ((diagram-fret-top
773 (car (stencil-fretboard-extent
777 (xo-stencil (draw-xo xo-list))
779 (stencil-fretboard-offset
780 xo-stencil 'fret orientation))
782 (stencil-coordinate-offset
787 (set! fret-diagram-stencil
790 (ly:stencil-translate
792 xo-stencil-offset)))))
794 (set! fret-diagram-stencil
797 (draw-capo capo-fret))))
798 (if (> (car fret-range) 1)
799 (set! fret-diagram-stencil
802 (label-fret fret-range))))
803 (ly:stencil-aligned-to fret-diagram-stencil X alignment)))
805 (define (fret-parse-definition-string props definition-string)
806 "Parse a fret diagram string and return a pair containing:
807 @var{props}, modified as necessary by the definition-string
808 a fret-indication list with the appropriate values"
809 (let* ((fret-count 4)
811 (fret-range (cons 1 fret-count))
817 (details (merge-details 'fret-diagram-details props '()))
818 (items (string-split definition-string #\;)))
819 (let parse-item ((myitems items))
820 (if (not (null? (cdr myitems)))
821 (let ((test-string (car myitems)))
822 (case (car (string->list (substring test-string 0 1)))
823 ((#\s) (let ((size (get-numeric-from-key test-string)))
824 (set! props (prepend-alist-chain 'size size props))))
825 ((#\f) (let* ((finger-code (get-numeric-from-key test-string))
826 (finger-id (case finger-code
829 ((2) 'below-string))))
831 (acons 'finger-code finger-id details))))
832 ((#\c) (set! output-list
837 (string-split (substring test-string 2) #\-)))
839 ((#\h) (let ((fret-count (get-numeric-from-key test-string)))
841 (acons 'fret-count fret-count details))))
842 ((#\w) (let ((string-count (get-numeric-from-key test-string)))
844 (acons 'string-count string-count details))))
845 ((#\d) (let ((dot-size (get-numeric-from-key test-string)))
847 (acons 'dot-radius dot-size details))))
848 ((#\p) (let ((dot-position (get-numeric-from-key test-string)))
850 (acons 'dot-position dot-position details))))
852 (let ((this-list (string-split test-string #\-)))
853 (if (string->number (cadr this-list))
856 (cons 'place-fret (numerify this-list))
858 (if (equal? (cadr this-list) "x" )
861 (list 'mute (string->number (car this-list)))
865 (list 'open (string->number (car this-list)))
867 (parse-item (cdr myitems)))))
868 ; add the modified details
870 (prepend-alist-chain 'fret-diagram-details details props))
871 `(,props . ,output-list))) ;ugh -- hard-coded spell -- procedure better
874 (fret-parse-terse-definition-string props definition-string)
875 "Parse a fret diagram string that uses terse syntax;
876 return a pair containing:
877 @var{props}, modified to include the string-count determined by the
878 definition-string, and
879 a fret-indication list with the appropriate values"
880 ;TODO -- change syntax to fret\string-finger
882 (let* ((details (merge-details 'fret-diagram-details props '()))
883 (barre-start-list '())
886 (items (string-split definition-string #\;))
887 (string-count (- (length items) 1)))
888 (let parse-item ((myitems items))
889 (if (not (null? (cdr myitems)))
890 (let* ((test-string (car myitems))
891 (current-string (- (length myitems) 1))
892 (indicators (string-split test-string #\ )))
893 (let parse-indicators ((myindicators indicators))
894 (if (not (eq? '() myindicators))
895 (let* ((this-list (string-split (car myindicators) #\-))
896 (max-element-index (- (length this-list) 1))
898 (car (list-tail this-list max-element-index)))
900 (if (string->number (car this-list))
901 (string->number (car this-list))
903 (if (equal? last-element "(")
905 (set! barre-start-list
906 (cons-fret (list current-string fret)
909 (list-head this-list max-element-index))))
910 (if (equal? last-element ")")
912 (get-sub-list fret barre-start-list))
913 (insert-index (- (length this-barre) 1)))
915 (cons-fret (cons* 'barre
921 (list-head this-list max-element-index))))
928 (drop-paren (numerify this-list)))
930 (if (equal? (car this-list) "x" )
934 (list 'mute current-string)
939 (list 'open current-string)
941 (parse-indicators (cdr myindicators)))))
942 (parse-item (cdr myitems)))))
943 (set! details (acons 'string-count string-count details))
944 (set! props (prepend-alist-chain 'fret-diagram-details details props))
945 `(,props . ,output-list))) ; ugh -- hard coded; proc is better
948 (define-markup-command
949 (fret-diagram-verbose layout props marking-list)
950 (pair?) ; argument type (list, but use pair? for speed)
951 #:category instrument-specific-markup ; markup type
952 #:properties ((align-dir -0.4) ; properties and defaults
954 (fret-diagram-details)
956 "Make a fret diagram containing the symbols indicated in @var{marking-list}.
961 \\markup \\fret-diagram-verbose
962 #'((mute 6) (mute 5) (open 4)
963 (place-fret 3 2) (place-fret 2 3) (place-fret 1 2))
967 produces a standard D@tie{}chord diagram without fingering indications.
969 Possible elements in @var{marking-list}:
972 @item (mute @var{string-number})
973 Place a small @q{x} at the top of string @var{string-number}.
975 @item (open @var{string-number})
976 Place a small @q{o} at the top of string @var{string-number}.
978 @item (barre @var{start-string} @var{end-string} @var{fret-number})
979 Place a barre indicator (much like a tie) from string @var{start-string}
980 to string @var{end-string} at fret @var{fret-number}.
982 @item (capo @var{fret-number})
983 Place a capo indicator (a large solid bar) across the entire fretboard
984 at fret location @var{fret-number}. Also, set fret @var{fret-number}
985 to be the lowest fret on the fret diagram.
987 @item (place-fret @var{string-number} @var{fret-number} [@var{finger-value} [@var{color-modifier}]])
988 Place a fret playing indication on string @var{string-number} at fret
989 @var{fret-number} with an optional fingering label @var{finger-value},
990 and an optional color modifier @var{color-modifier}.
991 By default, the fret playing indicator is a solid dot. This can be
992 globally changed by setting the value of the variable @var{dot-color}.
993 Setting @var{color-modifier} to @code{inverted} inverts the dot color
994 for a specific fingering.
995 If the @var{finger} part of the @code{place-fret} element is present,
996 @var{finger-value} will be displayed according to the setting of the
997 variable @var{finger-code}. There is no limit to the number of fret
998 indications per string.
1001 (make-fret-diagram layout props marking-list))
1004 (define-markup-command (fret-diagram layout props definition-string)
1005 (string?) ; argument type
1006 #:category instrument-specific-markup ; markup category
1007 #:properties (fret-diagram-verbose-markup) ; properties and defaults
1008 "Make a (guitar) fret diagram. For example, say
1011 \\markup \\fret-diagram #\"s:0.75;6-x;5-x;4-o;3-2;2-3;1-2;\"
1015 for fret spacing 3/4 of staff space, D chord diagram
1017 Syntax rules for @var{definition-string}:
1021 Diagram items are separated by semicolons.
1028 @code{s:}@var{number} -- Set the fret spacing of the diagram (in staff
1033 @code{t:}@var{number} -- Set the line thickness (in staff spaces).
1037 @code{h:}@var{number} -- Set the height of the diagram in frets.
1041 @code{w:}@var{number} -- Set the width of the diagram in strings.
1045 @code{f:}@var{number} -- Set fingering label type
1046 (0@tie{}= none, 1@tie{}= in circle on string, 2@tie{}= below string).
1050 @code{d:}@var{number} -- Set radius of dot, in terms of fret spacing.
1054 @code{p:}@var{number} -- Set the position of the dot in the fret space.
1055 0.5 is centered; 1@tie{}is on lower fret bar, 0@tie{}is on upper fret bar.
1059 @code{c:}@var{string1}@code{-}@var{string2}@code{-}@var{fret} -- Include a
1060 barre mark from @var{string1} to @var{string2} on @var{fret}.
1063 @var{string}@code{-}@var{fret} -- Place a dot on @var{string} at @var{fret}.
1064 If @var{fret} is @samp{o}, @var{string} is identified as open.
1065 If @var{fret} is @samp{x}, @var{string} is identified as muted.
1068 @var{string}@code{-}@var{fret}@code{-}@var{fingering} -- Place a dot on
1069 @var{string} at @var{fret}, and label with @var{fingering} as defined
1070 by the @code{f:} code.
1074 Note: There is no limit to the number of fret indications per string.
1076 (let ((definition-list
1077 (fret-parse-definition-string props definition-string)))
1078 (fret-diagram-verbose-markup
1079 layout (car definition-list) (cdr definition-list))))
1081 (define-markup-command
1082 (fret-diagram-terse layout props definition-string)
1083 (string?) ; argument type
1084 #:category instrument-specific-markup ; markup category
1085 #:properties (fret-diagram-verbose-markup) ; properties
1086 "Make a fret diagram markup using terse string-based syntax.
1091 \\markup \\fret-diagram-terse #\"x;x;o;2;3;2;\"
1095 for a D@tie{}chord diagram.
1097 Syntax rules for @var{definition-string}:
1102 Strings are terminated by semicolons; the number of semicolons
1103 is the number of strings in the diagram.
1106 Mute strings are indicated by @samp{x}.
1109 Open strings are indicated by @samp{o}.
1112 A number indicates a fret indication at that fret.
1115 If there are multiple fret indicators desired on a string, they
1116 should be separated by spaces.
1119 Fingerings are given by following the fret number with a @code{-},
1120 followed by the finger indicator, e.g. @samp{3-2} for playing the third
1121 fret with the second finger.
1124 Where a barre indicator is desired, follow the fret (or fingering) symbol
1125 with @code{-(} to start a barre and @code{-)} to end the barre.
1128 ;; TODO -- change syntax to fret\string-finger
1129 (let ((definition-list
1130 (fret-parse-terse-definition-string props definition-string)))
1131 (fret-diagram-verbose-markup layout
1132 (car definition-list)
1133 (cdr definition-list))))