keepWithTag and removeWithTag.
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
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
-\version "2.3.16"
+\version "2.3.17"
\header {
texidoc = "The @code{\\tag} command marks music expressions with a
\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
}
}
}
(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:
(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."
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,