2 (define (denominator-tuplet-formatter mus)
3 (number->string (ly-get-mus-property mus 'denominator)))
5 (define (fraction-tuplet-formatter mus)
6 (string-append (number->string (ly-get-mus-property mus 'numerator))
8 (number->string (ly-get-mus-property mus 'denominator))
11 (define (unfold-repeats music)
13 This function replaces all repeats with unfold repeats. It was
14 written by Rune Zedeler. "
15 (let* ((es (ly-get-mus-property music 'elements))
16 (e (ly-get-mus-property music 'element))
17 (n (ly-music-name music)))
19 (if (equal? n "Repeated_music")
22 music 'length Repeated_music::unfolded_music_length)
24 music 'iterator-ctor Unfolded_repeat_iterator::constructor)))
29 (map unfold-repeats es)))
39 (define (pitchify-scripts music)
40 "Copy the pitch fields of the Note_requests into Text_script_requests, to aid
42 (define (find-note musics)
43 (filter-list (lambda (m) (equal? (ly-music-name m) "Note_req")) musics)
45 (define (find-scripts musics)
46 (filter-list (lambda (m) (equal? (ly-music-name m) "Text_script_req")) musics))
49 (e (ly-get-mus-property music 'element))
50 (es (ly-get-mus-property music 'elements))
51 (notes (find-note es))
52 (pitch (if (pair? notes) (ly-get-mus-property (car notes) 'pitch) #f))
56 (map (lambda (x) (ly-set-mus-property x 'pitch pitch)) (find-scripts es))
62 (map pitchify-scripts es)))
67 (pitchify-scripts e)))
77 (define (make-grob-property-set grob gprop val)
78 "Make a M-exp that sets GPROP to VAL in GROBS. Does a pop first, i.e.
79 this is not an override
82 (let* ((m (ly-make-music "Music")))
83 (ly-set-mus-property m 'iterator-ctor Push_property_iterator::constructor)
84 (ly-set-mus-property m 'symbol grob)
85 (ly-set-mus-property m 'grob-property gprop)
86 (ly-set-mus-property m 'grob-value val)
87 (ly-set-mus-property m 'pop-first #t)
93 (define (make-grob-property-revert grob gprop)
94 "Revert the grob property GPROP for GROB."
95 (let* ((m (ly-make-music "Music")))
96 (ly-set-mus-property m 'iterator-ctor Pop_property_iterator::constructor)
97 (ly-set-mus-property m 'symbol grob)
98 (ly-set-mus-property m 'grob-property gprop)
104 (define (make-voice-props-set n)
105 (make-sequential-music
107 (map (lambda (x) (make-grob-property-set x 'direction
109 '(Tie Slur Stem Dots))
110 (list (make-grob-property-set 'NoteColumn 'horizontal-shift (quotient n 2)))
114 (define (make-voice-props-revert)
115 (make-sequential-music
117 (make-grob-property-revert 'Tie 'direction)
118 (make-grob-property-revert 'Dots 'direction)
119 (make-grob-property-revert 'Stem 'direction)
120 (make-grob-property-revert 'Slur 'direction)
121 (make-grob-property-revert 'NoteColumn 'horizontal-shift)
125 (define (context-spec-music m context . rest)
126 "Add \context CONTEXT = foo to M. "
128 (let* ((cm (ly-make-music "Context_specced_music")))
129 (ly-set-mus-property cm 'element m)
130 (ly-set-mus-property cm 'context-type context)
131 (if (and (pair? rest) (string? (car rest)))
132 (ly-set-mus-property cm 'context-id (car rest))
137 (define (make-sequential-music elts)
138 (let* ((m (ly-make-music "Sequential_music")))
139 (ly-set-mus-property m 'elements elts)
142 (define (make-simultaneous-music elts)
143 (let* ((m (ly-make-music "Simultaneous_music")))
144 (ly-set-mus-property m 'elements elts)
147 (define (music-separator? m)
149 (let* ((n (ly-get-mus-property m 'name )))
150 (and (symbol? n) (equal? 'separator n))
153 (define (split-one sep? l acc)
154 "Split off the first parts before separator and return both parts.
161 (split-one sep? (cdr l) (cons (car l) acc))
165 (define (split-list l sep?)
168 (let* ((c (split-one sep? l '())))
169 (cons (reverse! (car c) '()) (split-list (cdr c) sep?))
175 ; (display (split-list '(a b c / d e f / g) (lambda (x) (equal? x '/))) )
178 ;;; splitting chords into voices.
180 (define (voicify-list lst number)
181 "Make a list of Musics.
183 voicify-list :: [ [Music ] ] -> number -> [Music]
184 LST is a list music-lists.
188 (cons (context-spec-music
189 (make-sequential-music
191 (make-voice-props-set number)
192 (make-simultaneous-music (car lst))))
194 "Voice" (number->string number))
195 (voicify-list (cdr lst) (+ number 1))
199 (define (voicify-chord ch)
200 "Split the parts of a chord into different Voices using separator"
201 (let* ((es (ly-get-mus-property ch 'elements)))
204 (ly-set-mus-property ch 'elements
205 (voicify-list (split-list es music-separator?) 0))
209 (define (voicify-music m)
210 "Recursively split chords that are separated with \\ "
214 (error "not music!"))
217 ((es (ly-get-mus-property m 'elements))
218 (e (ly-get-mus-property m 'element))
222 (and (equal? (ly-music-name m) "Simultaneous_music")
223 (reduce (lambda (x y ) (or x y)) (map music-separator? es)))
227 (ly-set-mus-property m 'elements (map voicify-music es)))
229 (ly-set-mus-property m 'element (voicify-music e)))