From 8a07c9e873be8f6ba3f5476874735aefa817147c Mon Sep 17 00:00:00 2001 From: Graham Percival Date: Fri, 10 Jun 2011 16:15:17 +0100 Subject: [PATCH] event-listener.ly: print explicit grace durations --- ly/event-listener.ly | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/ly/event-listener.ly b/ly/event-listener.ly index 9089750263..7ba28602e6 100644 --- a/ly/event-listener.ly +++ b/ly/event-listener.ly @@ -60,28 +60,25 @@ name, it uses "unnamed-staff" for that part of the filename." (/ (ly:moment-main-numerator moment) (ly:moment-main-denominator moment)))) -#(define (adjust-for-grace moment) - "Adjusts any moment with a grace note by subtracting half of -the grace note duration. For example, an eighth note grace note -which would otherwise occur at score time 0.5 will now occur at -score time 0.375." +#(define (moment-grace->string moment) + "Prints a moment without grace note(s) as a float such as +0.25000. Grace notes are written with the grace duration as a +separate \"dashed\" number, i.e. 0.25000-0.12500. This allows any +program using the output of this function to interpret grace notes +however they want (half duration, quarter duration? before beat, +after beat? etc.)." (if (eq? 0 (ly:moment-grace-numerator moment)) - moment - ;; get moment including grace note - ;; grace notes have a negative numerator, so add - (ly:moment-add moment - ;; make the "grace duration" half as long - (ly:moment-mul - (ly:make-moment 1 2) + (ly:format "~a" (format-moment moment)) + ;; grace notes have a negative numerator, so no "-" necessary + (ly:format + "~a~a" + (format-moment moment) + (format-moment (ly:make-moment (ly:moment-grace-numerator moment) (ly:moment-grace-denominator moment)))))) -#(define (get-moment moment) - (format-moment (adjust-for-grace - moment))) - #(define (make-output-string-line engraver values) "Constructs a tab-separated string beginning with the score time (derived from the engraver) and then adding all the @@ -90,12 +87,12 @@ values. The string ends with a newline." (moment (ly:context-current-moment context))) (string-append (string-join - (map - (lambda (x) (ly:format "~a" x)) - (append - (list (get-moment moment)) - values)) - "\t") + (append + (list (moment-grace->string moment)) + (map + (lambda (x) (ly:format "~a" x)) + values)) + "\t") "\n"))) -- 2.39.5