Re: Time measurement

2024-03-15 Thread Kieren MacMillan
Hi Jean,

> To get 2-digit precision on the number of seconds, you can simply replace
> 
> (format #f "~as" (round rest))
> 
> with
> 
> (format #f "~,2fs" rest)
> 
> in the format-time function.
> 
> For seconds:frames at 24 frames/second, replace format-time with
> 
>   (define (format-time seconds)
> (let* ((minutes (euclidean-quotient seconds 60))
>(rest (euclidean-remainder seconds 60))
>(seconds (euclidean-quotient rest 1))
>(rest (euclidean-remainder rest 1)))
>   (string-append (if (zero? minutes) "" (format #f "~a:" minutes))
>  (format #f "~a:~a" seconds (round (* rest 24))

Fantastic!

For future readers: for 0 minutes, 2 seconds, and 8 frames, the formatting 
above will return "2:8". If you [like me] would prefer "0:02:08", then use

  (string-append (format #f "~d:" minutes)
 (format #f "~2,'0d:~2,'0d" seconds (round (* rest 24))

Thanks again, Jean!
Another “wow” feature to show my colleagues who are still toiling away in 
lesser engraving apps.  ;)

Cheers,
Kieren.
__

My work day may look different than your work day. Please do not feel obligated 
to read or respond to this email outside of your normal working hours.




Re: Time measurement

2024-03-15 Thread Jean Abou Samra
> Hi Jean,
> 
> As always… remarkable.
> 
> One question: How hard would it be to have this output more precise
> timings (e.g., 1/4 or 1/10th or 1/100th of a second, or SMPTE timecode
> in minutes:seconds:frames)? I could imagine this being *very* useful
> for film/video/media composers.


To get 2-digit precision on the number of seconds, you can simply replace

(format #f "~as" (round rest))

with

(format #f "~,2fs" rest)

in the format-time function.


For seconds:frames at 24 frames/second, replace format-time with

   (define (format-time seconds)
 (let* ((minutes (euclidean-quotient seconds 60))
(rest (euclidean-remainder seconds 60))
(seconds (euclidean-quotient rest 1))
(rest (euclidean-remainder rest 1)))
   (string-append (if (zero? minutes) "" (format #f "~a:" minutes))
  (format #f "~a:~a" seconds (round (* rest 24))


Best,
Jean




signature.asc
Description: This is a digitally signed message part


Re: Time measurement

2024-03-15 Thread Kieren MacMillan
Hi Lukas,

I love that we have two custom engravers to compare and learn from!
Thank you so much for this solution — looking forward to analyzing it when I 
have a moment.

Best,
Kieren.

> On Mar 14, 2024, at 5:54 PM, Lukas-Fabian Moser  wrote:
>> “This sounds like a job for… Custom Engraver!!”  :)
> It sure does.

__

My work day may look different than your work day. Please do not feel obligated 
to read or respond to this email outside of your normal working hours.




Re: Time measurement

2024-03-15 Thread Kieren MacMillan
Hi Jean,

As always… remarkable.

One question: How hard would it be to have this output more precise timings 
(e.g., 1/4 or 1/10th or 1/100th of a second, or SMPTE timecode in 
minutes:seconds:frames)? I could imagine this being *very* useful for 
film/video/media composers.

Thanks!
Kieren.

> On Mar 14, 2024, at 5:45 PM, Jean Abou Samra  wrote:
> 
>> “This sounds like a job for… Custom Engraver!!”  :)
> 
> \version "2.24.2"
> 
> #(define (Custom_engraver!! context)
>   (define (format-time seconds)
> (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)
>   (let ((wholes-per-minute 15)
> (last-time ZERO-MOMENT)
> (total-time 0)
> (marks '()))
> (make-engraver
>  ((process-music 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)))
> (set! total-time
>   (+ total-time (* 60 (/ time-delta wholes-per-minute
> (set! last-time new-time)
> (when new-wholes-per-minute
>   (set! wholes-per-minute new-wholes-per-minute
>  (acknowledgers
>   ((text-mark-interface engraver grob source-engraver)
>(set! marks (cons grob marks
>  ((process-acknowledged engraver)
>   (for-each (lambda (grob)
>   (when (assq-ref (ly:grob-property grob 'details) 'time-mark)
> (ly:grob-set-property! grob 'text (format-time 
> total-time
> marks)
>   (set! marks '())
> 
> \layout {
>  \context {
>\Score
>\consists #Custom_engraver!!
>  }
> }
> 
> timeMark = \tweak details.time-mark ##t \tweak color "red" \textEndMark 
> "Abracadabra"
> 
> {
>  c'1
>  \timeMark
>  \tempo 4 = 120
>  c'4 8. 16 2
>  \timeMark
>  \tempo 4 = 180
>  c'2 2
>  \timeMark
>  \repeat unfold 180 c'4
>  \timeMark
> }
> 

__

My work day may look different than your work day. Please do not feel obligated 
to read or respond to this email outside of your normal working hours.