Reviewers: zefram_fysh.org,
Message:
adding zefram to the rietveld
Description:
Enhancement: Factor out some duration processing
Issue 3081
New functions duration-log-factor, duration-dot-factor, duration-length,
duration-visual, and duration-visual-length. All concerned with
low-level
numerical processing of durations, so that other code doesn't have to
understand dot counts and the like.
Please review this at https://codereview.appspot.com/7068062/
Affected files:
M ly/articulate.ly
M scm/lily-library.scm
Index: ly/articulate.ly
diff --git a/ly/articulate.ly b/ly/articulate.ly
index
3b8c11020d762cabb9f8dc82158f5ddebd05d768..ed4e7aa75269c14fc55d667e38abd76430bf8d36
100644
--- a/ly/articulate.ly
+++ b/ly/articulate.ly
@@ -456,21 +456,13 @@
(tremtype-log (1- (integer-length tremtype)))
(durev (find (lambda (v) (not (null? (ly:music-property v 'duration))))
evl))
(totaldur (if durev (ly:music-property durev 'duration)
(ly:make-duration tremtype-log 0 1)))
- (tgt-nrep (* (/ (ash 1 tremtype-log) (ash 1 (ly:duration-log
totaldur)))
- (/ (1- (ash 2 (ly:duration-dot-count totaldur)))
- (ash 1 (ly:duration-dot-count totaldur)))))
+ (tgt-nrep (/ (duration-visual-length totaldur) (duration-log-factor
tremtype-log)))
(eff-nrep (max (truncate tgt-nrep) 1))
(tremdur (ly:make-duration tremtype-log 0
(* (/ tgt-nrep eff-nrep) (ly:duration-scale totaldur)))))
(or (and (= eff-nrep tgt-nrep) (= (ash 1 tremtype-log) tremtype))
(ly:warning (_ "non-integer tremolo ~a:~a")
- (duration->lily-string
- (ly:make-duration
- (ly:duration-log totaldur)
- (ly:duration-dot-count totaldur)
- 1)
- #:force-duration #t
- #:time-scale 1)
+ (duration->lily-string (duration-visual totaldur) #:force-duration #t
#:time-scale 1)
tremtype))
(for-each
(lambda (v)
Index: scm/lily-library.scm
diff --git a/scm/lily-library.scm b/scm/lily-library.scm
index
5519bb8263207d5faa33c5ec77ecdfefd324d2bf..ecf5a4598fe6ee66c3347c9ba5613731989aaddb
100644
--- a/scm/lily-library.scm
+++ b/scm/lily-library.scm
@@ -79,6 +79,42 @@
(ly:moment-main-denominator moment)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; durations
+
+(define-public (duration-log-factor lognum)
+"Given a logarithmic duration number, return the length of the duration,
+as a number of whole notes."
+ (or (and (exact? lognum) (integer? lognum))
+ (scm-error 'wrong-type-arg "duration-log-factor" "Not an integer: ~S"
(list lognum) #f))
+ (if (<= lognum 0)
+ (ash 1 (- lognum))
+ (/ (ash 1 lognum))))
+
+(define-public (duration-dot-factor dotcount)
+"Given a count of the dots used to extend a musical duration, return
+the numeric factor by which they increase the duration."
+ (or (and (exact? dotcount) (integer? dotcount) (>= dotcount 0))
+ (scm-error 'wrong-type-arg "duration-dot-factor" "Not a count: ~S"
(list dotcount) #f))
+ (- 2 (/ (ash 1 dotcount))))
+
+(define-public (duration-length dur)
+"Return the overall length of a duration, as a number of whole notes.
+(Not to be confused with ly:duration-length, which returns a less-useful
+moment object.)"
+ (ly:moment-main (ly:duration-length dur)))
+
+(define-public (duration-visual dur)
+"Given a duration object, return the visual part of the duration (base
+note length and dot count), in the form of a duration object with
+non-visual scale factor 1."
+ (ly:make-duration (ly:duration-log dur) (ly:duration-dot-count dur) 1))
+
+(define-public (duration-visual-length dur)
+"Given a duration object, return the length of the visual part of the
+duration (base note length and dot count), as a number of whole notes."
+ (duration-length (duration-visual dur)))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; arithmetic
(define-public (average x . lst)
(/ (+ x (apply + lst)) (1+ (length lst))))
_______________________________________________
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel