About a year ago, I had a question about a double \repeat percent measure
symbol ("double" simile) being used inside \repeat volta and segnos.
Valentin solved my problem by writing a snippet which created the specific
symbol
<https://lists.gnu.org/archive/html/lilypond-user/2024-08/msg00047.html>;
I'm still very thankful, Tina!
However, when I switched from version 2.25.20 to 2.25.25 (and now to the
latest 2.25.28), Tina's code stopped working. The logged error was due to
"ly:duration-length" not being used in later versions of lilypond.

Thanks to modern technology (at least giving AI a good use...), "I"¹ have
updated Valentin's code to work on version 2.24.0 to the latest unstable
version. I'm not sure if the code is as good or optimazed as it can be, but
better to be safe than sorry. So I'm sharing the snippet like I did the
last time (with the explicit return/ritornello counter - which now is on
Github).

Best regards,
Lucas


%%Code starts
%
%%Snippet starts
% Define a function to create double percent repeats that work across
LilyPond 2.24+.
makeDPercent =
#(define-music-function (duration) (ly:duration?)
   "Make a double percent repeat of given duration, works across 2.24+."
   (make-music 'DoublePercentEvent
               'length
               ;; Check which duration function is available:
               ;; - 'ly:duration->moment' is used in newer versions (>=
2.25.21)
               ;; - 'ly:duration-length' is legacy and used in older
versions
               (if (defined? 'ly:duration->moment)
                   (ly:duration->moment duration)
                   (ly:duration-length duration))))
%
% Define a function to create single percent repeats with backward
compatibility.
makePercent =
#(define-music-function (note) (ly:music?)
   "Make a percent repeat with backward compatibility."
   (let* (
           ;; Select appropriate function for getting note length:
           ;; - 'ly:music-length' works in most versions
           ;; - If unavailable, log a warning and return a dummy value (1)
           (use-music-length
             (cond
               ((defined? 'ly:music-length)
                (lambda (n) (ly:music-length n))) ; Standard case
               (else
                (begin
                  (ly:message "WARNING: No valid music-length function
found for makePercent.")
                  (lambda (n) 1))))))
     ;; Create a PercentEvent using the determined length function.
     (make-music 'PercentEvent
                 'length (use-music-length note))))
%
%%Snippet ends
%
\score { \new Staff {c''1 \makePercent s1 \makeDPercent 1*2
} }
%%Code ends


¹I'm aware of vibe coding. However, I'm not versed enough in Scheme or
Lilypond's internal mechanisms to be able to write the code by myself. I
try to (or would like to) think I'm not "vibe coding"... at least I'm
getting my issues fixed.

Reply via email to