lilypond-user
[Top][All Lists]

## Re: How to do simple arithmetic on bar numbers?

 From: Graham King Subject: Re: How to do simple arithmetic on bar numbers? Date: Sun, 16 Jan 2011 22:45:51 +0000

```On Sun, 2011-01-16 at 22:55 +0100, jakob lund wrote:

> > -----Original Message-----
> > From: Graham King <address@hidden>
> > Date: Sun, 16 Jan 2011 21:11:25 +0000
> > Subject: How to do simple arithmetic on bar numbers?
> >
> >>I'm preparing a modern-notation edition of a piece of choral renaissance
> >>polyphony, in which the maxima at the end of each section is notated as
> >>a neomensural "\maxima*n/m" (where, for each part, n,m are chosen to
> >>cause all the parts to end the section together).
> >>
> >>Example lilypond code and the result are attached.
> >>
> >>Bar-numbering is attached to the top part in the score so, when that
> >>part's maxima starts early and other parts are still moving, the other
> >>parts sometimes have "extra" bars of music.  As a result, I have to
> >>reset the bar numbering manually afterwards (see line 27 of the example
> >>attached):
> >>
> >>       \set Staff.currentBarNumber = #4
> >>
> >>Rather than specifying a static bar number, how could the following
> >>pseudocode be programmed?
> >>
> >>       \set Staff.currentBarNumber = Staff.currentBarNumber + x
> >>
> >>where, in this example, x = 1
> >>
> >>As you can tell, I'm not a Scheme programmer!  Thanks for any help you
> >>can offer.
> >>-

> the same thing that the snippet [333] does, but only for bar number, and
> with a parameter (the number to add, in case it isn't 1) could look
> like this
>
> addtobarnumber = #(define-music-function (P L m) (integer?)
>      #{
>   \applyContext
>   #(lambda (voice)
>     (let ((staff (ly:context-property-where-defined voice 'currentBarNumber))
>         (n (ly:context-property voice 'currentBarNumber)))
>     (ly:context-set-property! staff 'currentBarNumber
>      (+ \$m n))))
>      #})
>
> %% example
> { \override Score.BarNumber #'break-visibility = #'#(#t #t #t)
>   \key c \major
>   c''1
>   c'1
>   c''1
>  c'1
> }
>
>
> I don't know how it will work but try it out.
>
> Jakob

Thanks Jakob,
I've restored Bar_number_engraver to the Voice context "Mean" to avoid
the spurious barline in that part.  I then incorporated your code
(verbatim) and tried "addtobarnumber #2" in the Mean part just before
the double bar.  This didn't change the bar numbering.

Am I missing something?  Are there some things I should change in your
code to fit my circumstances?
--