[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: arranger.ly and lilypond 2.21+: error with the \note markup command
From: |
Thomas Morley |
Subject: |
Re: arranger.ly and lilypond 2.21+: error with the \note markup command |
Date: |
Sat, 16 Jan 2021 01:10:55 +0100 |
Am Fr., 15. Jan. 2021 um 23:26 Uhr schrieb Stefano Troncaro
<stefanotroncaro@gmail.com>:
>
> Hi everyone,
>
> I started learning to use the spectacular arranger.ly library that was
> mentioned in the list a while ago.
>
> While most of it works great, I found that internally it sometimes uses the
> \note markup command, that changed between versions: in 2.20 it requires an
> argument of type string, while from 2.21 onwards it requires an argument of
> type duration. This causes an error and makes it so that files that use
> arranger.ly do not compile on Lilypond 2.21 onwards.
>
> I'm sure it'd be easy to patch. Is there an easy way to transform strings
> into durations?
Iiuc, how about:
%% from define-markup-commands
#(use-modules (ice-9 regex))
#(define-public log2
(let ((divisor (log 2)))
(lambda (z) (inexact->exact (/ (log z) divisor)))))
#(define (parse-simple-duration duration-string)
"Parse the `duration-string', e.g. ''4..'' or ''breve.'',
and return a (log dots) list."
(let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
duration-string)))
(if (and match (string=? duration-string (match:substring match 0)))
(let ((len (match:substring match 1))
(dots (match:substring match 2)))
(list (cond ((string=? len "breve") -1)
((string=? len "longa") -2)
((string=? len "maxima") -3)
(else (log2 (string->number len))))
(if dots (string-length dots) 0)))
(ly:error (_ "not a valid duration string: ~a") duration-string))))
%% and then:
#(define (string->duration strg)
(apply ly:make-duration (parse-simple-duration strg)))
%% test
#(display-scheme-music (string->duration "16.."))
Cheers,
Harm