%%%%%%%%%%% functions %%%%%%%%%%%%%%%%% #(define currentmoment (ly:make-moment 0 1 0 1)) #(define (clean-Music music) (music-filter (lambda (evt) ;% don't keep simultaneous and sequential music with empty 'elements (or (not (eq? 'EventChord (ly:music-property evt 'name))) (pair? (ly:music-property evt 'elements)) (pair? (ly:music-property evt 'articulations)) (ly:music? (ly:music-property evt 'element)) ) ) (music-filter ;% don't keep articulations or slurs with no notes assigned to (lambda (evt) (let ((elts (ly:music-property evt 'elements))) (not (and (eq? (ly:music-property evt 'name) 'EventChord) (pair? elts) (not (memq (ly:music-property (car elts) 'name) (list 'NoteEvent 'RestEvent))) ))) ) music)) ) #(define (extract-Music music from to) ;% from and to as moment (let* ( (musicname (ly:music-property music 'name)) (elts (ly:music-property music 'elements)) (elt (ly:music-property music 'element)) (dur (ly:music-property music 'duration)) (res music) ) (begin ;%(display musicname)(newline) (cond ((pair? elts) (if (not (eq? musicname 'SimultaneousMusic)) (set! (ly:music-property music 'elements) ;% for SequentialMusic (filter (lambda (evt)(extract-Music evt from to)) elts ) ) ;% for SimultaneousMusic (let ( (maxmoment (ly:make-moment 0 1 0 1)) (savemoment currentmoment) (tempmoment (ly:make-moment 0 1 0 1)) (resmusic (make-music 'Music))) (begin (set! (ly:music-property music 'elements) (filter (lambda (evt) (begin (set! resmusic (extract-Music evt from to)) (set! tempmoment (ly:moment-sub currentmoment savemoment)) (if (ly:moment> g'4\< a b c\! < b\! }>> d4( c) b-. a-. <<{g1-> g4-. f-. e( d)}\\{g4 f e d e2 r}>> c1} \score {<< \new Staff {\music } %% original \new Staff {R1*2 \extractMusic \music s1*2 s1*4 %% extract the music begining at the 2 measures and during 4 measures R1*2 } >>} %%%%%%%%%%%%%%%%%%%%%%