From 8cd2400e7e8c438ca3d3ec686e7d10d78122d3eb Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Tue, 23 Oct 2012 13:07:16 +0200 Subject: [PATCH] Issue 2917: Extend \keepWithTag to allow multiple tags Also extends \removeWithTag accordingly. --- ly/music-functions-init.ly | 40 +++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly index 71bd76ca54..b5af930f1d 100644 --- a/ly/music-functions-init.ly +++ b/ly/music-functions-init.ly @@ -501,15 +501,21 @@ instrumentSwitch = keepWithTag = -#(define-music-function (parser location tag music) (symbol? ly:music?) - (_i "Include only elements of @var{music} that are tagged with @var{tag}.") +#(define-music-function (parser location tag music) + (symbol-list-or-symbol? ly:music?) + (_i "Include only elements of @var{music} that are either untagged +or tagged with one of the tags in @var{tag}. @var{tag} may be either +a single symbol or a list of symbols.") (music-filter - (lambda (m) - (let* ((tags (ly:music-property m 'tags)) - (res (memq tag tags))) - (or - (eq? tags '()) - res))) + (if (symbol? tag) + (lambda (m) + (let ((music-tags (ly:music-property m 'tags))) + (or (null? music-tags) + (memq tag music-tags)))) + (lambda (m) + (let ((music-tags (ly:music-property m 'tags))) + (or (null? music-tags) + (any (lambda (t) (memq t music-tags)) tag))))) music)) key = @@ -1004,13 +1010,19 @@ relative = 'element music)) removeWithTag = -#(define-music-function (parser location tag music) (symbol? ly:music?) - (_i "Remove elements of @var{music} that are tagged with @var{tag}.") +#(define-music-function (parser location tag music) + (symbol-list-or-symbol? ly:music?) + (_i "Remove elements of @var{music} that are tagged with one of the +tags in @var{tag}. @var{tag} may be either a single symbol or a list +of symbols.") (music-filter - (lambda (m) - (let* ((tags (ly:music-property m 'tags)) - (res (memq tag tags))) - (not res))) + (if (symbol? tag) + (lambda (m) + (not (memq tag (ly:music-property m 'tags)))) + (lambda (m) + (let ((music-tags (ly:music-property m 'tags))) + (or (null? music-tags) + (not (any (lambda (t) (memq t music-tags)) tag)))))) music)) resetRelativeOctave = -- 2.39.2