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)))
41 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
42 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
44 (define (pitchify-scripts music)
45 "Copy the pitch fields of the Note_requests into Text_script_requests, to aid
47 (define (find-note musics)
48 (filter-list (lambda (m) (equal? (ly-music-name m) "Note_req")) musics)
50 (define (find-scripts musics)
51 (filter-list (lambda (m) (equal? (ly-music-name m) "Text_script_req")) musics))
54 (e (ly-get-mus-property music 'element))
55 (es (ly-get-mus-property music 'elements))
56 (notes (find-note es))
57 (pitch (if (pair? notes) (ly-get-mus-property (car notes) 'pitch) #f))
61 (map (lambda (x) (ly-set-mus-property x 'pitch pitch)) (find-scripts es))
67 (map pitchify-scripts es)))
72 (pitchify-scripts e)))
82 (define (make-grob-property-set grob gprop val)
83 "Make a M-exp that sets GPROP to VAL in GROBS. Does a pop first, i.e.
84 this is not an override
87 (let* ((m (ly-make-music "Music")))
88 (ly-set-mus-property m 'iterator-ctor Push_property_iterator::constructor)
89 (ly-set-mus-property m 'symbol grob)
90 (ly-set-mus-property m 'grob-property gprop)
91 (ly-set-mus-property m 'grob-value val)
92 (ly-set-mus-property m 'pop-first #t)
98 (define (make-grob-property-revert grob gprop)
99 "Revert the grob property GPROP for GROB."
100 (let* ((m (ly-make-music "Music")))
101 (ly-set-mus-property m 'iterator-ctor Pop_property_iterator::constructor)
102 (ly-set-mus-property m 'symbol grob)
103 (ly-set-mus-property m 'grob-property gprop)
109 (define (make-voice-props-set n)
110 (make-sequential-music
112 (map (lambda (x) (make-grob-property-set x 'direction
114 '(Tie Slur Stem Dots))
115 (list (make-grob-property-set 'NoteColumn 'horizontal-shift (quotient n 2)))
119 (define (make-voice-props-revert)
120 (make-sequential-music
122 (make-grob-property-revert 'Tie 'direction)
123 (make-grob-property-revert 'Dots 'direction)
124 (make-grob-property-revert 'Stem 'direction)
125 (make-grob-property-revert 'Slur 'direction)
126 (make-grob-property-revert 'NoteColumn 'horizontal-shift)
130 (define (context-spec-music m context . rest)
131 "Add \context CONTEXT = foo to M. "
133 (let* ((cm (ly-make-music "Context_specced_music")))
134 (ly-set-mus-property cm 'element m)
135 (ly-set-mus-property cm 'context-type context)
136 (if (and (pair? rest) (string? (car rest)))
137 (ly-set-mus-property cm 'context-id (car rest))
142 (define (make-sequential-music elts)
143 (let* ((m (ly-make-music "Sequential_music")))
144 (ly-set-mus-property m 'elements elts)
147 (define (make-simultaneous-music elts)
148 (let* ((m (ly-make-music "Simultaneous_music")))
149 (ly-set-mus-property m 'elements elts)
152 (define (music-separator? m)
154 (let* ((n (ly-get-mus-property m 'name )))
155 (and (symbol? n) (equal? 'separator n))
158 (define (split-one sep? l acc)
159 "Split off the first parts before separator and return both parts.
166 (split-one sep? (cdr l) (cons (car l) acc))
170 (define (split-list l sep?)
173 (let* ((c (split-one sep? l '())))
174 (cons (reverse! (car c) '()) (split-list (cdr c) sep?))
180 ; (display (split-list '(a b c / d e f / g) (lambda (x) (equal? x '/))) )
183 ;;; splitting chords into voices.
185 (define (voicify-list lst number)
186 "Make a list of Musics.
188 voicify-list :: [ [Music ] ] -> number -> [Music]
189 LST is a list music-lists.
193 (cons (context-spec-music
194 (make-sequential-music
196 (make-voice-props-set number)
197 (make-simultaneous-music (car lst))))
199 "Voice" (number->string number))
200 (voicify-list (cdr lst) (+ number 1))
204 (define (voicify-chord ch)
205 "Split the parts of a chord into different Voices using separator"
206 (let* ((es (ly-get-mus-property ch 'elements)))
209 (ly-set-mus-property ch 'elements
210 (voicify-list (split-list es music-separator?) 0))
214 (define (voicify-music m)
215 "Recursively split chords that are separated with \\ "
219 (error "not music!"))
222 ((es (ly-get-mus-property m 'elements))
223 (e (ly-get-mus-property m 'element))
226 (ly-set-mus-property m 'elements (map voicify-music es)))
228 (ly-set-mus-property m 'element (voicify-music e)))
230 (and (equal? (ly-music-name m) "Simultaneous_music")
231 (reduce (lambda (x y ) (or x y)) (map music-separator? es)))
243 (define (has-request-chord elts)
244 (reduce (lambda (x y) (or x y)) (map (lambda (x) (equal? (ly-music-name x)
245 "Request_chord")) elts)
248 (define (ly-music-message music msg)
250 (ip (ly-get-mus-property music 'origin))
253 (if (ly-input-location? ip)
254 (ly-input-message ip msg)
258 (define (check-start-chords music)
259 "Check music expression for a Simultaneous_music containing notes\n(ie. Request_chords), without context specification. Called from parser."
262 ((es (ly-get-mus-property music 'elements))
263 (e (ly-get-mus-property music 'element))
264 (name (ly-music-name music))
268 ((equal? name "Context_specced_music") #t)
269 ((equal? name "Simultaneous_music")
271 (if (has-request-chord es)
272 (ly-music-message music "Starting score with a chord.\nPlease insert an explicit \\context before chord")
273 (map check-start-chords es)))
275 ((equal? name "Sequential_music")
277 (check-start-chords (car es))))
278 (else (if (music? e) (check-start-chords e )))
285 (define toplevel-music-functions (list check-start-chords voicify-music))