Jump to content

Printing only odd bar numbers: Difference between revisions

From LilyPond wiki
Import snippet from LSR
 
m New category
 
(2 intermediate revisions by 2 users not shown)
Line 12: Line 12:
<span class="small">This modulo function can also be used in a more general way!</span>
<span class="small">This modulo function can also be used in a more general way!</span>


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


Line 37: Line 37:


[[Category:Staff notation]]
[[Category:Staff notation]]
[[Category:Snippet]]

Latest revision as of 23:38, 21 November 2025

To print only the odd bar numbers you must set the barNumberVisibility

  • to a mode showing all bar numbers
  • based on a calculation of the bar numbers to be visible.

Moreover, the Score.BarNumber #'break-visibility should be overridden e.g. to #all-visible

This is best placed in a \layout block to keep the music part "clean".

The first bar number can also be printed by inserting \bar "" before the music.

This modulo function can also be used in a more general way!

\version "2.24"

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

%LSR modified/updated by P.P.Schneider on Feb 15, 2014.

\layout { 
  \context { 
    \Score 
    barNumberVisibility = #all-bar-numbers-visible 
    % this line hereunder is just to fix a v2.18.0 bug (P.P.Schneider Feb.2014)
    % (see : http://lilypond.1069038.n5.nabble.com/Bar-number-on-odd-bars-does-not-work-on-new-release-td157263.html)
    barNumberVisibility = #(lambda (n x) (= (modulo n 2) 1)) 
    % for higher version use :
    %barNumberVisibility = #(modulo-bar-number-visible 2 1) % or 2 0 to see the even bar numbers 
    \override BarNumber.break-visibility = #all-visible 
  } 
} 

\new Staff { 
  \bar ""
  \repeat unfold 8 { c'2 c' } 
}