Hi all,

I'm trying to get the combination of consecutive MultiMeasureRests working but got stuck.

I have the function combineMMRests from
http://lilypond.1069038.n5.nabble.com/new-snippet-combine-multimeasure-rests-td144688.html

which works pretty well usually, but it doesn't merge rests when "something" is between them, even if that "something" is actually "nothing".

Consider the attached files.
Uncommenting one of the lines in the music expression causes either a \barNumberCheck or an empty music function to happen between the two rests, with the result of not merging them properly.

As far as I can see the problem is in the combinable-rest? predicate defined in the .ily file. I assume what I'd want is extending the list of cases where this predicate returns true by some more (currently the barnumber checks and empty music expressions returned by a function. Of course it may be that I'd find more cases in the future, but for now that would be it.

So I think my question is: is there a way to test if a list element is the result of an empty music function?

Thanks for any hints, explanations or improvements.
Urs
\version "2.16.0"

\include "combineMultimeasureRests.ily"

insert =
#(define-music-function (parser location)()
   #{ #})

music = \relative c' {

  \combineMMRests {
    c2 c
    R1*4 |
    %\barNumberCheck #6
    %\insert
    R1*3
    c1
  }
}

\score {
  \new Staff {
    \compressFullBarRests
    \music
  }
}
\version "2.16.0"

% Taken from improved version from
% 
http://lilypond.1069038.n5.nabble.com/new-snippet-combine-multimeasure-rests-td144688.html


#(define (add-durations dur1 dur2)
         (let* ((len1 (ly:duration-length dur1))
                (len2 (ly:duration-length dur2))
                (mult (ly:moment-div (ly:moment-add len1 len2) len1)))
               (ly:make-duration (ly:duration-log dur1)
                                 (ly:duration-dot-count dur1)
                                 (* (ly:duration-scale dur1) (ly:moment-main 
mult)))))

#(define (combinable-rest? rest)
         (and (ly:music? rest)
              (or (eq? 'MultiMeasureRestMusic (ly:music-property rest 'name))
                  (eq? 'SkipEvent (ly:music-property rest 'name)))
              (null? (ly:music-property rest 'articulations))))

#(define (combine-rests rest1 rest2)
         (make-music (ly:music-property rest1 'name)
           'duration (add-durations (ly:music-property rest1 'duration)
                                    (ly:music-property rest2 'duration))
           'articulations '()))

#(define (consolidator curr rest)
         (if (and (combinable-rest? curr)
                  (not (null? rest)))
             (if (and (combinable-rest? (car rest))
                      (eq? (ly:music-property curr 'name) (ly:music-property 
(car rest) 'name)))
                 (consolidator (combine-rests curr (car rest))
                               (cdr rest))
                 (if (eq? 'BarCheck (ly:music-property (car rest) 'name))
                     (consolidator curr (cdr rest))
                     (cons curr rest)))
         (cons curr rest)))

#(define (accumulate-result output input)
         (if (null? input)
             output
             (let ((done output)
                   (curr (car input))
                   (rest (cdr input)))
                  (if (null? rest)
                      (append done (list curr))
                      (let ((prev (consolidator curr rest)))
                           (accumulate-result (append done (list (car prev))) 
(cdr prev)))))))

#(define (condense music)
         (let* ((output music)
               (elts (ly:music-property output 'elements))
               (elt (ly:music-property output 'element)))
              (if (pair? elts)
                  (ly:music-set-property! output 'elements (map condense 
(accumulate-result '() elts))))
              (if (ly:music? elt)
                  (ly:music-set-property! output 'element (condense elt)))
              output))

combineMMRests =
#(define-music-function (parser location music) (ly:music?)
                        (condense music))
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to