1 %%%% -*- Mode: Scheme -*-
3 %%%% This file is part of LilyPond, the GNU music typesetter.
5 %%%% Copyright (C) 2003--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 %%%% Jan Nieuwenhuizen <janneke@gnu.org>
8 %%%% LilyPond is free software: you can redistribute it and/or modify
9 %%%% it under the terms of the GNU General Public License as published by
10 %%%% the Free Software Foundation, either version 3 of the License, or
11 %%%% (at your option) any later version.
13 %%%% LilyPond is distributed in the hope that it will be useful,
14 %%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
15 %%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 %%%% GNU General Public License for more details.
18 %%%% You should have received a copy of the GNU General Public License
19 %%%% 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-void-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)))
47 #(define-void-function (parser location name music) (string? ly:music?)
48 (_i "Define @var{music} as a quotable music expression named
50 (add-quotable parser name music))
52 %% keep these two together
53 afterGraceFraction = #(cons 6 8)
55 #(define-music-function (parser location main grace) (ly:music? ly:music?)
56 (_i "Create @var{grace} note(s) after a @var{main} music expression.")
57 (let ((main-length (ly:music-length main))
58 (fraction (ly:parser-lookup parser 'afterGraceFraction)))
59 (make-simultaneous-music
62 (make-sequential-music
65 (make-music 'SkipMusic
66 'duration (ly:make-duration
68 (* (ly:moment-main-numerator main-length)
70 (* (ly:moment-main-denominator main-length)
72 (make-music 'GraceMusic
76 %% music identifiers not allowed at top-level,
77 %% so this is a music-function instead.
79 #(define-music-function (location parser) ()
80 (_i "Allow a page turn. May be used at toplevel (ie between scores or
81 markups), or inside a score.")
82 (make-music 'EventChord
84 'page-turn-permission 'allow
85 'elements (list (make-music 'PageTurnEvent
86 'break-permission 'allow))))
89 #(define-music-function (parser location tag more music)
90 (symbol? ly:music? ly:music?)
91 (_i "Append @var{more} to the @code{elements} of all music
92 expressions in @var{music} that are tagged with @var{tag}.")
93 (music-map (lambda (m)
94 (if (memq tag (ly:music-property m 'tags))
95 (set! (ly:music-property m 'elements)
96 (append (ly:music-property m 'elements)
102 #(define-music-function (parser location proc) (procedure?)
103 (_i "Modify context properties with Scheme procedure @var{proc}.")
104 (make-music 'ApplyContext
108 #(define-music-function (parser location func music) (procedure? ly:music?)
109 (_i"Apply procedure @var{func} to @var{music}.")
113 #(define-music-function (parser location ctx proc) (symbol? procedure?)
114 (_i "Apply function @code{proc} to every layout object in context @code{ctx}")
115 (make-music 'ApplyOutputEvent
120 #(def-grace-function startAppoggiaturaMusic stopAppoggiaturaMusic
121 (_i "Create an appoggiatura from @var{music}"))
123 % for regression testing purposes.
125 #(define-music-function (parser location l r) (pair? pair?)
126 (_i "Testing function: check whether the beam quants @var{l} and @var{r} are correct")
127 (make-grob-property-override 'Beam 'positions (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 (check-slope-callbacks comp)))
136 #(define-music-function (parser location music) (ly:music?)
137 (_i "Make voices that switch between staves automatically")
138 (make-autochange-music parser music))
143 #(define-music-function (parser location grob-name offset text)
144 (symbol? number-pair? markup?)
145 (_i "Attach @var{text} to @var{grob-name} at offset @var{offset}
146 (use like @code{\\once})")
147 (make-music 'AnnotateOutputEvent
149 'X-offset (car offset)
150 'Y-offset (cdr offset)
154 #(define-music-function (parser location offset text) (number-pair? markup?)
155 (_i "Attach @var{text} at @var{offset} (use like @code{\\tweak})")
156 (make-music 'AnnotateOutputEvent
157 'X-offset (car offset)
158 'Y-offset (cdr offset)
162 #(define-music-function (parser location type) (string?)
163 (_i "Insert a bar line of type @var{type}")
165 (make-property-set 'whichBar type)
169 #(define-music-function (parser location n) (integer?)
170 (_i "Print a warning if the current bar number is not @var{n}.")
171 (make-music 'ApplyContext
174 (let ((cbn (ly:context-property c 'currentBarNumber)))
175 (if (and (number? cbn) (not (= cbn n)))
176 (ly:input-warning location
177 "Barcheck failed got ~a expect ~a"
181 #(define-music-function (parser location delta) (real?)
182 (_i "Create a fall or doit of pitch interval @var{delta}.")
183 (make-music 'BendAfterEvent
187 #(define-void-function (parser location newfilename) (string?)
188 (_i "Direct output for the current book block to @var{newfilename}.")
189 (set! book-filename newfilename))
192 #(define-void-function (parser location newsuffix) (string?)
193 (_i "Set the output filename suffix for the current book block to
195 (set! book-output-suffix newsuffix))
197 %% \breathe is defined as a music function rather than an event identifier to
198 %% ensure it gets useful input location information: as an event identifier,
199 %% it would have to be wrapped in an EventChord to prevent it from being
200 %% treated as a post_event by the parser
202 #(define-music-function (parser location) ()
203 (_i "Insert a breath mark.")
204 (make-music 'BreathingEvent))
207 #(define-music-function (parser location type) (string?)
208 (_i "Set the current clef to @var{type}.")
209 (make-clef-set type))
213 #(define-music-function (parser location args) (pair?)
214 (_i "Create compound time signatures. The argument is a Scheme list of
215 lists. Each list describes one fraction, with the last entry being the
216 denominator, while the first entries describe the summands in the
217 enumerator. If the time signature consists of just one fraction,
218 the list can be given directly, i.e. not as a list containing a single list.
219 For example, a time signature of (3+1)/8 + 2/4 would be created as
220 @code{\\compoundMeter #'((3 1 8) (2 4))}, and a time signature of (3+2)/8
221 as @code{\\compoundMeter #'((3 2 8))} or shorter
222 @code{\\compoundMeter #'(3 2 8)}.")
223 (let* ((mlen (calculate-compound-measure-length args))
224 (beat (calculate-compound-base-beat args))
225 (beatGrouping (calculate-compound-beat-grouping args))
226 (timesig (cons (ly:moment-main-numerator mlen)
227 (ly:moment-main-denominator mlen))))
229 \once \override Staff.TimeSignature #'stencil = #(lambda (grob)
230 (grob-interpret-markup grob (format-compound-time args)))
231 \set Timing.timeSignatureFraction = $timesig
232 \set Timing.baseMoment = $beat
233 \set Timing.beatStructure = $beatGrouping
234 \set Timing.beamExceptions = #'()
235 \set Timing.measureLength = $mlen
240 #(define-music-function (parser location type) (string?)
241 (_i "Set the current cue clef to @var{type}.")
242 (make-cue-clef-set type))
244 #(define-music-function (parser location) ()
245 (_i "Unset the current cue clef.")
246 (make-cue-clef-unset))
249 #(define-music-function
250 (parser location what dir main-music) (string? ly:dir? ly:music?)
251 (_i "Insert contents of quote @var{what} corresponding to @var{main-music},
252 in a CueVoice oriented by @var{dir}.")
253 (make-music 'QuoteMusic
255 'quoted-context-type 'Voice
256 'quoted-context-id "cue"
257 'quoted-music-name what
258 'quoted-voice-direction dir))
261 #(define-music-function
262 (parser location what dir clef main-music) (string? ly:dir? string? ly:music?)
263 (_i "Insert contents of quote @var{what} corresponding to @var{main-music},
264 in a CueVoice oriented by @var{dir}.")
265 (make-music 'QuoteMusic
267 'quoted-context-type 'Voice
268 'quoted-context-id "cue"
269 'quoted-music-name what
270 'quoted-music-clef clef
271 'quoted-voice-direction dir))
276 #(define-music-function (parser location music) (ly:music?)
277 (_i "Display the LilyPond input representation of @var{music}
280 (display-lily-music music parser)
284 #(define-music-function (parser location music) (ly:music?)
285 (_i "Display the internal representation of @var{music} to the console.")
287 (display-scheme-music music)
293 #(define-music-function (parser location music) (ly:music?)
294 (_i "Terminate the next spanner prematurely after exactly one note
295 without the need of a specific end spanner.")
296 (if (eq? (ly:music-property music 'name) 'EventChord)
297 (let* ((elts (ly:music-property music 'elements))
298 (start-span-evs (filter (lambda (ev)
299 (and (music-has-type ev 'span-event)
300 (equal? (ly:music-property ev 'span-direction)
305 (let ((c (music-clone m)))
306 (set! (ly:music-property c 'span-direction) STOP)
309 (end-ev-chord (make-music 'EventChord
310 'elements stop-span-evs))
311 (total (make-music 'SequentialMusic
312 'elements (list music
317 (ly:input-message location (_ "argument endSpanners is not an EventChord: ~a" music))
323 #(define-music-function (parser location factor argument) (ly:moment? ly:music?)
324 (_i "Adjust durations of music in @var{argument} by rational @var{factor}.")
325 (let ((orig-duration (ly:music-length argument))
326 (multiplier (ly:make-moment 1 1)))
330 (if (and (eq? (ly:music-property mus 'name) 'EventChord)
331 (< 0 (ly:moment-main-denominator (ly:music-length mus))))
333 (ly:music-compress mus multiplier)
334 (set! multiplier (ly:moment-mul factor multiplier))))
340 (ly:moment-div orig-duration (ly:music-length argument)))
345 #(define-music-function (parser location grob-name offset text footnote)
346 (symbol? number-pair? markup? markup?)
347 (_i "Attach @var{text} to @var{grob-name} at offset @var{offset},
348 with @var{text} referring to @var{footnote} (use like @code{\\once})")
349 (make-music 'FootnoteEvent
350 'automatically-numbered #f
352 'X-offset (car offset)
353 'Y-offset (cdr offset)
355 'footnote-text footnote))
358 #(define-music-function (parser location grob-name offset footnote)
359 (symbol? number-pair? markup?)
360 (_i "Footnote @var{grob-name} with the text in @var{footnote}
361 allowing for the footnote to be automatically numbered such that
362 the number appears at @var{offset}. Note that, for this to take effect,
363 auto-numbering must be turned on in the paper block. Otherwise, no
364 number will appear. Use like @code{\\once})")
365 (make-music 'FootnoteEvent
366 'automatically-numbered #t
368 'X-offset (car offset)
369 'Y-offset (cdr offset)
370 'text (make-null-markup)
371 'footnote-text footnote))
375 #(define-music-function (parser location offset text footnote)
376 (number-pair? markup? markup?)
377 (_i "Attach @var{text} at @var{offset} with @var{text} referring
378 to @var{footnote} (use like @code{\\tweak})")
379 (make-music 'FootnoteEvent
380 'automatically-numbered #f
381 'X-offset (car offset)
382 'Y-offset (cdr offset)
384 'footnote-text footnote))
387 #(define-music-function (parser location offset footnote)
388 (number-pair? markup?)
389 (_i "Footnote the item after which this comes with the text in
390 @var{footnote} allowing for the footnote to be automatically numbered
391 such that the number appears at @var{offset}. Note that, for this to
392 take effect, auto-numbering must be turned on in the paper block.
393 Otherwise, no number will appear. Use like @code{\\tweak})")
394 (make-music 'FootnoteEvent
395 'automatically-numbered #t
396 'X-offset (car offset)
397 'Y-offset (cdr offset)
398 'text (make-null-markup)
399 'footnote-text footnote))
402 #(def-grace-function startGraceMusic stopGraceMusic
403 (_i "Insert @var{music} as grace notes."))
406 #(define-scheme-function (parser location descriptions) (list?)
407 (_i "Create a context modification from @var{descriptions}, a list
408 in the format of @code{all-grob-descriptions}.")
411 (list 'assign (car p) (list (cdr p))))
414 harmonicByFret = #(define-music-function (parser location fret music) (number? ly:music?)
415 (_i "Convert @var{music} into harmonics; the resulting notes resemble
416 harmonics played on a fretted instrument by touching the strings above @var{fret}.")
417 (let* ((fret (number->string fret))
418 (pitch (fret->pitch fret)))
419 (make-sequential-music
422 \override TabNoteHead #'stencil = #(tab-note-head::print-custom-fret-label fret)
425 (calc-harmonic-pitch pitch music))
427 \revert TabNoteHead #'stencil
430 harmonicByRatio = #(define-music-function (parser location ratio music) (number? ly:music?)
431 (_i "Convert @var{music} into harmonics; the resulting notes resemble
432 harmonics played on a fretted instrument by touching the strings above the point
433 given through @var{ratio}.")
434 (let ((pitch (ratio->pitch ratio))
435 (fret (ratio->fret ratio)))
436 (make-sequential-music
439 \override TabNoteHead #'stencil = #(tab-note-head::print-custom-fret-label fret)
442 (calc-harmonic-pitch pitch music))
444 \revert TabNoteHead #'stencil
448 #(define-music-function
449 (parser location name) (string?)
450 (_i "Switch instrument to @var{name}, which must be predefined with
451 @code{\\addInstrumentDefinition}.")
452 (let* ((handle (assoc name instrument-definitions))
453 (instrument-def (if handle (cdr handle) '())))
456 (ly:input-warning location "No such instrument: ~a" name))
458 (make-music 'SimultaneousMusic
470 #(define-music-function (parser location tag music) (symbol? ly:music?)
471 (_i "Include only elements of @var{music} that are tagged with @var{tag}.")
474 (let* ((tags (ly:music-property m 'tags))
475 (res (memq tag tags)))
482 #(define-music-function (parser location tonic pitch-alist)
483 ((ly:pitch? '()) (list? '()))
484 (_i "Set key to @var{tonic} and scale @var{pitch-alist}.
485 If both are null, just generate @code{KeyChangeEvent}.")
486 (cond ((null? tonic) (make-music 'KeyChangeEvent))
488 (ly:parser-error parser (_ "second argument must be pitch list")
490 (make-music 'SequentialMusic 'void #t))
493 (make-music 'KeyChangeEvent
494 'tonic (ly:make-pitch 0 0 0)
495 'pitch-alist pitch-alist)
499 #(define-music-function (parser location music) (ly:music?)
500 (_i "Remove cue notes from @var{music}.")
503 (if (and (string? (ly:music-property mus 'quoted-music-name))
504 (string=? (ly:music-property mus 'quoted-context-id "") "cue"))
505 (ly:music-property mus 'element)
512 #(define-music-function (parser location label) (symbol?)
513 (_i "Create @var{label} as a bookmarking label.")
514 (make-music 'EventChord
517 'elements (list (make-music 'LabelEvent
518 'page-label label))))
522 #(define-void-function (parser location language) (string?)
523 (_i "Set note names for language @var{language}.")
524 (note-names-language parser language))
526 languageSaveAndChange =
527 #(define-void-function (parser location language) (string?)
528 (_i "Store the previous pitchnames alist, and set a new one.")
529 (set! previous-pitchnames pitchnames)
530 (note-names-language parser language))
533 #(define-void-function (parser location) ()
534 (_i "Restore a previously-saved pitchnames alist.")
535 (if previous-pitchnames
537 (set! pitchnames previous-pitchnames)
538 (ly:parser-set-note-names parser pitchnames))
539 (ly:input-warning location (_ "No other language was defined previously. Ignoring."))))
543 #(define-music-function (parser location arg) (ly:music?)
544 (_i "Display chords in @var{arg} as clusters.")
545 (music-map note-to-cluster arg))
548 #(define-music-function (parser location around to scale music)
549 (ly:pitch? ly:pitch? ly:music? ly:music?)
550 (_i "Invert @var{music} about @var{around} using @var{scale} and
551 transpose from @var{around} to @var{to}.")
552 (let ((inverter (make-modal-inverter around to scale)))
553 (change-pitches music inverter)
557 #(define-music-function (parser location from to scale music)
558 (ly:pitch? ly:pitch? ly:music? ly:music?)
559 (_i "Transpose @var{music} from pitch @var{from} to pitch @var{to}
561 (let ((transposer (make-modal-transposer from to scale)))
562 (change-pitches music transposer)
566 #(define-music-function
567 (parser location around to music) (ly:pitch? ly:pitch? ly:music?)
568 (_i "Invert @var{music} about @var{around} and
569 transpose from @var{around} to @var{to}.")
570 (music-invert around to music))
573 #(define-music-function
574 (parser location label) ((scheme? '()))
575 "Make the music for the \\mark command."
576 (let* ((set (and (integer? label)
577 (context-spec-music (make-property-set 'rehearsalMark label)
579 (ev (make-music 'MarkEvent
583 (make-sequential-music (list set ev))
585 (set! (ly:music-property ev 'label) label)
589 #(define-music-function (parser location proc mus) (procedure? ly:music?)
590 (_i "Apply @var{proc} to @var{mus} and all of the music it contains.")
591 (music-map proc mus))
593 %% noPageBreak and noPageTurn are music functions (not music indentifiers),
594 %% because music identifiers are not allowed at top-level.
596 #(define-music-function (location parser) ()
597 (_i "Forbid a page break. May be used at toplevel (i.e., between scores or
598 markups), or inside a score.")
599 (make-music 'EventChord
601 'page-break-permission 'forbid
602 'elements (list (make-music 'PageBreakEvent
603 'break-permission '()))))
606 #(define-music-function (location parser) ()
607 (_i "Forbid a page turn. May be used at toplevel (i.e., between scores or
608 markups), or inside a score.")
609 (make-music 'EventChord
611 'page-turn-permission 'forbid
612 'elements (list (make-music 'PageTurnEvent
613 'break-permission '()))))
618 #(define-music-function (parser location pitch) (ly:pitch?)
620 (make-music 'RelativeOctaveCheck
624 #(define-music-function (parser location music) (ly:music?)
625 (_i "Set @code{once} to @code{#t} on all layout instruction events in @var{music}.")
628 (cond ((music-is-of-type? m 'layout-instruction-event)
629 (set! (ly:music-property m 'once) #t))
630 ((ly:duration? (ly:music-property m 'duration))
631 (ly:music-warning m (_ "Cannot apply \\once to timed music"))))
636 #(define-music-function (parser location octave) (integer?)
637 (_i "Set the octavation.")
638 (make-music 'OttavaMusic
639 'ottava-number octave))
641 overrideTimeSignatureSettings =
642 #(define-music-function
643 (parser location time-signature base-moment beat-structure beam-exceptions)
644 (pair? pair? cheap-list? cheap-list?)
646 (_i "Override @code{timeSignatureSettings}
647 for time signatures of @var{time-signature} to have settings
648 of @var{base-moment}, @var{beat-structure}, and @var{beam-exceptions}.")
650 ;; TODO -- add warning if largest value of grouping is
651 ;; greater than time-signature.
652 (let ((setting (make-setting base-moment beat-structure beam-exceptions)))
653 (override-time-signature-setting time-signature setting)))
656 #(define-music-function (parser location name property value)
657 (string? symbol? scheme?)
659 (_i "Set @var{property} to @var{value} in all grobs named @var{name}.
660 The @var{name} argument is a string of the form @code{\"Context.GrobName\"}
661 or @code{\"GrobName\"}.")
663 (let ((name-components (string-split name #\.))
664 (context-name 'Bottom)
667 (if (> 2 (length name-components))
668 (set! grob-name (string->symbol (car name-components)))
670 (set! grob-name (string->symbol (list-ref name-components 1)))
671 (set! context-name (string->symbol (list-ref name-components 0)))))
673 (make-music 'ApplyOutputEvent
674 'context-type context-name
676 (lambda (grob orig-context context)
678 (cdr (assoc 'name (ly:grob-property grob 'meta)))
680 (set! (ly:grob-property grob property) value))))))
684 %% pageBreak and pageTurn are music functions (iso music indentifiers),
685 %% because music identifiers are not allowed at top-level.
687 #(define-music-function (location parser) ()
688 (_i "Force a page break. May be used at toplevel (i.e., between scores or
689 markups), or inside a score.")
690 (make-music 'EventChord
692 'line-break-permission 'force
693 'page-break-permission 'force
694 'elements (list (make-music 'LineBreakEvent
695 'break-permission 'force)
696 (make-music 'PageBreakEvent
697 'break-permission 'force))))
700 #(define-music-function (location parser) ()
701 (_i "Force a page turn between two scores or top-level markups.")
702 (make-music 'EventChord
704 'line-break-permission 'force
705 'page-break-permission 'force
706 'page-turn-permission 'force
707 'elements (list (make-music 'LineBreakEvent
708 'break-permission 'force)
709 (make-music 'PageBreakEvent
710 'break-permission 'force)
711 (make-music 'PageTurnEvent
712 'break-permission 'force))))
715 #(define-void-function (parser location voice-ids music) (list? ly:music?)
716 (_i "Define parallel music sequences, separated by '|' (bar check signs),
717 and assign them to the identifiers provided in @var{voice-ids}.
719 @var{voice-ids}: a list of music identifiers (symbols containing only letters)
721 @var{music}: a music sequence, containing BarChecks as limiting expressions.
726 \\parallelMusic #'(A B C) {
736 (let* ((voices (apply circular-list (make-list (length voice-ids) (list))))
737 (current-voices voices)
738 (current-sequence (list)))
741 (define (push-music m)
742 "Push the music expression into the current sequence"
743 (set! current-sequence (cons m current-sequence)))
744 (define (change-voice)
745 "Stores the previously built sequence into the current voice and
746 change to the following voice."
747 (list-set! current-voices 0 (cons (make-music 'SequentialMusic
748 'elements (reverse! current-sequence))
749 (car current-voices)))
750 (set! current-sequence (list))
751 (set! current-voices (cdr current-voices)))
752 (define (bar-check? m)
753 "Checks whether m is a bar check."
754 (eq? (ly:music-property m 'name) 'BarCheck))
755 (define (music-origin music)
756 "Recursively search an origin location stored in music."
757 (cond ((null? music) #f)
758 ((not (null? (ly:music-property music 'origin)))
759 (ly:music-property music 'origin))
760 (else (or (music-origin (ly:music-property music 'element))
761 (let ((origins (remove not (map music-origin
762 (ly:music-property music 'elements)))))
763 (and (not (null? origins)) (car origins)))))))
765 ;; first, split the music and fill in voices
766 ;; We flatten direct layers of SequentialMusic since they are
767 ;; pretty much impossible to avoid when writing music functions.
768 (let rec ((music music))
769 (for-each (lambda (m)
770 (if (eq? (ly:music-property m 'name) 'SequentialMusic)
774 (if (bar-check? m) (change-voice)))))
775 (ly:music-property music 'elements)))
776 (if (not (null? current-sequence)) (change-voice))
777 ;; un-circularize `voices' and reorder the voices
778 (set! voices (map-in-order (lambda (dummy seqs)
782 ;; set origin location of each sequence in each voice
783 ;; for better type error tracking
784 (for-each (lambda (voice)
785 (for-each (lambda (seq)
786 (set! (ly:music-property seq 'origin)
787 (or (music-origin seq) location)))
791 ;; check sequence length
792 (apply for-each (lambda* (#:rest seqs)
793 (let ((moment-reference (ly:music-length (car seqs))))
794 (for-each (lambda (seq moment)
795 (if (not (equal? moment moment-reference))
796 (ly:music-warning seq
797 "Bars in parallel music don't have the same length")))
798 seqs (map-in-order ly:music-length seqs))))
801 ;; bind voice identifiers to the voices
802 (for-each (lambda (voice-id voice)
803 (ly:parser-define! parser voice-id
804 (make-music 'SequentialMusic
810 #(define-music-function (parser loc arg) (ly:music?)
811 (_i "Tag @var{arg} to be parenthesized.")
813 (if (memq 'event-chord (ly:music-property arg 'types))
814 ;; arg is an EventChord -> set the parenthesize property
815 ;; on all child notes and rests
818 (if (or (memq 'note-event (ly:music-property ev 'types))
819 (memq 'rest-event (ly:music-property ev 'types)))
820 (set! (ly:music-property ev 'parenthesize) #t)))
821 (ly:music-property arg 'elements))
822 ;; No chord, simply set property for this expression:
823 (set! (ly:music-property arg 'parenthesize) #t))
827 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
828 (_i "Take the music in @var{part1} and @var{part2} and typeset so
829 that they share a staff.")
830 (make-part-combine-music parser
831 (list part1 part2) #f))
834 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
835 (_i "Take the music in @var{part1} and @var{part2} and typeset so
836 that they share a staff with stems directed upward.")
837 (make-part-combine-music parser
838 (list part1 part2) UP))
841 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
842 (_i "Take the music in @var{part1} and @var{part2} and typeset so
843 that they share a staff with stems directed downward.")
844 (make-part-combine-music parser
845 (list part1 part2) DOWN))
848 #(define-music-function (location parser type once) (symbol-or-boolean? boolean?)
849 (_i "Override the part-combiner.")
850 (make-music 'EventChord
851 'elements (list (make-music 'PartCombineForceEvent
854 partcombineApart = \partcombineForce #'apart ##f
855 partcombineApartOnce = \partcombineForce #'apart ##t
856 partcombineChords = \partcombineForce #'chords ##f
857 partcombineChordsOnce = \partcombineForce #'chords ##t
858 partcombineUnisono = \partcombineForce #'unisono ##f
859 partcombineUnisonoOnce = \partcombineForce #'unisono ##t
860 partcombineSoloI = \partcombineForce #'solo1 ##f
861 partcombineSoloIOnce = \partcombineForce #'solo1 ##t
862 partcombineSoloII = \partcombineForce #'solo2 ##f
863 partcombineSoloIIOnce = \partcombineForce #'solo2 ##t
864 partcombineAutomatic = \partcombineForce ##f ##f
865 partcombineAutomaticOnce = \partcombineForce ##f ##t
868 #(define-music-function (parser location dur) (ly:duration?)
869 (_i "Make a partial measure.")
871 ;; We use `descend-to-context' here instead of `context-spec-music' to
872 ;; ensure \partial still works if the Timing_translator is moved
874 (context-spec-music (make-music 'PartialSet
876 'partial-duration dur)
881 #(define-music-function
882 (parser location main-note secondary-note)
883 (ly:music? ly:music?)
884 (_i "Print a trill with @var{main-note} as the main note of the trill and
885 print @var{secondary-note} as a stemless note head in parentheses.")
886 (let* ((get-notes (lambda (ev-chord)
888 (lambda (m) (eq? 'NoteEvent (ly:music-property m 'name)))
889 (ly:music-property ev-chord 'elements))))
890 (sec-note-events (get-notes secondary-note))
891 (trill-events (filter (lambda (m) (music-has-type m 'trill-span-event))
892 (ly:music-property main-note 'elements))))
894 (if (pair? sec-note-events)
896 (let* ((trill-pitch (ly:music-property (car sec-note-events) 'pitch))
897 (forced (ly:music-property (car sec-note-events) 'force-accidental)))
899 (if (ly:pitch? trill-pitch)
900 (for-each (lambda (m)
901 (ly:music-set-property! m 'pitch trill-pitch)) trill-events)
903 (ly:input-warning location (_ "Second argument of \\pitchedTrill should be single note: "))
904 (display sec-note-events)))
907 (for-each (lambda (m)
908 (ly:music-set-property! m 'force-accidental forced))
913 #(define-music-function (parser location tag more music)
914 (symbol? ly:music? ly:music?)
915 (_i "Add @var{more} to the front of @code{elements} of all music
916 expressions in @var{music} that are tagged with @var{tag}.")
917 (music-map (lambda (m)
918 (if (memq tag (ly:music-property m 'tags))
919 (set! (ly:music-property m 'elements)
920 (cons more (ly:music-property m 'elements))))
925 #(define-music-function (parser location what main-music) (string? ly:music?)
926 (_i "Indicate a section of music to be quoted. @var{what} indicates the name
927 of the quoted voice, as specified in an @code{\\addQuote} command.
928 @var{main-music} is used to indicate the length of music to be quoted;
929 usually contains spacers or multi-measure rests.")
930 (make-music 'QuoteMusic
932 'quoted-music-name what))
935 #(define-music-function (parser location pitch music)
936 ((ly:pitch? (ly:make-pitch 0 0 0)) ly:music?)
937 (_i "Make @var{music} relative to @var{pitch} (default @code{c'}).")
938 (ly:make-music-relative! music pitch)
939 (make-music 'RelativeOctaveMusic
943 #(define-music-function (parser location tag music) (symbol? ly:music?)
944 (_i "Remove elements of @var{music} that are tagged with @var{tag}.")
947 (let* ((tags (ly:music-property m 'tags))
948 (res (memq tag tags)))
952 resetRelativeOctave =
953 #(define-music-function (parser location pitch) (ly:pitch?)
954 (_i "Set the octave inside a \\relative section.")
956 (make-music 'SequentialMusic
957 'to-relative-callback
958 (lambda (music last-pitch) pitch)))
961 #(define-music-function (parser location music)
963 (_i "Return @var{music} in reverse order.")
964 (retrograde-music music))
966 revertTimeSignatureSettings =
967 #(define-music-function
968 (parser location time-signature)
971 (_i "Revert @code{timeSignatureSettings}
972 for time signatures of @var{time-signature}.")
973 (revert-time-signature-setting time-signature))
976 #(define-music-function (parser location finger) (number-or-string?)
977 (_i "Apply @var{finger} as a fingering indication.")
982 (if (string? finger) 'text 'digit)
986 #(define-music-function (parser location fraction music)
987 (fraction? ly:music?)
988 (_i "Multiply the duration of events in @var{music} by @var{fraction}.")
989 (ly:music-compress music
990 (ly:make-moment (car fraction) (cdr fraction))))
993 #(define-scheme-function (parser location ctx music)
994 ((symbol?) ly:music?)
995 (_i "Take the layout instruction events from @var{music}, optionally
996 restricted to those applying to context type @var{ctx}, and return
997 a context modification duplicating their effect.")
998 (let ((mods (ly:make-context-mod)))
1000 (if (music-is-of-type? m 'layout-instruction-event)
1003 (case (ly:music-property m 'name)
1006 (ly:music-property m 'symbol)
1007 (ly:music-property m 'value)))
1010 (ly:music-property m 'symbol)))
1013 (ly:music-property m 'symbol)
1014 (ly:music-property m 'grob-property-path)
1015 (ly:music-property m 'grob-value)))
1018 (ly:music-property m 'symbol)
1019 (ly:music-property m 'grob-property-path)))))
1020 (case (ly:music-property m 'name)
1021 ((SequentialMusic SimultaneousMusic)
1022 (for-each musicop (ly:music-property m 'elements)))
1023 ((ContextSpeccedMusic)
1025 (eq? ctx (ly:music-property m 'context-type)))
1026 (musicop (ly:music-property m 'element)))))))
1031 #(define-music-function (parser location dur dots arg)
1032 (integer? integer? ly:music?)
1033 (_i "Change the duration of @var{arg} by adding @var{dur} to the
1034 @code{durlog} of @var{arg} and @var{dots} to the @code{dots} of @var{arg}.")
1038 (shift-one-duration-log x dur dots)) arg))
1041 #(define-music-function (parser location dur) (ly:duration?)
1042 (_i "Skip forward by @var{dur}.")
1043 (make-music 'SkipMusic
1048 #(def-grace-function startSlashedGraceMusic stopSlashedGraceMusic
1049 (_i "Create slashed graces (slashes through stems, but no slur) from
1050 the following music expression"))
1053 #(define-music-function (parser location parameters) (list?)
1054 (_i "Set the system stretch, by reading the 'system-stretch property of
1055 the `parameters' assoc list.")
1057 \overrideProperty #"Score.NonMusicalPaperColumn"
1058 #'line-break-system-details
1059 #(list (cons 'alignment-extra-space (cdr (assoc 'system-stretch parameters)))
1060 (cons 'system-Y-extent (cdr (assoc 'system-Y-extent parameters))))
1064 #(define-music-function (parser location style heads music)
1065 (symbol? list-or-symbol? ly:music?)
1066 (_i "Set @var{heads} in @var{music} to @var{style}.")
1067 (style-note-heads heads style music))
1071 tabChordRepetition =
1072 #(define-music-function (parser location) ()
1073 (_i "Include the string information in a chord repetition.")
1074 (ly:parser-set-repetition-function parser tab-repeat-chord)
1075 (make-music 'SequentialMusic 'void #t))
1078 #(define-music-function (parser location tag arg) (symbol? ly:music?)
1080 (_i "Add @var{tag} to the @code{tags} property of @var{arg}.")
1083 (ly:music-property arg 'tags)
1085 (ly:music-property arg 'tags)))
1089 #(define-music-function (parser location beat-structure fraction)
1090 ((number-list? '()) fraction?)
1091 (_i "Set @var{fraction} as time signature, with optional
1092 number list @var{beat-structure} before it.")
1093 (make-music 'TimeSignatureMusic
1094 'numerator (car fraction)
1095 'denominator (cdr fraction)
1096 'beat-structure beat-structure))
1099 #(define-music-function (parser location fraction music)
1100 (fraction? ly:music?)
1101 (_i "Scale @var{music} in time by @var{fraction}.")
1102 (make-music 'TimeScaledMusic
1103 'element (ly:music-compress music (ly:make-moment (car fraction) (cdr fraction)))
1104 'numerator (car fraction)
1105 'denominator (cdr fraction)))
1108 #(define-music-function
1109 (parser location from to music)
1110 (ly:pitch? ly:pitch? ly:music?)
1112 (_i "Transpose @var{music} from pitch @var{from} to pitch @var{to}.")
1113 (make-music 'TransposedMusic
1114 'element (ly:music-transpose music (ly:pitch-diff to from))))
1116 transposedCueDuring =
1117 #(define-music-function
1118 (parser location what dir pitch main-music)
1119 (string? ly:dir? ly:pitch? ly:music?)
1121 (_i "Insert notes from the part @var{what} into a voice called @code{cue},
1122 using the transposition defined by @var{pitch}. This happens
1123 simultaneously with @var{main-music}, which is usually a rest. The
1124 argument @var{dir} determines whether the cue notes should be notated
1125 as a first or second voice.")
1127 (make-music 'QuoteMusic
1129 'quoted-context-type 'Voice
1130 'quoted-context-id "cue"
1131 'quoted-music-name what
1132 'quoted-voice-direction dir
1133 'quoted-transposition pitch))
1136 #(define-music-function (parser location pitch) (ly:pitch?)
1137 (_i "Set instrument transposition")
1140 (make-property-set 'instrumentTransposition
1141 (ly:pitch-negate pitch))
1145 #(define-music-function (parser location sym val arg)
1146 (symbol? scheme? ly:music?)
1147 (_i "Add @code{sym . val} to the @code{tweaks} property of @var{arg}.")
1149 (if (equal? (object-property sym 'backend-type?) #f)
1151 (ly:input-warning location (_ "cannot find property type-check for ~a") sym)
1152 (ly:warning (_ "doing assignment anyway"))))
1154 (ly:music-property arg 'tweaks)
1156 (ly:music-property arg 'tweaks)))
1162 #(define-music-function (parser location music) (ly:music?)
1163 (_i "Force any @code{\\repeat volta}, @code{\\repeat tremolo} or
1164 @code{\\repeat percent} commands in @var{music} to be interpreted
1165 as @code{\\repeat unfold}.")
1166 (unfold-repeats music))
1169 #(define-void-function (parser location arg) (scheme?)
1170 (_i "Accept a scheme argument, return a void expression.
1171 Use this if you want to have a scheme expression evaluated
1172 because of its side-effects, but its value ignored."))
1175 #(define-music-function (parser location sym val music)
1176 (symbol? scheme? ly:music?)
1177 (_i "Set @var{sym} to @var{val} in @var{music}.")
1179 (set! (ly:music-property music sym) val)