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))
160 (list (make-grob-property-set 'NoteColumn 'horizontal-shift (quotient n 2)))
164 (define-public (make-voice-props-revert)
165 (make-sequential-music
167 (make-grob-property-revert 'Tie 'direction)
168 (make-grob-property-revert 'Dots 'direction)
169 (make-grob-property-revert 'Stem 'direction)
170 (make-grob-property-revert 'Slur 'direction)
171 (make-grob-property-revert 'NoteColumn 'horizontal-shift)
175 (define-public (context-spec-music m context . rest)
176 "Add \context CONTEXT = foo to M. "
178 (let* ((cm (make-music-by-name 'ContextSpeccedMusic)))
179 (ly-set-mus-property! cm 'element m)
180 (ly-set-mus-property! cm 'context-type context)
181 (if (and (pair? rest) (string? (car rest)))
182 (ly-set-mus-property! cm 'context-id (car rest))
187 (define-public (make-sequential-music elts)
188 (let* ((m (make-music-by-name 'SequentialMusic)))
189 (ly-set-mus-property! m 'elements elts)
193 (define-public (make-simultaneous-music elts)
194 (let* ((m (make-music-by-name 'SimultaneousMusic)))
195 (ly-set-mus-property! m 'elements elts)
199 (define-public (set-mus-properties! m alist)
202 (ly-set-mus-property! m (caar alist) (cdar alist))
203 (set-mus-properties! m (cdr alist)))
206 (define-public (music-separator? m)
208 (let* ((ts (ly-get-mus-property m 'types )))
212 (define (split-one sep? l acc)
213 "Split off the first parts before separator and return both parts.
220 (split-one sep? (cdr l) (cons (car l) acc))
224 (define-public (split-list l sep?)
227 (display (split-list '(a b c / d e f / g) (lambda (x) (equal? x '/))) )
234 (let* ((c (split-one sep? l '())))
235 (cons (reverse! (car c) '()) (split-list (cdr c) sep?))
240 ;;; splitting chords into voices.
242 (define (voicify-list lst number)
243 "Make a list of Musics.
245 voicify-list :: [ [Music ] ] -> number -> [Music]
246 LST is a list music-lists.
250 (cons (context-spec-music
251 (make-sequential-music
253 (make-voice-props-set number)
254 (make-simultaneous-music (car lst))))
256 "Voice" (number->string number))
257 (voicify-list (cdr lst) (+ number 1))
261 (define (voicify-chord ch)
262 "Split the parts of a chord into different Voices using separator"
263 (let* ((es (ly-get-mus-property ch 'elements)))
266 (ly-set-mus-property! ch 'elements
267 (voicify-list (split-list es music-separator?) 0))
271 (define (voicify-music m)
272 "Recursively split chords that are separated with \\ "
276 (error "not music!"))
279 ((es (ly-get-mus-property m 'elements))
280 (e (ly-get-mus-property m 'element))
283 (ly-set-mus-property! m 'elements (map voicify-music es)))
285 (ly-set-mus-property! m 'element (voicify-music e)))
287 (and (equal? (ly-music-name m) "Simultaneous_music")
288 (reduce (lambda (x y ) (or x y)) (map music-separator? es)))
295 (define-public (empty-music)
296 (ly-id (make-music-by-name 'Music))
300 ; Make a function that checks score element for being of a specific type.
301 (define-public (make-type-checker symbol)
304 ;;(eq? #t (ly-get-grob-property elt symbol))
305 (not (eq? #f (memq symbol (ly-get-grob-property elt 'interfaces))))))
308 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
309 ;; warn for bare chords at start.
311 (define (has-request-chord elts)
312 (reduce (lambda (x y) (or x y)) (map (lambda (x) (equal? (ly-music-name x)
313 "Request_chord")) elts)
316 (define (ly-music-message music msg)
318 (ip (ly-get-mus-property music 'origin))
321 (if (ly-input-location? ip)
322 (ly-input-message ip msg)
326 (define (check-start-chords music)
327 "Check music expression for a Simultaneous_music containing notes\n(ie. Request_chords), without context specification. Called from parser."
330 ((es (ly-get-mus-property music 'elements))
331 (e (ly-get-mus-property music 'element))
332 (name (ly-music-name music))
336 ((equal? name "Context_specced_music") #t)
337 ((equal? name "Simultaneous_music")
339 (if (has-request-chord es)
340 (ly-music-message music "Starting score with a chord.\nPlease insert an explicit \\context before chord")
341 (map check-start-chords es)))
343 ((equal? name "Sequential_music")
345 (check-start-chords (car es))))
346 (else (if (music? e) (check-start-chords e )))
353 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
354 ;; switch it on here, so parsing and init isn't checked (too slow!)
356 ;; automatic music transformations.
358 (define (switch-on-debugging m)
359 (set-debug-cell-accesses! 15000)
363 (define-public toplevel-music-functions
364 (list check-start-chords
367 ; switch-on-debugging