LilyPond snippets: Repeats

# Repeats

Repeats

## Adding volta brackets to additional staves

The `Volta_engraver` by default resides in the `Score` context, and brackets for the repeat are thus normally only printed over the topmost staff. This can be adjusted by adding the `Volta_engraver` to the `Staff` context where the brackets should appear; see also the “Volta multi staff” snippet.

    <<
      \new Staff { \repeat volta 2 { c'1 } \alternative { c' } }
      \new Staff { \repeat volta 2 { c'1 } \alternative { c' } }
      \new Staff \with { \consists "Volta_engraver" } { c'2 g' e' a' }
      \new Staff { \repeat volta 2 { c'1 } \alternative { c' } }
    >>

## Cross-staff tremolos

Since `\repeat tremolo` expects exactly two musical arguments for chord tremolos, the note or chord which changes staff within a cross-staff tremolo should be placed inside curly braces together with its `\change Staff` command.

    \new PianoStaff <<
      \new Staff = "up" \relative c'' {
        \key a \major
        \time 3/8
        s4.
      }
      \new Staff = "down" \relative c'' {
        \key a \major
        \time 3/8
        \voiceOne
        \repeat tremolo 6 {
          <a e'>32
          {
            \change Staff = "up"
            \voiceTwo
            <cis a' dis>32
          }
        }
      }
    >>

## Engraving tremolos with floating beams

If a tremolo’s total duration is less than a quarter-note, or exactly a half-note, or between a half-note and a whole-note, it is normally typeset with all beams touching the stems. Certain engraving styles typeset some of these beams as centered floating beams that do not touch the stems. The number of floating beams in this type of tremolo is controlled with the `'gap-count` property of the `Beam` object, and the size of the gaps between beams and stems is set with the `'gap` property.

    \relative c'' {
      \repeat tremolo 8 { a32 f }
      \override Beam #'gap-count = #1
      \repeat tremolo 8 { a32 f }
      \override Beam #'gap-count = #2
      \repeat tremolo 8 { a32 f }
      \override Beam #'gap-count = #3
      \repeat tremolo 8 { a32 f }

      \override Beam #'gap-count = #3
      \override Beam #'gap = #1.33
      \repeat tremolo 8 { a32 f }
      \override Beam #'gap = #1
      \repeat tremolo 8 { a32 f }
      \override Beam #'gap = #0.67
      \repeat tremolo 8 { a32 f }
      \override Beam #'gap = #0.33
      \repeat tremolo 8 { a32 f }
    }

## Isolated percent repeats

Isolated percents can also be printed.

    makePercent =
    #(define-music-function (parser location note) (ly:music?)
       "Make a percent repeat the same length as NOTE."
       (make-music 'PercentEvent
                   'length (ly:music-length note)))

    \relative c'' {
      \makePercent s1
    }

## Measure counter

This snippet provides a workaround for emitting measure counters using transparent percent repeats.

    <<
      \context Voice = "foo" {
        \clef bass
        c4 r g r
        c4 r g r
        c4 r g r
        c4 r g r
      }
      \context Voice = "foo" {
        \set countPercentRepeats = ##t
        \override PercentRepeat #'transparent = ##t
        \override PercentRepeatCounter #'staff-padding = #1
        \repeat percent 4 { s1 }
      }
    >>

## Percent repeat count visibility

Percent repeat counters can be shown at regular intervals by setting the context property `repeatCountVisibility`.

    \relative c'' {
      \set countPercentRepeats = ##t
      \set repeatCountVisibility = #(every-nth-repeat-count-visible 5)
      \repeat percent 10 { c1 } \break
      \set repeatCountVisibility = #(every-nth-repeat-count-visible 2)
      \repeat percent 6 { c1 d1 }
    }

## Percent repeat counter

Measure repeats of more than two repeats can get a counter when the convenient property is switched, as shown in this example:

    \relative c'' {
      \set countPercentRepeats = ##t
      \repeat percent 4 { c1 }
    }

## Positioning segno and coda (with line break)

If you want to place an exiting segno sign and add text like “D.S. al Coda” next to it where usually the staff lines are you can use this snippet. The coda will resume in a new line. There is a variation documented in this snippet, where the coda will remain on the same line.

    {
      \clef treble
      \key g \major
      \time 4/4
      \relative c'' {
        \repeat unfold 2 {
          | c4 c c c
        }

        % Set segno sign as rehearsal mark and adjust size if needed
        % \once \override Score.RehearsalMark #'font-size = #3
        \mark \markup { \musicglyph #"scripts.segno" }
        \repeat unfold 2 {
          | c4 c c c
        }

        % Set coda sign as rehearsal mark and adjust size if needed
        \once \override Score.RehearsalMark #'font-size = #4
        \mark \markup { \musicglyph #"scripts.coda" }
        \repeat unfold 2 {
          | c4 c c c
        }

        % Should Coda be on anew line?
        % Coda NOT on new line: use \nobreak
        % Coda on new line: DON'T use \nobreak
        % \noBreak

        \bar "||"

        % Set segno sign as rehearsal mark and adjust size if needed
        \once \override Score.RehearsalMark #'break-visibility = #begin-of-line-invisible
        % \once \override Score.RehearsalMark #'font-size = #3
        \mark \markup { \musicglyph #"scripts.segno" }

        % Here begins the trickery!
        % \cadenzaOn will suppress the bar count and \stopStaff removes the staff lines.
        \cadenzaOn
          \stopStaff
            % Some examples of possible text-displays

            % text line-aligned
            % ==================
            % Move text to the desired position
            % \once \override TextScript #'extra-offset = #'( 2 . -3.5 )
            % | s1*0^\markup { D.S. al Coda } }

            % text center-aligned
            % ====================
            % Move text to the desired position
            % \once \override TextScript #'extra-offset = #'( 6 . -5.0 )
            % | s1*0^\markup { \center-column { D.S. "al Coda" } }

            % text and symbols center-aligned
            % ===============================
            % Move text to the desired position and tweak spacing for optimum text alignment
            %\once \override TextScript #'extra-offset = #'( 8 . -5.5 )
            \once \override TextScript #'word-space = #1.5
            \once \override TextScript #'X-offset = #8
            \once \override TextScript #'Y-offset = #1.5
            | s1*0^\markup { \center-column { "D.S. al Coda" \line { \musicglyph #"scripts.coda" \musicglyph #"scripts.tenuto" \musicglyph #"scripts.coda"} } }

            % Increasing the unfold counter will expand the staff-free space
            \repeat unfold 4 {
              s4 s4 s4 s4
              \bar ""
            }
            % Resume bar count and show staff lines again
         \startStaff
       \cadenzaOff

       % Should Coda be on new line?
       % Coda NOT on new line: DON'T use \break
       % Coda on new line: use \break
       \break

       % Show up, you clef and key!
       \once \override Staff.KeySignature #'break-visibility = #end-of-line-invisible
       \once \override Staff.Clef #'break-visibility = #end-of-line-invisible

       % Set coda sign as rehearsal mark and adjust size and position

       % Put the coda sign ontop of the (treble-)clef dependend on coda's line-position

         % Coda NOT on new line, use this:
         % \once \override Score.RehearsalMark #'extra-offset = #'( -2 . 1.75 )

         % Coda on new line, use this:
         \once \override Score.RehearsalMark #'extra-offset = #'( -8.42 . 1.75 )

       \once \override Score.RehearsalMark #'font-size = #5
       \mark \markup { \musicglyph #"scripts.coda" }

       % The coda
       \repeat unfold 5 {
          | c4 c c c
        }
        \bar"|."
      }
    }

## Printing a repeat sign at the beginning of a piece

A `|:` bar line can be printed at the beginning of a piece, by overriding the relevant property:

    \relative c'' {
      \once \override Score.BreakAlignment #'break-align-orders =
        #(make-vector 3 '(instrument-name
                          left-edge
                          ambitus
                          breathing-sign
                          clef
                          key-signature
                          time-signature
                          staff-bar
                          custos))
      \once \override Staff.TimeSignature #'space-alist =
        #'((first-note . (fixed-space . 2.0))
           (right-edge . (extra-space . 0.5))
           ;; free up some space between time signature
           ;; and repeat bar line
           (staff-bar . (extra-space . 1)))
      \bar "|:"
      c1
      d1
      d4 e f g
    }

## Setting the double repeat default for volte

There are three different styles of double repeats for volte, that can be set using `doubleRepeatType`.

    \relative c'' {
      \repeat volta 1 { c1 }
      \set Score.doubleRepeatType = #":|:"
      \repeat volta 1 { c1 }
      \set Score.doubleRepeatType = #":|.|:"
      \repeat volta 1 { c1 }
      \set Score.doubleRepeatType = #":|.:"
      \repeat volta 1 { c1 }
    }

## Shortening volta brackets

By default, the volta brackets will be drawn over all of the alternative music, but it is possible to shorten them by setting `voltaSpannerDuration`. In the next example, the bracket only lasts one measure, which is a duration of 3/4.

    \relative c'' {
      \time 3/4
      c4 c c
      \set Score.voltaSpannerDuration = #(ly:make-moment 3 4)
      \repeat volta 5 { d4 d d }
      \alternative {
        {
          e4 e e
          f4 f f
        }
        { g4 g g }
      }
    }

## Volta below chords

By adding the `Volta_engraver` to the relevant staff, volte can be put under chords.

    \score {
      <<
        \chords {
          c1
          c1
        }
        \new Staff \with {
          \consists "Volta_engraver"
        }
        {
          \repeat volta 2 { c'1 }
          \alternative { c' }
        }
      >>
      \layout {
        \context {
          \Score
          \remove "Volta_engraver"
        }
      }
    }

## Volta multi staff

By adding the `Volta_engraver` to the relevant staff, volte can be put over staves other than the topmost one in a score.

    voltaMusic = \relative c'' {
      \repeat volta 2 {
        c1
      }
      \alternative {
        d1
        e1
      }
    }

    <<
      \new StaffGroup <<
        \new Staff \voltaMusic
        \new Staff \voltaMusic
      >>
      \new StaffGroup <<
        \new Staff \with { \consists "Volta_engraver" }
          \voltaMusic
        \new Staff \voltaMusic
      >>
    >>

## Volta text markup using repeatCommands

Though volte are best specified using `\repeat volta`, the context property `repeatCommands` must be used in cases where the volta text needs more advanced formatting with `\markup`.

Since `repeatCommands` takes a list, the simplest method of including markup is to use an identifier for the text and embed it in the command list using the Scheme syntax `#(list (list 'volta textIdentifier))`. Start- and end-repeat commands can be added as separate list elements:

    voltaAdLib = \markup { 1. 2. 3... \text \italic { ad lib. } }

    \relative c'' {
      c1
      \set Score.repeatCommands = #(list (list 'volta voltaAdLib) 'start-repeat)
      c4 b d e
      \set Score.repeatCommands = #'((volta #f) (volta "4.") end-repeat)
      f1
      \set Score.repeatCommands = #'((volta #f))
    }

#### LilyPond — Snippets