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 (make-music 'ApplyOutputEvent
67 #(def-grace-function startAppoggiaturaMusic stopAppoggiaturaMusic)
71 % for regression testing purposes.
73 #(define-music-function (parser location l r) (pair? pair?)
74 (make-grob-property-override 'Beam 'positions
75 (ly:make-simple-closure
76 (ly:make-simple-closure
78 (list chain-grob-member-functions `(,cons 0 0))
79 (check-quant-callbacks l r))))))
81 % for regression testing purposes.
83 #(define-music-function (parser location comp) (procedure?)
84 (make-grob-property-override 'Beam 'positions
85 (ly:make-simple-closure
86 (ly:make-simple-closure
88 (list chain-grob-member-functions `(,cons 0 0))
89 (check-slope-callbacks comp))))))
94 #(define-music-function (parser location music) (ly:music?)
95 (make-autochange-music parser music))
98 #(define-music-function (parser location proc) (procedure?)
99 (_i "Modify context properties with Scheme procedure @var{proc}.")
100 (make-music 'ApplyContext
106 #(define-music-function (parser location grob-name offset text) (symbol? number-pair? markup?)
108 (make-music 'AnnotateOutputEvent
110 'X-offset (car offset)
111 'Y-offset (cdr offset)
115 #(define-music-function (parser location offset text) (number-pair? markup?)
117 (make-music 'AnnotateOutputEvent
118 'X-offset (car offset)
119 'Y-offset (cdr offset)
124 #(define-music-function (parser location type)
127 (make-property-set 'whichBar type)
132 #(define-music-function (parser location n) (integer?)
133 (_i "Print a warning if the current bar number is not @var{n}.")
134 (make-music 'ApplyContext
139 ((cbn (ly:context-property c 'currentBarNumber)))
140 (if (and (number? cbn) (not (= cbn n)))
141 (ly:input-message location "Barcheck failed got ~a expect ~a"
146 #(define-music-function (parser location delta) (real?)
147 (_i "Create a fall or doit of pitch interval @var{delta}.")
148 (make-music 'BendAfterEvent
153 #(define-music-function (parser location) ()
154 (_i "Insert a breath mark.")
155 (make-music 'EventChord
157 'elements (list (make-music 'BreathingEvent))))
161 #(define-music-function (parser location type) (string?)
162 (_i "Set the current clef to @var{type}.")
163 (make-clef-set type))
167 #(define-music-function
168 (parser location what dir main-music) (string? ly:dir? ly:music?)
169 (_i "Insert contents of quote @var{what} corresponding to @var{main-music},
170 in a CueVoice oriented by @var{dir}.")
171 (make-music 'QuoteMusic
173 'quoted-context-type 'Voice
174 'quoted-context-id "cue"
175 'quoted-music-name what
176 'quoted-voice-direction dir
180 #(define-music-function (parser location music) (ly:music?)
181 (_i "Display the LilyPond input representation of @var{music}
184 (display-lily-music music parser)
188 #(define-music-function (parser location music) (ly:music?)
189 (_i "Display the internal representation of @var{music} to the console.")
191 (display-scheme-music music)
196 #(define-music-function (parser location music) (ly:music?)
197 (_i "Terminate the next spanner prematurely after exactly one note without the need of a specific end spanner.")
198 (if (eq? (ly:music-property music 'name) 'EventChord)
200 ((elts (ly:music-property music 'elements))
201 (start-span-evs (filter (lambda (ev)
202 (and (music-has-type ev 'span-event)
203 (equal? (ly:music-property ev 'span-direction)
208 (let* ((c (music-clone m)))
209 (set! (ly:music-property c 'span-direction) STOP)
212 (end-ev-chord (make-music 'EventChord
213 'elements stop-span-evs))
214 (total (make-music 'SequentialMusic
215 'elements (list music
219 (ly:input-message location (_ "argument endSpanners is not an EventChord: ~a" music))))
222 #(define-music-function (parser location factor argument) (ly:moment? ly:music?)
223 (_i "Adjust durations of music in @var{argument} by rational @var{factor}. ")
225 ((orig-duration (ly:music-length argument))
226 (multiplier (ly:make-moment 1 1)))
230 (if (and (eq? (ly:music-property mus 'name) 'EventChord)
231 (< 0 (ly:moment-main-denominator (ly:music-length mus))))
233 (ly:music-compress mus multiplier)
234 (set! multiplier (ly:moment-mul factor multiplier)))
241 (ly:moment-div orig-duration (ly:music-length argument)))
246 #(def-grace-function startGraceMusic stopGraceMusic
247 (_i "Insert @var{music} as grace notes."))
249 "instrument-definitions" = #'()
251 addInstrumentDefinition =
252 #(define-music-function
253 (parser location name lst) (string? list?)
254 (_i "Create instrument @var{name} with properties @var{list}.")
255 (set! instrument-definitions (acons name lst instrument-definitions))
257 (make-music 'SequentialMusic 'void #t))
261 #(define-music-function
262 (parser location name) (string?)
263 (_i "Switch instrument to @var{name}, which must be predefined with
264 @var{\addInstrumentDefinition}.")
266 ((handle (assoc name instrument-definitions))
267 (instrument-def (if handle (cdr handle) '()))
271 (ly:input-message "No such instrument: ~a" name))
273 (make-music 'SimultaneousMusic
283 %% Parser used to read page-layout file, and then retreive score tweaks.
284 #(define page-layout-parser #f)
286 includePageLayoutFile =
287 #(define-music-function (parser location) ()
288 (_i "Include the file @var{<basename>-page-layout.ly}. Deprecated as
289 part of two-pass spacing.")
290 (if (not (ly:get-option 'dump-tweaks))
291 (let ((tweak-filename (format #f "~a-page-layout.ly"
292 (ly:parser-output-name parser))))
293 (if (access? tweak-filename R_OK)
295 (ly:message "Including tweak file ~a" tweak-filename)
296 (set! page-layout-parser (ly:parser-clone parser))
297 (ly:parser-parse-string page-layout-parser
298 (format #f "\\include \"~a\""
300 (make-music 'SequentialMusic 'void #t))
303 #(define-music-function
304 (parser location tag music) (symbol? ly:music?)
305 (_i "Include only elements of @var{music} that are tagged with @var{tag}.")
308 (let* ((tags (ly:music-property m 'tags))
309 (res (memq tag tags)))
316 #(define-music-function
317 (parser location tag music) (symbol? ly:music?)
318 (_i "Remove elements of @var{music} that are tagged with @var{tag}.")
321 (let* ((tags (ly:music-property m 'tags))
322 (res (memq tag tags)))
327 #(define-music-function
328 (parser location music)
330 (_i "Remove cue notes from @var{music}.")
333 (if (string? (ly:music-property mus 'quoted-music-name))
334 (ly:music-property mus 'element)
338 #(define-music-function (parser location label) (symbol?)
339 (_i "Create @var{label} as a bookmarking label")
340 (make-music 'EventChord
343 'elements (list (make-music 'LabelEvent
344 'page-label label))))
347 #(define-music-function
348 (parser location arg) (ly:music?)
349 (_i "Display chords in @var{arg} as clusters")
350 (music-map note-to-cluster arg))
353 #(define-music-function (parser location proc mus) (procedure? ly:music?)
354 (music-map proc mus))
358 #(define-music-function (parser location name property value)
359 (string? symbol? scheme?)
361 (_i "Set @var{property} to @var{value} in all grobs named @var{name}.
362 The @var{name} argument is a string of the form @code{\"Context.GrobName\"}
363 or @code{\"GrobName\"}")
366 ((name-components (string-split name #\.))
367 (context-name 'Bottom)
370 (if (> 2 (length name-components))
371 (set! grob-name (string->symbol (car name-components)))
373 (set! grob-name (string->symbol (list-ref name-components 1)))
374 (set! context-name (string->symbol (list-ref name-components 0)))))
376 (make-music 'ApplyOutputEvent
378 'context-type context-name
380 (lambda (grob orig-context context)
382 (cdr (assoc 'name (ly:grob-property grob 'meta)))
384 (set! (ly:grob-property grob property) value))))))
386 %% These are music functions (iso music indentifiers), because music identifiers
387 %% are not allowed at top-level.
389 #(define-music-function (location parser) ()
390 (_i "Force a page break. May be used at toplevel (ie between scores or
391 markups), or inside a score.")
392 (make-music 'EventChord
394 'line-break-permission 'force
395 'page-break-permission 'force
396 'elements (list (make-music 'LineBreakEvent
397 'break-permission 'force)
398 (make-music 'PageBreakEvent
399 'break-permission 'force))))
402 #(define-music-function (location parser) ()
403 (_i "Forbid a page break. May be used at toplevel (ie between scores or
404 markups), or inside a score.")
405 (make-music 'EventChord
407 'page-break-permission 'forbid
408 'elements (list (make-music 'PageBreakEvent
409 'break-permission '()))))
412 #(define-music-function (location parser) ()
413 (_i "Force a page turn between two scores or top-level markups.")
414 (make-music 'EventChord
416 'line-break-permission 'force
417 'page-break-permission 'force
418 'page-turn-permission 'force
419 'elements (list (make-music 'LineBreakEvent
420 'break-permission 'force)
421 (make-music 'PageBreakEvent
422 'break-permission 'force)
423 (make-music 'PageTurnEvent
424 'break-permission 'force))))
427 #(define-music-function (location parser) ()
428 (_i "Forbid a page turn. May be used at toplevel (ie between scores or
429 markups), or inside a score.")
430 (make-music 'EventChord
432 'page-turn-permission 'forbid
433 'elements (list (make-music 'PageTurnEvent
434 'break-permission '()))))
437 #(define-music-function (location parser) ()
438 (_i "Allow a page turn. May be used at toplevel (ie between scores or
439 markups), or inside a score.")
440 (make-music 'EventChord
442 'page-turn-permission 'allow
443 'elements (list (make-music 'PageTurnEvent
444 'break-permission 'allow))))
448 %% define-music-function in a .scm causes crash.
451 #(define-music-function (parser location pitch-note) (ly:music?)
454 (make-music 'RelativeOctaveCheck
456 'pitch (pitch-of-note pitch-note)
459 ottava = #(define-music-function (parser location octave) (number?)
460 (_i "set the octavation ")
461 (make-ottava-set octave))
464 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
465 (make-part-combine-music parser
470 #(define-music-function
471 (parser location main-note secondary-note)
472 (ly:music? ly:music?)
474 ((get-notes (lambda (ev-chord)
476 (lambda (m) (eq? 'NoteEvent (ly:music-property m 'name)))
477 (ly:music-property ev-chord 'elements))))
478 (sec-note-events (get-notes secondary-note))
479 (trill-events (filter (lambda (m) (music-has-type m 'trill-span-event))
480 (ly:music-property main-note 'elements))))
482 (if (pair? sec-note-events)
485 ((trill-pitch (ly:music-property (car sec-note-events) 'pitch))
486 (forced (ly:music-property (car sec-note-events ) 'force-accidental)))
488 (if (ly:pitch? trill-pitch)
489 (for-each (lambda (m) (ly:music-set-property! m 'pitch trill-pitch))
492 (ly:warning (_ "Second argument of \\pitchedTrill should be single note: "))
493 (display sec-note-events)))
496 (for-each (lambda (m) (ly:music-set-property! m 'force-accidental forced))
503 #(use-modules (ice-9 optargs))
506 #(define-music-function (parser location voice-ids music) (list? ly:music?)
507 (_i "Define parallel music sequences, separated by '|' (bar check signs),
508 and assign them to the identifiers provided in @var{voice-ids}.
510 @var{voice-ids}: a list of music identifiers (symbols containing only letters)
512 @var{music}: a music sequence, containing BarChecks as limiting expressions.
517 \\parallelMusic #'(A B C) {
527 (let* ((voices (apply circular-list (make-list (length voice-ids) (list))))
528 (current-voices voices)
529 (current-sequence (list)))
532 (define (push-music m)
533 "Push the music expression into the current sequence"
534 (set! current-sequence (cons m current-sequence)))
535 (define (change-voice)
536 "Stores the previously built sequence into the current voice and
537 change to the following voice."
538 (list-set! current-voices 0 (cons (make-music 'SequentialMusic
539 'elements (reverse! current-sequence))
540 (car current-voices)))
541 (set! current-sequence (list))
542 (set! current-voices (cdr current-voices)))
543 (define (bar-check? m)
544 "Checks whether m is a bar check."
545 (eq? (ly:music-property m 'name) 'BarCheck))
546 (define (music-origin music)
547 "Recursively search an origin location stored in music."
548 (cond ((null? music) #f)
549 ((not (null? (ly:music-property music 'origin)))
550 (ly:music-property music 'origin))
551 (else (or (music-origin (ly:music-property music 'element))
552 (let ((origins (remove not (map music-origin
553 (ly:music-property music 'elements)))))
554 (and (not (null? origins)) (car origins)))))))
556 ;; first, split the music and fill in voices
557 (map-in-order (lambda (m)
559 (if (bar-check? m) (change-voice)))
560 (ly:music-property music 'elements))
561 (if (not (null? current-sequence)) (change-voice))
562 ;; un-circularize `voices' and reorder the voices
563 (set! voices (map-in-order (lambda (dummy seqs)
567 ;; set origin location of each sequence in each voice
568 ;; for better type error tracking
569 (for-each (lambda (voice)
570 (for-each (lambda (seq)
571 (set! (ly:music-property seq 'origin)
572 (or (music-origin seq) location)))
576 ;; check sequence length
577 (apply for-each (lambda* (#:rest seqs)
578 (let ((moment-reference (ly:music-length (car seqs))))
579 (for-each (lambda (seq moment)
580 (if (not (equal? moment moment-reference))
581 (ly:music-message seq
582 "Bars in parallel music don't have the same length")))
583 seqs (map-in-order ly:music-length seqs))))
586 ;; bind voice identifiers to the voices
587 (map (lambda (voice-id voice)
588 (ly:parser-define! parser voice-id
589 (make-music 'SequentialMusic
593 ;; Return an empty sequence. this function is actually a "void" function.
594 (make-music 'SequentialMusic 'void #t))
599 #(define-music-function (parser loc arg) (ly:music?)
600 (_i "Tag @var{arg} to be parenthesized.")
602 (if (memq 'event-chord (ly:music-property arg 'types))
603 ; arg is an EventChord -> set the parenthesize property on all child notes and rests
606 (if (or (memq 'note-event (ly:music-property ev 'types))
607 (memq 'rest-event (ly:music-property ev 'types)))
608 (set! (ly:music-property ev 'parenthesize) #t)))
609 (ly:music-property arg 'elements))
610 ; No chord, simply set property for this expression:
611 (set! (ly:music-property arg 'parenthesize) #t))
616 (define-music-function
617 (parser location what main-music)
619 (make-music 'QuoteMusic
621 'quoted-music-name what
626 resetRelativeOctave =
627 #(define-music-function
628 (parser location reference-note)
630 (_i "Set the octave inside a \\relative section.")
633 ((notes (ly:music-property reference-note 'elements))
634 (pitch (ly:music-property (car notes) 'pitch)))
636 (set! (ly:music-property reference-note 'elements) '())
637 (set! (ly:music-property reference-note
638 'to-relative-callback)
639 (lambda (music last-pitch)
646 #(define-music-function
647 (parser location fraction music) (number-pair? ly:music?)
648 (ly:music-compress music (ly:make-moment (car fraction) (cdr fraction))))
653 #(define-music-function (parser location dur dots arg) (integer? integer? ly:music?)
658 (shift-one-duration-log x dur dots)) arg))
661 #(define-music-function (parser location parameters) (list?)
662 (_i "Set the system stretch, by reading the 'system-stretch property of
663 the `parameters' assoc list.")
665 \overrideProperty #"Score.NonMusicalPaperColumn"
666 #'line-break-system-details
667 #$(list (cons 'alignment-extra-space (cdr (assoc 'system-stretch parameters)))
668 (cons 'system-Y-extent (cdr (assoc 'system-Y-extent parameters))))
673 #(define-music-function (parser location finger) (number-or-string?)
674 (_i "Define a StrokeFingerEvent")
683 (list 'digit finger)))))
686 #(define-music-function (parser location name) (string?)
687 (_i "Include the score tweak, if exists.")
688 (if (and page-layout-parser (not (ly:get-option 'dump-tweaks)))
689 (let ((tweak-music (ly:parser-lookup page-layout-parser
690 (string->symbol name))))
691 (if (ly:music? tweak-music)
693 (make-music 'SequentialMusic)))
694 (make-music 'SequentialMusic)))
698 #(define-music-function (parser location tag arg)
701 (_i "Add @var{tag} to the @code{tags} property of @var{arg}.")
704 (ly:music-property arg 'tags)
706 (ly:music-property arg 'tags)))
711 transposedCueDuring =
712 #(define-music-function
713 (parser location what dir pitch-note main-music)
714 (string? ly:dir? ly:music? ly:music?)
716 (_i "Insert notes from the part @var{what} into a voice called @code{cue},
717 using the transposition defined by @var{pitch-note}. This happens
718 simultaneously with @var{main-music}, which is usually a rest. The
719 argument @var{dir} determines whether the cue notes should be notated
720 as a first or second voice.")
722 (make-music 'QuoteMusic
724 'quoted-context-type 'Voice
725 'quoted-context-id "cue"
726 'quoted-music-name what
727 'quoted-voice-direction dir
728 'quoted-transposition (pitch-of-note pitch-note)
734 #(define-music-function (parser location pitch-note) (ly:music?)
735 (_i "Set instrument transposition")
738 (make-property-set 'instrumentTransposition
739 (ly:pitch-negate (pitch-of-note pitch-note)))
743 #(define-music-function (parser location sym val arg)
744 (symbol? scheme? ly:music?)
745 (_i "Add @code{sym . val} to the @code{tweaks} property of @var{arg}.")
747 (if (equal? (object-property sym 'backend-type?) #f)
749 (ly:warning (_ "cannot find property type-check for ~a") sym)
750 (ly:warning (_ "doing assignment anyway"))))
752 (ly:music-property arg 'tweaks)
754 (ly:music-property arg 'tweaks)))
760 #(define-music-function (parser location music) (ly:music?)
761 (unfold-repeats music))
766 #(define-music-function (parser location sym val music) (symbol? scheme? ly:music?)
767 (_i "Set @var{sym} to @var{val} in @var{music}.")
769 (set! (ly:music-property music sym) val)