Hello,
For what it's worth, you can do the following.
Please be aware, however, that not being fully
knowledgeable about LilyPond's representation of
music, I cannot guarantee the correctness of this
code in all cases.
Best,
Jean
\version "2.22.0"
implicitRests =
#(define-music-function (music) (ly:music?)
(map-some-music
(lambda (m)
(ly:music-set-property!
m
'elements
(let loop ((remaining-elements (ly:music-property m 'elements))
(last-rhythmic-event #f)
(acc '()))
(if (null? remaining-elements)
(reverse acc)
(let ((next-event (car remaining-elements))
(other-events (cdr remaining-elements)))
(if (and (music-is-of-type? next-event 'note-event)
(null? (ly:music-property next-event 'pitch)))
(loop other-events
last-rhythmic-event
(cons
(make-music (ly:music-property
last-rhythmic-event 'name)
'pitch
(ly:music-property
last-rhythmic-event 'pitch)
'duration
(ly:music-property next-event
'duration))
acc))
(loop other-events
(if (music-is-of-type? next-event
'rhythmic-event)
next-event
last-rhythmic-event)
(cons next-event acc)))))))
#f)
music))
\implicitRests \new Voice \relative {
c'4 4 r4 4
c'4 4 r8 8 4
c d8 r8 8 r4 8
<< { c'4 4 r8 4 8 } \\ { r8 8 16 16 16. 32 2 } >>
}