Harm, Aaron, thank you both for your answers. Both are great solutions!

El sáb, 16 ene 2021 a las 0:27, Aaron Hill (<[email protected]>)
escribió:

> On 2021-01-15 4:10 pm, Thomas Morley wrote:
> > Am Fr., 15. Jan. 2021 um 23:26 Uhr schrieb Stefano Troncaro
> > <[email protected]>:
> >>
> >> 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
>
> Here's a back-compat patch that should allow \note to accept strings.
> Could be useful until arranger.ly is updated to use ly:durations in
> places where it relied on strings before.
>
> %%%%
> \version "2.22.0"
>
> #(begin
>    (define (duration-or-string? arg)
>     (or (ly:duration? arg) (string? arg)))
>    (define-markup-command
>     (note layout props duration dir)
>     (duration-or-string? number?)
>     #:category music
>     #:properties (note-by-number-markup)
>     (if (string? duration)
>      (set! duration
>       (ly:parse-string-expression (ly:parser-clone) duration)))
>     (note-by-number-markup layout props
>                            (ly:duration-log duration)
>                            (ly:duration-dot-count duration)
>                            dir)))
>
> \markup {
>    \note { 8. } #DOWN \note "8." #DOWN
>    \note { \longa*2/3 } #UP \note "\longa*2/3" #UP
> }
> %%%%
>
>
> -- Aaron Hill
>

Reply via email to