%% Generated by lilypond-book
%% Options: [exampleindent=10.16\mm,indent=0\mm,line-width=160\mm,paper-height=845.047\pt,paper-width=597.508\pt,papersize='(cons (* 597.508 pt) (* 845.047 pt))]
\include "lilypond-book-preamble.ly"


% ****************************************************************
% Start cut-&-pastable-section
% ****************************************************************

#(ly:set-option 'eps-box-padding 3.000000)



\paper {
  #(set-paper-size '(cons (* 597.508 pt) (* 845.047 pt)))
  indent = 0\mm
  line-width = 160\mm
  % offset the left padding, also add 1mm as lilypond creates cropped
  % images with a little space on the right
  line-width = #(- line-width (* mm  3.000000) (* mm 1))
}

\layout {
  
}




% ****************************************************************
% ly snippet:
% ****************************************************************
\sourcefilename "snippets/unfolding-tremolo-repeats.ly"
\sourcefileline 0
%% DO NOT EDIT this file manually; it was automatically
%% generated from the LilyPond Wiki
%% (https://wiki.lilypond.community).
%%
%% Make any changes in the Wiki itself, or in
%% `Documentation/snippets/new/`, then run
%% `scripts/auxiliar/makelsr.pl`.
%%
%% This file is in the public domain.

\version "2.24.0"

\header {
%% Translation of GIT committish: 1abe87de51b9b00a391da1be4cf4b5ebe4021ca9
  texidocfr = "
Actuellement, saisir @code{@var{note}:@var{durée}} est en quelque sorte
un raccourci de @code{\\repeat tremolo}, mais n'est pas expansé par une
directive @code{\\unfoldRepeats} (ceci fait l'objet du
@uref{https://gitlab.com/lilypond/lilypond/-/issues/6145, ticket 6145}).
La fonction ci-dessous présentée constitue un contournement à cette
faiblesse.
"

  doctitlefr = "Expansion de répétition de trémolo"

  categories = "Repeats, Workaround"

  texidoc = "
Currently, @code{@var{note}:@var{duration}}, which is more or
less a shortcut for @code{\\repeat tremolo}, is not unfolded by
@code{\\unfoldRepeats} (this is tracked in
@uref{https://gitlab.com/lilypond/lilypond/-/issues/6145,Issue #6145}).
The function given in this snippet provides a workaround.
"

  doctitle = "Unfolding tremolo repeats"
} % begin verbatim


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 }

{
  \music
  \unfoldRepeats \music
}



% ****************************************************************
% end ly snippet
% ****************************************************************
