]> git.donarmstrong.com Git - lilypond.git/commitdiff
(keepWithTag): add music functions
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sat, 18 Sep 2004 08:56:08 +0000 (08:56 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sat, 18 Sep 2004 08:56:08 +0000 (08:56 +0000)
keepWithTag and removeWithTag.

ChangeLog
Documentation/user/notation.itely
input/regression/tag-filter.ly
ly/music-functions-init.ly
scm/music-functions.scm
scripts/convert-ly.py

index 9cac9e3e142849a1212ac8fd3efa52c933ee69fd..27e91392702d2b6d4428a6798e640cd6e79f4b81 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2004-09-18  Han-Wen Nienhuys   <hanwen@xs4all.nl>
 
+       * ly/music-functions-init.ly (keepWithTag): add music functions
+       keepWithTag and removeWithTag
+
        * lily/quote-iterator.cc (Quote_iterator): init transposed_musics_.
 
        * lily/accidental-engraver.cc (recent_enough): interpret laziness
index d1c0efa885df58dd2983c8716df855602ed6c653..58673e3da6503fd7167e0a05c2586ce42dd5bd3f 100644 (file)
@@ -5383,19 +5383,20 @@ to an articulation, for example,
 
 This defines a note with a conditional fingering indication.
 
-By applying the @code{remove-tag} function, tagged expressions can be
-filtered.  For example,
+By applying the @code{removeTag} music function, tagged expressions
+can be filtered.  For example,
 @example
 <<
   @var{the music}
-  \applymusic #(remove-tag 'score) @var{the music}
-  \applymusic #(remove-tag 'part) @var{the music}
+  \onlyWithTag #'score @var{the music}
+  \onlyWithTag #'part @var{the music}
 >>
 @end example
 would yield
 
 @lilypondfile[quote]{tag-filter.ly}
 
+
 The argument of the @code{\tag} command should be a symbol, or a list
 of symbols, for example,
 @example
index 5b2bd7df082a9feea8c75c4887e337cdfc762d3c..004f3086311adca4bfca1a1b3fef1f8b210d20ec 100644 (file)
@@ -1,5 +1,5 @@
 
-\version "2.3.16"
+\version "2.3.17"
 \header {
 
 texidoc = "The @code{\\tag} command marks music expressions with a
@@ -31,18 +31,18 @@ common =
 
 
 \score {
-     \simultaneous { 
+    \simultaneous { 
     \new Staff {
        \set Staff.instrument = #"both"
        \common
        }
     \new Staff {
        \set Staff.instrument = #"part"
-       \applymusic #(remove-tag 'score) \common
+       \keepWithTag #'part \common
        }
     \new Staff {
        \set Staff.instrument = #"score"
-       \applymusic #(remove-tag 'part) \common
+       \keepWithTag #'score \common
        }
     }
 }
index a36284df328dc8b5875bc4e9908a0d469d725fb4..0410976cbb522ec1d64af34914776a7c03ba7cb2 100644 (file)
@@ -48,6 +48,27 @@ makeClusters = #(def-music-function
                (music-map note-to-cluster arg))
 
 
+removeWithTag = 
+#(def-music-function
+  (location tag music) (symbol? ly:music?)
+  (music-filter
+   (lambda (m)
+    (let* ((tags (ly:music-property m 'tags))
+           (res (memq tag tags)))
+       (not res)))))
+             
+keepWithTag =
+#(def-music-function
+  (location tag music) (symbol? ly:music?)
+  (music-filter
+   (lambda (m)
+    (let* ((tags (ly:music-property m 'tags))
+           (res (memq tag tags)))
+       (or
+       (eq? tags '())
+       (memq tag tags))))
+   music))
+
 %{
 
 TODO:
index aa3ecb9fb0598a872e4789bcbc27392097a1e949..20b88d111c118d8a443bb8d15b6b6f9b7c388dda 100644 (file)
@@ -48,7 +48,7 @@
       (set! (ly:music-property music 'elements) filtered-es)
       (set! (ly:music-property music 'articulations) filtered-as)
       ;; if filtering emptied the expression, we remove it completely.
-      (if (or (pred? music)
+      (if (or (not (pred? music))
              (and (eq? filtered-es '()) (not (ly:music? e))
                   (or (not (eq? es '()))
                       (ly:music? e))))
       music
       (make-music 'Music)))      ;must return music.
 
-(define-public (remove-tag tag)
-  (lambda (mus)
-    (music-filter
-     (lambda (m)
-       (let* ((tags (ly:music-property m 'tags))
-             (res (memq tag tags)))
-        res))
-     mus)))
 
 (define-public (display-music music)
   "Display music, not done with music-map for clarity of presentation."
index ad5bfd3cc1467398206bf602354857fd4598c25c..74a62ff7d2eed14de54ea13f8f50b5c43ac2e1fa 100644 (file)
@@ -2199,7 +2199,8 @@ fold \new FooContext \foomode into \foo.'''))
 
 def conv (str):
        str = re.sub (r'(slur|stem|phrasingSlur|tie|dynamic|dots|tuplet|arpeggio|)Both', r'\1Neutral', str)
-
+       str = re.sub (r"\\applymusic\s*#\(remove-tag\s*'([a-z-0-9]+)\)",
+                     r"\\removeTag #'\1", str)
        return str
 
 conversions.append (((2, 3, 17), conv,