6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 %% this file is alphabetically sorted.
8 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 #(use-modules (srfi srfi-1))
15 #(def-grace-function startAcciaccaturaMusic stopAcciaccaturaMusic
16 (_i "Create an acciaccatura from the following music expression"))
19 #(define-music-function (parser location name music) (string? ly:music?)
20 (_i "Define @var{music} as a quotable music expression named
22 (add-quotable parser name music)
23 (make-music 'SequentialMusic 'void #t))
29 #(define-music-function
30 (parser location main grace)
32 (_i "Create @var{grace} note(s) after a @var{main} music expression.")
34 ((main-length (ly:music-length main))
35 (fraction (ly:parser-lookup parser 'afterGraceFraction)))
37 (make-simultaneous-music
40 (make-sequential-music
43 (make-music 'SkipMusic
44 'duration (ly:make-duration
46 (* (ly:moment-main-numerator main-length)
48 (* (ly:moment-main-denominator main-length)
50 (make-music 'GraceMusic
54 #(define-music-function (parser location func music) (procedure? ly:music?)
55 (_i"Apply procedure @var{func} to @var{music}.")
60 #(define-music-function (parser location ctx proc) (symbol? procedure?)
61 (_i "Apply function @code{proc} to every layout object in context @code{ctx}")
62 (make-music 'ApplyOutputEvent
68 #(def-grace-function startAppoggiaturaMusic stopAppoggiaturaMusic
69 (_i "Create an appoggiatura from @var{music}"))
72 % for regression testing purposes.
74 #(define-music-function (parser location l r) (pair? pair?)
75 (_i "Testing function: check whether the beam quants @var{l} and @var{r} are correct")
76 (make-grob-property-override 'Beam 'positions
77 (ly:make-simple-closure
78 (ly:make-simple-closure
80 (list chain-grob-member-functions `(,cons 0 0))
81 (check-quant-callbacks l r))))))
83 % for regression testing purposes.
85 #(define-music-function (parser location comp) (procedure?)
86 (_i "Testing function: check whether the slope of the beam is the same as @code{comp}")
87 (make-grob-property-override 'Beam 'positions
88 (ly:make-simple-closure
89 (ly:make-simple-closure
91 (list chain-grob-member-functions `(,cons 0 0))
92 (check-slope-callbacks comp))))))
97 #(define-music-function (parser location music) (ly:music?)
98 (_i "Make voices that switch between staves automatically")
99 (make-autochange-music parser music))
102 #(define-music-function (parser location proc) (procedure?)
103 (_i "Modify context properties with Scheme procedure @var{proc}.")
104 (make-music 'ApplyContext
110 #(define-music-function (parser location grob-name offset text)
111 (symbol? number-pair? markup?)
112 (_i "Attach @var{text} to @var{grob-name} at offset @var{offset}
113 (use like @code{\\once})")
114 (make-music 'AnnotateOutputEvent
116 'X-offset (car offset)
117 'Y-offset (cdr offset)
121 #(define-music-function (parser location offset text) (number-pair? markup?)
122 (_i "Attach @var{text} at @var{offset} (use like @code{\\tweak})")
123 (make-music 'AnnotateOutputEvent
124 'X-offset (car offset)
125 'Y-offset (cdr offset)
130 #(define-music-function (parser location type) (string?)
131 (_i "Insert a bar line of type @var{type}")
133 (make-property-set 'whichBar type)
138 #(define-music-function (parser location n) (integer?)
139 (_i "Print a warning if the current bar number is not @var{n}.")
140 (make-music 'ApplyContext
145 ((cbn (ly:context-property c 'currentBarNumber)))
146 (if (and (number? cbn) (not (= cbn n)))
147 (ly:input-message location "Barcheck failed got ~a expect ~a"
152 #(define-music-function (parser location delta) (real?)
153 (_i "Create a fall or doit of pitch interval @var{delta}.")
154 (make-music 'BendAfterEvent
159 #(define-music-function (parser location) ()
160 (_i "Insert a breath mark.")
161 (make-music 'EventChord
163 'elements (list (make-music 'BreathingEvent))))
167 #(define-music-function (parser location type) (string?)
168 (_i "Set the current clef to @var{type}.")
169 (make-clef-set type))
173 #(define-music-function
174 (parser location what dir main-music) (string? ly:dir? ly:music?)
175 (_i "Insert contents of quote @var{what} corresponding to @var{main-music},
176 in a CueVoice oriented by @var{dir}.")
177 (make-music 'QuoteMusic
179 'quoted-context-type 'Voice
180 'quoted-context-id "cue"
181 'quoted-music-name what
182 'quoted-voice-direction dir
186 #(define-music-function (parser location music) (ly:music?)
187 (_i "Display the LilyPond input representation of @var{music}
190 (display-lily-music music parser)
194 #(define-music-function (parser location music) (ly:music?)
195 (_i "Display the internal representation of @var{music} to the console.")
197 (display-scheme-music music)
202 #(define-music-function (parser location music) (ly:music?)
203 (_i "Terminate the next spanner prematurely after exactly one note without the need of a specific end spanner.")
204 (if (eq? (ly:music-property music 'name) 'EventChord)
206 ((elts (ly:music-property music 'elements))
207 (start-span-evs (filter (lambda (ev)
208 (and (music-has-type ev 'span-event)
209 (equal? (ly:music-property ev 'span-direction)
214 (let* ((c (music-clone m)))
215 (set! (ly:music-property c 'span-direction) STOP)
218 (end-ev-chord (make-music 'EventChord
219 'elements stop-span-evs))
220 (total (make-music 'SequentialMusic
221 'elements (list music
225 (ly:input-message location (_ "argument endSpanners is not an EventChord: ~a" music))))
228 #(define-music-function (parser location factor argument) (ly:moment? ly:music?)
229 (_i "Adjust durations of music in @var{argument} by rational @var{factor}. ")
231 ((orig-duration (ly:music-length argument))
232 (multiplier (ly:make-moment 1 1)))
236 (if (and (eq? (ly:music-property mus 'name) 'EventChord)
237 (< 0 (ly:moment-main-denominator (ly:music-length mus))))
239 (ly:music-compress mus multiplier)
240 (set! multiplier (ly:moment-mul factor multiplier)))
247 (ly:moment-div orig-duration (ly:music-length argument)))
252 #(def-grace-function startGraceMusic stopGraceMusic
253 (_i "Insert @var{music} as grace notes."))
255 "instrument-definitions" = #'()
257 addInstrumentDefinition =
258 #(define-music-function
259 (parser location name lst) (string? list?)
260 (_i "Create instrument @var{name} with properties @var{list}.")
261 (set! instrument-definitions (acons name lst instrument-definitions))
263 (make-music 'SequentialMusic 'void #t))
267 #(define-music-function
268 (parser location name) (string?)
269 (_i "Switch instrument to @var{name}, which must be predefined with
270 @code{\\addInstrumentDefinition}.")
272 ((handle (assoc name instrument-definitions))
273 (instrument-def (if handle (cdr handle) '()))
277 (ly:input-message "No such instrument: ~a" name))
279 (make-music 'SimultaneousMusic
289 %% Parser used to read page-layout file, and then retreive score tweaks.
290 #(define page-layout-parser #f)
292 includePageLayoutFile =
293 #(define-music-function (parser location) ()
294 (_i "Include the file @var{<basename>-page-layout.ly}. Deprecated as
295 part of two-pass spacing.")
296 (if (not (ly:get-option 'dump-tweaks))
297 (let ((tweak-filename (format #f "~a-page-layout.ly"
298 (ly:parser-output-name parser))))
299 (if (access? tweak-filename R_OK)
301 (ly:message "Including tweak file ~a" tweak-filename)
302 (set! page-layout-parser (ly:parser-clone parser))
303 (ly:parser-parse-string page-layout-parser
304 (format #f "\\include \"~a\""
306 (make-music 'SequentialMusic 'void #t))
309 #(define-music-function
310 (parser location tag music) (symbol? ly:music?)
311 (_i "Include only elements of @var{music} that are tagged with @var{tag}.")
314 (let* ((tags (ly:music-property m 'tags))
315 (res (memq tag tags)))
322 #(define-music-function
323 (parser location tag music) (symbol? ly:music?)
324 (_i "Remove elements of @var{music} that are tagged with @var{tag}.")
327 (let* ((tags (ly:music-property m 'tags))
328 (res (memq tag tags)))
333 #(define-music-function
334 (parser location music)
336 (_i "Remove cue notes from @var{music}.")
339 (if (string? (ly:music-property mus 'quoted-music-name))
340 (ly:music-property mus 'element)
344 #(define-music-function (parser location label) (symbol?)
345 (_i "Create @var{label} as a bookmarking label")
346 (make-music 'EventChord
349 'elements (list (make-music 'LabelEvent
350 'page-label label))))
353 #(define-music-function
354 (parser location arg) (ly:music?)
355 (_i "Display chords in @var{arg} as clusters")
356 (music-map note-to-cluster arg))
359 #(define-music-function (parser location proc mus) (procedure? ly:music?)
360 (music-map proc mus))
362 overrideBeamSettings =
363 #(define-music-function
365 context time-signature rule-type grouping-rule)
366 (symbol? pair? symbol? pair?)
368 (_i "Override beamSettings in @var{context}
369 for time signatures of @var{time-signature} and rules of type
370 @var{rule-type} to have a grouping rule alist
372 @var{rule-type} can be @code{end} or @code{subdivide},
373 with a potential future value of @code{begin}.
374 @var{grouping-rule} is an alist of @var{(beam-type . grouping)}
375 entries. @var{grouping} is in units of @var{beam-type}. If
376 @var{beam-type} is @code{*}, grouping is in units of the denominator
377 of @var{time-signature}.")
379 ;; TODO -- add warning if largest value of grouping is
380 ;; greater than time-signature.
383 #(override-beam-setting
384 $time-signature $rule-type $grouping-rule $context)
388 #(define-music-function (parser location name property value)
389 (string? symbol? scheme?)
391 (_i "Set @var{property} to @var{value} in all grobs named @var{name}.
392 The @var{name} argument is a string of the form @code{\"Context.GrobName\"}
393 or @code{\"GrobName\"}")
396 ((name-components (string-split name #\.))
397 (context-name 'Bottom)
400 (if (> 2 (length name-components))
401 (set! grob-name (string->symbol (car name-components)))
403 (set! grob-name (string->symbol (list-ref name-components 1)))
404 (set! context-name (string->symbol (list-ref name-components 0)))))
406 (make-music 'ApplyOutputEvent
408 'context-type context-name
410 (lambda (grob orig-context context)
412 (cdr (assoc 'name (ly:grob-property grob 'meta)))
414 (set! (ly:grob-property grob property) value))))))
416 %% These are music functions (iso music indentifiers), because music identifiers
417 %% are not allowed at top-level.
419 #(define-music-function (location parser) ()
420 (_i "Force a page break. May be used at toplevel (ie between scores or
421 markups), or inside a score.")
422 (make-music 'EventChord
424 'line-break-permission 'force
425 'page-break-permission 'force
426 'elements (list (make-music 'LineBreakEvent
427 'break-permission 'force)
428 (make-music 'PageBreakEvent
429 'break-permission 'force))))
432 #(define-music-function (location parser) ()
433 (_i "Forbid a page break. May be used at toplevel (ie between scores or
434 markups), or inside a score.")
435 (make-music 'EventChord
437 'page-break-permission 'forbid
438 'elements (list (make-music 'PageBreakEvent
439 'break-permission '()))))
442 #(define-music-function (location parser) ()
443 (_i "Force a page turn between two scores or top-level markups.")
444 (make-music 'EventChord
446 'line-break-permission 'force
447 'page-break-permission 'force
448 'page-turn-permission 'force
449 'elements (list (make-music 'LineBreakEvent
450 'break-permission 'force)
451 (make-music 'PageBreakEvent
452 'break-permission 'force)
453 (make-music 'PageTurnEvent
454 'break-permission 'force))))
457 #(define-music-function (location parser) ()
458 (_i "Forbid a page turn. May be used at toplevel (ie between scores or
459 markups), or inside a score.")
460 (make-music 'EventChord
462 'page-turn-permission 'forbid
463 'elements (list (make-music 'PageTurnEvent
464 'break-permission '()))))
467 #(define-music-function (location parser) ()
468 (_i "Allow a page turn. May be used at toplevel (ie between scores or
469 markups), or inside a score.")
470 (make-music 'EventChord
472 'page-turn-permission 'allow
473 'elements (list (make-music 'PageTurnEvent
474 'break-permission 'allow))))
478 %% define-music-function in a .scm causes crash.
481 #(define-music-function (parser location pitch-note) (ly:music?)
484 (make-music 'RelativeOctaveCheck
486 'pitch (pitch-of-note pitch-note)
489 ottava = #(define-music-function (parser location octave) (number?)
490 (_i "set the octavation ")
491 (make-ottava-set octave))
494 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
495 (make-part-combine-music parser
500 #(define-music-function
501 (parser location main-note secondary-note)
502 (ly:music? ly:music?)
504 ((get-notes (lambda (ev-chord)
506 (lambda (m) (eq? 'NoteEvent (ly:music-property m 'name)))
507 (ly:music-property ev-chord 'elements))))
508 (sec-note-events (get-notes secondary-note))
509 (trill-events (filter (lambda (m) (music-has-type m 'trill-span-event))
510 (ly:music-property main-note 'elements))))
512 (if (pair? sec-note-events)
515 ((trill-pitch (ly:music-property (car sec-note-events) 'pitch))
516 (forced (ly:music-property (car sec-note-events ) 'force-accidental)))
518 (if (ly:pitch? trill-pitch)
519 (for-each (lambda (m) (ly:music-set-property! m 'pitch trill-pitch))
522 (ly:warning (_ "Second argument of \\pitchedTrill should be single note: "))
523 (display sec-note-events)))
526 (for-each (lambda (m) (ly:music-set-property! m 'force-accidental forced))
533 #(use-modules (ice-9 optargs))
536 #(define-music-function (parser location voice-ids music) (list? ly:music?)
537 (_i "Define parallel music sequences, separated by '|' (bar check signs),
538 and assign them to the identifiers provided in @var{voice-ids}.
540 @var{voice-ids}: a list of music identifiers (symbols containing only letters)
542 @var{music}: a music sequence, containing BarChecks as limiting expressions.
547 \\parallelMusic #'(A B C) {
557 (let* ((voices (apply circular-list (make-list (length voice-ids) (list))))
558 (current-voices voices)
559 (current-sequence (list)))
562 (define (push-music m)
563 "Push the music expression into the current sequence"
564 (set! current-sequence (cons m current-sequence)))
565 (define (change-voice)
566 "Stores the previously built sequence into the current voice and
567 change to the following voice."
568 (list-set! current-voices 0 (cons (make-music 'SequentialMusic
569 'elements (reverse! current-sequence))
570 (car current-voices)))
571 (set! current-sequence (list))
572 (set! current-voices (cdr current-voices)))
573 (define (bar-check? m)
574 "Checks whether m is a bar check."
575 (eq? (ly:music-property m 'name) 'BarCheck))
576 (define (music-origin music)
577 "Recursively search an origin location stored in music."
578 (cond ((null? music) #f)
579 ((not (null? (ly:music-property music 'origin)))
580 (ly:music-property music 'origin))
581 (else (or (music-origin (ly:music-property music 'element))
582 (let ((origins (remove not (map music-origin
583 (ly:music-property music 'elements)))))
584 (and (not (null? origins)) (car origins)))))))
586 ;; first, split the music and fill in voices
587 (map-in-order (lambda (m)
589 (if (bar-check? m) (change-voice)))
590 (ly:music-property music 'elements))
591 (if (not (null? current-sequence)) (change-voice))
592 ;; un-circularize `voices' and reorder the voices
593 (set! voices (map-in-order (lambda (dummy seqs)
597 ;; set origin location of each sequence in each voice
598 ;; for better type error tracking
599 (for-each (lambda (voice)
600 (for-each (lambda (seq)
601 (set! (ly:music-property seq 'origin)
602 (or (music-origin seq) location)))
606 ;; check sequence length
607 (apply for-each (lambda* (#:rest seqs)
608 (let ((moment-reference (ly:music-length (car seqs))))
609 (for-each (lambda (seq moment)
610 (if (not (equal? moment moment-reference))
611 (ly:music-message seq
612 "Bars in parallel music don't have the same length")))
613 seqs (map-in-order ly:music-length seqs))))
616 ;; bind voice identifiers to the voices
617 (map (lambda (voice-id voice)
618 (ly:parser-define! parser voice-id
619 (make-music 'SequentialMusic
623 ;; Return an empty sequence. this function is actually a "void" function.
624 (make-music 'SequentialMusic 'void #t))
629 #(define-music-function (parser loc arg) (ly:music?)
630 (_i "Tag @var{arg} to be parenthesized.")
632 (if (memq 'event-chord (ly:music-property arg 'types))
633 ; arg is an EventChord -> set the parenthesize property on all child notes and rests
636 (if (or (memq 'note-event (ly:music-property ev 'types))
637 (memq 'rest-event (ly:music-property ev 'types)))
638 (set! (ly:music-property ev 'parenthesize) #t)))
639 (ly:music-property arg 'elements))
640 ; No chord, simply set property for this expression:
641 (set! (ly:music-property arg 'parenthesize) #t))
646 (define-music-function
647 (parser location what main-music)
649 (make-music 'QuoteMusic
651 'quoted-music-name what
656 resetRelativeOctave =
657 #(define-music-function
658 (parser location reference-note)
660 (_i "Set the octave inside a \\relative section.")
663 ((notes (ly:music-property reference-note 'elements))
664 (pitch (ly:music-property (car notes) 'pitch)))
666 (set! (ly:music-property reference-note 'elements) '())
667 (set! (ly:music-property reference-note
668 'to-relative-callback)
669 (lambda (music last-pitch)
675 #(define-music-function
677 context time-signature rule-type)
678 (symbol? pair? symbol?)
680 (_i "Revert beam settings in @var{context} for time signatures of
681 @var{time-signature} and groups of type
682 @var{group-type}. @var{group-type} can be @code{end}
683 or @code{subdivide}.")
685 #(revert-beam-setting $time-signature $rule-type $context)
689 #(define-music-function (parser location fraction music) (number-pair? ly:music?)
690 (_i "Multiply the duration of events in @var{music} by @var{fraction}.")
691 (ly:music-compress music
692 (ly:make-moment (car fraction) (cdr fraction))))
695 #(define-music-function (parser location grouping) (pair?)
696 (_i "Set the beat grouping in the current time signature to
698 (define (default-group-setting c)
699 (let* ((context-time-signature
700 (ly:context-property c 'timeSignatureFraction))
701 (time-signature (if (null? context-time-signature)
703 context-time-signature)))
704 (override-property-setting
707 (list time-signature 'end)
708 (list (cons '* grouping)))))
711 (make-apply-context default-group-setting)
716 #(define-music-function (parser location dur dots arg) (integer? integer? ly:music?)
717 (_i "Scale @var{arg} up by a factor of @var{2^dur*(2-(1/2)^dots)}.")
721 (shift-one-duration-log x dur dots)) arg))
724 #(define-music-function (parser location parameters) (list?)
725 (_i "Set the system stretch, by reading the 'system-stretch property of
726 the `parameters' assoc list.")
728 \overrideProperty #"Score.NonMusicalPaperColumn"
729 #'line-break-system-details
730 #$(list (cons 'alignment-extra-space (cdr (assoc 'system-stretch parameters)))
731 (cons 'system-Y-extent (cdr (assoc 'system-Y-extent parameters))))
735 #(define-music-function
736 (parser location style heads music)
737 (symbol? list-or-symbol? ly:music?)
738 (_i "Set @var{heads} in @var{music} to @var{style}.")
739 (style-note-heads heads style music))
742 #(define-music-function (parser location finger) (number-or-string?)
743 (_i "Apply @var{finger} as a fingering indication.")
752 (list 'digit finger)))))
755 #(define-music-function (parser location name) (string?)
756 (_i "Include the score tweak, if exists.")
757 (if (and page-layout-parser (not (ly:get-option 'dump-tweaks)))
758 (let ((tweak-music (ly:parser-lookup page-layout-parser
759 (string->symbol name))))
760 (if (ly:music? tweak-music)
762 (make-music 'SequentialMusic)))
763 (make-music 'SequentialMusic)))
767 #(define-music-function (parser location tag arg)
770 (_i "Add @var{tag} to the @code{tags} property of @var{arg}.")
773 (ly:music-property arg 'tags)
775 (ly:music-property arg 'tags)))
780 transposedCueDuring =
781 #(define-music-function
782 (parser location what dir pitch-note main-music)
783 (string? ly:dir? ly:music? ly:music?)
785 (_i "Insert notes from the part @var{what} into a voice called @code{cue},
786 using the transposition defined by @var{pitch-note}. This happens
787 simultaneously with @var{main-music}, which is usually a rest. The
788 argument @var{dir} determines whether the cue notes should be notated
789 as a first or second voice.")
791 (make-music 'QuoteMusic
793 'quoted-context-type 'Voice
794 'quoted-context-id "cue"
795 'quoted-music-name what
796 'quoted-voice-direction dir
797 'quoted-transposition (pitch-of-note pitch-note)
803 #(define-music-function (parser location pitch-note) (ly:music?)
804 (_i "Set instrument transposition")
807 (make-property-set 'instrumentTransposition
808 (ly:pitch-negate (pitch-of-note pitch-note)))
812 #(define-music-function (parser location sym val arg)
813 (symbol? scheme? ly:music?)
814 (_i "Add @code{sym . val} to the @code{tweaks} property of @var{arg}.")
816 (if (equal? (object-property sym 'backend-type?) #f)
818 (ly:warning (_ "cannot find property type-check for ~a") sym)
819 (ly:warning (_ "doing assignment anyway"))))
821 (ly:music-property arg 'tweaks)
823 (ly:music-property arg 'tweaks)))
829 #(define-music-function (parser location music) (ly:music?)
830 (unfold-repeats music))
835 #(define-music-function (parser location sym val music) (symbol? scheme? ly:music?)
836 (_i "Set @var{sym} to @var{val} in @var{music}.")
838 (set! (ly:music-property music sym) val)