# Re: Define nr of measures per system

Hi Omri,

> Another beginner question, but can't seem to find the answer in the
> documentation:
> is it possible to define a constant number of measures per staff system?

There is no dead-simple, built-in way… but there are many ways of accomplishing
what you want, each with pros and cons depending on exactly what functionality
and flexibility you want.

For a constant number of measures per system, my favourite is David K's
\bar-keeper, which I’ve shown in the snippet below.

(Aside: I’m not sure why this isn’t in the main base code… Given that David K
coded it, I imagine it’s the most elegant solution possible to the problem he
was tasked to solve. And it is a function that many, many users would

Hope this helps!
Kieren.

%%%  SNIPPET BEGINS
\version "2.19"

#(define (index-list? x)
(and (list? x)
(every index? x)))

#(define (index-pattern numbers)
"Convert an index pattern' into a circular list.  Zeros are removed,
with the last zero preceding the part of the list that should become
circular.  If that list part is empty, the resulting list has no circular
end.  Without any zero, the whole list is turned into a circular one."
(define (creverse! x y)
"Reverse both x and y, make y circular and append to x."
(if (pair? y)
(let* ((rev-y (reverse! y))
(rev-x (reverse! x rev-y)))
(set-cdr! y rev-y)
rev-x)
(reverse! x y)))
(let loop ((non-reps '()) (reps '()) (rest numbers))
(cond ((null? rest) (creverse! non-reps reps))
((zero? (car rest))
(loop (append! reps non-reps) '() (cdr rest)))
((index? (car rest))
(loop non-reps (cons (car rest) reps) (cdr rest)))
(else (ly:input-warning (*location*)
(_ "Not an index: ~a") (car rest))
(loop non-reps reps (cdr rest))))))

bar-keeper =
#(define-scheme-function (numbers) (index-list?)
"Create a context mod for consisting a Timing-level engraver
breaking after bar group lengths specified in the list.  If the list
is exhausted, it starts over from the start or from after a 0 marker
contained in the list.  If the list @emph{ends} with@tie{}0, line
breaking reverts to normal after using up the list."
(ly:make-context-mod
((consists
,(lambda (c)
(let ((target #f) (numbers (index-pattern numbers)))
(make-engraver
(acknowledgers
((paper-column-interface eng grob from)
(and (pair? numbers)
(ly:grob-property grob 'non-musical #f)
(let ((bar (ly:context-property (ly:translator-context eng)
'internalBarNumber)))
(if (not target)
(set! target bar)
(set! (ly:grob-property grob 'line-break-permission)
(and (>= bar (+ target (car numbers)))
(begin
(set! target (+ target (car numbers)))
(set! numbers (cdr numbers))
'force)))))))))))))))

\score {
\new Score \with \bar-keeper 4 {
\repeat unfold 100 { c''4 }
}
}
%%%  SNIPPET ENDS
________________________________

Kieren MacMillan, composer
‣ website: www.kierenmacmillan.info
‣ email: i...@kierenmacmillan.info

_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user