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 'start-moment-function Repeated_music::first_start)
26 music 'iterator-ctor Unfolded_repeat_iterator::constructor)))
31 (map unfold-repeats es)))
42 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
43 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
45 (define (pitchify-scripts music)
46 "Copy the pitch fields of the Note_requests into Text_script_requests, to aid
48 (define (find-note musics)
49 (filter-list (lambda (m) (equal? (ly-music-name m) "Note_req")) musics)
51 (define (find-scripts musics)
52 (filter-list (lambda (m) (equal? (ly-music-name m) "Text_script_req")) musics))
55 (e (ly-get-mus-property music 'element))
56 (es (ly-get-mus-property music 'elements))
57 (notes (find-note es))
58 (pitch (if (pair? notes) (ly-get-mus-property (car notes) 'pitch) #f))
62 (map (lambda (x) (ly-set-mus-property x 'pitch pitch)) (find-scripts es))
68 (map pitchify-scripts es)))
73 (pitchify-scripts e)))
83 (define (make-grob-property-set grob gprop val)
84 "Make a M-exp that sets GPROP to VAL in GROBS. Does a pop first, i.e.
85 this is not an override
88 (let* ((m (ly-make-music "Music")))
89 (ly-set-mus-property m 'iterator-ctor Push_property_iterator::constructor)
90 (ly-set-mus-property m 'symbol grob)
91 (ly-set-mus-property m 'grob-property gprop)
92 (ly-set-mus-property m 'grob-value val)
93 (ly-set-mus-property m 'pop-first #t)
99 (define (make-grob-property-revert grob gprop)
100 "Revert the grob property GPROP for GROB."
101 (let* ((m (ly-make-music "Music")))
102 (ly-set-mus-property m 'iterator-ctor Pop_property_iterator::constructor)
103 (ly-set-mus-property m 'symbol grob)
104 (ly-set-mus-property m 'grob-property gprop)
110 (define (make-voice-props-set n)
111 (make-sequential-music
113 (map (lambda (x) (make-grob-property-set x 'direction
115 '(Tie Slur Stem Dots))
116 (list (make-grob-property-set 'NoteColumn 'horizontal-shift (quotient n 2)))
120 (define (make-voice-props-revert)
121 (make-sequential-music
123 (make-grob-property-revert 'Tie 'direction)
124 (make-grob-property-revert 'Dots 'direction)
125 (make-grob-property-revert 'Stem 'direction)
126 (make-grob-property-revert 'Slur 'direction)
127 (make-grob-property-revert 'NoteColumn 'horizontal-shift)
131 (define (context-spec-music m context . rest)
132 "Add \context CONTEXT = foo to M. "
134 (let* ((cm (ly-make-music "Context_specced_music")))
135 (ly-set-mus-property cm 'element m)
136 (ly-set-mus-property cm 'context-type context)
137 (if (and (pair? rest) (string? (car rest)))
138 (ly-set-mus-property cm 'context-id (car rest))
143 (define (make-sequential-music elts)
144 (let* ((m (ly-make-music "Sequential_music")))
145 (ly-set-mus-property m 'elements elts)
148 (define (make-simultaneous-music elts)
149 (let* ((m (ly-make-music "Simultaneous_music")))
150 (ly-set-mus-property m 'elements elts)
153 (define (music-separator? m)
155 (let* ((n (ly-get-mus-property m 'name )))
156 (and (symbol? n) (equal? 'separator n))
159 (define (split-one sep? l acc)
160 "Split off the first parts before separator and return both parts.
167 (split-one sep? (cdr l) (cons (car l) acc))
171 (define (split-list l sep?)
174 (let* ((c (split-one sep? l '())))
175 (cons (reverse! (car c) '()) (split-list (cdr c) sep?))
181 ; (display (split-list '(a b c / d e f / g) (lambda (x) (equal? x '/))) )
184 ;;; splitting chords into voices.
186 (define (voicify-list lst number)
187 "Make a list of Musics.
189 voicify-list :: [ [Music ] ] -> number -> [Music]
190 LST is a list music-lists.
194 (cons (context-spec-music
195 (make-sequential-music
197 (make-voice-props-set number)
198 (make-simultaneous-music (car lst))))
200 "Voice" (number->string number))
201 (voicify-list (cdr lst) (+ number 1))
205 (define (voicify-chord ch)
206 "Split the parts of a chord into different Voices using separator"
207 (let* ((es (ly-get-mus-property ch 'elements)))
210 (ly-set-mus-property ch 'elements
211 (voicify-list (split-list es music-separator?) 0))
215 (define (voicify-music m)
216 "Recursively split chords that are separated with \\ "
220 (error "not music!"))
223 ((es (ly-get-mus-property m 'elements))
224 (e (ly-get-mus-property m 'element))
228 (and (equal? (ly-music-name m) "Simultaneous_music")
229 (reduce (lambda (x y ) (or x y)) (map music-separator? es)))
233 (ly-set-mus-property m 'elements (map voicify-music es)))
235 (ly-set-mus-property m 'element (voicify-music e)))
247 (define (has-request-chord elts)
248 (reduce (lambda (x y) (or x y)) (map (lambda (x) (equal? (ly-music-name x)
249 "Request_chord")) elts)
252 (define (ly-music-message music msg)
254 (ip (ly-get-mus-property music 'origin))
257 (if (ly-input-location? ip)
258 (ly-input-message ip msg)
262 (define (check-start-chords music)
263 "Check music expression for a Simultaneous_music containing notes
264 (ie. Request_chords), without context specification. Called from parser."
266 ((es (ly-get-mus-property music 'elements))
267 (e (ly-get-mus-property music 'element))
268 (name (ly-music-name music))
272 ((equal? name "Context_specced_music") #t)
273 ((equal? name "Simultaneous_music")
275 (if (has-request-chord es)
276 (ly-music-message music "Starting score with a chord.
277 Please insert an explicit \\context before chord")
278 (map check-start-chords es)))
280 ((equal? name "Sequential_music")
282 (check-start-chords (car es))))
283 (else (if (music? e) (check-start-chords e )))