From ff49e9c43cf3180ee1d0f0a7c63d50a926e2fb5e Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sat, 18 Sep 2004 08:56:08 +0000 Subject: [PATCH] (keepWithTag): add music functions keepWithTag and removeWithTag. --- ChangeLog | 3 +++ Documentation/user/notation.itely | 9 +++++---- input/regression/tag-filter.ly | 8 ++++---- ly/music-functions-init.ly | 21 +++++++++++++++++++++ scm/music-functions.scm | 10 +--------- scripts/convert-ly.py | 3 ++- 6 files changed, 36 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9cac9e3e14..27e9139270 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2004-09-18 Han-Wen Nienhuys + * 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 diff --git a/Documentation/user/notation.itely b/Documentation/user/notation.itely index d1c0efa885..58673e3da6 100644 --- a/Documentation/user/notation.itely +++ b/Documentation/user/notation.itely @@ -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 diff --git a/input/regression/tag-filter.ly b/input/regression/tag-filter.ly index 5b2bd7df08..004f308631 100644 --- a/input/regression/tag-filter.ly +++ b/input/regression/tag-filter.ly @@ -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 } } } diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly index a36284df32..0410976cbb 100644 --- a/ly/music-functions-init.ly +++ b/ly/music-functions-init.ly @@ -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: diff --git a/scm/music-functions.scm b/scm/music-functions.scm index aa3ecb9fb0..20b88d111c 100644 --- a/scm/music-functions.scm +++ b/scm/music-functions.scm @@ -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)))) @@ -60,14 +60,6 @@ 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." diff --git a/scripts/convert-ly.py b/scripts/convert-ly.py index ad5bfd3cc1..74a62ff7d2 100644 --- a/scripts/convert-ly.py +++ b/scripts/convert-ly.py @@ -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, -- 2.39.2