]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 4500: Support chaining \tweak variant of overrides
authorDavid Kastrup <dak@gnu.org>
Sat, 11 Jul 2015 11:13:34 +0000 (13:13 +0200)
committerDavid Kastrup <dak@gnu.org>
Tue, 21 Jul 2015 06:25:03 +0000 (08:25 +0200)
Something like

{ \once \tweak color #red \tweak font-size 2 NoteHead
  <c' e'>2 c'2
}

previously failed to result in having both tweaks register.

input/regression/tweaks-as-overrides.ly [new file with mode: 0644]
ly/music-functions-init.ly

diff --git a/input/regression/tweaks-as-overrides.ly b/input/regression/tweaks-as-overrides.ly
new file mode 100644 (file)
index 0000000..7bece45
--- /dev/null
@@ -0,0 +1,18 @@
+\version "2.19.24"
+
+\header {
+  texidoc = "@code{\\tweak} commands can be used to effect overrides
+when given a symbol list as argument.  Such overrides can be the
+target of another tweak, with the tweaks accumulating.  This example
+should show the starting chord with blue, cross-styled note heads
+and a red stem."
+}
+
+\layout { ragged-right = ##t }
+
+{
+  \once \tweak Stem.color #red
+  \tweak color #blue
+  \tweak style #'cross NoteHead
+  <c' e'>2 c'2
+}
index 01169d1e951f4f0dd4c08fee8ff3af14dc4fcfaa..7699d638d44a832a8a63100377723d519ae4cf6b 100644 (file)
@@ -1836,14 +1836,53 @@ property (inside of an alist) is tweaked.")
                                  #:start 1
                                  #:default #t
                                  #:min 2)))
-         (if p
-             (set! (ly:music-property item 'tweaks)
-                   (acons (cond ((pair? (cddr p)) p)
-                                ((symbol? (car p))
-                                 (cons (car p) (cadr p)))
-                                (else (cadr p)))
-                          value
-                          (ly:music-property item 'tweaks))))
+         (cond ((not p))
+               ;; p now contains at least two elements.  The first
+               ;; element is #t when no grob has been explicitly
+               ;; specified, otherwise it is a grob name.
+               ((music-is-of-type? item 'context-specification)
+                ;; This is essentially dealing with the case
+                ;; \tweak color #red \tweak font-size #3 NoteHead
+                ;; namely when stacked tweaks end in a symbol list
+                ;; rather than a music expression.
+                ;;
+                ;; We have a tweak here to convert into an override,
+                ;; so we need to know the grob to apply it to.  That's
+                ;; easy if we have a directed tweak, and otherwise we
+                ;; need to find the symbol in the expression itself.
+                (let* ((elt (ly:music-property item 'element))
+                       (seq (if (music-is-of-type? elt 'sequential-music)
+                                elt
+                                (make-sequential-music (list elt))))
+                       (elts (ly:music-property seq 'elements))
+                       (symbol (if (symbol? (car p))
+                                   (car p)
+                                   (and (pair? elts)
+                                        (ly:music-property (car elts)
+                                                           'symbol)))))
+                  (if (symbol? symbol)
+                      (begin
+                        (set! (ly:music-property seq 'elements)
+                              (cons (make-music 'OverrideProperty
+                                                'symbol symbol
+                                                'grob-property-path (cdr p)
+                                                'pop-first #t
+                                                'grob-value value
+                                                'origin (*location*))
+                                    elts))
+                        (set! (ly:music-property item 'element) seq))
+                      (begin
+                        (ly:parser-error (_ "Cannot \\tweak")
+                                         (*location*))
+                        (ly:music-message item (_ "untweakable"))))))
+               (else
+                (set! (ly:music-property item 'tweaks)
+                      (acons (cond ((pair? (cddr p)) p)
+                                   ((symbol? (car p))
+                                    (cons (car p) (cadr p)))
+                                   (else (cadr p)))
+                             value
+                             (ly:music-property item 'tweaks)))))
          item)
        (propertyOverride (append item (if (symbol? prop) (list prop) prop)) value)))