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))
10 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13 (define (shift-duration-log music shift )
14 "Recurse through music, adding SHIFT to duration-log to any note
15 encountered. This scales the music up by a factor 2^k."
16 (let* ((es (ly-get-mus-property music 'elements))
17 (e (ly-get-mus-property music 'element))
18 (n (ly-music-name music))
19 (f (lambda (x) (shift-duration-log x shift)))
21 (if (or (equal? n "Note_req")
22 (equal? n "Rest_req"))
24 (d (ly-get-mus-property music 'duration))
25 (cp (duration-factor d))
26 (nd (make-duration (+ shift (duration-log d))
27 (duration-dot-count d)
32 (ly-set-mus-property music 'duration nd)
48 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
49 (define (unfold-repeats music)
51 This function replaces all repeats with unfold repeats. It was
52 written by Rune Zedeler. "
53 (let* ((es (ly-get-mus-property music 'elements))
54 (e (ly-get-mus-property music 'element))
55 (n (ly-music-name music)))
57 (if (equal? n "Repeated_music")
59 (if (equal? (ly-get-mus-property 'type music) 'tremolo)
60 (shift-duration-log music (- (intlog2 (ly-get-mus-property 'repeat-count music))))
63 music 'length Repeated_music::unfolded_music_length)
65 music 'start-moment-function Repeated_music::first_start)
67 music 'iterator-ctor Unfolded_repeat_iterator::constructor)))
72 (map unfold-repeats es)))
82 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
83 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
85 (define (pitchify-scripts music)
86 "Copy the pitch fields of the Note_requests into Text_script_requests, to aid
88 (define (find-note musics)
89 (filter-list (lambda (m) (equal? (ly-music-name m) "Note_req")) musics)
91 (define (find-scripts musics)
92 (filter-list (lambda (m) (equal? (ly-music-name m) "Text_script_req")) musics))
95 (e (ly-get-mus-property music 'element))
96 (es (ly-get-mus-property music 'elements))
97 (notes (find-note es))
98 (pitch (if (pair? notes) (ly-get-mus-property (car notes) 'pitch) #f))
102 (map (lambda (x) (ly-set-mus-property x 'pitch pitch)) (find-scripts es))
108 (map pitchify-scripts es)))
113 (pitchify-scripts e)))
123 (define (make-grob-property-set grob gprop val)
124 "Make a M-exp that sets GPROP to VAL in GROBS. Does a pop first, i.e.
125 this is not an override
128 (let* ((m (ly-make-music "Music")))
129 (ly-set-mus-property m 'iterator-ctor Push_property_iterator::constructor)
130 (ly-set-mus-property m 'symbol grob)
131 (ly-set-mus-property m 'grob-property gprop)
132 (ly-set-mus-property m 'grob-value val)
133 (ly-set-mus-property m 'pop-first #t)
139 (define (make-grob-property-revert grob gprop)
140 "Revert the grob property GPROP for GROB."
141 (let* ((m (ly-make-music "Music")))
142 (ly-set-mus-property m 'iterator-ctor Pop_property_iterator::constructor)
143 (ly-set-mus-property m 'symbol grob)
144 (ly-set-mus-property m 'grob-property gprop)
150 (define (make-voice-props-set n)
151 (make-sequential-music
153 (map (lambda (x) (make-grob-property-set x 'direction
155 '(Tie Slur Stem Dots))
156 (list (make-grob-property-set 'NoteColumn 'horizontal-shift (quotient n 2)))
160 (define (make-voice-props-revert)
161 (make-sequential-music
163 (make-grob-property-revert 'Tie 'direction)
164 (make-grob-property-revert 'Dots 'direction)
165 (make-grob-property-revert 'Stem 'direction)
166 (make-grob-property-revert 'Slur 'direction)
167 (make-grob-property-revert 'NoteColumn 'horizontal-shift)
171 (define (context-spec-music m context . rest)
172 "Add \context CONTEXT = foo to M. "
174 (let* ((cm (ly-make-music "Context_specced_music")))
175 (ly-set-mus-property cm 'element m)
176 (ly-set-mus-property cm 'context-type context)
177 (if (and (pair? rest) (string? (car rest)))
178 (ly-set-mus-property cm 'context-id (car rest))
183 (define (make-sequential-music elts)
184 (let* ((m (ly-make-music "Sequential_music")))
185 (ly-set-mus-property m 'elements elts)
188 (define (make-simultaneous-music elts)
189 (let* ((m (ly-make-music "Simultaneous_music")))
190 (ly-set-mus-property m 'elements elts)
193 (define (music-separator? m)
195 (let* ((n (ly-get-mus-property m 'name )))
196 (and (symbol? n) (equal? 'separator n))
199 (define (split-one sep? l acc)
200 "Split off the first parts before separator and return both parts.
207 (split-one sep? (cdr l) (cons (car l) acc))
211 (define (split-list l sep?)
214 (let* ((c (split-one sep? l '())))
215 (cons (reverse! (car c) '()) (split-list (cdr c) sep?))
221 ; (display (split-list '(a b c / d e f / g) (lambda (x) (equal? x '/))) )
224 ;;; splitting chords into voices.
226 (define (voicify-list lst number)
227 "Make a list of Musics.
229 voicify-list :: [ [Music ] ] -> number -> [Music]
230 LST is a list music-lists.
234 (cons (context-spec-music
235 (make-sequential-music
237 (make-voice-props-set number)
238 (make-simultaneous-music (car lst))))
240 "Voice" (number->string number))
241 (voicify-list (cdr lst) (+ number 1))
245 (define (voicify-chord ch)
246 "Split the parts of a chord into different Voices using separator"
247 (let* ((es (ly-get-mus-property ch 'elements)))
250 (ly-set-mus-property ch 'elements
251 (voicify-list (split-list es music-separator?) 0))
255 (define (voicify-music m)
256 "Recursively split chords that are separated with \\ "
260 (error "not music!"))
263 ((es (ly-get-mus-property m 'elements))
264 (e (ly-get-mus-property m 'element))
267 (ly-set-mus-property m 'elements (map voicify-music es)))
269 (ly-set-mus-property m 'element (voicify-music e)))
271 (and (equal? (ly-music-name m) "Simultaneous_music")
272 (reduce (lambda (x y ) (or x y)) (map music-separator? es)))
284 (define (has-request-chord elts)
285 (reduce (lambda (x y) (or x y)) (map (lambda (x) (equal? (ly-music-name x)
286 "Request_chord")) elts)
289 (define (ly-music-message music msg)
291 (ip (ly-get-mus-property music 'origin))
294 (if (ly-input-location? ip)
295 (ly-input-message ip msg)
299 (define (check-start-chords music)
300 "Check music expression for a Simultaneous_music containing notes\n(ie. Request_chords), without context specification. Called from parser."
303 ((es (ly-get-mus-property music 'elements))
304 (e (ly-get-mus-property music 'element))
305 (name (ly-music-name music))
309 ((equal? name "Context_specced_music") #t)
310 ((equal? name "Simultaneous_music")
312 (if (has-request-chord es)
313 (ly-music-message music "Starting score with a chord.\nPlease insert an explicit \\context before chord")
314 (map check-start-chords es)))
316 ((equal? name "Sequential_music")
318 (check-start-chords (car es))))
319 (else (if (music? e) (check-start-chords e )))
326 (define toplevel-music-functions (list check-start-chords voicify-music))