[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Changing the bar-number string
From: |
Francesco Guglie |
Subject: |
Re: Changing the bar-number string |
Date: |
Sat, 8 Mar 2008 14:54:31 +0100 |
User-agent: |
KMail/1.9.9 |
Alle sabato 8 marzo 2008, Trevor Daniels ha scritto:
> Hi Keiren
>
> Rather than just give you a Scheme procedure to do
> this, I thought it might be more helpful to say
> how I arrived at this code, as I'm still learning
> too, and needed to work this out.
>
> First I looked at the BarNumber grob in the IR and
> saw that the stencil property is set by default to
> ly:text-interface::print, and in this interface we
> find that the 'text property contains the text to
> be printed. As this text needs to vary with the
> bar number it must be set up by Lily before the
> stencil procedure is called.
>
> As the value of 'text is set up dynamically
> in this way we cannot simply change it with an
> override - it has to be changed *after* Lily has
> set up the current bar number, so we need a Scheme
> call-back procedure. This procedure needs to lift
> out the current value of the 'text property, append
> " bis" to it, and store it back, finally calling
> ly:text-interface::print to print it.
>
> Having worked out what to do, we have to generate
> the correct Scheme code to do it. I needed to look
> up how to append text to a string, but otherwise
> this is fairly straight-forward. The stencil
> call-back is called with the BarNumber grob as its
> argument, so the text property is immediately
> available, and we need to pass on the BarNumber
> grob to the ::print procedure. The only remaining
> difficulty, as always with Scheme, is to get all
> the brackets in the right places!
>
> Here it is, well-annotated, with some artificial
> code to demonstrate it working:
>
> #(define (bis-bar-number BarNumber)
> "Append bis to the bar number."
> (let* (
> ; Set barNumber to the current value
> (barNumber (ly:grob-property BarNumber 'text))
> ; Append " bis" to it
> (bisBarNumber (string-append barNumber " bis")))
> ; Store the new value back
> (ly:grob-set-property! BarNumber 'text bisBarNumber))
> ; and print it
> (ly:text-interface::print BarNumber))
>
> music = \relative
> {
> \override Score.BarNumber #'self-alignment-X = #center
> \override Score.BarNumber #'break-visibility =
> #all-visible
> \repeat unfold 4 { a1 }
> \override Score.BarNumber #'stencil = #bis-bar-number
> \repeat unfold 4 { a1 }
> \revert Score.BarNumber #'stencil
> \repeat unfold 4 { a1 }
> }
>
> \score { \music }
>
> > -----Original Message-----
> > From: address@hidden
> > [mailto:lilypond-user-bounces+t.daniels=treda.co.u
> > address@hidden Behalf Of
> > Kieren MacMillan
> > Sent: 07 March 2008 17:23
> > To: Francesco Guglie
> > Cc: address@hidden
> > Subject: Re: Changing the bar-number string
> >
> >
> > Hi Francesco,
> >
> > > I'd like to change the bar-numbers of a
> >
> > repeated section so that it
> >
> > > shows the bar-number of the first time with a
> >
> > "bis" added.
> >
> > If I knew Scheme, I would write something like
> >
> > %%%%%%%%%%
> > \version "2.11.37"
> >
> > #(define (special-bar-number context)
> > (markup (#:line ((ly:context-property
> > 'Score 'currentBarNumber)
> > "bis"))))
> >
> > music = \relative
> > {
> > \override Score.BarNumber #'stencil =
> > #special-bar-number
> > \repeat unfold 16 { a1 }
> > }
> >
> > \score { \music }
> > %%%%%%%%%%
> >
> > Unfortunately, the code I wrote doesn't work... =\
> > Maybe someone out there can fix it -- or tell us
> > why this idea can't
> > possibly work.
> >
> > Cheers,
> > Kieren.
> >
> >
> > _______________________________________________
> > lilypond-user mailing list
> > address@hidden
> > http://lists.gnu.org/mailman/listinfo/lilypond-user
Thank you very much, both for the code and for your clear explanation! A good
lesson indeed :) Thanks again!
Francesco