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: Kieren MacMillan
Subject: Re: printing the current moment in a context
Date: Wed, 16 Aug 2017 09:38:19 -0400

Hi David,

> Perhaps it would have been worthwhile creating a minimal example
> demonstrating the exact circumstance you actually need it for...

Your revised code — brilliant, as always! — appears to work perfectly on the 
attached MWE of the exact circumstance I need.
I'll try it in my "real-world" score and report back.

Thanks!
Kieren.

%%%  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))))

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.")))

\layout {
  \context {
    \Score
    \remove "Timing_translator"
    \remove "Default_bar_line_engraver"
  }
  \context {
    \Staff
    \consists "Timing_translator"
    \consists "Default_bar_line_engraver"
    \consists "Current_moment_engraver"
  }
}

<<
  \new Staff { c d-"@" f g }
  \new Staff { \time 3/4 c4 d f g2.-"@" }
>>
%%%  SNIPPET ENDS

________________________________

Kieren MacMillan, composer
‣ website: www.kierenmacmillan.info
‣ email: address@hidden




reply via email to

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