Jump to content

Percent repeat counters for piano music: Difference between revisions

From LilyPond wiki
Import snippet from LSR
 
m New category
Tags: Mobile edit Mobile web edit
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
In piano music parts it is customary to put the repeat counters between the staves. While it is rather straightforward to add the two percent repeat engravers to the <code>Dynamics</code> context (which we use for centering the counter numbers), it is non-trivial to get some vertical whitespace above and below the digits for the double percent repeat counter.
In piano music parts it is customary to put the repeat counters between the staves. While it is rather straightforward to add the two percent repeat engravers to the <code>Dynamics</code> context (which we use for centering the counter numbers), it is non-trivial to get some vertical whitespace above and below the digits for the double percent repeat counter.


<lilypond version="2.24.0">
<lilypond version="2.24">
%% http://lsr.di.unimi.it/LSR/Item?id=883
%% http://lsr.di.unimi.it/LSR/Item?id=883


Line 73: Line 73:
[[Category:Contexts and engravers]]
[[Category:Contexts and engravers]]
[[Category:Scheme]]
[[Category:Scheme]]
[[Category:Snippet]]

Latest revision as of 23:27, 21 November 2025

In piano music parts it is customary to put the repeat counters between the staves. While it is rather straightforward to add the two percent repeat engravers to the Dynamics context (which we use for centering the counter numbers), it is non-trivial to get some vertical whitespace above and below the digits for the double percent repeat counter.

\version "2.24"

%% http://lsr.di.unimi.it/LSR/Item?id=883

\relative c' {
  \new PianoStaff <<
    \new Staff {
      \repeat percent 2 { e4 e e e } |
      \repeat percent 2 { 
        f4 f f f |
        d4 d d d 
      }
    }

    \new Dynamics {
      \set countPercentRepeats = ##t
      \repeat percent 2 { s1 } |
      \repeat percent 2 { s1*2 }
    }

    \new Staff {
      \repeat percent 2 { e4 e e e } |
      \repeat percent 2 { 
        f4 f f f |
        d4 d d d 
      } |
    }
  >>
}

\layout {
  \context {
    \Dynamics

    % Add percent repeat engravers.
    \consists "Percent_repeat_engraver"
    \consists "Double_percent_repeat_engraver"

    % Don't display the repeat glyphs.
    \override PercentRepeat.transparent = ##t
    \override DoublePercentRepeat.transparent = ##t

    % Center the counter numbers -- this is easy,
    % since the used feta digits are exactly two staff spaces high.
    \override PercentRepeatCounter.Y-offset = #-1
    \override DoublePercentRepeatCounter.Y-offset = #-1

    % Simply setting the `whiteout' property avoids a clash between
    % the counter and the barline, however, there is no vertical
    % padding which makes the result unsatisfactory.
    %
    % We thus use a hand-made stencil instead to white out 0.5 units
    % above and below the digit.  The code is based on the
    % `stencil-whiteout-box' function (in file `scm/stencil.scm').
    \override DoublePercentRepeatCounter.stencil =
      #(lambda (grob)
         (let* ((stencil (ly:text-interface::print grob))
                (x-ext (ly:stencil-extent stencil X))
                (y-ext (ly:stencil-extent stencil Y))
                (y-ext (interval-widen y-ext 0.5)))
           (ly:stencil-add
             (stencil-with-color (ly:round-filled-box x-ext y-ext 0.0)
                                 white)
             stencil)))
  }
}