Hi Ahanu,
In lilypond 2.20.0, I was able to use "afterGrace" like this:
\version "2.20.0"
\language "english"
\relative c' { d2 \afterGrace 4 { cs16 d } }
However, this now presents an error: "warning: \afterGrace exceeds
duration of main argument". Running ly-convert does not fix it.
If I change "\aftergrace 4" to "\aftergrace d4", it works fine.
However, I have multiple documents written with the aforementioned
syntax, and it would take a long time to fix them manually. Any
suggestions?
Actually, the example you posted gives a different warning because you
reduced it "too much".
Here's what happens: \afterGrace accepts an optional argument indicating
the amount of time (as a fraction of the main note) after which the
grace should appear.
In 2.20, this was defined via:
#(define-music-function (fraction main grace) ((fraction?) ly:music?
ly:music?) ...
LilyPond now sees that 4 is not a fraction?, hence assumes no "fraction"
was given, and interprets 4 as ly:music? yielding the "main" note. Then,
{ cs16 d } becomes the "grace" part, as intended by you.
In 2.22, the definition was changed to:
#(define-music-function (fraction main grace) ((scale?) ly:music?
ly:music?) ...
Now scale? is defined (in c++.scm) as
(define-public (scale? x)
(or (and (rational? x) (exact? x) (not (negative? x)))
(fraction? x)
(and (ly:moment? x) (scale? (ly:moment-main x)))))
meaning: A scale? can be
- a fraction?
- an non-negative exact rational number
- a LilyPond moment whose main part is in turn a scale?.
This is fulfilled by 4, hence in your call to \afterGrace 4 { cs16 d },
... 4 is taken to be the afterGrace "fraction" (and in recent versions,
there is the warning, added by me, that this fraction is larger than 1)
... { cs16 d } is taken to be the "main" note
... whatever comes after is taken to be the "main" note (since in your
minimal example, nothing comes after this, compilation fails completely).
I'm not sure about David Kastrup's rationale for allowing a scale? as an
afterGraceFraction, but if anybody is aware about the implications his
changes might have for LilyPond's syntax, it's him.
https://gitlab.com/lilypond/lilypond/-/issues/5327
https://gitlab.com/lilypond/lilypond/-/commit/027538606b016afb643555d654cefaee94dfb424
If you never use the optional fraction argument to afterGrace, a quick
and easy fix would be to state
afterGrace = \afterGrace \afterGraceFraction \etc
in the top-level part of your file: This re-defines afterGrace by always
adding an explicit (default) afterGraceFraction. But this is really
dirty since it makes it impossible to change afterGraceFraction
afterwards OR to use the explicit afterGrace factors.
A slightly more verbose and robust version would be to manually restore
the fraction? predicate in the definition of afterGrace while retaining
new functionality:
#(define factoryAfterGrace afterGrace)
afterGrace =
#(define-music-function (fraction main grace) ((fraction?) ly:music?
ly:music?)
(pretty-print fraction)
#{
\factoryAfterGrace
#(or fraction (ly:parser-lookup 'afterGraceFraction))
#main #grace
#})
Lukas