1 %%%% This file is part of LilyPond, the GNU music typesetter.
3 %%%% Copyright (C) 2003--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
4 %%%% Jan Nieuwenhuizen <janneke@gnu.org>
6 %%%% LilyPond is free software: you can redistribute it and/or modify
7 %%%% it under the terms of the GNU General Public License as published by
8 %%%% the Free Software Foundation, either version 3 of the License, or
9 %%%% (at your option) any later version.
11 %%%% LilyPond is distributed in the hope that it will be useful,
12 %%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
13 %%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 %%%% GNU General Public License for more details.
16 %%%% You should have received a copy of the GNU General Public License
17 %%%% along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25 %% this file is alphabetically sorted.
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28 %% need SRFI-1 for filter; optargs for lambda*
29 #(use-modules (srfi srfi-1)
32 %% TODO: using define-music-function in a .scm causes crash.
35 #(def-grace-function startAcciaccaturaMusic stopAcciaccaturaMusic
36 (_i "Create an acciaccatura from the following music expression"))
38 %% keep these two together
39 "instrument-definitions" = #'()
40 addInstrumentDefinition =
41 #(define-music-function
42 (parser location name lst) (string? list?)
43 (_i "Create instrument @var{name} with properties @var{list}.")
44 (set! instrument-definitions (acons name lst instrument-definitions))
45 (make-music 'SequentialMusic 'void #t))
48 #(define-music-function (parser location name music) (string? ly:music?)
49 (_i "Define @var{music} as a quotable music expression named
51 (add-quotable parser name music)
52 (make-music 'SequentialMusic 'void #t))
54 %% keep these two together
55 afterGraceFraction = #(cons 6 8)
57 #(define-music-function
58 (parser location main grace)
60 (_i "Create @var{grace} note(s) after a @var{main} music expression.")
62 ((main-length (ly:music-length main))
63 (fraction (ly:parser-lookup parser 'afterGraceFraction)))
65 (make-simultaneous-music
68 (make-sequential-music
71 (make-music 'SkipMusic
72 'duration (ly:make-duration
74 (* (ly:moment-main-numerator main-length)
76 (* (ly:moment-main-denominator main-length)
78 (make-music 'GraceMusic
82 %% music identifiers not allowed at top-level,
83 %% so this is a music-function instead.
85 #(define-music-function (location parser) ()
86 (_i "Allow a page turn. May be used at toplevel (ie between scores or
87 markups), or inside a score.")
88 (make-music 'EventChord
90 'page-turn-permission 'allow
91 'elements (list (make-music 'PageTurnEvent
92 'break-permission 'allow))))
95 #(define-music-function (parser location proc) (procedure?)
96 (_i "Modify context properties with Scheme procedure @var{proc}.")
97 (make-music 'ApplyContext
102 #(define-music-function (parser location func music) (procedure? ly:music?)
103 (_i"Apply procedure @var{func} to @var{music}.")
107 #(define-music-function (parser location ctx proc) (symbol? procedure?)
108 (_i "Apply function @code{proc} to every layout object in context @code{ctx}")
109 (make-music 'ApplyOutputEvent
115 #(def-grace-function startAppoggiaturaMusic stopAppoggiaturaMusic
116 (_i "Create an appoggiatura from @var{music}"))
118 % for regression testing purposes.
120 #(define-music-function (parser location l r) (pair? pair?)
121 (_i "Testing function: check whether the beam quants @var{l} and @var{r} are correct")
122 (make-grob-property-override 'Beam 'positions
123 (ly:make-simple-closure
124 (ly:make-simple-closure
126 (list chain-grob-member-functions `(,cons 0 0))
127 (check-quant-callbacks l r))))))
129 % for regression testing purposes.
131 #(define-music-function (parser location comp) (procedure?)
132 (_i "Testing function: check whether the slope of the beam is the same as @code{comp}")
133 (make-grob-property-override 'Beam 'positions
134 (ly:make-simple-closure
135 (ly:make-simple-closure
137 (list chain-grob-member-functions `(,cons 0 0))
138 (check-slope-callbacks comp))))))
141 #(define-music-function (parser location music) (ly:music?)
142 (_i "Make voices that switch between staves automatically")
143 (make-autochange-music parser music))
148 #(define-music-function (parser location grob-name offset text)
149 (symbol? number-pair? markup?)
150 (_i "Attach @var{text} to @var{grob-name} at offset @var{offset}
151 use like @code{\\once})")
152 (make-music 'AnnotateOutputEvent
154 'X-offset (car offset)
155 'Y-offset (cdr offset)
159 #(define-music-function (parser location offset text) (number-pair? markup?)
160 (_i "Attach @var{text} at @var{offset} (use like @code{\\tweak})")
161 (make-music 'AnnotateOutputEvent
162 'X-offset (car offset)
163 'Y-offset (cdr offset)
167 #(define-music-function (parser location type) (string?)
168 (_i "Insert a bar line of type @var{type}")
170 (make-property-set 'whichBar type)
174 #(define-music-function (parser location n) (integer?)
175 (_i "Print a warning if the current bar number is not @var{n}.")
176 (make-music 'ApplyContext
181 ((cbn (ly:context-property c 'currentBarNumber)))
182 (if (and (number? cbn) (not (= cbn n)))
183 (ly:input-message location "Barcheck failed got ~a expect ~a"
187 #(define-music-function (parser location delta) (real?)
188 (_i "Create a fall or doit of pitch interval @var{delta}.")
189 (make-music 'BendAfterEvent
193 #(define-music-function (parser location newfilename) (string?)
194 (_i "Direct output for the current book block to @var{newfilename}.")
195 (set! book-filename newfilename)
196 (make-music 'SequentialMusic 'void #t))
199 #(define-music-function (parser location newsuffix) (string?)
200 (_i "Set the output filename suffix for the current book block to
202 (set! book-output-suffix newsuffix)
203 (make-music 'SequentialMusic 'void #t))
207 #(define-music-function (parser location) ()
208 (_i "Insert a breath mark.")
209 (make-music 'EventChord
211 'elements (list (make-music 'BreathingEvent))))
216 #(define-music-function (parser location type) (string?)
217 (_i "Set the current clef to @var{type}.")
218 (make-clef-set type))
221 #(define-music-function
222 (parser location what dir main-music) (string? ly:dir? ly:music?)
223 (_i "Insert contents of quote @var{what} corresponding to @var{main-music},
224 in a CueVoice oriented by @var{dir}.")
225 (make-music 'QuoteMusic
227 'quoted-context-type 'Voice
228 'quoted-context-id "cue"
229 'quoted-music-name what
230 'quoted-voice-direction dir
236 #(define-music-function (parser location music) (ly:music?)
237 (_i "Display the LilyPond input representation of @var{music}
240 (display-lily-music music parser)
244 #(define-music-function (parser location music) (ly:music?)
245 (_i "Display the internal representation of @var{music} to the console.")
247 (display-scheme-music music)
253 #(define-music-function (parser location music) (ly:music?)
254 (_i "Terminate the next spanner prematurely after exactly one note without the need of a specific end spanner.")
255 (if (eq? (ly:music-property music 'name) 'EventChord)
257 ((elts (ly:music-property music 'elements))
258 (start-span-evs (filter (lambda (ev)
259 (and (music-has-type ev 'span-event)
260 (equal? (ly:music-property ev 'span-direction)
265 (let* ((c (music-clone m)))
266 (set! (ly:music-property c 'span-direction) STOP)
269 (end-ev-chord (make-music 'EventChord
270 'elements stop-span-evs))
271 (total (make-music 'SequentialMusic
272 'elements (list music
276 (ly:input-message location (_ "argument endSpanners is not an EventChord: ~a" music))))
281 #(define-music-function (parser location factor argument) (ly:moment? ly:music?)
282 (_i "Adjust durations of music in @var{argument} by rational @var{factor}. ")
284 ((orig-duration (ly:music-length argument))
285 (multiplier (ly:make-moment 1 1)))
289 (if (and (eq? (ly:music-property mus 'name) 'EventChord)
290 (< 0 (ly:moment-main-denominator (ly:music-length mus))))
292 (ly:music-compress mus multiplier)
293 (set! multiplier (ly:moment-mul factor multiplier)))
300 (ly:moment-div orig-duration (ly:music-length argument)))
307 #(def-grace-function startGraceMusic stopGraceMusic
308 (_i "Insert @var{music} as grace notes."))
313 #(define-music-function
314 (parser location name) (string?)
315 (_i "Switch instrument to @var{name}, which must be predefined with
316 @code{\\addInstrumentDefinition}.")
318 ((handle (assoc name instrument-definitions))
319 (instrument-def (if handle (cdr handle) '()))
323 (ly:input-message location "No such instrument: ~a" name))
325 (make-music 'SimultaneousMusic
337 #(define-music-function
338 (parser location tag music) (symbol? ly:music?)
339 (_i "Include only elements of @var{music} that are tagged with @var{tag}.")
342 (let* ((tags (ly:music-property m 'tags))
343 (res (memq tag tags)))
350 #(define-music-function
351 (parser location music)
353 (_i "Remove cue notes from @var{music}.")
356 (if (and (string? (ly:music-property mus 'quoted-music-name))
357 (string=? (ly:music-property mus 'quoted-context-id "") "cue"))
358 (ly:music-property mus 'element)
364 #(define-music-function (parser location label) (symbol?)
365 (_i "Create @var{label} as a bookmarking label")
366 (make-music 'EventChord
369 'elements (list (make-music 'LabelEvent
370 'page-label label))))
375 #(define-music-function
376 (parser location arg) (ly:music?)
377 (_i "Display chords in @var{arg} as clusters")
378 (music-map note-to-cluster arg))
381 #(define-music-function (parser location proc mus) (procedure? ly:music?)
382 (music-map proc mus))
386 %% noPageBreak and noPageTurn are music functions (not music indentifiers),
387 %% because music identifiers are not allowed at top-level.
389 #(define-music-function (location parser) ()
390 (_i "Forbid a page break. May be used at toplevel (ie between scores or
391 markups), or inside a score.")
392 (make-music 'EventChord
394 'page-break-permission 'forbid
395 'elements (list (make-music 'PageBreakEvent
396 'break-permission '()))))
399 #(define-music-function (location parser) ()
400 (_i "Forbid a page turn. May be used at toplevel (ie between scores or
401 markups), or inside a score.")
402 (make-music 'EventChord
404 'page-turn-permission 'forbid
405 'elements (list (make-music 'PageTurnEvent
406 'break-permission '()))))
411 #(define-music-function (parser location pitch-note) (ly:music?)
414 (make-music 'RelativeOctaveCheck
416 'pitch (pitch-of-note pitch-note)
419 ottava = #(define-music-function (parser location octave) (number?)
420 (_i "set the octavation ")
421 (make-ottava-set octave))
423 overrideBeamSettings =
424 #(define-music-function
426 context time-signature rule-type grouping-rule)
427 (symbol? pair? symbol? pair?)
429 (_i "Override beamSettings in @var{context}
430 for time signatures of @var{time-signature} and rules of type
431 @var{rule-type} to have a grouping rule alist
433 @var{rule-type} can be @code{end} or @code{subdivide},
434 with a potential future value of @code{begin}.
435 @var{grouping-rule} is an alist of @var{(beam-type . grouping)}
436 entries. @var{grouping} is in units of @var{beam-type}. If
437 @var{beam-type} is @code{*}, grouping is in units of the denominator
438 of @var{time-signature}.")
440 ;; TODO -- add warning if largest value of grouping is
441 ;; greater than time-signature.
444 #(override-beam-setting
445 $time-signature $rule-type $grouping-rule $context)
449 #(define-music-function (parser location name property value)
450 (string? symbol? scheme?)
452 (_i "Set @var{property} to @var{value} in all grobs named @var{name}.
453 The @var{name} argument is a string of the form @code{\"Context.GrobName\"}
454 or @code{\"GrobName\"}")
457 ((name-components (string-split name #\.))
458 (context-name 'Bottom)
461 (if (> 2 (length name-components))
462 (set! grob-name (string->symbol (car name-components)))
464 (set! grob-name (string->symbol (list-ref name-components 1)))
465 (set! context-name (string->symbol (list-ref name-components 0)))))
467 (make-music 'ApplyOutputEvent
469 'context-type context-name
471 (lambda (grob orig-context context)
473 (cdr (assoc 'name (ly:grob-property grob 'meta)))
475 (set! (ly:grob-property grob property) value))))))
479 %% pageBreak and pageTurn are music functions (iso music indentifiers),
480 %% because music identifiers are not allowed at top-level.
482 #(define-music-function (location parser) ()
483 (_i "Force a page break. May be used at toplevel (i.e. between scores or
484 markups), or inside a score.")
485 (make-music 'EventChord
487 'line-break-permission 'force
488 'page-break-permission 'force
489 'elements (list (make-music 'LineBreakEvent
490 'break-permission 'force)
491 (make-music 'PageBreakEvent
492 'break-permission 'force))))
495 #(define-music-function (location parser) ()
496 (_i "Force a page turn between two scores or top-level markups.")
497 (make-music 'EventChord
499 'line-break-permission 'force
500 'page-break-permission 'force
501 'page-turn-permission 'force
502 'elements (list (make-music 'LineBreakEvent
503 'break-permission 'force)
504 (make-music 'PageBreakEvent
505 'break-permission 'force)
506 (make-music 'PageTurnEvent
507 'break-permission 'force))))
510 #(define-music-function (parser location voice-ids music) (list? ly:music?)
511 (_i "Define parallel music sequences, separated by '|' (bar check signs),
512 and assign them to the identifiers provided in @var{voice-ids}.
514 @var{voice-ids}: a list of music identifiers (symbols containing only letters)
516 @var{music}: a music sequence, containing BarChecks as limiting expressions.
521 \\parallelMusic #'(A B C) {
531 (let* ((voices (apply circular-list (make-list (length voice-ids) (list))))
532 (current-voices voices)
533 (current-sequence (list)))
536 (define (push-music m)
537 "Push the music expression into the current sequence"
538 (set! current-sequence (cons m current-sequence)))
539 (define (change-voice)
540 "Stores the previously built sequence into the current voice and
541 change to the following voice."
542 (list-set! current-voices 0 (cons (make-music 'SequentialMusic
543 'elements (reverse! current-sequence))
544 (car current-voices)))
545 (set! current-sequence (list))
546 (set! current-voices (cdr current-voices)))
547 (define (bar-check? m)
548 "Checks whether m is a bar check."
549 (eq? (ly:music-property m 'name) 'BarCheck))
550 (define (music-origin music)
551 "Recursively search an origin location stored in music."
552 (cond ((null? music) #f)
553 ((not (null? (ly:music-property music 'origin)))
554 (ly:music-property music 'origin))
555 (else (or (music-origin (ly:music-property music 'element))
556 (let ((origins (remove not (map music-origin
557 (ly:music-property music 'elements)))))
558 (and (not (null? origins)) (car origins)))))))
560 ;; first, split the music and fill in voices
561 (map-in-order (lambda (m)
563 (if (bar-check? m) (change-voice)))
564 (ly:music-property music 'elements))
565 (if (not (null? current-sequence)) (change-voice))
566 ;; un-circularize `voices' and reorder the voices
567 (set! voices (map-in-order (lambda (dummy seqs)
571 ;; set origin location of each sequence in each voice
572 ;; for better type error tracking
573 (for-each (lambda (voice)
574 (for-each (lambda (seq)
575 (set! (ly:music-property seq 'origin)
576 (or (music-origin seq) location)))
580 ;; check sequence length
581 (apply for-each (lambda* (#:rest seqs)
582 (let ((moment-reference (ly:music-length (car seqs))))
583 (for-each (lambda (seq moment)
584 (if (not (equal? moment moment-reference))
585 (ly:music-message seq
586 "Bars in parallel music don't have the same length")))
587 seqs (map-in-order ly:music-length seqs))))
590 ;; bind voice identifiers to the voices
591 (map (lambda (voice-id voice)
592 (ly:parser-define! parser voice-id
593 (make-music 'SequentialMusic
597 ;; Return an empty sequence. this function is actually a "void" function.
598 (make-music 'SequentialMusic 'void #t))
601 #(define-music-function (parser loc arg) (ly:music?)
602 (_i "Tag @var{arg} to be parenthesized.")
604 (if (memq 'event-chord (ly:music-property arg 'types))
605 ; arg is an EventChord -> set the parenthesize property on all child notes and rests
608 (if (or (memq 'note-event (ly:music-property ev 'types))
609 (memq 'rest-event (ly:music-property ev 'types)))
610 (set! (ly:music-property ev 'parenthesize) #t)))
611 (ly:music-property arg 'elements))
612 ; No chord, simply set property for this expression:
613 (set! (ly:music-property arg 'parenthesize) #t))
617 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
618 (_i "Take the music in @var{part1} and @var{part2} and typeset so that they share a staff.")
619 (make-part-combine-music parser
623 #(define-music-function
624 (parser location main-note secondary-note)
625 (ly:music? ly:music?)
626 (_i "Print a trill with @var{main-note} as the main note of the trill and
627 print @var{secondary-note} as a stemless note head in parentheses.")
628 (let* ((get-notes (lambda (ev-chord)
630 (lambda (m) (eq? 'NoteEvent (ly:music-property m 'name)))
631 (ly:music-property ev-chord 'elements))))
632 (sec-note-events (get-notes secondary-note))
633 (trill-events (filter (lambda (m) (music-has-type m 'trill-span-event))
634 (ly:music-property main-note 'elements))))
636 (if (pair? sec-note-events)
638 (let* ((trill-pitch (ly:music-property (car sec-note-events) 'pitch))
639 (forced (ly:music-property (car sec-note-events) 'force-accidental)))
641 (if (ly:pitch? trill-pitch)
642 (for-each (lambda (m)
643 (ly:music-set-property! m 'pitch trill-pitch)) trill-events)
645 (ly:warning (_ "Second argument of \\pitchedTrill should be single note: "))
646 (display sec-note-events)))
649 (for-each (lambda (m)
650 (ly:music-set-property! m 'force-accidental forced))
655 #(define-music-function
656 (parser location what main-music)
658 (_i "Indicate a section of music to be quoted. @var{what} indicates the name
659 of the quoted voice, as specified in an @code{\\addQuote} command.
660 @var{main-music} is used to indicate the length of music to be quoted;
661 usually contains spacers or multi-measure rests.")
662 (make-music 'QuoteMusic
664 'quoted-music-name what
668 #(define-music-function
669 (parser location tag music) (symbol? ly:music?)
670 (_i "Remove elements of @var{music} that are tagged with @var{tag}.")
673 (let* ((tags (ly:music-property m 'tags))
674 (res (memq tag tags)))
678 resetRelativeOctave =
679 #(define-music-function
680 (parser location reference-note)
682 (_i "Set the octave inside a \\relative section.")
685 ((notes (ly:music-property reference-note 'elements))
686 (pitch (ly:music-property (car notes) 'pitch)))
688 (set! (ly:music-property reference-note 'elements) '())
689 (set! (ly:music-property reference-note
690 'to-relative-callback)
691 (lambda (music last-pitch)
697 #(define-music-function
699 context time-signature rule-type)
700 (symbol? pair? symbol?)
702 (_i "Revert beam settings in @var{context} for time signatures of
703 @var{time-signature} and groups of type
704 @var{group-type}. @var{group-type} can be @code{end}
705 or @code{subdivide}.")
707 #(revert-beam-setting $time-signature $rule-type $context)
711 #(define-music-function (parser location finger) (number-or-string?)
712 (_i "Apply @var{finger} as a fingering indication.")
721 (list 'digit finger)))))
726 #(define-music-function (parser location fraction music) (number-pair? ly:music?)
727 (_i "Multiply the duration of events in @var{music} by @var{fraction}.")
728 (ly:music-compress music
729 (ly:make-moment (car fraction) (cdr fraction))))
732 #(define-music-function (parser location grouping) (pair?)
733 (_i "Set the beat grouping in the current time signature to
735 (define (default-group-setting c)
736 (let* ((context-time-signature
737 (ly:context-property c 'timeSignatureFraction))
738 (time-signature (if (null? context-time-signature)
740 context-time-signature)))
741 (override-property-setting
744 (list time-signature 'end)
745 (list (cons '* grouping)))))
748 (make-apply-context default-group-setting)
752 #(define-music-function (parser location dur dots arg) (integer? integer? ly:music?)
753 (_i "Scale @var{arg} up by a factor of @var{2^dur*(2-(1/2)^dots)}.")
757 (shift-one-duration-log x dur dots)) arg))
760 #(define-music-function (parser location parameters) (list?)
761 (_i "Set the system stretch, by reading the 'system-stretch property of
762 the `parameters' assoc list.")
764 \overrideProperty #"Score.NonMusicalPaperColumn"
765 #'line-break-system-details
766 #$(list (cons 'alignment-extra-space (cdr (assoc 'system-stretch parameters)))
767 (cons 'system-Y-extent (cdr (assoc 'system-Y-extent parameters))))
771 #(define-music-function
772 (parser location style heads music)
773 (symbol? list-or-symbol? ly:music?)
774 (_i "Set @var{heads} in @var{music} to @var{style}.")
775 (style-note-heads heads style music))
780 #(define-music-function (parser location tag arg)
783 (_i "Add @var{tag} to the @code{tags} property of @var{arg}.")
786 (ly:music-property arg 'tags)
788 (ly:music-property arg 'tags)))
791 transposedCueDuring =
792 #(define-music-function
793 (parser location what dir pitch-note main-music)
794 (string? ly:dir? ly:music? ly:music?)
796 (_i "Insert notes from the part @var{what} into a voice called @code{cue},
797 using the transposition defined by @var{pitch-note}. This happens
798 simultaneously with @var{main-music}, which is usually a rest. The
799 argument @var{dir} determines whether the cue notes should be notated
800 as a first or second voice.")
802 (make-music 'QuoteMusic
804 'quoted-context-type 'Voice
805 'quoted-context-id "cue"
806 'quoted-music-name what
807 'quoted-voice-direction dir
808 'quoted-transposition (pitch-of-note pitch-note)
812 #(define-music-function (parser location pitch-note) (ly:music?)
813 (_i "Set instrument transposition")
816 (make-property-set 'instrumentTransposition
817 (ly:pitch-negate (pitch-of-note pitch-note)))
821 #(define-music-function (parser location sym val arg)
822 (symbol? scheme? ly:music?)
823 (_i "Add @code{sym . val} to the @code{tweaks} property of @var{arg}.")
825 (if (equal? (object-property sym 'backend-type?) #f)
827 (ly:warning (_ "cannot find property type-check for ~a") sym)
828 (ly:warning (_ "doing assignment anyway"))))
830 (ly:music-property arg 'tweaks)
832 (ly:music-property arg 'tweaks)))
838 #(define-music-function (parser location music) (ly:music?)
839 (_i "Force any @code{\\repeat volta}, @code{\\repeat tremolo} or
840 @code{\\repeat percent} commands in @var{music} to be interpreted
841 as @code{\\repeat unfold}.")
842 (unfold-repeats music))
847 #(define-music-function (parser location sym val music) (symbol? scheme? ly:music?)
848 (_i "Set @var{sym} to @var{val} in @var{music}.")
850 (set! (ly:music-property music sym) val)