> Folks > > I would like to help uncover the many treasures hidden in the mailing > list archives - especially those from which I personally benefit. For > that reason, I have created my first wiki page here: > > https://wiki.lilypond.community/wiki/Time_Mark_Engraver > > I would appreciate any guidance on what I should correct or do > differently next time. > > I'm really happy about the wiki, because it finally allows me to > contribute to helping others without needing any > documentation-compilation expertise ;-) > > Regards > Stephan
Thank you for doing this. For this one it might make sense to do something
like this instead:
%%%
\version "2.24"
#(set-object-property! 'currentTime
'translation-type?
number?)
#(define (format-time seconds) ; example: 2m15s
(let* ((minutes (euclidean-quotient seconds 60))
(rest (euclidean-remainder seconds 60)))
(string-append (if (zero? minutes) "" (format #f "~am" minutes))
(format #f "~as" (round rest)))))
#(define (time-mark::text-from-seconds grob)
(let* ((det (ly:grob-property grob 'details))
(seconds (assoc-get 'seconds det 0))
(format (assoc-get 'format-seconds det format-time)))
(format seconds)))
#(define (Elapsed_time_translator context)
(let ((wholes-per-minute 15)
(last-time ZERO-MOMENT)
(total-time 0))
(make-engraver
((start-translation-timestep engraver)
(let* ((new-time (ly:context-current-moment context))
(time-delta (ly:moment-main
(ly:moment-sub new-time last-time)))
(new-wholes-per-minute
(and=> (ly:context-property context
'tempoWholesPerMinute #f)
ly:moment-main)))
(when new-wholes-per-minute
(set! wholes-per-minute new-wholes-per-minute))
(set! total-time
(+ total-time (* 60 (/ time-delta wholes-per-minute))))
(set! last-time new-time)
(ly:context-set-property! context 'currentTime total-time))))))
#(define (Time_mark_translator context)
(let ((marks '()))
(make-engraver
(acknowledgers
((text-mark-interface engraver grob source-engraver)
(let ((det (ly:grob-property grob 'details)))
(when (assq-ref det 'time-mark)
(ly:grob-set-property!
grob 'details
(acons 'seconds
(ly:context-property context 'currentTime 0)
det)))))))))
\layout {
\context {
\Score
\consists #Elapsed_time_translator
\consists #Time_mark_translator
}
}
% The argument of the `\textEndMark` here is just a placeholder
% that the engraver replaces with a time stamp (because the
% `time-mark` subproperty is set).
timeMark = \tweak details.time-mark ##t
\tweak text #time-mark::text-from-seconds
\tweak color "red"
\textEndMark ""
{
c'1 | \timeMark
\tempo 4 = 120 c'4 8. 16 2 | \timeMark
\tempo 4 = 180 \repeat unfold 4 c'2 | \timeMark
\repeat unfold 180 c'4 | \timeMark
}
%%%
This would use two translators, one which keeps a context property
`currentTime` up to date and one which sets details.seconds of the time marks
to the current time value. The calculaction of text is then done in the `text`
callback (which in itself uses details.format-time for formatting if set).
The advantages of this are:
1. The time value is now available to any other translator that might want to
use it without having to implement a counter for each
2. It is possible to change the way the marks are printed in user code without
having to change the engravers. This even allows for different formats of time
in different parts of the score.
Cheers,
Tina
signature.asc
Description: This is a digitally signed message part.
