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 (make-penalty-music pen)
239 ((m (make-music-by-name 'BreakEvent)))
240 (ly-set-mus-property! m 'penalty pen)
243 (define-public (make-articulation name)
245 (m (make-music-by-name 'ArticulationEvent))
247 (ly-set-mus-property! m 'articulation-type name)
252 (define-public (set-mus-properties! m alist)
253 "Set all of ALIST as properties of M."
256 (ly-set-mus-property! m (caar alist) (cdar alist))
257 (set-mus-properties! m (cdr alist)))
260 (define-public (music-separator? m)
262 (let* ((ts (ly-get-mus-property m 'types )))
266 (define (split-one sep? l acc)
267 "Split off the first parts before separator and return both parts.
274 (split-one sep? (cdr l) (cons (car l) acc))
278 (define-public (split-list l sep?)
281 (display (split-list '(a b c / d e f / g) (lambda (x) (equal? x '/))) )
288 (let* ((c (split-one sep? l '())))
289 (cons (reverse! (car c) '()) (split-list (cdr c) sep?))
294 ;;; splitting chords into voices.
296 (define (voicify-list lst number)
297 "Make a list of Musics.
299 voicify-list :: [ [Music ] ] -> number -> [Music]
300 LST is a list music-lists.
304 (cons (context-spec-music
305 (make-sequential-music
307 (make-voice-props-set number)
308 (make-simultaneous-music (car lst))))
310 "Voice" (number->string number))
311 (voicify-list (cdr lst) (+ number 1))
315 (define (voicify-chord ch)
316 "Split the parts of a chord into different Voices using separator"
317 (let* ((es (ly-get-mus-property ch 'elements)))
320 (ly-set-mus-property! ch 'elements
321 (voicify-list (split-list es music-separator?) 0))
325 (define (voicify-music m)
326 "Recursively split chords that are separated with \\ "
330 (error "not music!"))
333 ((es (ly-get-mus-property m 'elements))
334 (e (ly-get-mus-property m 'element))
337 (ly-set-mus-property! m 'elements (map voicify-music es)))
339 (ly-set-mus-property! m 'element (voicify-music e)))
341 (and (equal? (ly-music-name m) "Simultaneous_music")
342 (reduce (lambda (x y ) (or x y)) (map music-separator? es)))
349 (define-public (empty-music)
350 (ly-id (make-music-by-name 'Music))
354 ; Make a function that checks score element for being of a specific type.
355 (define-public (make-type-checker symbol)
358 ;;(eq? #t (ly-get-grob-property elt symbol))
359 (not (eq? #f (memq symbol (ly-get-grob-property elt 'interfaces))))))
362 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
363 ;; warn for bare chords at start.
365 (define (has-request-chord elts)
366 (reduce (lambda (x y) (or x y)) (map (lambda (x) (equal? (ly-music-name x)
367 "Request_chord")) elts)
370 (define (ly-music-message music msg)
372 (ip (ly-get-mus-property music 'origin))
375 (if (ly-input-location? ip)
376 (ly-input-message ip msg)
380 (define (check-start-chords music)
381 "Check music expression for a Simultaneous_music containing notes\n(ie. Request_chords), without context specification. Called from parser."
384 ((es (ly-get-mus-property music 'elements))
385 (e (ly-get-mus-property music 'element))
386 (name (ly-music-name music))
390 ((equal? name "Context_specced_music") #t)
391 ((equal? name "Simultaneous_music")
393 (if (has-request-chord es)
394 (ly-music-message music "Starting score with a chord.\nPlease insert an explicit \\context before chord")
395 (map check-start-chords es)))
397 ((equal? name "Sequential_music")
399 (check-start-chords (car es))))
400 (else (if (music? e) (check-start-chords e )))
407 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
408 ;; switch it on here, so parsing and init isn't checked (too slow!)
410 ;; automatic music transformations.
412 (define (switch-on-debugging m)
413 (set-debug-cell-accesses! 15000)
417 (define-public toplevel-music-functions
418 (list check-start-chords
421 ; switch-on-debugging