issue 4575
Whitespace-characters are deleted before further processing.
Allows for
\markup \fret-diagram #"s:2;h:5;
6-3;5-5;4-5;3-4;2-3;1-x;"
Also adding errors for typos in fret-diagram with a meaningful message:
\markup \fret-diagram #"s:2;g:r;
6-3;5-5;4-5;3-4;2-3;1-x;"
will return:
fatal error: Unhandled entry in fret-diagram "g:r" in "g:r"
This error would not apply, if something for #\g would be defined
in fret-parse-definition-string somewhere in the future.
Then, the message would be:
fatal error: Unhandled entry in fret-diagram "r" in "g:r"
Something similiar is already in harp-pedals.scm
(define (get-numeric-from-key keystring)
"Get the numeric value from a key of the form k:val"
(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))))
+ (let* ((entry (substring keystring 2 (string-length keystring)))
+ (numeric-entry (string->number entry)))
+ ;; throw an error, if `entry' can't be transformed into a number
+ (if numeric-entry
+ numeric-entry
+ (ly:error
+ "Unhandled entry in fret-diagram \"~a\" in \"~a\""
+ entry
+ keystring))))
(define (numerify mylist)
"Convert string values to numeric or character"
(define (numerify mylist)
"Convert string values to numeric or character"
((or (eq? my-code 'open)(eq? my-code 'mute))
(set! xo-list (cons* my-item xo-list)))
((eq? my-code 'barre)
((or (eq? my-code 'open)(eq? my-code 'mute))
(set! xo-list (cons* my-item xo-list)))
((eq? my-code 'barre)
- (set! barre-list (cons* (cdr my-item) barre-list)))
+ (if (every number? (cdr my-item))
+ (set! barre-list (cons* (cdr my-item) barre-list))
+ (ly:error
+ "barre-indications should contain only numbers: ~a"
+ (cdr my-item))))
((eq? my-code 'capo)
(set! capo-fret (cadr my-item)))
((eq? my-code 'place-fret)
((eq? my-code 'capo)
(set! capo-fret (cadr my-item)))
((eq? my-code 'place-fret)
(output-list '())
(new-props '())
(details (merge-details 'fret-diagram-details props '()))
(output-list '())
(new-props '())
(details (merge-details 'fret-diagram-details props '()))
- (items (string-split definition-string #\;)))
+ ;; remove whitespace-characters from definition-string
+ (cleared-string (remove-whitespace definition-string))
+ (items (string-split cleared-string #\;)))
(let parse-item ((myitems items))
(if (not (null? (cdr myitems)))
(let ((test-string (car myitems)))
(let parse-item ((myitems items))
(if (not (null? (cdr myitems)))
(let ((test-string (car myitems)))
(set! details
(acons 'dot-position dot-position details))))
(else
(set! details
(acons 'dot-position dot-position details))))
(else
- (let ((this-list (string-split test-string #\-)))
+ (let* ((this-list (string-split test-string #\-))
+ (fret-number (string->number (car this-list))))
+ ;; If none of the above applies, `fret-number' needs to be a
+ ;; number. Throw an error, if not.
+ (if (not fret-number)
+ (ly:error
+ "Unhandled entry in fret-diagrams \"~a\" in \"~a\""
+ (car this-list)
+ test-string))
(if (string->number (cadr this-list))
(set! output-list
(cons-fret
(if (string->number (cadr this-list))
(set! output-list
(cons-fret
(if (equal? (cadr this-list) "x" )
(set! output-list
(cons-fret
(if (equal? (cadr this-list) "x" )
(set! output-list
(cons-fret
- (list 'mute (string->number (car this-list)))
+ (list 'mute fret-number)
output-list))
(set! output-list
(cons-fret
output-list))
(set! output-list
(cons-fret
- (list 'open (string->number (car this-list)))
+ (list 'open fret-number)
output-list)))))))
(parse-item (cdr myitems)))))
;; add the modified details
output-list)))))))
(parse-item (cdr myitems)))))
;; add the modified details
stencils)))
;; Parse the harp pedal definition string into list of directions (-1/0/1), #\o and #\|
stencils)))
;; Parse the harp pedal definition string into list of directions (-1/0/1), #\o and #\|
+;; Whitespace is removed from definition string before the procedure applies.
(define (harp-pedals-parse-string definition-string)
"Parse a harp pedals diagram string and return a list containing 1, 0, -1, #\\o or #\\|"
(map (lambda (c)
(define (harp-pedals-parse-string definition-string)
"Parse a harp pedals diagram string and return a list containing 1, 0, -1, #\\o or #\\|"
(map (lambda (c)
((#\-) 0)
((#\| #\o) c)
(else c)))
((#\-) 0)
((#\| #\o) c)
(else c)))
- (string->list definition-string)))
+ (string->list (remove-whitespace definition-string))))
;; Analyze the pedal-list: Return (pedalcount . (divider positions))
;; Analyze the pedal-list: Return (pedalcount . (divider positions))
(define-public (string-startswith s prefix)
(equal? prefix (substring s 0 (min (string-length s) (string-length prefix)))))
(define-public (string-startswith s prefix)
(equal? prefix (substring s 0 (min (string-length s) (string-length prefix)))))
+(define-public (remove-whitespace strg)
+"Remove characters satisfying @code{char-whitespace?} from string @var{strg}"
+ (string-delete
+ strg
+ char-whitespace?))
+
(define-public (string-encode-integer i)
(cond
((= i 0) "o")
(define-public (string-encode-integer i)
(cond
((= i 0) "o")