I hope this message lands in the right 2018 thread. I find an ossia function very worth the work! I tried several things yesterday but none of them really worked. I amended a few details to Urs/David's code (a couple of \with attributes) but there are still some minor issues (other than this big 13 years old bug
https://gitlab.com/lilypond/lilypond/-/issues/127).
When I look at the code (see below) I would expect this to happen: \ossia {%ossiamusic} {%music}. What happens is the opposite. This is trivial, since the only thing you have to tell the user is that the normal music goes before the ossia music, but it makes me wonder why anyways... Other minor issues are that the ossia music doesn't inherit the clef from the normal music, and that placing all this inside a \relative is not reliable (the first note of whichever of both components might be in an unexpected octave). Does Urs, who started working on this, or David (or anyone :-)) have any idea on how to solve these minor issues? Here the amended code with an example that demonstrate them:
ossia =
#(define-music-function
(music ossia-music) (ly:music? ly:music?)
(let ((name "initialized"))
#{
\applyContext
#(lambda (context)
(set! name (ly:context-id (ly:context-find context 'Staff)))
)
<< \new Staff \with {
#(ly:make-context-mod
`((apply ,(lambda (c)
(set! (ly:context-property c 'alignAboveContext) name)
))))
\remove "Time_signature_engraver"
\magnifyStaff #2/3
\hide Clef
firstClef = ##f
} { #ossia-music }
#music
>>
% Create \new Staff with ossia-music
#}))
\new Staff = "viola" \relative {
\clef alto
c'4 d e g
\ossia {c^"c'?" b c d } { e^"Treble clef? I'm not a violin!" d f e }
c b c2
}
Cheers,
Martín.
--