lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding durations (for \after)


From: Jean Abou Samra
Subject: Re: Adding durations (for \after)
Date: Wed, 9 Nov 2022 19:51:41 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.1

Le 09/11/2022 à 19:21, Lukas-Fabian Moser a écrit :
I'm a bit surprised that

\version "2.23.4"

#(define (duration-or-music? x)
   (or (ly:duration? x) (ly:music? x)))

duration =
#(define-scheme-function (x) (duration-or-music?)
   (if (ly:duration? x)
       x
       (make-duration-of-length (ly:music-length x))))

{
  \after \duration 2. ->
  \repeat unfold 16 { 8 }
}

actually seems to work, but to me it looks kind of fishy...



Well, duration-or-music? already exists and it's used by \skip. However,
this makes for the slight oddity that \skip 4 ... does not set the
default duration for the following music, whereas \skip {4} does.

It makes me muse about

diff --git a/lily/parser.yy b/lily/parser.yy
index a5e67c9773..65046e797e 100644
--- a/lily/parser.yy
+++ b/lily/parser.yy
@@ -3511,12 +3511,23 @@ steno_duration:
        }
        ;

-duration:
+duration_part:
        steno_duration multipliers {
                $$ = make_duration ($1, 0, $2);
        }
        ;

+duration:
+       duration_part
+       | duration '+' duration_part {
+               Duration *acc = unsmob<Duration> ($1);
+               Duration *added = unsmob<Duration> ($3);
+               Rational acc_len = acc->get_length ();
+               Rational new_len = acc_len + added->get_length ();
+               $$ = acc->compressed (new_len/acc_len).smobbed_copy ();
+       }
+       ;
+
 dots:
        /* empty */     {
                $$ = SCM_INUM0;



This allows writing

  \after 2.+4. \!

Something like the edition-engraver might benefit from this as well.

Admittedly, I was surprised not to get Bison screaming at me about
parser conflicts.

I don't know if this is actually useful enough and the right concept
to warrant adding. Also, it can hardly be extended to accepting "-"
as well as "+", since { 4-16 } is already valid.


Jean

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]