When writing music, normal repetition marks ("fat" bar lines with dots) is read as "repeat twice". When something should repeat e.g. four times, you might write "4×" below the closing repetition mark (like in the riff above which is from ''Superstition'' by Stevie Wonder). In LilyPond you'd write
which logically means "repeat four times", but it doesn't get you the text saying "4×". You could (like I tried) use the \mark command to place the text above the bar line, but that'll mess up if either (a) you have an actual mark in the following bar or (b) the repeated section ends at the end of a line — and both cases are quite likely.
This snippet creates a function that inserts an invisible bar of length 1/32, and places the text below the hidden 1/32 note (ref. http://www.kainhofer.com/~lilypond/Documentation/snippets/expressive-mar...):
repeatVoltaNoAlt = #(define-music-function (P L n music) (integer? ly:music?) #{ \repeat volta $n { $music \bar "" \once \override Score.TimeSignature #'stencil = ##f \time 1/32 s32_\markup{\concat{ $(markup (number->string n)) "×" } } \once \override Score.TimeSignature #'stencil = ##f \time 4/4 } #})
It can be used like this
riff = \relative c' { \repeatVoltaNoAlt #4 { r8 c r16 c r8 es,16 f g bes \prall (bes) g c c | r8 c bes16 c8 g16 g'8-> es-> c-> r }}
which is what generated the riff at the top. The general time signature of the piece must be hard-coded in the definition (where it says \time 4/4
) because the function temporarily switches to 1/32 time.