Reviewers: ,
Message:
Please review.
Description:
Improvements to \offset
Property can be specified with or without #' prefix.
Directed tweaks are possible.
Regtest:
--remove #' prefix before property names
--remove unnecessary # before numbers
--add example showing directed tweaks
Revise docstring of find-value-to-offset in `scm/music-functions.scm.'
Please review this at https://codereview.appspot.com/15850044/
Affected files (+57, -26 lines):
input/regression/offsets.ly
ly/music-functions-init.ly
scm/music-functions.scm
Index: input/regression/offsets.ly
diff --git a/input/regression/offsets.ly b/input/regression/offsets.ly
index
53489724036b8cabc7a89217f149cf98ed8d2b9f..624788e04ad59c34a2d4b866ad7ea2c7e3ef8a96
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,44 @@ default appearance. The command is demonstrated as a
tweak and as an override."
%% ARPEGGIO %%
% default
<c e g b>1\arpeggio
- <c e g b>1-\offset #'positions #'(-1 . 1) \arpeggio
+ <c e g b>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
+ c1-\offset padding 1 \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 +63,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
}
Index: ly/music-functions-init.ly
diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly
index
02c6ac6531a01775563d6afe61bd37827fb65066..25c8dd581cff92a114e09675357f51f12b70f7f9
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
+ #})
+ (make-music 'Music)))
+ ; 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},
Index: scm/music-functions.scm
diff --git a/scm/music-functions.scm b/scm/music-functions.scm
index
ccecf4b43d0cef88d43cce97b79d5a3b61449b28..383b7f3f6defb7e85373397b08b7b1000aaec08c
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)
_______________________________________________
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel