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))
359 #(define-music-function (parser location music lyrics) (ly:music? ly:music?)
361 (make-music 'OldLyricCombineMusic
363 'elements (list music lyrics)))
367 #(define-music-function (parser location name property value)
368 (string? symbol? scheme?)
371 (_i "Set @var{property} to @var{value} in all grobs named @var{name}.
372 The @var{name} argument is a string of the form @code{\"Context.GrobName\"}
373 or @code{\"GrobName\"}")
376 ((name-components (string-split name #\.))
377 (context-name 'Bottom)
380 (if (> 2 (length name-components))
381 (set! grob-name (string->symbol (car name-components)))
383 (set! grob-name (string->symbol (list-ref name-components 1)))
384 (set! context-name (string->symbol (list-ref name-components 0)))))
386 (make-music 'ApplyOutputEvent
388 'context-type context-name
390 (lambda (grob orig-context context)
392 (cdr (assoc 'name (ly:grob-property grob 'meta)))
394 (set! (ly:grob-property grob property) value))))))
396 %% These are music functions (iso music indentifiers), because music identifiers
397 %% are not allowed at top-level.
399 #(define-music-function (location parser) ()
400 (_i "Force a page break. May be used at toplevel (ie between scores or
401 markups), or inside a score.")
402 (make-music 'EventChord
404 'line-break-permission 'force
405 'page-break-permission 'force
406 'elements (list (make-music 'LineBreakEvent
407 'break-permission 'force)
408 (make-music 'PageBreakEvent
409 'break-permission 'force))))
412 #(define-music-function (location parser) ()
413 (_i "Forbid a page break. May be used at toplevel (ie between scores or
414 markups), or inside a score.")
415 (make-music 'EventChord
417 'page-break-permission 'forbid
418 'elements (list (make-music 'PageBreakEvent
419 'break-permission '()))))
422 #(define-music-function (location parser) ()
423 (_i "Force a page turn between two scores or top-level markups.")
424 (make-music 'EventChord
426 'line-break-permission 'force
427 'page-break-permission 'force
428 'page-turn-permission 'force
429 'elements (list (make-music 'LineBreakEvent
430 'break-permission 'force)
431 (make-music 'PageBreakEvent
432 'break-permission 'force)
433 (make-music 'PageTurnEvent
434 'break-permission 'force))))
437 #(define-music-function (location parser) ()
438 (_i "Forbid 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 'forbid
443 'elements (list (make-music 'PageTurnEvent
444 'break-permission '()))))
447 #(define-music-function (location parser) ()
448 (_i "Allow a page turn. May be used at toplevel (ie between scores or
449 markups), or inside a score.")
450 (make-music 'EventChord
452 'page-turn-permission 'allow
453 'elements (list (make-music 'PageTurnEvent
454 'break-permission 'allow))))
458 %% define-music-function in a .scm causes crash.
461 #(define-music-function (parser location pitch-note) (ly:music?)
464 (make-music 'RelativeOctaveCheck
466 'pitch (pitch-of-note pitch-note)
469 ottava = #(define-music-function (parser location octave) (number?)
470 (_i "set the octavation ")
471 (make-ottava-set octave))
474 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
475 (make-part-combine-music parser
480 #(define-music-function
481 (parser location main-note secondary-note)
482 (ly:music? ly:music?)
484 ((get-notes (lambda (ev-chord)
486 (lambda (m) (eq? 'NoteEvent (ly:music-property m 'name)))
487 (ly:music-property ev-chord 'elements))))
488 (sec-note-events (get-notes secondary-note))
489 (trill-events (filter (lambda (m) (music-has-type m 'trill-span-event))
490 (ly:music-property main-note 'elements))))
492 (if (pair? sec-note-events)
495 ((trill-pitch (ly:music-property (car sec-note-events) 'pitch))
496 (forced (ly:music-property (car sec-note-events ) 'force-accidental)))
498 (if (ly:pitch? trill-pitch)
499 (for-each (lambda (m) (ly:music-set-property! m 'pitch trill-pitch))
502 (ly:warning (_ "Second argument of \\pitchedTrill should be single note: "))
503 (display sec-note-events)))
506 (for-each (lambda (m) (ly:music-set-property! m 'force-accidental forced))
513 #(use-modules (ice-9 optargs))
516 #(define-music-function (parser location voice-ids music) (list? ly:music?)
517 (_i "Define parallel music sequences, separated by '|' (bar check signs),
518 and assign them to the identifiers provided in @var{voice-ids}.
520 @var{voice-ids}: a list of music identifiers (symbols containing only letters)
522 @var{music}: a music sequence, containing BarChecks as limiting expressions.
527 \\parallelMusic #'(A B C) {
537 (let* ((voices (apply circular-list (make-list (length voice-ids) (list))))
538 (current-voices voices)
539 (current-sequence (list)))
542 (define (push-music m)
543 "Push the music expression into the current sequence"
544 (set! current-sequence (cons m current-sequence)))
545 (define (change-voice)
546 "Stores the previously built sequence into the current voice and
547 change to the following voice."
548 (list-set! current-voices 0 (cons (make-music 'SequentialMusic
549 'elements (reverse! current-sequence))
550 (car current-voices)))
551 (set! current-sequence (list))
552 (set! current-voices (cdr current-voices)))
553 (define (bar-check? m)
554 "Checks whether m is a bar check."
555 (eq? (ly:music-property m 'name) 'BarCheck))
556 (define (music-origin music)
557 "Recursively search an origin location stored in music."
558 (cond ((null? music) #f)
559 ((not (null? (ly:music-property music 'origin)))
560 (ly:music-property music 'origin))
561 (else (or (music-origin (ly:music-property music 'element))
562 (let ((origins (remove not (map music-origin
563 (ly:music-property music 'elements)))))
564 (and (not (null? origins)) (car origins)))))))
566 ;; first, split the music and fill in voices
567 (map-in-order (lambda (m)
569 (if (bar-check? m) (change-voice)))
570 (ly:music-property music 'elements))
571 (if (not (null? current-sequence)) (change-voice))
572 ;; un-circularize `voices' and reorder the voices
573 (set! voices (map-in-order (lambda (dummy seqs)
577 ;; set origin location of each sequence in each voice
578 ;; for better type error tracking
579 (for-each (lambda (voice)
580 (for-each (lambda (seq)
581 (set! (ly:music-property seq 'origin)
582 (or (music-origin seq) location)))
586 ;; check sequence length
587 (apply for-each (lambda* (#:rest seqs)
588 (let ((moment-reference (ly:music-length (car seqs))))
589 (for-each (lambda (seq moment)
590 (if (not (equal? moment moment-reference))
591 (ly:music-message seq
592 "Bars in parallel music don't have the same length")))
593 seqs (map-in-order ly:music-length seqs))))
596 ;; bind voice identifiers to the voices
597 (map (lambda (voice-id voice)
598 (ly:parser-define! parser voice-id
599 (make-music 'SequentialMusic
603 ;; Return an empty sequence. this function is actually a "void" function.
604 (make-music 'SequentialMusic 'void #t))
609 #(define-music-function (parser loc arg) (ly:music?)
610 (_i "Tag @var{arg} to be parenthesized.")
612 (if (memq 'event-chord (ly:music-property arg 'types))
613 ; arg is an EventChord -> set the parenthesize property on all child notes and rests
616 (if (or (memq 'note-event (ly:music-property ev 'types))
617 (memq 'rest-event (ly:music-property ev 'types)))
618 (set! (ly:music-property ev 'parenthesize) #t)))
619 (ly:music-property arg 'elements))
620 ; No chord, simply set property for this expression:
621 (set! (ly:music-property arg 'parenthesize) #t))
626 (define-music-function
627 (parser location what main-music)
629 (make-music 'QuoteMusic
631 'quoted-music-name what
636 resetRelativeOctave =
637 #(define-music-function
638 (parser location reference-note)
640 (_i "Set the octave inside a \\relative section.")
643 ((notes (ly:music-property reference-note 'elements))
644 (pitch (ly:music-property (car notes) 'pitch)))
646 (set! (ly:music-property reference-note 'elements) '())
647 (set! (ly:music-property reference-note
648 'to-relative-callback)
649 (lambda (music last-pitch)
656 #(define-music-function
657 (parser location fraction music) (number-pair? ly:music?)
658 (ly:music-compress music (ly:make-moment (car fraction) (cdr fraction))))
663 #(define-music-function (parser location dur dots arg) (integer? integer? ly:music?)
668 (shift-one-duration-log x dur dots)) arg))
671 #(define-music-function (parser location parameters) (list?)
672 (_i "Set the system stretch, by reading the 'system-stretch property of
673 the `parameters' assoc list.")
675 \overrideProperty #"Score.NonMusicalPaperColumn"
676 #'line-break-system-details
677 #$(list (cons 'alignment-extra-space (cdr (assoc 'system-stretch parameters)))
678 (cons 'system-Y-extent (cdr (assoc 'system-Y-extent parameters))))
683 #(define-music-function (parser location finger) (number-or-string?)
684 (_i "Define a StrokeFingerEvent")
693 (list 'digit finger)))))
696 #(define-music-function (parser location name) (string?)
697 (_i "Include the score tweak, if exists.")
698 (if (and page-layout-parser (not (ly:get-option 'dump-tweaks)))
699 (let ((tweak-music (ly:parser-lookup page-layout-parser
700 (string->symbol name))))
701 (if (ly:music? tweak-music)
703 (make-music 'SequentialMusic)))
704 (make-music 'SequentialMusic)))
707 tag = #(define-music-function (parser location tag arg)
710 (_i "Add @var{tag} to the @code{tags} property of @var{arg}.")
713 (ly:music-property arg 'tags)
715 (ly:music-property arg 'tags)))
720 transposedCueDuring =
721 #(define-music-function
722 (parser location what dir pitch-note main-music)
723 (string? ly:dir? ly:music? ly:music?)
725 (_i "Insert notes from the part @var{what} into a voice called @code{cue},
726 using the transposition defined by @var{pitch-note}. This happens
727 simultaneously with @var{main-music}, which is usually a rest. The
728 argument @var{dir} determines whether the cue notes should be notated
729 as a first or second voice.")
731 (make-music 'QuoteMusic
733 'quoted-context-type 'Voice
734 'quoted-context-id "cue"
735 'quoted-music-name what
736 'quoted-voice-direction dir
737 'quoted-transposition (pitch-of-note pitch-note)
743 #(define-music-function (parser location pitch-note) (ly:music?)
744 (_i "Set instrument transposition")
747 (make-property-set 'instrumentTransposition
748 (ly:pitch-negate (pitch-of-note pitch-note)))
751 tweak = #(define-music-function (parser location sym val arg)
752 (symbol? scheme? ly:music?)
754 (_i "Add @code{sym . val} to the @code{tweaks} property of @var{arg}.")
757 (ly:music-property arg 'tweaks)
759 (ly:music-property arg 'tweaks)))
765 #(define-music-function (parser location music) (ly:music?)
766 (unfold-repeats music))
771 #(define-music-function (parser location sym val music) (symbol? scheme? ly:music?)
772 (_i "Set @var{sym} to @var{val} in @var{music}.")
774 (set! (ly:music-property music sym) val)