[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: get current bar number
From: |
Thomas Morley |
Subject: |
Re: get current bar number |
Date: |
Sun, 25 Mar 2018 20:46:36 +0200 |
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)
(ly:grob-set-property!
grob
'text
(format #f "\ncurrentBarNumber: ~a"
(ly:context-property ctx 'currentBarNumber))))
{
\textLengthOn
\repeat unfold 3 { \foo c1^"" }
}
HTH,
Harm