]> git.donarmstrong.com Git - lilypond.git/blob - scm/autochange.scm
Fix some bugs in the dynamic engraver and PostScript backend
[lilypond.git] / scm / autochange.scm
1
2
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4 ;; autochange - fairly related to part combining.
5
6 (define-public (make-autochange-music music)
7   (define (generate-split-list change-moment event-list acc)
8     (if (null? event-list)
9         acc
10         (let* ((now-tun (caar event-list))
11                (evs (map car (cdar event-list)))
12                (now (car now-tun))
13                (notes (filter (lambda (x)
14                                 (equal? (ly:music-property  x 'name) 'NoteEvent))
15                               evs))
16                (pitch (if (pair? notes)
17                           (ly:music-property (car notes) 'pitch)
18                           #f)))
19           ;; tail recursive.
20           (if (and pitch (not (= (ly:pitch-steps pitch) 0)))
21               (generate-split-list #f
22                                    (cdr event-list)
23                                    (cons (cons
24
25                                           (if change-moment
26                                               change-moment
27                                               now)
28                                           (sign (ly:pitch-steps pitch))) acc))
29               (generate-split-list
30                (if pitch #f now)
31                (cdr event-list) acc)))))
32   
33   (set! noticed '())
34   (let* ((m (make-music 'AutoChangeMusic))
35          (context (ly:run-translator (make-non-relative-music music) part-combine-listener))
36          (evs (last-pair noticed))
37          (split (reverse! (generate-split-list
38                            #f
39                            (if (pair? evs)
40                                (reverse! (cdar evs) '()) '())
41                            '())
42                           '())))
43     (set! (ly:music-property m 'element) music)
44     (set! (ly:music-property m 'split-list) split)
45     (set! noticed '())
46     m))