From 11a9e5701316d46d34993fadb85482282c9753cc Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Sat, 11 Jul 2015 13:13:34 +0200 Subject: [PATCH] Issue 4500: Support chaining \tweak variant of overrides Something like { \once \tweak color #red \tweak font-size 2 NoteHead 2 c'2 } previously failed to result in having both tweaks register. --- input/regression/tweaks-as-overrides.ly | 18 ++++++++ ly/music-functions-init.ly | 55 +++++++++++++++++++++---- 2 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 input/regression/tweaks-as-overrides.ly diff --git a/input/regression/tweaks-as-overrides.ly b/input/regression/tweaks-as-overrides.ly new file mode 100644 index 0000000000..7bece45db8 --- /dev/null +++ b/input/regression/tweaks-as-overrides.ly @@ -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 + 2 c'2 +} diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly index 01169d1e95..7699d638d4 100644 --- a/ly/music-functions-init.ly +++ b/ly/music-functions-init.ly @@ -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))) -- 2.39.5