From: Carl Sorensen Date: Thu, 24 Nov 2011 15:31:13 +0000 (-0700) Subject: Don't let dots go negative in scaleDurations -- Fix Issue 2048 X-Git-Tag: release/2.15.21-1~19 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=b74a70d8cf571d18e7fdca00e8d9fd90edbb539f;p=lilypond.git Don't let dots go negative in scaleDurations -- Fix Issue 2048 --- diff --git a/input/regression/shift-durations-negative-dots.ly b/input/regression/shift-durations-negative-dots.ly new file mode 100644 index 0000000000..d41ab2bc9f --- /dev/null +++ b/input/regression/shift-durations-negative-dots.ly @@ -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 } + diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly index 8b5cddf013..038f2ef6ac 100644 --- a/ly/music-functions-init.ly +++ b/ly/music-functions-init.ly @@ -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) diff --git a/scm/music-functions.scm b/scm/music-functions.scm index 3ea1ba887d..250defcdd2 100644 --- a/scm/music-functions.scm +++ b/scm/music-functions.scm @@ -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)