From 0b716515bfd610a04bbe4289f171f3cd80a0fc14 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Tue, 15 May 2012 19:11:03 +0200 Subject: [PATCH] Give \tweak an optional grob parameter for tweaking indirect grobs You can now use something akin to \tweak Accidental #'color #red cis' for tweaking a grob created indirectly from the given music expression. --- lily/tweak-engraver.cc | 15 +++++++++++++-- ly/music-functions-init.ly | 30 ++++++++++++++++++------------ 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/lily/tweak-engraver.cc b/lily/tweak-engraver.cc index b145f3dd4b..d1c3c240a4 100644 --- a/lily/tweak-engraver.cc +++ b/lily/tweak-engraver.cc @@ -39,12 +39,23 @@ Tweak_engraver::Tweak_engraver () void Tweak_engraver::acknowledge_grob (Grob_info info) { - if (Stream_event *ev = info.event_cause ()) + Stream_event *ev = info.event_cause (); + bool direct = ev; + SCM grobname = SCM_UNDEFINED; + if (!direct) + ev = info.ultimate_event_cause (); + if (ev) { for (SCM s = ev->get_property ("tweaks"); scm_is_pair (s); s = scm_cdr (s)) { - info.grob ()->set_property (scm_caar (s), scm_cdar (s)); + if (scm_is_pair (scm_caar (s))) { + if (SCM_UNBNDP (grobname)) + grobname = scm_from_locale_symbol (info.grob ()->name ().c_str ()); + if (scm_is_eq (scm_caaar (s), grobname)) + info.grob ()->set_property (scm_cdaar (s), scm_cdar (s)); + } else if (direct) + info.grob ()->set_property (scm_caar (s), scm_cdar (s)); } } } diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly index 842da9ace6..6244f1dd7d 100644 --- a/ly/music-functions-init.ly +++ b/ly/music-functions-init.ly @@ -1119,21 +1119,27 @@ transposition = 'Staff)) tweak = -#(define-music-function (parser location sym val arg) - (symbol? scheme? ly:music?) - (_i "Add @code{sym . val} to the @code{tweaks} property of @var{arg}.") - - (if (equal? (object-property sym 'backend-type?) #f) +#(define-music-function (parser location grob prop value music) + ((string?) symbol? scheme? ly:music?) + (_i "Add a tweak to the following @var{music}. +Layout objects created by @var{music} get their property @var{prop} +set to @var{value}. If @var{grob} is specified, like with +@example +\\tweak Accidental #'color #red cis' +@end example +an indirectly created grob (@samp{Accidental} is caused by +@samp{NoteHead}) can be tweaked; otherwise only directly created grobs +are affected.") + (if (not (object-property prop 'backend-type?)) (begin - (ly:input-warning location (_ "cannot find property type-check for ~a") sym) + (ly:input-warning location (_ "cannot find property type-check for ~a") prop) (ly:warning (_ "doing assignment anyway")))) (set! - (ly:music-property arg 'tweaks) - (acons sym val - (ly:music-property arg 'tweaks))) - arg) - - + (ly:music-property music 'tweaks) + (acons (if grob (cons (string->symbol grob) prop) prop) + value + (ly:music-property music 'tweaks))) + music) unfoldRepeats = #(define-music-function (parser location music) (ly:music?) -- 2.39.2