[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: get current bar number

From: Kevin Barry
Subject: Re: get current bar number
Date: Thu, 29 Mar 2018 18:05:57 +0100

That worked perfectly!

Thanks to all for responding.

On 25 March 2018 at 19:46, Thomas Morley <address@hidden> wrote:
2018-03-25 0:04 GMT+01:00 Kevin Barry <address@hidden>:
> Hi Jan/Wols,
> Thank you for responding. I have tinkered with \applyContext and
> cannot get the property out of it to do anything useful with it. Since
> it always returns music I can't feed it to a markup command or convert
> it to markup or set it as the value for a property (using a callback
> or something like that). I have tried using it to set! another
> property and print that, but it doesn't work.
> I tried looking at the code for the rehearsal mark engraver, but it's
> in C++ and I don't understand it (and I suspect context objects are in
> the #included contexts.hh). I also looked at the code for the
> Measure_counter_engraver, which is in scheme, but it takes a context
> object as its parameter, which doesn't seem to get me any closer.
> I must be misunderstanding something. My best attempt is below. Any
> further help would be appreciated.
> #(define-markup-command (print-bar-number layout props) ()
>   (define barnum 0)
>   (let* ((setbarnum (lambda (context)
>                        (set! barnum
>                              (ly:context-property context 'currentBarNumber)))))
>     (make-apply-context setbarnum)
>     (interpret-markup layout props
>       (markup (number->string barnum)))))
> \repeat unfold 3 { b1^\markup \print-bar-number }
> Kevin

How about:

foo =
\applyOutput Voice.TextScript
  #(lambda (grob ctx c)
      (format #f "\ncurrentBarNumber: ~a"
        (ly:context-property ctx 'currentBarNumber))))

  \repeat unfold 3 { \foo c1^"" }


reply via email to

[Prev in Thread] Current Thread [Next in Thread]