1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4 (define-public (denominator-tuplet-formatter mus)
5 (number->string (ly-get-mus-property mus 'denominator)))
7 (define-public (fraction-tuplet-formatter mus)
8 (string-append (number->string (ly-get-mus-property mus 'numerator))
10 (number->string (ly-get-mus-property mus 'denominator))
13 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16 (define-public (shift-duration-log music shift dot)
17 "Recurse through music, adding SHIFT to duration-log and optionally
18 a dot to any note encountered. This scales the music up by a factor
19 2^shift * (2 - (1/2)^dot)"
20 (let* ((es (ly-get-mus-property music 'elements))
21 (e (ly-get-mus-property music 'element))
22 (n (ly-music-name music))
23 (f (lambda (x) (shift-duration-log x shift dot)))
25 (if (or (equal? n "Note_req")
26 (equal? n "Rest_req"))
28 (d (ly-get-mus-property music 'duration))
29 (cp (duration-factor d))
30 (nd (make-duration (+ shift (duration-log d))
31 (+ dot (duration-dot-count d))
36 (ly-set-mus-property! music 'duration nd)
52 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
55 (define-public (repeat-name-to-ctor name)
58 `(("volta" . ((iterator-ctor . ,Volta_repeat_iterator::constructor)
59 (start-moment-function . ,Repeated_music::first_start)
60 (length . ,Repeated_music::volta_music_length)))
62 ("unfold" . ((iterator-ctor . ,Unfolded_repeat_iterator::constructor)
63 (start-moment-function . ,Repeated_music::first_start)
64 (length . ,Repeated_music::unfolded_music_length)))
65 ("fold" . ((iterator-ctor . ,Folded_repeat_iterator::constructor)
66 (start-moment-function . ,Repeated_music::minimum_start)
67 (length . ,Repeated_music::folded_music_length)))
68 ("percent" . ((iterator-ctor . ,Percent_repeat_iterator::constructor)
69 (start-moment-function . ,Repeated_music::first_start)
70 (length . ,Repeated_music::unfolded_music_length)))
71 ("tremolo" . ((iterator-ctor . ,Chord_tremolo_iterator::constructor)
72 (start-moment-function . ,Repeated_music::first_start)
74 ;; the length of the repeat is handled by shifting the note logs
75 (length . ,Repeated_music::folded_music_length)))))
77 (handle (assoc name supported-reps)))
83 (string-append "Unknown repeat type `" name "'\nSee scm/c++.scm for supported repeats"))
84 '(type . 'repeated-music)))))
86 (define-public (unfold-repeats music)
88 This function replaces all repeats with unfold repeats. It was
89 written by Rune Zedeler. "
90 (let* ((es (ly-get-mus-property music 'elements))
91 (e (ly-get-mus-property music 'element))
92 (n (ly-music-name music)))
94 (if (equal? n "Repeated_music")
97 (ly-get-mus-property music 'iterator-ctor)
98 Chord_tremolo_iterator::constructor)
99 (shift-duration-log music (intlog2 (ly-get-mus-property music 'repeat-count)) 0)
101 (ly-set-mus-property!
102 music 'length Repeated_music::unfolded_music_length)
103 (ly-set-mus-property!
104 music 'start-moment-function Repeated_music::first_start)
105 (ly-set-mus-property!
106 music 'iterator-ctor Unfolded_repeat_iterator::constructor)))
109 (ly-set-mus-property!
111 (map unfold-repeats es)))
114 (ly-set-mus-property!
121 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
122 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
124 (define (pitchify-scripts music)
125 "Copy the pitch fields of the Note_requests into Text_script_requests, to aid
127 (define (find-note musics)
128 (filter-list (lambda (m) (equal? (ly-music-name m) "Note_req")) musics)
130 (define (find-scripts musics)
131 (filter-list (lambda (m) (equal? (ly-music-name m) "Text_script_req")) musics))
134 (e (ly-get-mus-property music 'element))
135 (es (ly-get-mus-property music 'elements))
136 (notes (find-note es))
137 (pitch (if (pair? notes) (ly-get-mus-property (car notes) 'pitch) #f))
141 (map (lambda (x) (ly-set-mus-property! x 'pitch pitch)) (find-scripts es))
145 (ly-set-mus-property!
147 (map pitchify-scripts es)))
150 (ly-set-mus-property!
152 (pitchify-scripts e)))
157 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
158 ;; property setting music objs.
159 (define-public (make-grob-property-set grob gprop val)
160 "Make a M-exp that sets GPROP to VAL in GROBS. Does a pop first, i.e.
161 this is not an override
164 (let* ((m (ly-make-music "Music")))
165 (ly-set-mus-property! m 'iterator-ctor Push_property_iterator::constructor)
166 (ly-set-mus-property! m 'symbol grob)
167 (ly-set-mus-property! m 'grob-property gprop)
168 (ly-set-mus-property! m 'grob-value val)
169 (ly-set-mus-property! m 'pop-first #t)
176 (define-public (make-grob-property-revert grob gprop)
177 "Revert the grob property GPROP for GROB."
178 (let* ((m (ly-make-music "Music")))
179 (ly-set-mus-property! m 'iterator-ctor Pop_property_iterator::constructor)
180 (ly-set-mus-property! m 'symbol grob)
181 (ly-set-mus-property! m 'grob-property gprop)
187 (define-public (make-voice-props-set n)
188 (make-sequential-music
190 (map (lambda (x) (make-grob-property-set x 'direction
192 '(Tie Slur Stem Dots))
193 (list (make-grob-property-set 'NoteColumn 'horizontal-shift (quotient n 2)))
197 (define-public (make-voice-props-revert)
198 (make-sequential-music
200 (make-grob-property-revert 'Tie 'direction)
201 (make-grob-property-revert 'Dots 'direction)
202 (make-grob-property-revert 'Stem 'direction)
203 (make-grob-property-revert 'Slur 'direction)
204 (make-grob-property-revert 'NoteColumn 'horizontal-shift)
208 (define-public (context-spec-music m context . rest)
209 "Add \context CONTEXT = foo to M. "
211 (let* ((cm (ly-make-music "Context_specced_music")))
212 (ly-set-mus-property! cm 'element m)
213 (ly-set-mus-property! cm 'context-type context)
214 (if (and (pair? rest) (string? (car rest)))
215 (ly-set-mus-property! cm 'context-id (car rest))
220 (define-public (make-sequential-music elts)
221 (let* ((m (ly-make-music "Sequential_music")))
222 (ly-set-mus-property! m 'elements elts)
226 (define-public (make-simultaneous-music elts)
227 (let* ((m (ly-make-music "Simultaneous_music")))
228 (ly-set-mus-property! m 'elements elts)
232 (define-public (set-mus-properties! m alist)
235 (ly-set-mus-property! m (caar alist) (cdar alist))
236 (set-mus-properties! m (cdr alist)))
239 (define-public (music-separator? m)
241 (let* ((n (ly-get-mus-property m 'name )))
242 (and (symbol? n) (equal? 'separator n))
245 (define (split-one sep? l acc)
246 "Split off the first parts before separator and return both parts.
253 (split-one sep? (cdr l) (cons (car l) acc))
257 (define (split-list l sep?)
260 (display (split-list '(a b c / d e f / g) (lambda (x) (equal? x '/))) )
267 (let* ((c (split-one sep? l '())))
268 (cons (reverse! (car c) '()) (split-list (cdr c) sep?))
273 ;;; splitting chords into voices.
275 (define (voicify-list lst number)
276 "Make a list of Musics.
278 voicify-list :: [ [Music ] ] -> number -> [Music]
279 LST is a list music-lists.
283 (cons (context-spec-music
284 (make-sequential-music
286 (make-voice-props-set number)
287 (make-simultaneous-music (car lst))))
289 "Voice" (number->string number))
290 (voicify-list (cdr lst) (+ number 1))
294 (define (voicify-chord ch)
295 "Split the parts of a chord into different Voices using separator"
296 (let* ((es (ly-get-mus-property ch 'elements)))
299 (ly-set-mus-property! ch 'elements
300 (voicify-list (split-list es music-separator?) 0))
304 (define (voicify-music m)
305 "Recursively split chords that are separated with \\ "
309 (error "not music!"))
312 ((es (ly-get-mus-property m 'elements))
313 (e (ly-get-mus-property m 'element))
316 (ly-set-mus-property! m 'elements (map voicify-music es)))
318 (ly-set-mus-property! m 'element (voicify-music e)))
320 (and (equal? (ly-music-name m) "Simultaneous_music")
321 (reduce (lambda (x y ) (or x y)) (map music-separator? es)))
330 ; Make a function that checks score element for being of a specific type.
331 (define-public (make-type-checker symbol)
334 ;;(eq? #t (ly-get-grob-property elt symbol))
335 (not (eq? #f (memq symbol (ly-get-grob-property elt 'interfaces))))))
338 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
339 ;; warn for bare chords at start.
341 (define (has-request-chord elts)
342 (reduce (lambda (x y) (or x y)) (map (lambda (x) (equal? (ly-music-name x)
343 "Request_chord")) elts)
346 (define (ly-music-message music msg)
348 (ip (ly-get-mus-property music 'origin))
351 (if (ly-input-location? ip)
352 (ly-input-message ip msg)
356 (define (check-start-chords music)
357 "Check music expression for a Simultaneous_music containing notes\n(ie. Request_chords), without context specification. Called from parser."
360 ((es (ly-get-mus-property music 'elements))
361 (e (ly-get-mus-property music 'element))
362 (name (ly-music-name music))
366 ((equal? name "Context_specced_music") #t)
367 ((equal? name "Simultaneous_music")
369 (if (has-request-chord es)
370 (ly-music-message music "Starting score with a chord.\nPlease insert an explicit \\context before chord")
371 (map check-start-chords es)))
373 ((equal? name "Sequential_music")
375 (check-start-chords (car es))))
376 (else (if (music? e) (check-start-chords e )))
383 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
384 ;; switch it on here, so parsing and init isn't checked (too slow!)
386 ;; automatic music transformations.
388 (define (switch-on-debugging m)
389 (set-debug-cell-accesses! 15000)
393 (define-public toplevel-music-functions
394 (list check-start-chords
397 ; switch-on-debugging