6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 %% this file is alphabetically sorted.
8 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10 %% need SRFI-1 for filter; optargs for lambda*
11 #(use-modules (srfi srfi-1)
14 %% TODO: using define-music-function in a .scm causes crash.
17 #(def-grace-function startAcciaccaturaMusic stopAcciaccaturaMusic
18 (_i "Create an acciaccatura from the following music expression"))
20 %% keep these two together
21 "instrument-definitions" = #'()
22 addInstrumentDefinition =
23 #(define-music-function
24 (parser location name lst) (string? list?)
25 (_i "Create instrument @var{name} with properties @var{list}.")
26 (set! instrument-definitions (acons name lst instrument-definitions))
27 (make-music 'SequentialMusic 'void #t))
30 #(define-music-function (parser location name music) (string? ly:music?)
31 (_i "Define @var{music} as a quotable music expression named
33 (add-quotable parser name music)
34 (make-music 'SequentialMusic 'void #t))
36 %% keep these two together
37 afterGraceFraction = #(cons 6 8)
39 #(define-music-function
40 (parser location main grace)
42 (_i "Create @var{grace} note(s) after a @var{main} music expression.")
44 ((main-length (ly:music-length main))
45 (fraction (ly:parser-lookup parser 'afterGraceFraction)))
47 (make-simultaneous-music
50 (make-sequential-music
53 (make-music 'SkipMusic
54 'duration (ly:make-duration
56 (* (ly:moment-main-numerator main-length)
58 (* (ly:moment-main-denominator main-length)
60 (make-music 'GraceMusic
64 %% music identifiers not allowed at top-level,
65 %% so this is a music-function instead.
67 #(define-music-function (location parser) ()
68 (_i "Allow a page turn. May be used at toplevel (ie between scores or
69 markups), or inside a score.")
70 (make-music 'EventChord
72 'page-turn-permission 'allow
73 'elements (list (make-music 'PageTurnEvent
74 'break-permission 'allow))))
77 #(define-music-function (parser location proc) (procedure?)
78 (_i "Modify context properties with Scheme procedure @var{proc}.")
79 (make-music 'ApplyContext
84 #(define-music-function (parser location func music) (procedure? ly:music?)
85 (_i"Apply procedure @var{func} to @var{music}.")
89 #(define-music-function (parser location ctx proc) (symbol? procedure?)
90 (_i "Apply function @code{proc} to every layout object in context @code{ctx}")
91 (make-music 'ApplyOutputEvent
97 #(def-grace-function startAppoggiaturaMusic stopAppoggiaturaMusic
98 (_i "Create an appoggiatura from @var{music}"))
100 % for regression testing purposes.
102 #(define-music-function (parser location l r) (pair? pair?)
103 (_i "Testing function: check whether the beam quants @var{l} and @var{r} are correct")
104 (make-grob-property-override 'Beam 'positions
105 (ly:make-simple-closure
106 (ly:make-simple-closure
108 (list chain-grob-member-functions `(,cons 0 0))
109 (check-quant-callbacks l r))))))
111 % for regression testing purposes.
113 #(define-music-function (parser location comp) (procedure?)
114 (_i "Testing function: check whether the slope of the beam is the same as @code{comp}")
115 (make-grob-property-override 'Beam 'positions
116 (ly:make-simple-closure
117 (ly:make-simple-closure
119 (list chain-grob-member-functions `(,cons 0 0))
120 (check-slope-callbacks comp))))))
123 #(define-music-function (parser location music) (ly:music?)
124 (_i "Make voices that switch between staves automatically")
125 (make-autochange-music parser music))
130 #(define-music-function (parser location grob-name offset text)
131 (symbol? number-pair? markup?)
132 (_i "Attach @var{text} to @var{grob-name} at offset @var{offset}
133 (use like @code{\\once})")
134 (make-music 'AnnotateOutputEvent
136 'X-offset (car offset)
137 'Y-offset (cdr offset)
141 #(define-music-function (parser location offset text) (number-pair? markup?)
142 (_i "Attach @var{text} at @var{offset} (use like @code{\\tweak})")
143 (make-music 'AnnotateOutputEvent
144 'X-offset (car offset)
145 'Y-offset (cdr offset)
149 #(define-music-function (parser location type) (string?)
150 (_i "Insert a bar line of type @var{type}")
152 (make-property-set 'whichBar type)
156 #(define-music-function (parser location n) (integer?)
157 (_i "Print a warning if the current bar number is not @var{n}.")
158 (make-music 'ApplyContext
163 ((cbn (ly:context-property c 'currentBarNumber)))
164 (if (and (number? cbn) (not (= cbn n)))
165 (ly:input-message location "Barcheck failed got ~a expect ~a"
169 #(define-music-function (parser location delta) (real?)
170 (_i "Create a fall or doit of pitch interval @var{delta}.")
171 (make-music 'BendAfterEvent
176 #(define-music-function (parser location) ()
177 (_i "Insert a breath mark.")
178 (make-music 'EventChord
180 'elements (list (make-music 'BreathingEvent))))
185 #(define-music-function (parser location type) (string?)
186 (_i "Set the current clef to @var{type}.")
187 (make-clef-set type))
190 #(define-music-function
191 (parser location what dir main-music) (string? ly:dir? ly:music?)
192 (_i "Insert contents of quote @var{what} corresponding to @var{main-music},
193 in a CueVoice oriented by @var{dir}.")
194 (make-music 'QuoteMusic
196 'quoted-context-type 'Voice
197 'quoted-context-id "cue"
198 'quoted-music-name what
199 'quoted-voice-direction dir
205 #(define-music-function (parser location music) (ly:music?)
206 (_i "Display the LilyPond input representation of @var{music}
209 (display-lily-music music parser)
213 #(define-music-function (parser location music) (ly:music?)
214 (_i "Display the internal representation of @var{music} to the console.")
216 (display-scheme-music music)
222 #(define-music-function (parser location music) (ly:music?)
223 (_i "Terminate the next spanner prematurely after exactly one note without the need of a specific end spanner.")
224 (if (eq? (ly:music-property music 'name) 'EventChord)
226 ((elts (ly:music-property music 'elements))
227 (start-span-evs (filter (lambda (ev)
228 (and (music-has-type ev 'span-event)
229 (equal? (ly:music-property ev 'span-direction)
234 (let* ((c (music-clone m)))
235 (set! (ly:music-property c 'span-direction) STOP)
238 (end-ev-chord (make-music 'EventChord
239 'elements stop-span-evs))
240 (total (make-music 'SequentialMusic
241 'elements (list music
245 (ly:input-message location (_ "argument endSpanners is not an EventChord: ~a" music))))
250 #(define-music-function (parser location factor argument) (ly:moment? ly:music?)
251 (_i "Adjust durations of music in @var{argument} by rational @var{factor}. ")
253 ((orig-duration (ly:music-length argument))
254 (multiplier (ly:make-moment 1 1)))
258 (if (and (eq? (ly:music-property mus 'name) 'EventChord)
259 (< 0 (ly:moment-main-denominator (ly:music-length mus))))
261 (ly:music-compress mus multiplier)
262 (set! multiplier (ly:moment-mul factor multiplier)))
269 (ly:moment-div orig-duration (ly:music-length argument)))
276 #(def-grace-function startGraceMusic stopGraceMusic
277 (_i "Insert @var{music} as grace notes."))
282 #(define-music-function
283 (parser location name) (string?)
284 (_i "Switch instrument to @var{name}, which must be predefined with
285 @code{\\addInstrumentDefinition}.")
287 ((handle (assoc name instrument-definitions))
288 (instrument-def (if handle (cdr handle) '()))
292 (ly:input-message location "No such instrument: ~a" name))
294 (make-music 'SimultaneousMusic
306 #(define-music-function
307 (parser location tag music) (symbol? ly:music?)
308 (_i "Include only elements of @var{music} that are tagged with @var{tag}.")
311 (let* ((tags (ly:music-property m 'tags))
312 (res (memq tag tags)))
319 #(define-music-function
320 (parser location music)
322 (_i "Remove cue notes from @var{music}.")
325 (if (and (string? (ly:music-property mus 'quoted-music-name))
326 (string=? (ly:music-property mus 'quoted-context-id) "cue"))
327 (ly:music-property mus 'element)
333 #(define-music-function (parser location label) (symbol?)
334 (_i "Create @var{label} as a bookmarking label")
335 (make-music 'EventChord
338 'elements (list (make-music 'LabelEvent
339 'page-label label))))
344 #(define-music-function
345 (parser location arg) (ly:music?)
346 (_i "Display chords in @var{arg} as clusters")
347 (music-map note-to-cluster arg))
350 #(define-music-function (parser location proc mus) (procedure? ly:music?)
351 (music-map proc mus))
355 %% noPageBreak and noPageTurn are music functions (not music indentifiers),
356 %% because music identifiers are not allowed at top-level.
358 #(define-music-function (location parser) ()
359 (_i "Forbid a page break. May be used at toplevel (ie between scores or
360 markups), or inside a score.")
361 (make-music 'EventChord
363 'page-break-permission 'forbid
364 'elements (list (make-music 'PageBreakEvent
365 'break-permission '()))))
368 #(define-music-function (location parser) ()
369 (_i "Forbid a page turn. May be used at toplevel (ie between scores or
370 markups), or inside a score.")
371 (make-music 'EventChord
373 'page-turn-permission 'forbid
374 'elements (list (make-music 'PageTurnEvent
375 'break-permission '()))))
380 #(define-music-function (parser location pitch-note) (ly:music?)
383 (make-music 'RelativeOctaveCheck
385 'pitch (pitch-of-note pitch-note)
388 ottava = #(define-music-function (parser location octave) (number?)
389 (_i "set the octavation ")
390 (make-ottava-set octave))
392 overrideBeamSettings =
393 #(define-music-function
395 context time-signature rule-type grouping-rule)
396 (symbol? pair? symbol? pair?)
398 (_i "Override beamSettings in @var{context}
399 for time signatures of @var{time-signature} and rules of type
400 @var{rule-type} to have a grouping rule alist
402 @var{rule-type} can be @code{end} or @code{subdivide},
403 with a potential future value of @code{begin}.
404 @var{grouping-rule} is an alist of @var{(beam-type . grouping)}
405 entries. @var{grouping} is in units of @var{beam-type}. If
406 @var{beam-type} is @code{*}, grouping is in units of the denominator
407 of @var{time-signature}.")
409 ;; TODO -- add warning if largest value of grouping is
410 ;; greater than time-signature.
413 #(override-beam-setting
414 $time-signature $rule-type $grouping-rule $context)
418 #(define-music-function (parser location name property value)
419 (string? symbol? scheme?)
421 (_i "Set @var{property} to @var{value} in all grobs named @var{name}.
422 The @var{name} argument is a string of the form @code{\"Context.GrobName\"}
423 or @code{\"GrobName\"}")
426 ((name-components (string-split name #\.))
427 (context-name 'Bottom)
430 (if (> 2 (length name-components))
431 (set! grob-name (string->symbol (car name-components)))
433 (set! grob-name (string->symbol (list-ref name-components 1)))
434 (set! context-name (string->symbol (list-ref name-components 0)))))
436 (make-music 'ApplyOutputEvent
438 'context-type context-name
440 (lambda (grob orig-context context)
442 (cdr (assoc 'name (ly:grob-property grob 'meta)))
444 (set! (ly:grob-property grob property) value))))))
448 %% pageBreak and pageTurn are music functions (iso music indentifiers),
449 %% because music identifiers are not allowed at top-level.
451 #(define-music-function (location parser) ()
452 (_i "Force a page break. May be used at toplevel (ie between scores or
453 markups), or inside a score.")
454 (make-music 'EventChord
456 'line-break-permission 'force
457 'page-break-permission 'force
458 'elements (list (make-music 'LineBreakEvent
459 'break-permission 'force)
460 (make-music 'PageBreakEvent
461 'break-permission 'force))))
464 #(define-music-function (location parser) ()
465 (_i "Force a page turn between two scores or top-level markups.")
466 (make-music 'EventChord
468 'line-break-permission 'force
469 'page-break-permission 'force
470 'page-turn-permission 'force
471 'elements (list (make-music 'LineBreakEvent
472 'break-permission 'force)
473 (make-music 'PageBreakEvent
474 'break-permission 'force)
475 (make-music 'PageTurnEvent
476 'break-permission 'force))))
479 #(define-music-function (parser location voice-ids music) (list? ly:music?)
480 (_i "Define parallel music sequences, separated by '|' (bar check signs),
481 and assign them to the identifiers provided in @var{voice-ids}.
483 @var{voice-ids}: a list of music identifiers (symbols containing only letters)
485 @var{music}: a music sequence, containing BarChecks as limiting expressions.
490 \\parallelMusic #'(A B C) {
500 (let* ((voices (apply circular-list (make-list (length voice-ids) (list))))
501 (current-voices voices)
502 (current-sequence (list)))
505 (define (push-music m)
506 "Push the music expression into the current sequence"
507 (set! current-sequence (cons m current-sequence)))
508 (define (change-voice)
509 "Stores the previously built sequence into the current voice and
510 change to the following voice."
511 (list-set! current-voices 0 (cons (make-music 'SequentialMusic
512 'elements (reverse! current-sequence))
513 (car current-voices)))
514 (set! current-sequence (list))
515 (set! current-voices (cdr current-voices)))
516 (define (bar-check? m)
517 "Checks whether m is a bar check."
518 (eq? (ly:music-property m 'name) 'BarCheck))
519 (define (music-origin music)
520 "Recursively search an origin location stored in music."
521 (cond ((null? music) #f)
522 ((not (null? (ly:music-property music 'origin)))
523 (ly:music-property music 'origin))
524 (else (or (music-origin (ly:music-property music 'element))
525 (let ((origins (remove not (map music-origin
526 (ly:music-property music 'elements)))))
527 (and (not (null? origins)) (car origins)))))))
529 ;; first, split the music and fill in voices
530 (map-in-order (lambda (m)
532 (if (bar-check? m) (change-voice)))
533 (ly:music-property music 'elements))
534 (if (not (null? current-sequence)) (change-voice))
535 ;; un-circularize `voices' and reorder the voices
536 (set! voices (map-in-order (lambda (dummy seqs)
540 ;; set origin location of each sequence in each voice
541 ;; for better type error tracking
542 (for-each (lambda (voice)
543 (for-each (lambda (seq)
544 (set! (ly:music-property seq 'origin)
545 (or (music-origin seq) location)))
549 ;; check sequence length
550 (apply for-each (lambda* (#:rest seqs)
551 (let ((moment-reference (ly:music-length (car seqs))))
552 (for-each (lambda (seq moment)
553 (if (not (equal? moment moment-reference))
554 (ly:music-message seq
555 "Bars in parallel music don't have the same length")))
556 seqs (map-in-order ly:music-length seqs))))
559 ;; bind voice identifiers to the voices
560 (map (lambda (voice-id voice)
561 (ly:parser-define! parser voice-id
562 (make-music 'SequentialMusic
566 ;; Return an empty sequence. this function is actually a "void" function.
567 (make-music 'SequentialMusic 'void #t))
570 #(define-music-function (parser loc arg) (ly:music?)
571 (_i "Tag @var{arg} to be parenthesized.")
573 (if (memq 'event-chord (ly:music-property arg 'types))
574 ; arg is an EventChord -> set the parenthesize property on all child notes and rests
577 (if (or (memq 'note-event (ly:music-property ev 'types))
578 (memq 'rest-event (ly:music-property ev 'types)))
579 (set! (ly:music-property ev 'parenthesize) #t)))
580 (ly:music-property arg 'elements))
581 ; No chord, simply set property for this expression:
582 (set! (ly:music-property arg 'parenthesize) #t))
586 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
587 (make-part-combine-music parser
591 #(define-music-function
592 (parser location main-note secondary-note)
593 (ly:music? ly:music?)
595 ((get-notes (lambda (ev-chord)
597 (lambda (m) (eq? 'NoteEvent (ly:music-property m 'name)))
598 (ly:music-property ev-chord 'elements))))
599 (sec-note-events (get-notes secondary-note))
600 (trill-events (filter (lambda (m) (music-has-type m 'trill-span-event))
601 (ly:music-property main-note 'elements))))
603 (if (pair? sec-note-events)
606 ((trill-pitch (ly:music-property (car sec-note-events) 'pitch))
607 (forced (ly:music-property (car sec-note-events ) 'force-accidental)))
609 (if (ly:pitch? trill-pitch)
610 (for-each (lambda (m) (ly:music-set-property! m 'pitch trill-pitch))
613 (ly:warning (_ "Second argument of \\pitchedTrill should be single note: "))
614 (display sec-note-events)))
617 (for-each (lambda (m) (ly:music-set-property! m 'force-accidental forced))
624 #(define-music-function
625 (parser location what main-music)
627 (make-music 'QuoteMusic
629 'quoted-music-name what
635 #(define-music-function
636 (parser location tag music) (symbol? ly:music?)
637 (_i "Remove elements of @var{music} that are tagged with @var{tag}.")
640 (let* ((tags (ly:music-property m 'tags))
641 (res (memq tag tags)))
645 resetRelativeOctave =
646 #(define-music-function
647 (parser location reference-note)
649 (_i "Set the octave inside a \\relative section.")
652 ((notes (ly:music-property reference-note 'elements))
653 (pitch (ly:music-property (car notes) 'pitch)))
655 (set! (ly:music-property reference-note 'elements) '())
656 (set! (ly:music-property reference-note
657 'to-relative-callback)
658 (lambda (music last-pitch)
664 #(define-music-function
666 context time-signature rule-type)
667 (symbol? pair? symbol?)
669 (_i "Revert beam settings in @var{context} for time signatures of
670 @var{time-signature} and groups of type
671 @var{group-type}. @var{group-type} can be @code{end}
672 or @code{subdivide}.")
674 #(revert-beam-setting $time-signature $rule-type $context)
678 #(define-music-function (parser location finger) (number-or-string?)
679 (_i "Apply @var{finger} as a fingering indication.")
688 (list 'digit finger)))))
693 #(define-music-function (parser location fraction music) (number-pair? ly:music?)
694 (_i "Multiply the duration of events in @var{music} by @var{fraction}.")
695 (ly:music-compress music
696 (ly:make-moment (car fraction) (cdr fraction))))
699 #(define-music-function (parser location grouping) (pair?)
700 (_i "Set the beat grouping in the current time signature to
702 (define (default-group-setting c)
703 (let* ((context-time-signature
704 (ly:context-property c 'timeSignatureFraction))
705 (time-signature (if (null? context-time-signature)
707 context-time-signature)))
708 (override-property-setting
711 (list time-signature 'end)
712 (list (cons '* grouping)))))
715 (make-apply-context default-group-setting)
719 #(define-music-function (parser location dur dots arg) (integer? integer? ly:music?)
720 (_i "Scale @var{arg} up by a factor of @var{2^dur*(2-(1/2)^dots)}.")
724 (shift-one-duration-log x dur dots)) arg))
727 #(define-music-function (parser location parameters) (list?)
728 (_i "Set the system stretch, by reading the 'system-stretch property of
729 the `parameters' assoc list.")
731 \overrideProperty #"Score.NonMusicalPaperColumn"
732 #'line-break-system-details
733 #$(list (cons 'alignment-extra-space (cdr (assoc 'system-stretch parameters)))
734 (cons 'system-Y-extent (cdr (assoc 'system-Y-extent parameters))))
738 #(define-music-function
739 (parser location style heads music)
740 (symbol? list-or-symbol? ly:music?)
741 (_i "Set @var{heads} in @var{music} to @var{style}.")
742 (style-note-heads heads style music))
747 #(define-music-function (parser location tag arg)
750 (_i "Add @var{tag} to the @code{tags} property of @var{arg}.")
753 (ly:music-property arg 'tags)
755 (ly:music-property arg 'tags)))
758 transposedCueDuring =
759 #(define-music-function
760 (parser location what dir pitch-note main-music)
761 (string? ly:dir? ly:music? ly:music?)
763 (_i "Insert notes from the part @var{what} into a voice called @code{cue},
764 using the transposition defined by @var{pitch-note}. This happens
765 simultaneously with @var{main-music}, which is usually a rest. The
766 argument @var{dir} determines whether the cue notes should be notated
767 as a first or second voice.")
769 (make-music 'QuoteMusic
771 'quoted-context-type 'Voice
772 'quoted-context-id "cue"
773 'quoted-music-name what
774 'quoted-voice-direction dir
775 'quoted-transposition (pitch-of-note pitch-note)
779 #(define-music-function (parser location pitch-note) (ly:music?)
780 (_i "Set instrument transposition")
783 (make-property-set 'instrumentTransposition
784 (ly:pitch-negate (pitch-of-note pitch-note)))
788 #(define-music-function (parser location sym val arg)
789 (symbol? scheme? ly:music?)
790 (_i "Add @code{sym . val} to the @code{tweaks} property of @var{arg}.")
792 (if (equal? (object-property sym 'backend-type?) #f)
794 (ly:warning (_ "cannot find property type-check for ~a") sym)
795 (ly:warning (_ "doing assignment anyway"))))
797 (ly:music-property arg 'tweaks)
799 (ly:music-property arg 'tweaks)))
805 #(define-music-function (parser location music) (ly:music?)
806 (unfold-repeats music))
811 #(define-music-function (parser location sym val music) (symbol? scheme? ly:music?)
812 (_i "Set @var{sym} to @var{val} in @var{music}.")
814 (set! (ly:music-property music sym) val)