From 8a493b7bc9aa4d34cd2970fc2223ec6920f0ed02 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Thu, 15 Sep 2016 14:50:14 +0200 Subject: Issue 4972: Make music-filter more conservative Deleting music when its 'elements field becomes null? led to repeat chords disappearing when articulations were removed. --- scm/music-functions.scm | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/scm/music-functions.scm b/scm/music-functions.scm index 9c36ceaf4d..e7728ec889 100644 --- a/scm/music-functions.scm +++ b/scm/music-functions.scm @@ -82,31 +82,33 @@ First it recurses over the children, then the function is applied to (define-public (music-filter pred? music) "Filter out music expressions that do not satisfy @var{pred?}." - (define (inner-music-filter pred? music) + (define (inner-music-filter music) "Recursive function." (let* ((es (ly:music-property music 'elements)) (e (ly:music-property music 'element)) (as (ly:music-property music 'articulations)) - (filtered-as (filter ly:music? (map (lambda (y) (inner-music-filter pred? y)) as))) + (filtered-as (filter ly:music? (map inner-music-filter as))) (filtered-e (if (ly:music? e) - (inner-music-filter pred? e) + (inner-music-filter e) e)) - (filtered-es (filter ly:music? (map (lambda (y) (inner-music-filter pred? y)) es)))) + (filtered-es (filter ly:music? (map inner-music-filter es)))) (if (not (null? e)) (set! (ly:music-property music 'element) filtered-e)) (if (not (null? es)) (set! (ly:music-property music 'elements) filtered-es)) (if (not (null? as)) (set! (ly:music-property music 'articulations) filtered-as)) - ;; if filtering emptied the expression, we remove it completely. + ;; if filtering invalidated 'element, we remove the music unless + ;; there are remaining 'elements in which case we just hope and + ;; pray. (if (or (not (pred? music)) - (and (eq? filtered-es '()) (not (ly:music? e)) - (or (not (eq? es '())) - (ly:music? e)))) + (and (null? filtered-es) + (not (ly:music? filtered-e)) + (ly:music? e))) (set! music '())) music)) - (set! music (inner-music-filter pred? music)) + (set! music (inner-music-filter music)) (if (ly:music? music) music (make-music 'Music))) ;must return music. -- cgit v1.2.3