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))
14 (define-public (make-metronome-markup event context)
16 ((dur (ly:get-mus-property event 'tempo-unit))
17 (count (ly:get-mus-property event 'metronome-count))
18 (note-mark (make-note-markup (ly:duration-log dur)
19 (ly:duration-dot-count dur)
27 (make-simple-markup "=")
28 (make-simple-markup (number->string count))
32 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34 (define-public (music-map function music)
35 "Apply @var{function} to @var{music} and all of the music it contains. "
36 (let* ((es (ly:get-mus-property music 'elements))
37 (e (ly:get-mus-property music 'element))
40 (ly:set-mus-property! music 'elements
41 (map (lambda (y) (music-map function y)) es))
43 (ly:set-mus-property! music 'element (music-map function e)))
47 (define-public (display-music music)
48 "Display music, not done with music-map for clarity of presentation."
52 (let* ((es (ly:get-mus-property music 'elements))
53 (e (ly:get-mus-property music 'element))
56 (display (ly:get-mutable-properties music))
59 (begin (display "\nElements: {\n")
60 (map display-music es)
80 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
82 (define (shift-one-duration-log music shift dot)
83 " add SHIFT to ly:duration-log and optionally
84 a dot to any note encountered. This scales the music up by a factor
85 2^shift * (2 - (1/2)^dot)"
89 (d (ly:get-mus-property music 'duration))
93 (cp (ly:duration-factor d))
94 (nd (ly:make-duration (+ shift (ly:duration-log d))
95 (+ dot (ly:duration-dot-count d))
100 (ly:set-mus-property! music 'duration nd)
106 (define-public (shift-duration-log music shift dot)
107 (music-map (lambda (x) (shift-one-duration-log x shift dot))
111 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
114 (define-public (unfold-repeats music)
116 This function replaces all repeats with unfold repeats. It was
117 written by Rune Zedeler. "
118 (let* ((es (ly:get-mus-property music 'elements))
119 (e (ly:get-mus-property music 'element))
120 (n (ly:music-name music)))
122 (if (equal? n "Repeated_music")
125 (ly:get-mus-property music 'iterator-ctor)
126 Chord_tremolo_iterator::constructor)
127 (shift-duration-log music (ly:intlog2 (ly:get-mus-property music 'repeat-count)) 0)
129 (ly:set-mus-property!
130 music 'length Repeated_music::unfolded_music_length)
131 (ly:set-mus-property!
132 music 'start-moment-function Repeated_music::first_start)
133 (ly:set-mus-property!
134 music 'iterator-ctor Unfolded_repeat_iterator::constructor)))
137 (ly:set-mus-property!
139 (map unfold-repeats es)))
142 (ly:set-mus-property!
149 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
150 ;; property setting music objs.
152 (define-public (make-grob-property-set grob gprop val)
154 "Make a Music expression that sets GPROP to VAL in GROB. Does a pop first,
155 i.e. this is not an override"
157 (let* ((m (make-music-by-name 'OverrideProperty)))
158 (ly:set-mus-property! m 'symbol grob)
159 (ly:set-mus-property! m 'grob-property gprop)
160 (ly:set-mus-property! m 'grob-value val)
161 (ly:set-mus-property! m 'pop-first #t)
168 (define-public (make-grob-property-revert grob gprop)
169 "Revert the grob property GPROP for GROB."
170 (let* ((m (make-music-by-name 'OverrideProperty)))
171 (ly:set-mus-property! m 'symbol grob)
172 (ly:set-mus-property! m 'grob-property gprop)
179 (define-public (make-voice-props-set n)
180 (make-sequential-music
182 (map (lambda (x) (make-grob-property-set x 'direction
184 '(Tie Slur Stem Dots))
186 (make-grob-property-set 'NoteColumn 'horizontal-shift (quotient n 2))
187 (make-grob-property-set 'MultiMeasureRest 'staff-position
196 (define-public (make-voice-props-revert)
197 (make-sequential-music
199 (make-grob-property-revert 'Tie 'direction)
200 (make-grob-property-revert 'Dots 'direction)
201 (make-grob-property-revert 'Stem 'direction)
202 (make-grob-property-revert 'Slur 'direction)
203 (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 (make-music-by-name 'ContextSpeccedMusic)))
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-apply-context func)
223 (m (make-music-by-name 'ApplyContext))
226 (ly:set-mus-property! m 'procedure func)
230 (define-public (make-sequential-music elts)
231 (let* ((m (make-music-by-name 'SequentialMusic)))
232 (ly:set-mus-property! m 'elements elts)
236 (define-public (make-simultaneous-music elts)
237 (let* ((m (make-music-by-name 'SimultaneousMusic)))
238 (ly:set-mus-property! m 'elements elts)
242 (define-public (make-event-chord elts)
243 (let* ((m (make-music-by-name 'EventChord)))
244 (ly:set-mus-property! m 'elements elts)
249 (define-public (make-multi-measure-rest duration location)
252 (start (make-music-by-name 'MultiMeasureRestEvent))
253 (stop (make-music-by-name 'MultiMeasureRestEvent))
254 (skip ( make-music-by-name 'SkipEvent))
255 (ch (make-music-by-name 'BarCheck))
256 (ch2 (make-music-by-name 'BarCheck))
257 (seq (make-music-by-name 'MultiMeasureRestMusicGroup))
260 (map (lambda (x) (ly:set-mus-property! x 'origin location))
261 (list start stop skip ch ch2 seq))
262 (ly:set-mus-property! start 'span-direction START)
263 (ly:set-mus-property! stop 'span-direction STOP)
264 (ly:set-mus-property! skip 'duration duration)
265 (ly:set-mus-property! seq 'elements
268 (make-event-chord (list start))
269 (make-event-chord (list skip))
270 (make-event-chord (list stop))
277 (define-public (glue-mm-rest-texts music)
278 "Check if we have R1*4-\markup { .. }, and if applicable convert to
279 a property set for MultiMeasureRestNumber."
281 (define (script-to-mmrest-text script-music)
282 "Extract 'direction and 'text from SCRIPT-MUSIC, and transform into property sets."
286 (text (ly:get-mus-property script-music 'text))
287 (dir (ly:get-mus-property script-music 'direction))
288 (p (make-music-by-name 'MultiMeasureTextEvent))
292 (ly:set-mus-property! p 'direction dir))
293 (ly:set-mus-property! p 'text text)
297 (if (eq? (ly:get-mus-property music 'name) 'MultiMeasureRestMusicGroup)
300 (text? (lambda (x) (memq 'script-event (ly:get-mus-property x 'types))))
301 (es (ly:get-mus-property music 'elements))
302 (texts (map script-to-mmrest-text (filter-list text? es)))
303 (others (filter-out-list text? es))
306 (ly:set-mus-property!
308 (cons (make-event-chord texts) others)
315 (define-public (make-property-set sym val)
318 (m (make-music-by-name 'PropertySet))
320 (ly:set-mus-property! m 'symbol sym)
321 (ly:set-mus-property! m 'value val)
325 (define-public (make-time-signature-set num den . rest)
326 " Set properties for time signature NUM/DEN.
327 Rest can contain a list of beat groupings
333 (set1 (make-property-set 'timeSignatureFraction (cons num den) ))
334 (beat (ly:make-moment 1 den))
335 (len (ly:make-moment num den))
336 (set2 (make-property-set 'beatLength beat))
337 (set3 (make-property-set 'measureLength len))
338 (set4 (make-property-set 'beatGrouping (if (pair? rest)
341 (basic (list set1 set2 set3 set4))
346 (make-sequential-music basic) "Timing")))
348 (define-public (set-time-signature num den . rest)
349 (ly:export (apply make-time-signature-set `(,num ,den . ,rest)))
352 (define-public (make-penalty-music pen)
354 ((m (make-music-by-name 'BreakEvent)))
355 (ly:set-mus-property! m 'penalty pen)
358 (define-public (make-articulation name)
360 (m (make-music-by-name 'ArticulationEvent))
362 (ly:set-mus-property! m 'articulation-type name)
366 (define-public (make-span-event type spandir)
368 (m (make-music-by-name type))
370 (ly:set-mus-property! m 'span-direction spandir)
374 (define-public (set-mus-properties! m alist)
375 "Set all of ALIST as properties of M."
378 (ly:set-mus-property! m (caar alist) (cdar alist))
379 (set-mus-properties! m (cdr alist)))
382 (define-public (music-separator? m)
384 (let* ((ts (ly:get-mus-property m 'types )))
389 ;;; splitting chords into voices.
391 (define (voicify-list lst number)
392 "Make a list of Musics.
394 voicify-list :: [ [Music ] ] -> number -> [Music]
395 LST is a list music-lists.
399 (cons (context-spec-music
400 (make-sequential-music
402 (make-voice-props-set number)
403 (make-simultaneous-music (car lst))))
405 "Voice" (number->string number))
406 (voicify-list (cdr lst) (+ number 1))
410 (define (voicify-chord ch)
411 "Split the parts of a chord into different Voices using separator"
412 (let* ((es (ly:get-mus-property ch 'elements)))
415 (ly:set-mus-property! ch 'elements
416 (voicify-list (split-list es music-separator?) 0))
420 (define (voicify-music m)
421 "Recursively split chords that are separated with \\ "
423 (if (not (ly:music? m))
425 (error "not music!"))
428 ((es (ly:get-mus-property m 'elements))
429 (e (ly:get-mus-property m 'element))
432 (ly:set-mus-property! m 'elements (map voicify-music es)))
434 (ly:set-mus-property! m 'element (voicify-music e)))
436 (and (equal? (ly:music-name m) "Simultaneous_music")
437 (reduce (lambda (x y ) (or x y)) (map music-separator? es)))
444 (define-public (empty-music)
445 (ly:export (make-music-by-name 'Music))
449 ; Make a function that checks score element for being of a specific type.
450 (define-public (make-type-checker symbol)
453 ;;(eq? #t (ly:get-grob-property elt symbol))
454 (not (eq? #f (memq symbol (ly:get-grob-property elt 'interfaces))))))
458 (define-public (smart-bar-check n)
459 "Make a bar check that checks for a specific bar number.
463 (m (make-music-by-name 'ApplyContext))
467 (let* ((bn (ly:get-context-property tr 'currentBarNumber)))
471 (format "Bar check failed, we should have reached ~a, instead at ~a\n"
475 (ly:set-mus-property! m 'procedure checker)
479 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
480 ;; warn for bare chords at start.
482 (define (has-request-chord elts)
483 (reduce (lambda (x y) (or x y)) (map (lambda (x) (equal? (ly:music-name x)
484 "Request_chord")) elts)
487 (define (ly:music-message music msg)
490 (ip (ly:get-mus-property music 'origin))
493 (if (ly:input-location? ip)
494 (ly:input-message ip msg)
498 (define (check-start-chords music)
499 "Check music expression for a Simultaneous_music containing notes\n(ie. Request_chords), without context specification. Called from parser."
502 ((es (ly:get-mus-property music 'elements))
503 (e (ly:get-mus-property music 'element))
504 (name (ly:music-name music))
508 ((equal? name "Context_specced_music") #t)
509 ((equal? name "Simultaneous_music")
511 (if (has-request-chord es)
512 (ly:music-message music "Starting score with a chord.\nPlease insert an explicit \\context before chord")
513 (map check-start-chords es)))
515 ((equal? name "Sequential_music")
517 (check-start-chords (car es))))
518 (else (if (ly:music? e) (check-start-chords e )))
524 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
525 ;; switch it on here, so parsing and init isn't checked (too slow!)
527 ;; automatic music transformations.
529 (define (switch-on-debugging m)
530 (set-debug-cell-accesses! 15000)
534 (define-public toplevel-music-functions
535 (list check-start-chords
537 (lambda (x) (music-map glue-mm-rest-texts x))
538 ; switch-on-debugging