1 ;;;; fret-diagrams.scm --
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2004 Carl D. Sorensen <c_sorensen@byu.edu>
9 (define (fret-parse-marking-list marking-list fret-count)
10 (let* ((fret-range (list 1 fret-count))
15 (let parse-item ((mylist marking-list))
16 (if (not (null? mylist))
17 (let* ((my-item (car mylist)) (my-code (car my-item)))
19 ((or (eq? my-code 'open)(eq? my-code 'mute))
20 (set! xo-list (cons* my-item xo-list)))
22 (set! barre-list (cons* (cdr my-item) barre-list)))
23 ((eq? my-code 'place-fret)
24 (set! dot-list (cons* (cdr my-item) dot-list))))
25 (parse-item (cdr mylist)))))
26 ; calculate fret-range
27 (let ((maxfret 0) (minfret 99))
28 (let updatemax ((fret-list dot-list))
31 (let ((fretval (second (car fret-list))))
32 (if (> fretval maxfret) (set! maxfret fretval))
33 (if (< fretval minfret) (set! minfret fretval))
34 (updatemax (cdr fret-list)))))
35 (if (> maxfret fret-count)
36 (set! fret-range (list minfret
37 (let ((upfret (- (+ minfret fret-count) 1)))
38 (if (> maxfret upfret) maxfret upfret)))))
39 ; subtract fret from dots
40 (set! dot-list (subtract-base-fret (- (car fret-range) 1) dot-list)))
41 (acons 'fret-range fret-range
42 (acons 'barre-list barre-list
43 (acons 'dot-list dot-list
44 (acons 'xo-list xo-list '()))))))
46 (define (subtract-base-fret base-fret dot-list)
47 "Subtract @var{base-fret} from every fret in @var{dot-list}"
50 (let ((this-list (car dot-list)))
51 (cons* (list (car this-list) (- (second this-list) base-fret) (if (null? (cddr this-list))
54 (subtract-base-fret base-fret (cdr dot-list))))))
56 (define (sans-serif-stencil paper props mag text)
57 "create a stencil in sans-serif font based on @var{paper} and @var{props}
58 with magnification @varr{mag} of the string @var{text}."
59 (let* ((my-props (prepend-alist-chain 'font-size (stepmag mag)
60 (prepend-alist-chain 'font-family 'sans props))))
61 (interpret-markup paper my-props text)))
63 (define (sans-serif-stencil-white paper props mag text)
64 "create a stencil with white text in sans-serif font based on @var{paper} and @var{props}
65 with magnification @varr{mag} of the string @var{text}."
66 (let* ((text-stencil (sans-serif-stencil paper props mag text))
67 (x-extent (ly:stencil-extent text-stencil X))
68 (y-extent (ly:stencil-extent text-stencil Y))
69 (c `(white-text ,(* 2 mag) ,text))) ;urg -- workaround for using ps font
70 (ly:make-stencil c x-extent y-extent))) ;urg -- extent is not from ps font, but we hope it's close
73 (define (draw-strings string-count fret-range th size)
74 "Draw the strings (vertical lines) for a fret diagram with @var{string-count} strings and frets as indicated
75 in @var{fret-range}. Line thickness is given by @var{th}, fret & string spacing by @var{size}. "
76 (let* ((fret-count (+ (- (cadr fret-range) (car fret-range)) 1))
77 (sl (* (+ fret-count 1) size))
79 (half-thickness (* sth 0.5))
81 (string-stencil (ly:make-stencil (list 'draw-line sth 0 0 0 sl)
82 (cons (- half-thickness) half-thickness)
83 (cons (- half-thickness) (+ sl half-thickness)))))
84 (if (= string-count 1)
86 (ly:stencil-combine-at-edge
87 (draw-strings (- string-count 1) fret-range th size) X RIGHT
91 (define (draw-fret-lines fret-count string-count th size)
92 "Draw @var{fret-count} frets (horizontal lines) for a fret diagram with @var{string-count} strings.
93 Line thickness is given by @var{th}, fret & string spacing by @var{size}. "
94 (let* ((fret-length (* (- string-count 1) size))
96 (half-thickness (* sth 0.5))
98 (fret-line (ly:make-stencil (list 'draw-line sth half-thickness size (- fret-length half-thickness) size)
100 (cons (- size half-thickness) (+ size half-thickness)))))
103 (ly:stencil-combine-at-edge fret-line Y UP
104 (draw-fret-lines (- fret-count 1) string-count th size)
107 (define (draw-thick-top-fret props string-count th size)
108 "Draw a thick top fret for a fret diagram whose base fret is not 1."
109 (let* ((sth (* th size))
110 ; (top-fret-thick (* sth (chain-assoc-get 'top-fret-thickness props 3.0)))
111 (top-fret-thick (* sth 3.0))
112 ; (top-half-thick (* top-fret-thick 0.5))
113 (half-thick (* sth 0.5))
115 (x2 (+ half-thick (* size (- string-count 1))))
117 (y2 (+ top-fret-thick half-thick))
118 (x-extent (cons (- x1) x2))
119 (y-extent (cons 0 y2)))
120 (ly:make-stencil (list 'round-filled-box x1 x2 y1 y2 sth)
124 (define (draw-frets paper props fret-range string-count th size)
125 "Draw the frets (horizontal lines) for a fret diagram with @var{string-count} strings and frets as indicated
126 in @var{fret-range}. Line thickness is given by @var{th}, fret & string spacing by @var{size}. "
127 (let* ((fret-count (+ (- (cadr fret-range) (car fret-range)) 1))
128 (fret-length (* (- string-count 1) size))
129 (half-thickness (* th 0.5))
130 (base-fret (car fret-range)))
131 (ly:stencil-combine-at-edge
132 (draw-fret-lines fret-count string-count th size) Y UP
134 (draw-thick-top-fret props string-count th size)
135 (draw-fret-lines 1 string-count th size))
139 (define (centered-stencil stencil)
140 "Center stencil @var{stencil} in both the X and Y directions"
141 (let* ((output-stencil stencil))
142 ; (if (= (cadr (ly:version)) 3)
144 (ly:stencil-align-to! output-stencil Y 0)
145 (ly:stencil-align-to! output-stencil X 0)
147 ; (ly:stencil-align-to (ly:stencil-align-to text-stencil X 0) Y 0))))
149 (define (draw-dots paper props string-count fret-range size finger-code dot-position dot-radius dot-list)
150 "Make dots for fret diagram."
151 (let* ((scale-dot-radius (* size dot-radius))
152 (dot-color (chain-assoc-get 'dot-color props 'black))
153 ; (finger-xoffset (chain-assoc-get 'finger-xoffset props -0.25))
154 ; (finger-yoffset (chain-assoc-get 'finger-yoffset props (- size)))
155 (finger-xoffset -0.25)
156 (finger-yoffset (- size))
157 ; (dot-label-font-mag (* scale-dot-radius (chain-assoc-get 'dot-label-font-mag props 1.0)))
158 (dot-label-font-mag scale-dot-radius)
159 ; (string-label-font-mag (* size (chain-assoc-get 'label-font-mag props 0.7)))
160 (string-label-font-mag (* size 0.7))
161 (fret-count (+ (- (cadr fret-range) (car fret-range) 1)))
162 (mypair (car dot-list))
163 (restlist (cdr dot-list))
164 (xpos (* size (- string-count (car mypair))))
165 ;TODO -- figure out what 4 is and get rid of it
167 (ypos (* size (+ 4 (- fret-count (cadr mypair) dot-position ))))
168 (extent (cons (- scale-dot-radius) scale-dot-radius))
169 (finger (caddr mypair))
170 (finger (if (number? finger) (number->string finger) finger))
171 (dotstencil (if (eq? dot-color 'white)
173 (ly:make-stencil (list 'white-dot 0 0 scale-dot-radius) extent extent))
174 (ly:make-stencil (list 'dot 0 0 scale-dot-radius ) extent extent)))
175 (positioned-dot (ly:stencil-translate-axis
176 (ly:stencil-translate-axis dotstencil xpos X)
179 (if (or (eq? finger '())(eq? finger-code 'none))
181 (if (eq? finger-code 'in-dot)
182 (let* ((dot-proc (if (eq? dot-color 'white) 'white-dot 'dot)))
184 (ly:stencil-translate-axis
185 (ly:stencil-translate-axis
186 (if (eq? dot-color 'white)
187 (centered-stencil (sans-serif-stencil paper props dot-label-font-mag finger))
188 (centered-stencil (sans-serif-stencil-white paper props
189 dot-label-font-mag finger)))
192 (ly:stencil-translate-axis
193 (ly:stencil-translate-axis
194 (ly:make-stencil (list dot-proc 0 0 scale-dot-radius) extent extent)
197 (if (eq? finger-code 'below-string)
200 (ly:stencil-translate-axis
201 (ly:stencil-translate-axis
202 (centered-stencil (sans-serif-stencil paper props
203 string-label-font-mag finger)) xpos X)
204 (* size finger-yoffset) Y))
210 (draw-dots paper props string-count fret-range size finger-code
211 dot-position dot-radius restlist)
212 labeled-dot-stencil))))
214 (define (draw-xo paper props string-count fret-range size xo-list)
215 "Put open and mute string indications on diagram, as contained in @var{xo-list}."
216 (let* ((fret-count (+ (- (cadr fret-range) (car fret-range) 1)))
217 ; (xo-font-mag (* size (chain-assoc-get 'xo-font-magnification props 0.5)))
218 (xo-font-mag (* size 0.5))
219 ; (xo-horizontal-offset (* size (chain-assoc-get 'xo-horizontal-offset props -0.35)))
220 (xo-horizontal-offset (* size -0.35))
221 (mypair (car xo-list))
222 (restlist (cdr xo-list))
223 (glyph-string (if (eq? (car mypair) 'mute) "X" "O"))
224 (xpos (+ (* (- string-count (cadr mypair)) size) xo-horizontal-offset ))
225 (glyph-stencil (ly:stencil-translate-axis
226 (sans-serif-stencil paper props (* size xo-font-mag) glyph-string) xpos X)))
230 (draw-xo paper props string-count fret-range size restlist)
233 (define (make-bezier-sandwich-list left right bottom height thickness)
234 " Make the argument list for a horizontal bezier sandwich from @var{left} to @var{right} with a bottom at @var{bottom},
235 a height of @var{height}, and a thickness of @var{thickness}."
236 (let* ((width (+ (- right left) 1))
237 (x1 (+ (* width thickness) left))
238 (x2 (- right (* width thickness)))
239 (bottom-control-point-height (+ bottom (- height thickness)))
240 (top-control-point-height (+ bottom height)))
241 ; order of points is: left cp low, right cp low, right end low, left end low
242 ; right cp high, left cp high, left end high, right end high.
243 (list (cons x1 bottom-control-point-height) (cons x2 bottom-control-point-height) (cons right bottom) (cons left bottom)
244 (cons x2 top-control-point-height) (cons x1 top-control-point-height) (cons left bottom) (cons right bottom))))
246 (define (draw-barre paper props string-count fret-range size finger-code dot-position dot-radius barre-list)
247 "Create barre indications for a fret diagram"
248 (if (not (null? barre-list))
249 (let* ((string1 (caar barre-list))
250 (string2 (cadar barre-list))
251 (fret (caddar barre-list))
252 (barre-type (chain-assoc-get 'barre-type props 'curved))
253 (scale-dot-radius (* size dot-radius))
254 (barre-vertical-offset (chain-assoc-get 'barre-vertical-offset props 0.5))
255 ; 2 is 1 for empty fret at bottom of figure + 1 for interval (top-fret - fret + 1) -- not an arbitrary constant
256 (dot-center-y (* size (- (+ 2 (- (cadr fret-range) fret))dot-position) ))
257 (bottom (+ dot-center-y (* barre-vertical-offset scale-dot-radius)))
258 (left (* size (- string-count string1)))
259 (right (* size (- string-count string2)))
260 ; (bezier-thick (chain-assoc-get 'bezier-thickness props 0.1))
262 ; (bezier-height (chain-assoc-get 'bezier-height props 0.5))
264 (bezier-list (make-bezier-sandwich-list left right bottom (* size bezier-height) (* size bezier-thick)))
265 (barre-stencil (if (eq? barre-type 'straight)
266 (ly:make-stencil (list 'draw-line (* size dot-radius) left dot-center-y right dot-center-y)
268 (cons (- dot-center-y scale-dot-radius) (+ dot-center-y scale-dot-radius)))
269 (ly:make-stencil (list 'bezier-sandwich `(quote ,bezier-list) (* size bezier-thick) )
271 (cons bottom (+ bottom (* size bezier-height)))))))
272 (if (not (null? (cdr barre-list)))
273 (ly:stencil-add barre-stencil
274 (draw-barre paper props string-count fret-range size finger-code
275 dot-position dot-radius (cdr barre-list)))
279 (define (stepmag mag)
280 "Calculate the font step necessary to get a desired magnification"
281 (* 6 (/ (log mag) (log 2))))
283 (define (label-fret paper props string-count fret-range size)
284 "Label the base fret on a fret diagram"
285 (let* ((base-fret (car fret-range))
286 ; (label-font-mag (chain-assoc-get 'label-font-mag props 0.7))
288 ; (label-vertical-offset (chain-assoc-get 'fret-label-vertical-offset props -0.2))
289 (label-vertical-offset -0.2)
290 (number-type (chain-assoc-get 'number-type props 'roman-lower))
291 (fret-count (+ (- (cadr fret-range) (car fret-range)) 1))
294 ('roman-lower (format #f "~(~:@r~)" base-fret))
295 ('roman-upper (format #f "~:@r" base-fret))
296 ('arabic (format #f "~d" base-fret))
297 (else (format #f "~(~:@r~)" base-fret)))))
298 (ly:stencil-translate-axis
299 (sans-serif-stencil paper props (* size label-font-mag) label-text)
300 (* size (+ fret-count label-vertical-offset)) Y)))
302 (def-markup-command (fret-diagram-verbose paper props marking-list)
304 "Make a fret diagram containing the symbols indicated in @var{marking-list}
306 Syntax: \\fret-diagram marking-list
311 \\markup \\fret-diagram #'((mute 6) (mute 5) (open 4)
312 (place-fret 3 2) (place-fret 2 3) (place-fret 1 2))
315 will produce a standard D chord diagram without fingering indications.
317 Possible elements in @var{marking-list}:
319 @item (mute string-number)
320 Place a small 'x' at the top of string @var{string-number}
322 @item (open string-number)
323 Place a small 'o' at the top of string @var{string-number}
325 @item (barre start-string end-string fret-number)
326 Place a barre indicator (much like a tie) from string @var{start-string}to string @var{end-string} at fret @var{fret-number}
328 @item (place-fret string-number fret-number finger-value)
329 Place a fret playing indication on string @var{string-number} at fret @var{fret-number} with an optional
330 fingering label @var{finger-value}. By default, the fret playing indicator is a solid dot. This can be
331 changed by setting the value of the variable @var{dot-color}. If the @var{finger}
332 part of the place-fret element is present, @var{finger-value} will be displayed according to the setting of the variable
333 @var{finger-code}. There is no limit to the number of fret indications per string.
336 (make-fret-diagram paper props marking-list))
338 (define (make-fret-diagram paper props marking-list)
339 " Make a fret diagram markup"
341 ; note: here we get items from props that are needed in this routine, or that are needed in more than one
342 ; of the procedures called from this routine. If they're only used in one of the sub-procedure, they're
343 ; obtained in that procedure
345 (size (chain-assoc-get 'size props 1.0)) ; needed for everything
346 ;TODO -- get string-count directly from length of stringTunings; requires FretDiagram engraver, which is not yet available
347 ;TODO -- adjust padding for fret label? it appears to be too close to dots
348 (string-count (chain-assoc-get 'string-count props 6)) ; needed for everything
349 (fret-count (chain-assoc-get 'fret-count props 4)) ; needed for everything
350 (finger-code (chain-assoc-get 'finger-code props 'none)) ; needed for both draw-dots and draw-barre
351 (default-dot-radius (if (eq? finger-code 'in-dot) 0.425 0.25)) ; bigger dots if labeled
352 (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
353 (dot-radius (chain-assoc-get 'dot-radius props default-dot-radius)) ; needed for both draw-dots and draw-barre
354 (dot-position (chain-assoc-get 'dot-position props default-dot-position)) ; needed for both draw-dots and draw-barre
355 (th (* (ly:output-def-lookup paper 'linethickness)
356 (chain-assoc-get 'thickness props 0.5))) ; needed for both draw-frets and draw-strings
358 (alignment (chain-assoc-get 'align-dir props -0.4)) ; needed only here
359 ; (xo-padding (* th (chain-assoc-get 'padding props 2))) ; needed only here
361 (xo-padding (* th 2))
362 (label-dir (chain-assoc-get 'label-dir props RIGHT))
363 (parameters (fret-parse-marking-list marking-list fret-count))
364 (dot-list (cdr (assoc 'dot-list parameters)))
365 (xo-list (cdr (assoc 'xo-list parameters)))
366 (fret-range (cdr (assoc 'fret-range parameters)))
367 (barre-list (cdr (assoc 'barre-list parameters)))
368 (fret-diagram-stencil (ly:stencil-add
369 (draw-strings string-count fret-range th size)
370 (draw-frets paper props fret-range string-count th size))))
371 (if (not (null? barre-list))
372 (set! fret-diagram-stencil (ly:stencil-add
373 (draw-barre paper props string-count fret-range size finger-code
374 dot-position dot-radius barre-list)
375 fret-diagram-stencil)))
376 (if (not (null? dot-list))
377 (set! fret-diagram-stencil (ly:stencil-add
378 (draw-dots paper props string-count fret-range size finger-code
379 dot-position dot-radius dot-list)
380 fret-diagram-stencil)))
381 (if (not (null? xo-list))
382 (set! fret-diagram-stencil (ly:stencil-combine-at-edge
383 fret-diagram-stencil Y UP
384 (draw-xo paper props string-count fret-range size xo-list) xo-padding 0)))
385 (if (> (car fret-range) 1)
386 (set! fret-diagram-stencil
387 (ly:stencil-combine-at-edge fret-diagram-stencil X label-dir
388 (label-fret paper props string-count fret-range size) label-space 0)))
389 (ly:stencil-align-to! fret-diagram-stencil X alignment)
390 fret-diagram-stencil))
392 (def-markup-command (fret-diagram paper props definition-string)
394 "Syntax: \\fret-diagram definition-string
396 eg: \\markup \\fret-diagram #\"s:0.75;6-x;5-x;4-o;3-2;2-3;1-2;\"
398 for fret spacing 3/4 of staff space, D chord diagram
400 Syntax rules for @var{definition-string}:
404 Diagram items are separated by semicolons.
411 s:number -- set the fret spacing of the diagram (in staff spaces). Default 1
414 t:number -- set the line thickness (in staff spaces). Default 0.05
417 h:number -- set the height of the diagram in frets. Default 4
420 w:number -- set the width of the diagram in strings. Default 6
423 f:number -- set fingering label type (0 = none, 1 = in circle on string, 2 = below string) Default 0
426 d:number -- set radius of dot, in terms of fret spacing. Default 0.25
429 p:number -- set the position of the dot in the fret space. 0.5 is centered; 1 is on lower fret bar,
430 0 is on upper fret bar. Default 0.6
433 c:string1-string2-fret -- include a barre mark from string1 to string2 on fret
436 string-fret -- place a dot on string at fret. If fret is o, string is identified
437 as open. If fret is x, string is identified as muted.
440 string-fret-fingering -- place a dot on string at fret, and label with fingering as
446 Note: There is no limit to the number of fret indications per string.
450 (let ((definition-list (fret-parse-definition-string props definition-string)))
451 (make-fret-diagram paper (car definition-list) (cdr definition-list))))
453 (define (fret-parse-definition-string props definition-string)
454 "parse a fret diagram string and return a pair containing:
455 props, modified as necessary by the definition-string
456 a fret-indication list with the appropriate values"
457 (let* ((fret-count 4)
459 (fret-range (list 1 fret-count))
465 (items (string-split definition-string #\;)))
466 (let parse-item ((myitems items))
467 (if (not (null? (cdr myitems)))
468 (let ((test-string (car myitems)))
469 (case (car (string->list (substring test-string 0 1)))
470 ((#\s) (let ((size (get-numeric-from-key test-string)))
471 (set! new-props (acons 'size size new-props))))
472 ((#\f) (let* ((finger-code (get-numeric-from-key test-string))
473 (finger-id (case finger-code
476 ((2) 'below-string))))
478 (acons 'finger-code finger-id new-props))))
479 ((#\c) (set! output-list (cons-fret (cons 'barre (numerify (string-split (substring test-string 2) #\-)))
481 ((#\h) (let ((fret-count (get-numeric-from-key test-string)))
482 (set! new-props (acons 'fret-count fret-count new-props))))
483 ((#\w) (let ((string-count (get-numeric-from-key test-string)))
484 (set! new-props (acons 'string-count string-count new-props))))
485 ((#\d) (let ((dot-size (get-numeric-from-key test-string)))
486 (set! new-props (acons 'dot-radius dot-size new-props))))
487 ((#\p) (let ((dot-position (get-numeric-from-key test-string)))
488 (set! new-props (acons 'dot-position dot-position new-props))))
490 (let ((this-list (string-split test-string #\-)))
491 (if (string->number (cadr this-list))
492 (set! output-list (cons-fret (cons 'place-fret (numerify this-list)) output-list))
493 (if (equal? (cadr this-list) "x" )
494 (set! output-list (cons-fret (list 'mute (string->number (car this-list))) output-list))
495 (set! output-list (cons-fret (list 'open (string->number (car this-list))) output-list)))))))
496 (parse-item (cdr myitems)))))
497 (if (eq? new-props '())
498 `(,props . ,output-list)
499 `(,(cons new-props props) . ,output-list))))
501 (define (cons-fret new-value old-list)
502 " Put together a fret-list in the format desired by parse-string "
503 (if (eq? old-list '())
505 (cons* new-value old-list)))
507 (define (get-numeric-from-key keystring)
508 "Get the numeric value from a key of the form k:val"
509 (string->number (substring keystring 2 (string-length keystring) )))
511 (define (numerify mylist)
512 "Convert string values to numeric or character"
515 (let ((numeric-value (string->number (car mylist))))
517 (cons* numeric-value (numerify (cdr mylist)))
518 (cons* (car (string->list (car mylist))) (numerify (cdr mylist)))))))
520 (def-markup-command (fret-diagram-terse paper props definition-string)
522 "Make a fret diagram markup using terse string-based syntax.
524 Syntax: \\fret-diagram-terse definition-string
526 eg: \\markup \\fret-diagram #\"x;x;o;2;3;2;\" for a D chord diagram.
528 Syntax rules for @var{definition-string}:
532 Strings are terminated by semicolons; the number of semicolons
533 is the number of strings in the diagram.
536 Mute strings are indicated by \"x\".
539 Open strings are indicated by \"o\".
542 A number indicates a fret indication at that fret.
545 If there are multiple fret indicators desired on a string, they
546 should be separated by spaces.
549 Fingerings are given by following the fret number with a \"-\",
550 followed by the finger indicator, e.g. 3-2 for playing the third
551 fret with the second finger.
554 Where a barre indicator is desired, follow the fret (or fingering) symbol
555 with \"-(\" to start a barre and \"-)\" to end the barre.
557 ;TODO -- change syntax to fret\string-finger
558 (let ((definition-list (fret-parse-terse-definition-string props definition-string)))
559 (make-fret-diagram paper (car definition-list) (cdr definition-list))))
561 (define (fret-parse-terse-definition-string props definition-string)
562 "parse a fret diagram string that uses terse syntax; return a pair containing:
563 props, modified to include the string-count determined by the definition-string
564 a fret-indication list with the appropriate values"
565 ;TODO -- change syntax to fret\string-finger
566 (let* ((barre-start-list '())
569 (items (string-split definition-string #\;))
570 (string-count (- (length items) 1)))
571 (let parse-item ((myitems items))
572 (if (not (null? (cdr myitems)))
573 (let* ((test-string (car myitems))
574 (current-string (- (length myitems) 1))
575 (indicators (string-split test-string #\ )))
576 (let parse-indicators ((myindicators indicators))
577 (if (not (eq? '() myindicators))
578 (let* ((this-list (string-split (car myindicators) #\-))
579 (max-element-index (- (length this-list) 1))
580 (last-element (car (list-tail this-list max-element-index)))
581 (fret (if (string->number (car this-list)) (string->number (car this-list)) (car this-list))))
582 (if (equal? last-element "(")
584 (set! barre-start-list (cons-fret (list current-string fret) barre-start-list))
585 (set! this-list (list-head this-list max-element-index))))
586 (if (equal? last-element ")")
587 (let* ((this-barre (get-sub-list fret barre-start-list))
588 (insert-index (- (length this-barre) 1)))
589 (set! output-list (cons-fret (cons* 'barre (car this-barre) current-string (cdr this-barre))
591 (set! this-list (list-head this-list max-element-index))))
593 (set! output-list (cons-fret (cons* 'place-fret current-string (drop-paren (numerify this-list))) output-list))
594 (if (equal? (car this-list) "x" )
595 (set! output-list (cons-fret (list 'mute current-string) output-list))
596 (set! output-list (cons-fret (list 'open current-string) output-list))))
597 (parse-indicators (cdr myindicators)))))
598 (parse-item (cdr myitems)))))
599 (set! new-props (acons 'string-count string-count new-props))
601 `(,(cons new-props props) . ,output-list)))
603 (define (drop-paren item-list)
604 " drop a final parentheses from a fret indication list resulting from a terse string specification of barre."
605 (if (> (length item-list) 0)
606 (let* ((max-index (- (length item-list) 1))
607 (last-element (car (list-tail item-list max-index))))
608 (if (or (equal? last-element ")") (equal? last-element "("))
609 (list-head item-list max-index)
613 (define (get-sub-list value master-list)
614 " Get a sub-list whose cadr is equal to @var{value} from @var{master-list}"
615 (if (eq? master-list '())
617 (let ((sublist (car master-list)))
618 (if (equal? (cadr sublist) value)
620 (get-sub-list value (cdr master-list))))))