7 #(use-modules (srfi srfi-1))
10 tweak = #(define-music-function (parser location sym val arg)
11 (symbol? scheme? ly:music?)
13 "Add @code{sym . val} to the @code{tweaks} property of @var{arg}."
17 (ly:music-property arg 'tweaks)
19 (ly:music-property arg 'tweaks)))
22 tag = #(define-music-function (parser location tag arg)
25 "Add @var{tag} to the @code{tags} property of @var{arg}."
28 (ly:music-property arg 'tags)
30 (ly:music-property arg 'tags)))
34 #(define-music-function (parser location type)
37 "Set the current clef."
42 #(define-music-function (parser location type)
45 (make-property-set 'whichBar type)
49 #(define-music-function (parser location func music) (procedure? ly:music?)
53 #(define-music-function (parser location music lyrics) (ly:music? ly:music?)
55 (make-music 'OldLyricCombineMusic
57 'elements (list music lyrics)))
60 #(def-grace-function startGraceMusic stopGraceMusic)
63 #(def-grace-function startAcciaccaturaMusic stopAcciaccaturaMusic)
65 #(def-grace-function startAppoggiaturaMusic stopAppoggiaturaMusic)
68 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
69 (make-part-combine-music (list part1 part2)))
72 #(define-music-function (parser location music) (ly:music?)
73 (make-autochange-music music))
76 #(define-music-function (parser location proc) (procedure?)
77 (make-music 'ApplyContext
82 #(define-music-function (parser location dur dots arg) (integer? integer? ly:music?)
88 (shift-one-duration-log x dur dots)) arg))
91 #(define-music-function (parser location proc mus) (procedure? ly:music?)
95 #(define-music-function (parser location music) (ly:music?)
96 (display-scheme-music music)
99 %% FIXME: guile-1.7 required?
100 %#(use-modules (scm display-lily))invalid module name for use-syntax ((srfi srfi-39))
102 #(use-modules (scm display-lily))
103 #(display-lily-init parser)
105 #(define-music-function (parser location music) (ly:music?)
106 (display-lily-music music)
110 #(define-music-function (parser location ctx proc) (symbol? procedure?)
111 (make-music 'ApplyOutputEvent
117 #(define-music-function (parser location name property value)
118 (string? symbol? scheme?)
121 "Set @var{property} to @var{value} in all grobs named @var{name}.
122 The @var{name} argument is a string of the form @code{\"Context.GrobName\"}
123 or @code{\"GrobName\"}"
126 ((name-components (string-split name #\.))
127 (context-name 'Bottom)
130 (if (> 2 (length name-components))
131 (set! grob-name (string->symbol (car name-components)))
133 (set! grob-name (string->symbol (list-ref name-components 1)))
134 (set! context-name (string->symbol (list-ref name-components 0)))))
136 (make-music 'ApplyOutputEvent
138 'context-type context-name
140 (lambda (grob orig-context context)
142 (cdr (assoc 'name (ly:grob-property grob 'meta)))
144 (set! (ly:grob-property grob property) value))))))
147 #(define-music-function (parser location) ()
148 (make-music 'EventChord
150 'elements (list (make-music 'BreathingSignEvent))))
154 #(define-music-function (parser location music) (ly:music?)
155 (unfold-repeats music))
158 #(define-music-function
159 (parser location fraction music) (number-pair? ly:music?)
160 (ly:music-compress music (ly:make-moment (car fraction) (cdr fraction))))
163 #(define-music-function
164 (parser location arg) (ly:music?)
165 (music-map note-to-cluster arg))
169 #(define-music-function
170 (parser location tag music) (symbol? ly:music?)
173 (let* ((tags (ly:music-property m 'tags))
174 (res (memq tag tags)))
179 #(define-music-function
180 (parser location tag music) (symbol? ly:music?)
183 (let* ((tags (ly:music-property m 'tags))
184 (res (memq tag tags)))
193 %% define-music-function in a .scm causes crash.
196 #(define-music-function
197 (parser location what dir main-music)
198 (string? ly:dir? ly:music?)
199 (make-music 'QuoteMusic
201 'quoted-context-type 'Voice
202 'quoted-context-id "cue"
203 'quoted-music-name what
204 'quoted-voice-direction dir
208 transposedCueDuring = #
209 (define-music-function
210 (parser location what dir pitch-note main-music)
211 (string? ly:dir? ly:music? ly:music?)
213 "Insert notes from the part @var{what} into a voice called @code{cue},
214 using the transposition defined by @var{pitch-note}. This happens
215 simultaneously with @var{main-music}, which is usually a rest. The
216 argument @var{dir} determines whether the cue notes should be notated
217 as a first or second voice."
219 (make-music 'QuoteMusic
221 'quoted-context-type 'Voice
222 'quoted-context-id "cue"
223 'quoted-music-name what
224 'quoted-voice-direction dir
225 'quoted-transposition (pitch-of-note pitch-note)
230 (define-music-function
231 (parser location what main-music)
233 (make-music 'QuoteMusic
235 'quoted-music-name what
240 #(define-music-function
241 (parser location main-note secondary-note)
242 (ly:music? ly:music?)
244 ((get-notes (lambda (ev-chord)
246 (lambda (m) (eq? 'NoteEvent (ly:music-property m 'name)))
247 (ly:music-property ev-chord 'elements))))
248 (sec-note-events (get-notes secondary-note))
249 (trill-events (filter (lambda (m) (memq 'trill-span-event (ly:music-property m 'types)))
250 (ly:music-property main-note 'elements)))
253 (if (pair? sec-note-events)
254 (ly:music-property (car sec-note-events) 'pitch)
257 (if (ly:pitch? trill-pitch)
258 (for-each (lambda (m) (ly:music-set-property! m 'pitch trill-pitch))
261 (ly:warning (_ "Second argument of \\pitchedTrill should be single note: "))
262 (display sec-note-events)))
267 #(define-music-function
268 (parser location music)
272 (if (string? (ly:music-property mus 'quoted-music-name))
273 (ly:music-property mus 'element)
281 #(define-music-function
282 (parser location main grace)
283 (ly:music? ly:music?)
286 ((main-length (ly:music-length main))
287 (fraction (ly:parser-lookup parser 'afterGraceFraction)))
289 (make-simultaneous-music
292 (make-sequential-music
295 (make-music 'SkipMusic
296 'duration (ly:make-duration
298 (* (ly:moment-main-numerator main-length)
300 (* (ly:moment-main-denominator main-length)
302 (make-music 'GraceMusic
303 'element grace)))))))
307 #(define-music-function (parser location n) (integer?)
308 (make-music 'ApplyContext
313 ((cbn (ly:context-property c 'currentBarNumber)))
315 (ly:input-message location "Barcheck failed got ~a expect ~a"
320 % for regression testing purposes.
322 #(define-music-function (parser location l r) (pair? pair?)
323 (make-grob-property-override 'Beam 'positions
324 (ly:make-simple-closure
325 (ly:make-simple-closure
327 (list chain-grob-member-functions `(,cons 0 0))
328 (check-quant-callbacks l r))))))
330 % for regression testing purposes.
332 #(define-music-function (parser location comp) (procedure?)
333 (make-grob-property-override 'Beam 'positions
334 (ly:make-simple-closure
335 (ly:make-simple-closure
337 (list chain-grob-member-functions `(,cons 0 0))
338 (check-slope-callbacks comp))))))
342 #(define-music-function (parser location voice-ids music) (list? ly:music?)
343 "Define parallel music sequences, separated by '|' (bar check signs),
344 and assign them to the identifiers provided in @var{voice-ids}.
346 @var{voice-ids}: a list of music identifiers (symbols containing only letters)
348 @var{music}: a music sequence, containing BarChecks as limiting expressions.
351 \\parallelMusic #'(A B C) {
360 (let* ((voices (apply circular-list (make-list (length voice-ids) (list))))
361 (current-voices voices)
362 (current-sequence (list)))
365 (define (push-music m)
366 "Push the music expression into the current sequence"
367 (set! current-sequence (cons m current-sequence)))
368 (define (change-voice)
369 "Stores the previously built sequence into the current voice and
370 change to the following voice."
371 (list-set! current-voices 0 (cons (make-music 'SequentialMusic
372 'elements (reverse! current-sequence))
373 (car current-voices)))
374 (set! current-sequence (list))
375 (set! current-voices (cdr current-voices)))
376 (define (bar-check? m)
377 "Checks whether m is a bar check."
378 (eq? (ly:music-property m 'name) 'BarCheck))
379 (define (music-origin music)
380 "Recursively search an origin location stored in music."
381 (cond ((null? music) #f)
382 ((not (null? (ly:music-property music 'origin)))
383 (ly:music-property music 'origin))
384 (else (or (music-origin (ly:music-property music 'element))
385 (let ((origins (remove not (map music-origin
386 (ly:music-property music 'elements)))))
387 (and (not (null? origins)) (car origins)))))))
389 ;; first, split the music and fill in voices
390 (map-in-order (lambda (m)
392 (if (bar-check? m) (change-voice)))
393 (ly:music-property music 'elements))
394 (if (not (null? current-sequence)) (change-voice))
395 ;; un-circularize `voices' and reorder the voices
396 (set! voices (map-in-order (lambda (dummy seqs)
400 ;; set origin location of each sequence in each voice
401 ;; for better type error tracking
402 (for-each (lambda (voice)
403 (for-each (lambda (seq)
404 (set! (ly:music-property seq 'origin)
405 (or (music-origin seq) location)))
409 ;; check sequence length
410 (apply for-each (lambda (. seqs)
411 (let ((moment-reference (ly:music-length (car seqs))))
412 (for-each (lambda (seq moment)
413 (if (not (equal? moment moment-reference))
414 (ly:music-message seq
415 "Bars in parallel music don't have the same length")))
416 seqs (map-in-order ly:music-length seqs))))
419 ;; bind voice identifiers to the voices
420 (map (lambda (voice-id voice)
421 (ly:parser-define! parser voice-id
422 (make-music 'SequentialMusic
426 ;; Return an empty sequence. this function is actually a "void" function.
427 (make-music 'SequentialMusic 'void #t))
432 %% this is a stub. Write your own to suit the spacing tweak output.
434 #(define-music-function (parser location parameters) (list?)
435 (make-music 'SequentialMusic 'void #t))
438 #(define-music-function (parser location pitch-note) (ly:music?)
441 (make-music 'RelativeOctaveCheck
443 'pitch (pitch-of-note pitch-note)
447 #(define-music-function (parser location name music) (string? ly:music?)
448 "Add a piece of music to be quoted "
449 (add-quotable name music)
450 (make-music 'SequentialMusic 'void #t))
454 #(define-music-function (parser loc arg) (ly:music?)
455 "Tag @var{arg} to be parenthesized."
457 (set! (ly:music-property arg 'parenthesize) #t)
462 #(define-music-function (parser location factor argument) (ly:moment? ly:music?)
464 "Rearrange durations in ARGUMENT so there is an
465 acceleration/deceleration. "
468 ((orig-duration (ly:music-length argument))
469 (multiplier (ly:make-moment 1 1)))
473 (if (and (eq? (ly:music-property mus 'name) 'EventChord)
474 (< 0 (ly:moment-main-denominator (ly:music-length mus))))
476 (ly:music-compress mus multiplier)
477 (set! multiplier (ly:moment-mul factor multiplier)))
484 (ly:moment-div orig-duration (ly:music-length argument)))
491 resetRelativeOctave =
492 #(define-music-function
493 (parser location reference-note)
495 "Set the octave inside a \\relative section."
498 ((notes (ly:music-property reference-note 'elements))
499 (pitch (ly:music-property (car notes) 'pitch)))
501 (set! (ly:music-property reference-note 'elements) '())
502 (set! (ly:music-property reference-note
503 'to-relative-callback)
504 (lambda (music last-pitch)