Without investigating how the bar number engraver (I'm guessing, or whatever engraves them), I am unsure how to correct what actually gets *engraved* (which is obviously important), but here's a partial solution.
\adjustBarNum
applies the repeats and
does the calculations
,
and seems to reset
each
next *currentBarNumber* to what it should be. Maybe someone with more knowledge of
how
bar number
s are
engrave
d can
have a look and see what is wrong/missing
.
=== begin snippet
adjustBarNum =
#(define-music-function (num mus)
(number? ly:music?)
(define startBar 0)
#{
#(make-apply-context
(lambda (context)
(let ((currentBar (ly:context-property context 'currentBarNumber)))
(set! startBar currentBar))))
\repeat volta #num { #mus }
#(make-apply-context
(lambda (context)
(let* ((endBar (ly:context-property context 'currentBarNumber))
(repLength (+ (if (equal? startBar 1) 0 1)
(- endBar startBar)))
(lenScaled (* repLength num))
(nextBar (+ startBar lenScaled)))
(ly:context-set-property! context 'currentBarNumber nextBar))))
#})
\score {
\new Staff {
\tempo 4 = 108
\clef "bass"
\time 4/4
\key f \minor
\override Score.BarNumber.break-visibility = #'#(#t #t #t)
\barNumberCheck #1
\adjustBarNum 4 { \rhPatternA }
% adds 4 bars ... (1 + 4 = 5)
\barNumberCheck #5
\adjustBarNum 16 { \rhPatternA }
% adds 16 bars ... (5 + 16 = 21)
\barNumberCheck #21
\adjustBarNum 4 { \rhPatternB }
% adds 4 bars ... (21 + 4 = 25)
\barNumberCheck #25
\adjustBarNum 2 {\rhPatternA }
}
}
=== end snippet