]> git.donarmstrong.com Git - lilypond.git/commitdiff
Give \tweak an optional grob parameter for tweaking indirect grobs
authorDavid Kastrup <dak@gnu.org>
Tue, 15 May 2012 17:11:03 +0000 (19:11 +0200)
committerDavid Kastrup <dak@gnu.org>
Sun, 20 May 2012 18:33:06 +0000 (20:33 +0200)
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
ly/music-functions-init.ly

index b145f3dd4b3113d8d92eda0d75da0d2247a2902e..d1c3c240a4a83fb7ae7fd28ff58cac68ecbca158 100644 (file)
@@ -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));
         }
     }
 }
index 842da9ace606dc026169808b6b5e664603cfc214..6244f1dd7d89042b76e1e6bfd871df3fca1199d5 100644 (file)
@@ -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?)