]> git.donarmstrong.com Git - lilypond.git/commitdiff
Improvements to \offset
authorDavid Nalesnik <david.nalesnik@gmail.com>
Mon, 21 Oct 2013 21:53:31 +0000 (16:53 -0500)
committerDavid Nalesnik <david.nalesnik@gmail.com>
Thu, 31 Oct 2013 15:44:34 +0000 (10:44 -0500)
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.'

input/regression/offsets.ly
ly/music-functions-init.ly
scm/music-functions.scm

index 53489724036b8cabc7a89217f149cf98ed8d2b9f..878664e4dd114afafc76f392e2709a1d72def3ce 100644 (file)
@@ -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
   <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
+  \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
 }
index dbecbf2f4413cbb8b191fd617b095dea11366876..bf738074cda120346f26b231c6854bd427ac72e7 100644 (file)
@@ -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},
index ccecf4b43d0cef88d43cce97b79d5a3b61449b28..383b7f3f6defb7e85373397b08b7b1000aaec08c 100644 (file)
@@ -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)