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 (unfold-repeats music)
57 This function replaces all repeats with unfold repeats. It was
58 written by Rune Zedeler. "
59 (let* ((es (ly-get-mus-property music 'elements))
60 (e (ly-get-mus-property music 'element))
61 (n (ly-music-name music)))
63 (if (equal? n "Repeated_music")
66 (ly-get-mus-property music 'iterator-ctor)
67 Chord_tremolo_iterator::constructor)
68 (shift-duration-log music (intlog2 (ly-get-mus-property music 'repeat-count)) 0)
71 music 'length Repeated_music::unfolded_music_length)
73 music 'start-moment-function Repeated_music::first_start)
75 music 'iterator-ctor Unfolded_repeat_iterator::constructor)))
80 (map unfold-repeats es)))
90 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
91 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
93 (define (pitchify-scripts music)
94 "Copy the pitch fields of the Note_requests into Text_script_requests, to aid
96 (define (find-note musics)
97 (filter-list (lambda (m) (equal? (ly-music-name m) "Note_req")) musics)
99 (define (find-scripts musics)
100 (filter-list (lambda (m) (equal? (ly-music-name m) "Text_script_req")) musics))
103 (e (ly-get-mus-property music 'element))
104 (es (ly-get-mus-property music 'elements))
105 (notes (find-note es))
106 (pitch (if (pair? notes) (ly-get-mus-property (car notes) 'pitch) #f))
110 (map (lambda (x) (ly-set-mus-property! x 'pitch pitch)) (find-scripts es))
114 (ly-set-mus-property!
116 (map pitchify-scripts es)))
119 (ly-set-mus-property!
121 (pitchify-scripts e)))
126 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
127 ;; property setting music objs.
128 (define-public (make-grob-property-set grob gprop val)
129 "Make a M-exp that sets GPROP to VAL in GROBS. Does a pop first, i.e.
130 this is not an override
133 (let* ((m (make-music-by-name 'OverrideProperty)))
134 (ly-set-mus-property! m 'symbol grob)
135 (ly-set-mus-property! m 'grob-property gprop)
136 (ly-set-mus-property! m 'grob-value val)
137 (ly-set-mus-property! m 'pop-first #t)
144 (define-public (make-grob-property-revert grob gprop)
145 "Revert the grob property GPROP for GROB."
146 (let* ((m (make-music-by-name 'OverrideProperty)))
147 (ly-set-mus-property! m 'symbol grob)
148 (ly-set-mus-property! m 'grob-property gprop)
154 (define-public (make-voice-props-set n)
155 (make-sequential-music
157 (map (lambda (x) (make-grob-property-set x 'direction
159 '(Tie Slur Stem Dots))
161 (make-grob-property-set 'NoteColumn 'horizontal-shift (quotient n 2))
162 (make-grob-property-set 'MultiMeasureRest 'staff-position
170 (define-public (make-voice-props-revert)
171 (make-sequential-music
173 (make-grob-property-revert 'Tie 'direction)
174 (make-grob-property-revert 'Dots 'direction)
175 (make-grob-property-revert 'Stem 'direction)
176 (make-grob-property-revert 'Slur 'direction)
177 (make-grob-property-revert 'NoteColumn 'horizontal-shift)
181 (define-public (context-spec-music m context . rest)
182 "Add \context CONTEXT = foo to M. "
184 (let* ((cm (make-music-by-name 'ContextSpeccedMusic)))
185 (ly-set-mus-property! cm 'element m)
186 (ly-set-mus-property! cm 'context-type context)
187 (if (and (pair? rest) (string? (car rest)))
188 (ly-set-mus-property! cm 'context-id (car rest))
193 (define-public (make-sequential-music elts)
194 (let* ((m (make-music-by-name 'SequentialMusic)))
195 (ly-set-mus-property! m 'elements elts)
199 (define-public (make-simultaneous-music elts)
200 (let* ((m (make-music-by-name 'SimultaneousMusic)))
201 (ly-set-mus-property! m 'elements elts)
205 (define-public (make-event-chord elts)
206 (let* ((m (make-music-by-name 'EventChord)))
207 (ly-set-mus-property! m 'elements elts)
212 (define-public (make-multi-measure-rest duration location)
215 (start (make-music-by-name 'MultiMeasureRestEvent))
216 (stop (make-music-by-name 'MultiMeasureRestEvent))
217 (skip ( make-music-by-name 'SkipEvent))
218 (ch (make-music-by-name 'BarCheck))
219 (ch2 (make-music-by-name 'BarCheck))
222 (ly-set-mus-property! start 'span-direction START)
223 (ly-set-mus-property! stop 'span-direction STOP)
224 (ly-set-mus-property! skip 'duration duration)
225 (map (lambda (x) (ly-set-mus-property! x 'origin location))
226 (list start stop skip ch ch2))
227 (make-sequential-music
230 (make-event-chord (list start))
231 (make-event-chord (list skip))
232 (make-event-chord (list stop))
237 (define-public (set-mus-properties! m alist)
238 "Set all of ALIST as properties of M."
241 (ly-set-mus-property! m (caar alist) (cdar alist))
242 (set-mus-properties! m (cdr alist)))
245 (define-public (music-separator? m)
247 (let* ((ts (ly-get-mus-property m 'types )))
251 (define (split-one sep? l acc)
252 "Split off the first parts before separator and return both parts.
259 (split-one sep? (cdr l) (cons (car l) acc))
263 (define-public (split-list l sep?)
266 (display (split-list '(a b c / d e f / g) (lambda (x) (equal? x '/))) )
273 (let* ((c (split-one sep? l '())))
274 (cons (reverse! (car c) '()) (split-list (cdr c) sep?))
279 ;;; splitting chords into voices.
281 (define (voicify-list lst number)
282 "Make a list of Musics.
284 voicify-list :: [ [Music ] ] -> number -> [Music]
285 LST is a list music-lists.
289 (cons (context-spec-music
290 (make-sequential-music
292 (make-voice-props-set number)
293 (make-simultaneous-music (car lst))))
295 "Voice" (number->string number))
296 (voicify-list (cdr lst) (+ number 1))
300 (define (voicify-chord ch)
301 "Split the parts of a chord into different Voices using separator"
302 (let* ((es (ly-get-mus-property ch 'elements)))
305 (ly-set-mus-property! ch 'elements
306 (voicify-list (split-list es music-separator?) 0))
310 (define (voicify-music m)
311 "Recursively split chords that are separated with \\ "
315 (error "not music!"))
318 ((es (ly-get-mus-property m 'elements))
319 (e (ly-get-mus-property m 'element))
322 (ly-set-mus-property! m 'elements (map voicify-music es)))
324 (ly-set-mus-property! m 'element (voicify-music e)))
326 (and (equal? (ly-music-name m) "Simultaneous_music")
327 (reduce (lambda (x y ) (or x y)) (map music-separator? es)))
334 (define-public (empty-music)
335 (ly-id (make-music-by-name 'Music))
339 ; Make a function that checks score element for being of a specific type.
340 (define-public (make-type-checker symbol)
343 ;;(eq? #t (ly-get-grob-property elt symbol))
344 (not (eq? #f (memq symbol (ly-get-grob-property elt 'interfaces))))))
347 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
348 ;; warn for bare chords at start.
350 (define (has-request-chord elts)
351 (reduce (lambda (x y) (or x y)) (map (lambda (x) (equal? (ly-music-name x)
352 "Request_chord")) elts)
355 (define (ly-music-message music msg)
357 (ip (ly-get-mus-property music 'origin))
360 (if (ly-input-location? ip)
361 (ly-input-message ip msg)
365 (define (check-start-chords music)
366 "Check music expression for a Simultaneous_music containing notes\n(ie. Request_chords), without context specification. Called from parser."
369 ((es (ly-get-mus-property music 'elements))
370 (e (ly-get-mus-property music 'element))
371 (name (ly-music-name music))
375 ((equal? name "Context_specced_music") #t)
376 ((equal? name "Simultaneous_music")
378 (if (has-request-chord es)
379 (ly-music-message music "Starting score with a chord.\nPlease insert an explicit \\context before chord")
380 (map check-start-chords es)))
382 ((equal? name "Sequential_music")
384 (check-start-chords (car es))))
385 (else (if (music? e) (check-start-chords e )))
392 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
393 ;; switch it on here, so parsing and init isn't checked (too slow!)
395 ;; automatic music transformations.
397 (define (switch-on-debugging m)
398 (set-debug-cell-accesses! 15000)
402 (define-public toplevel-music-functions
403 (list check-start-chords
406 ; switch-on-debugging