lilypond-user
[Top][All Lists]
Advanced

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

Re: printing the current moment in a context


From: David Kastrup
Subject: Re: printing the current moment in a context
Date: Wed, 16 Aug 2017 14:53:50 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

Kieren MacMillan <address@hidden> writes:

> Hi David,
>
>> Something like
>
> This is great!
>
> …except in the *exact* circumstance I actually need it for:
>
> %%%%  SNIPPET BEGINS
> \version "2.19.64"
>
> #(define (moment->string mom)
>  (if (zero? (ly:moment-grace mom))
>   (number->string (ly:moment-main mom))
>   (format "~sG~a" (ly:moment-main mom) (ly:moment-grace mom))))
>
> currentmom =
> -\tweak text
> #(lambda (grob)
>   (let* ((loc (grob::rhythmic-location grob)))
>     (if (pair? loc)
>        #{ \markup \with-color #red #(format "address@hidden" (car loc)
>                                             (moment->string (cdr loc))) #}
>         "")))
> -""
>
> \layout {
>   \context {
>     \Score
>     \remove "Timing_translator"
>     \remove "Default_bar_line_engraver"
>   }
>   \context {
>     \Staff
>     \consists "Timing_translator"
>     \consists "Default_bar_line_engraver"
>   }
> }
>
> { c d\currentmom f g }
> %%%%  SNIPPET ENDS
>
> Any way to get the moment of the current context when Timing has been moved 
> from Score?

That's more tricky since "rhythmic-location" is recorded in
PaperColumn/NonMusicalPaperColumn items that only exist per-Score.  You
could try moving Paper_column_engraver along with the other engravers
you move but I would be surprised if this does not cause a lot of havoc.

So maybe do this entirely differently?

\version "2.19.65"

#(define (moment->string mom)
  (if (zero? (ly:moment-grace mom))
   (number->string (ly:moment-main mom))
   (format "~sG~a" (ly:moment-main mom) (ly:moment-grace mom))))

Current_moment_engraver =
#(make-engraver
  (acknowledgers
   ((text-script-interface self grob origin)
    (let ((ctx (ly:translator-context self)))
      (if (equal? (ly:grob-property grob 'text) "@")
          (set! (ly:grob-property grob 'text)
                #{ \markup \with-color #red
                   #(format "address@hidden" (ly:context-property ctx 
'currentBarNumber)
                            (moment->string (ly:context-property ctx 
'measurePosition))) #}))))))

#(ly:register-translator
  Current_moment_engraver 'Current_moment_engraver
  '((description . "\
This engraver replaces text scripts with a text of @code{@@} with
a red address@hidden indicator.")))

\new Staff \with { \consists "Current_moment_engraver" }
{ c d-"@" f g }
Of course, here is to you not actually ever wanting to output just "@".
You'd consist this engraver where it can be expected to see useful
values of currentBarNumber/measurePosition, so likely in the same
contexts where you move your Timing_translator.

No idea whether this will behave sensibly in the context of timing
changes such as \partial .

-- 
David Kastrup

reply via email to

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