Jump to content

Unfolding tremolo repeats

From LilyPond wiki
Revision as of 22:06, 23 December 2025 by Schrodinger-s-kitten (talk | contribs) (added categories)

Under normal circumstances, <note>:<duration>, the shortcut of \repeat tremolo is not unfolded by \unfoldRepeats. This function works around that:

\version "2.24"

fixTremolos =
#(define-music-function (music) (ly:music?)
   (music-map
    (lambda (m)
      (let ((event (any (lambda (a)
                          (and (music-is-of-type? a 'tremolo-event)
                               a))
                        (ly:music-property m 'articulations))))
        (if event
            (let* ((total-tremolo-duration (ly:music-property m 'duration))
                   (tremolo-type (ly:music-property event 'tremolo-type))
                   (one-tremolo-note-duration (ly:make-duration (ly:intlog2 tremolo-type)))
                    (tremolo-note-count (/ tremolo-type (expt 2 (ly:duration-log total-tremolo-duration)))))
              (set! (ly:music-property m 'duration)
                    one-tremolo-note-duration)
              (set! (ly:music-property m 'articulations)
                    (delete! event (ly:music-property m 'articulations)))
              (make-music 'TremoloRepeatedMusic
                          'repeat-count tremolo-note-count
                          'element m))
            m)))
    music))

unfoldRepeats = \unfoldRepeats #'() \fixTremolos \etc

music = { \repeat tremolo 8 c'16 c'2:16 }

{
  \unfoldRepeats \music
}