From: David Nalesnik Date: Mon, 21 Oct 2013 21:53:31 +0000 (-0500) Subject: Improvements to \offset X-Git-Tag: release/2.17.95-1~4^2~11 X-Git-Url: https://git.donarmstrong.com/?p=lilypond.git;a=commitdiff_plain;h=bf168d9084446839ce050db03d1b828291e88e0c Improvements to \offset Property can be specified with or without #' prefix. Directed tweaks are possible. Music is returned in case of a failed tweak on that music. This eliminates cryptic "post-event expected" error. Regtest: --remove #' prefix before property names --remove unnecessary # before numbers --add example showing directed tweaks --faulty tweak converted to an override of correct property Revise docstring of find-value-to-offset in `scm/music-functions.scm.' --- diff --git a/input/regression/offsets.ly b/input/regression/offsets.ly index 5348972403..878664e4dd 100644 --- a/input/regression/offsets.ly +++ b/input/regression/offsets.ly @@ -1,4 +1,4 @@ -\version "2.17.28" +\version "2.17.29" \header { texidoc = "The @code{\\offset} command may be used to displace various properties @@ -18,44 +18,45 @@ default appearance. The command is demonstrated as a tweak and as an override." %% ARPEGGIO %% % default 1\arpeggio - 1-\offset #'positions #'(-1 . 1) \arpeggio + 1-\offset positions #'(-1 . 1) \arpeggio \bar "||" %% BREATHING SIGN %% % default c1 \breathe c1 - \once \offset #'Y-offset #1 BreathingSign + \once \offset Y-offset 1 BreathingSign \breathe \bar "||" %% DYNAMICS %% % default c1\f - \once \offset #'X-offset #-1 DynamicText + \once \offset X-offset #-1 DynamicText c1\f % DynamicLineSpanner - c1-\offset #'padding #1 \f + \once \offset padding 1 DynamicLineSpanner + c1\f \bar "||" %% BEAMS %% % default c'8 d e f - \once \offset #'positions #'(-1 . -1) Voice.Beam + \once \offset positions #'(-1 . -1) Voice.Beam c8 d e f % same effect as an offset of '(-2 . -2) - \once \offset #'positions #-2 Beam + \once \offset positions #-2 Beam c8 d e f \override Beam.breakable = ##t - c8-\offset #'positions #'((-1 . -3) (-3 . -1)) [ d e f + c8-\offset positions #'((-1 . -3) (-3 . -1)) [ d e f \break - g8 f e d] c-\offset #'beam-thickness #0.48 [ d e f] + g8 f e d] c-\offset beam-thickness 0.48 [ d e f] \bar "||" %% TEXT SPANNERS %% c4\startTextSpan d e f\stopTextSpan - \once \offset #'dash-fraction #'(0.1 0.3) TextSpanner - \once \offset #'staff-padding #'(1.0 2.0) TextSpanner + \once \offset dash-fraction #'(0.1 0.3) TextSpanner + \once \offset staff-padding #'(1.0 2.0) TextSpanner c4\startTextSpan d e f \break c4 d e f\stopTextSpan @@ -63,11 +64,19 @@ default appearance. The command is demonstrated as a tweak and as an override." %% SLURS %% % this duplicates the effect of the \shape command - \offset #'control-points #'( + \offset control-points #'( ((0 . 0) (0 . 1) (0 . 2) (0 . 1)) ((1 . 0) (0 . 4) (0 . 4) (0 . 0)) ) Slur - c4-\offset #'line-thickness #'(0 10) ( d e f + c4-\offset line-thickness #'(0 10) ( d e f \break c4 d e f) + \bar "||" + + %% ACCIDENTAL, STEM %% + % this illustrates use of \offset as a directed tweak + cis2 + \offset AccidentalPlacement.right-padding 0.5 + \offset Stem.thickness 4.0 + cis!2 } diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly index dbecbf2f44..bf738074cd 100644 --- a/ly/music-functions-init.ly +++ b/ly/music-functions-init.ly @@ -701,17 +701,39 @@ offset = a music expression, the result is the same music expression with an appropriate tweak applied.") (if (ly:music? item) - #{ \tweak #property #(offsetter property offsets) #item #} - (if (check-grob-path item parser location - #:default 'Bottom - #:min 2 - #:max 2) - #{ - \override #item . #property = - #(offsetter property offsets) - #} - (make-music 'Music)))) - + ; In case of a tweak, grob property path is Grob.property + (let ((prop-path (check-grob-path + (if (symbol? property) + (list property) + property) + parser location + #:start 1 #:default #t #:min 2 #:max 2))) + (if prop-path + ; If the head of the grob property path is a symbol--i.e., + ; a grob name, produce a directed tweak. Otherwise, create + ; an ordinary tweak. + (if (symbol? (car prop-path)) + #{ + \tweak #prop-path #(offsetter (second prop-path) offsets) #item + #} + #{ + \tweak #(second prop-path) #(offsetter (second prop-path) offsets) #item + #}) + item)) + ; In case of an override, grob property path is Context.Grob.property. + (let ((prop-path (check-grob-path + (append item + (if (symbol? property) + (list property) + property)) + parser location + #:default 'Bottom #:min 3 #:max 3))) + (if prop-path + #{ + \override #prop-path = #(offsetter (third prop-path) offsets) + #} + (make-music 'Music))))) + omit = #(define-music-function (parser location item) (symbol-list-or-music?) (_i "Set @var{item}'s @samp{stencil} property to @code{#f}, diff --git a/scm/music-functions.scm b/scm/music-functions.scm index ccecf4b43d..383b7f3f6d 100644 --- a/scm/music-functions.scm +++ b/scm/music-functions.scm @@ -2086,8 +2086,9 @@ Broken measures are numbered in parentheses." ;; The following are used by the \offset function (define (find-value-to-offset prop self alist) - "Return the first value of the property @var{prop} in the property alist -@var{alist} @em{after} having found @var{self}." + "Return the first value of the property @var{prop} in the property +alist @var{alist} -- after having found @var{self}. If @var{self} is +not found, return the first value of @var{prop}." (let ((segment (member (cons prop self) alist))) (if (not segment) (assoc-get prop alist)