From: David Kastrup <dak@gnu.org>
Date: Tue, 4 Aug 2015 15:32:38 +0000 (+0200)
Subject: Issue 4538: Provide \markupMap music function
X-Git-Tag: release/2.19.26-1~55
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=5d7dcf77fed5d0df3b25e0da59bba300e09b87cd;p=lilypond.git

Issue 4538: Provide \markupMap music function

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! }
}
---

diff --git a/input/regression/markup-map.ly b/input/regression/markup-map.ly
new file mode 100644
index 0000000000..dfa6984203
--- /dev/null
+++ b/input/regression/markup-map.ly
@@ -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! }
+}
diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly
index 9af5c88539..54590a4cdd 100644
--- a/ly/music-functions-init.ly
+++ b/ly/music-functions-init.ly
@@ -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.")