]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 4538: Provide \markupMap music function
authorDavid Kastrup <dak@gnu.org>
Tue, 4 Aug 2015 15:32:38 +0000 (17:32 +0200)
committerDavid Kastrup <dak@gnu.org>
Tue, 11 Aug 2015 06:24:13 +0000 (08:24 +0200)
This applies a markup function to all markup music properties matching a
given music property path.

For example,

\new Voice { g'2 c'' }
\addlyrics {
  \markupMap LyricEvent.text
             \markup \with-color #red \etc
             { Oh yes! }
}

input/regression/markup-map.ly [new file with mode: 0644]
ly/music-functions-init.ly

diff --git a/input/regression/markup-map.ly b/input/regression/markup-map.ly
new file mode 100644 (file)
index 0000000..dfa6984
--- /dev/null
@@ -0,0 +1,19 @@
+\version "2.19.26"
+
+\header {
+  texidoc = "@code{\\markupMap} can be used for applying a markup function
+to music properties throughout a music expressions, like the @code{text} of
+all contained lyric events."
+}
+
+\layout { ragged-right = ##t }
+
+\new Voice
+\markupMap TextScriptEvent.text
+           #italic-markup
+{ g'2^"See" c''^"this?" }
+\addlyrics {
+  \markupMap text
+             \markup \fontsize #5 \with-color #red \rotate #30 \etc
+  { Oh yes! }
+}
index 9af5c885395fffaf5a4b57215d4ba9ad462479ea..54590a4cdde8e9549ada4554d21a703fb716d2fa 100644 (file)
@@ -844,6 +844,37 @@ mark =
           (if label (set! (ly:music-property ev 'label) label))
           ev))))
 
+markupMap =
+#(define-music-function (path markupfun music)
+   (symbol-list-or-symbol? markup-function? ly:music?)
+   (_i "This applies the given markup function @var{markupfun} to all markup
+music properties matching @var{path} in @var{music}.
+
+For example,
+@example
+\\new Voice @{ g'2 c'' @}
+\\addlyrics @{
+  \\markupMap LyricEvent.text
+             \\markup \\with-color #red \\etc
+             @{ Oh yes! @}
+@}
+@end example
+")
+   (let* ((p (check-music-path path (*location*)))
+          (name (and p (car p)))
+          (prop (and p (cadr p))))
+     (if p
+         (for-some-music
+          (lambda (m)
+            (if (or (not name) (eq? (ly:music-property m 'name) name))
+                (let ((text (ly:music-property m prop)))
+                  (if (markup? text)
+                      (set! (ly:music-property m prop)
+                            (list markupfun text)))))
+            #f)
+          music)))
+   music)
+
 musicMap =
 #(define-music-function (proc mus) (procedure? ly:music?)
    (_i "Apply @var{proc} to @var{mus} and all of the music it contains.")