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")
60 (ly-get-mus-property music 'iterator-ctor)
61 Chord_tremolo_iterator::constructor)
62 (shift-duration-log music (intlog2 (ly-get-mus-property music 'repeat-count)))
65 music 'length Repeated_music::unfolded_music_length)
67 music 'start-moment-function Repeated_music::first_start)
69 music 'iterator-ctor Unfolded_repeat_iterator::constructor)))
74 (map unfold-repeats es)))
84 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
85 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
87 (define (pitchify-scripts music)
88 "Copy the pitch fields of the Note_requests into Text_script_requests, to aid
90 (define (find-note musics)
91 (filter-list (lambda (m) (equal? (ly-music-name m) "Note_req")) musics)
93 (define (find-scripts musics)
94 (filter-list (lambda (m) (equal? (ly-music-name m) "Text_script_req")) musics))
97 (e (ly-get-mus-property music 'element))
98 (es (ly-get-mus-property music 'elements))
99 (notes (find-note es))
100 (pitch (if (pair? notes) (ly-get-mus-property (car notes) 'pitch) #f))
104 (map (lambda (x) (ly-set-mus-property! x 'pitch pitch)) (find-scripts es))
108 (ly-set-mus-property!
110 (map pitchify-scripts es)))
113 (ly-set-mus-property!
115 (pitchify-scripts e)))
125 (define (make-grob-property-set grob gprop val)
126 "Make a M-exp that sets GPROP to VAL in GROBS. Does a pop first, i.e.
127 this is not an override
130 (let* ((m (ly-make-music "Music")))
131 (ly-set-mus-property! m 'iterator-ctor Push_property_iterator::constructor)
132 (ly-set-mus-property! m 'symbol grob)
133 (ly-set-mus-property! m 'grob-property gprop)
134 (ly-set-mus-property! m 'grob-value val)
135 (ly-set-mus-property! m 'pop-first #t)
141 (define (make-grob-property-revert grob gprop)
142 "Revert the grob property GPROP for GROB."
143 (let* ((m (ly-make-music "Music")))
144 (ly-set-mus-property! m 'iterator-ctor Pop_property_iterator::constructor)
145 (ly-set-mus-property! m 'symbol grob)
146 (ly-set-mus-property! m 'grob-property gprop)
152 (define (make-voice-props-set n)
153 (make-sequential-music
155 (map (lambda (x) (make-grob-property-set x 'direction
157 '(Tie Slur Stem Dots))
158 (list (make-grob-property-set 'NoteColumn 'horizontal-shift (quotient n 2)))
162 (define (make-voice-props-revert)
163 (make-sequential-music
165 (make-grob-property-revert 'Tie 'direction)
166 (make-grob-property-revert 'Dots 'direction)
167 (make-grob-property-revert 'Stem 'direction)
168 (make-grob-property-revert 'Slur 'direction)
169 (make-grob-property-revert 'NoteColumn 'horizontal-shift)
173 (define (context-spec-music m context . rest)
174 "Add \context CONTEXT = foo to M. "
176 (let* ((cm (ly-make-music "Context_specced_music")))
177 (ly-set-mus-property! cm 'element m)
178 (ly-set-mus-property! cm 'context-type context)
179 (if (and (pair? rest) (string? (car rest)))
180 (ly-set-mus-property! cm 'context-id (car rest))
185 (define (make-sequential-music elts)
186 (let* ((m (ly-make-music "Sequential_music")))
187 (ly-set-mus-property! m 'elements elts)
190 (define (make-simultaneous-music elts)
191 (let* ((m (ly-make-music "Simultaneous_music")))
192 (ly-set-mus-property! m 'elements elts)
195 (define (music-separator? m)
197 (let* ((n (ly-get-mus-property m 'name )))
198 (and (symbol? n) (equal? 'separator n))
201 (define (split-one sep? l acc)
202 "Split off the first parts before separator and return both parts.
209 (split-one sep? (cdr l) (cons (car l) acc))
213 (define (split-list l sep?)
216 (let* ((c (split-one sep? l '())))
217 (cons (reverse! (car c) '()) (split-list (cdr c) sep?))
223 ; (display (split-list '(a b c / d e f / g) (lambda (x) (equal? x '/))) )
226 ;;; splitting chords into voices.
228 (define (voicify-list lst number)
229 "Make a list of Musics.
231 voicify-list :: [ [Music ] ] -> number -> [Music]
232 LST is a list music-lists.
236 (cons (context-spec-music
237 (make-sequential-music
239 (make-voice-props-set number)
240 (make-simultaneous-music (car lst))))
242 "Voice" (number->string number))
243 (voicify-list (cdr lst) (+ number 1))
247 (define (voicify-chord ch)
248 "Split the parts of a chord into different Voices using separator"
249 (let* ((es (ly-get-mus-property ch 'elements)))
252 (ly-set-mus-property! ch 'elements
253 (voicify-list (split-list es music-separator?) 0))
257 (define (voicify-music m)
258 "Recursively split chords that are separated with \\ "
262 (error "not music!"))
265 ((es (ly-get-mus-property m 'elements))
266 (e (ly-get-mus-property m 'element))
269 (ly-set-mus-property! m 'elements (map voicify-music es)))
271 (ly-set-mus-property! m 'element (voicify-music e)))
273 (and (equal? (ly-music-name m) "Simultaneous_music")
274 (reduce (lambda (x y ) (or x y)) (map music-separator? es)))
286 (define (has-request-chord elts)
287 (reduce (lambda (x y) (or x y)) (map (lambda (x) (equal? (ly-music-name x)
288 "Request_chord")) elts)
291 (define (ly-music-message music msg)
293 (ip (ly-get-mus-property music 'origin))
296 (if (ly-input-location? ip)
297 (ly-input-message ip msg)
301 (define (check-start-chords music)
302 "Check music expression for a Simultaneous_music containing notes\n(ie. Request_chords), without context specification. Called from parser."
305 ((es (ly-get-mus-property music 'elements))
306 (e (ly-get-mus-property music 'element))
307 (name (ly-music-name music))
311 ((equal? name "Context_specced_music") #t)
312 ((equal? name "Simultaneous_music")
314 (if (has-request-chord es)
315 (ly-music-message music "Starting score with a chord.\nPlease insert an explicit \\context before chord")
316 (map check-start-chords es)))
318 ((equal? name "Sequential_music")
320 (check-start-chords (car es))))
321 (else (if (music? e) (check-start-chords e )))
328 (define toplevel-music-functions (list check-start-chords voicify-music))