]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 2717: Implement \single for converting overrides to tweaks
authorDavid Kastrup <dak@gnu.org>
Sun, 16 Sep 2012 20:04:07 +0000 (22:04 +0200)
committerDavid Kastrup <dak@gnu.org>
Mon, 1 Oct 2012 05:17:16 +0000 (07:17 +0200)
\single, like \once, can be applied to music consisting of one or more
overrides.  It translates such an override set, for example
\easyHeadsOn, into a tweak on the following music item, so you can use
it like

{ < \single\easyHeadsOn c' g' >2 q }

inside of a chord and have it only affect a single notehead of the
chord when \once\easyHeadsOn would affect all noteheads.

In that manner, most overrides defined in ly/property-init.ly
are made available as tweaks.

ly/music-functions-init.ly

index 0fa79af3ddb63acd68e1861710c29cfa6903ccf6..26db17c5ede8ce07e9b72f78fa7d05c0f82a7cbf 100644 (file)
@@ -1146,6 +1146,31 @@ shiftDurations =
     (lambda (x)
       (shift-one-duration-log x dur dots)) arg))
 
+single =
+#(define-music-function (parser location overrides music)
+   (ly:music? ly:music?)
+   (_i "Convert @var{overrides} to tweaks and apply them to @var{music}.
+This does not convert @code{\\revert}, @code{\\set} or @code{\\unset}
+and ignores nested overrides.")
+   (set! (ly:music-property music 'tweaks)
+         (fold-some-music
+          (lambda (m) (eq? (ly:music-property m 'name)
+                           'OverrideProperty))
+          (lambda (m tweaks)
+            (let ((p (cond
+                      ((ly:music-property m 'grob-property #f) => list)
+                      (else
+                       (ly:music-property m 'grob-property-path)))))
+              (if (pair? (cdr p))
+                  tweaks ;ignore nested properties
+                  (acons (cons (ly:music-property m 'symbol) ;grob name
+                               (car p)) ;grob property
+                         (ly:music-property m 'grob-value)
+                         tweaks))))
+          (ly:music-property music 'tweaks)
+          overrides))
+   music)
+
 skip =
 #(define-music-function (parser location dur) (ly:duration?)
   (_i "Skip forward by @var{dur}.")