]> git.donarmstrong.com Git - lilypond.git/commitdiff
Don't let dots go negative in scaleDurations -- Fix Issue 2048
authorCarl Sorensen <c_sorensen@byu.edu>
Thu, 24 Nov 2011 15:31:13 +0000 (08:31 -0700)
committerCarl Sorensen <c_sorensen@byu.edu>
Wed, 30 Nov 2011 21:16:13 +0000 (14:16 -0700)
input/regression/shift-durations-negative-dots.ly [new file with mode: 0644]
ly/music-functions-init.ly
scm/music-functions.scm

diff --git a/input/regression/shift-durations-negative-dots.ly b/input/regression/shift-durations-negative-dots.ly
new file mode 100644 (file)
index 0000000..d41ab2b
--- /dev/null
@@ -0,0 +1,12 @@
+\version "2.15.21"
+
+\header {
+
+  texidoc = "
+  @code{\shiftDurations} can use negative dot values without causing
+  a crash.
+  "
+}
+
+\shiftDurations #1 #-1 { c''1 }
+
index 8b5cddf013b85acc882b66c15c8be09878375430..038f2ef6ac89b9a42ac19a9df7d7c3179aaa98fb 100644 (file)
@@ -1024,7 +1024,8 @@ a context modification duplicating their effect.")
 shiftDurations =
 #(define-music-function (parser location dur dots arg)
    (integer? integer? ly:music?)
-   (_i "Scale @var{arg} up by a factor of 2^@var{dur}*(2-(1/2)^@var{dots}).")
+   (_i "Change the duration of @var{arg} by adding @var{dur} to the
+@code{durlog} of @var{arg} and @var{dots} to the @code{dots} of @var{arg}.")
 
    (music-map
     (lambda (x)
index 3ea1ba887d282d06190139bb2abd73c3e267dfa3..250defcdd2f98bdaa09761b16a98eb1d62cd2802 100644 (file)
@@ -233,15 +233,16 @@ Returns `obj'.
 
 (define-public (shift-one-duration-log music shift dot)
   "Add @var{shift} to @code{duration-log} of @code{'duration} in
-@var{music} and optionally @var{dot} to any note encountered.  This
-scales the music up by a factor `2^@var{shift} * (2 - (1/2)^@var{dot})'."
+@var{music} and optionally @var{dot} to any note encountered.
+The number of dots in the shifted music may not be less than zero."
   (let ((d (ly:music-property music 'duration)))
     (if (ly:duration? d)
        (let* ((cp (ly:duration-factor d))
-              (nd (ly:make-duration (+ shift (ly:duration-log d))
-                                    (+ dot (ly:duration-dot-count d))
-                                    (car cp)
-                                    (cdr cp))))
+              (nd (ly:make-duration
+                    (+ shift (ly:duration-log d))
+                    (max 0 (+ dot (ly:duration-dot-count d)))
+                   (car cp)
+                   (cdr cp))))
          (set! (ly:music-property music 'duration) nd)))
     music))
 
@@ -1485,7 +1486,7 @@ Entries that conform with the current key signature are not invalidated."
                   entry
                   (cons (car entry) (cons 'clef (cddr entry))))))
           (ly:context-property context 'localKeySignature)))))
-                   
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (define-public (skip-of-length mus)