1 %%%% -*- Mode: Scheme -*-
3 %%%% This file is part of LilyPond, the GNU music typesetter.
5 %%%% Copyright (C) 2003--2012 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-event-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! (paper-variable parser #f 'output-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! (paper-variable parser #f '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
239 #(define-music-function (parser location notes) (ly:music?)
240 (_i "Create cross-staff stems")
242 \override Stem #'cross-staff = #cross-staff-connect
243 \override Flag #'style = #'no-flag
245 \revert Stem #'cross-staff
250 #(define-music-function (parser location type) (string?)
251 (_i "Set the current cue clef to @var{type}.")
252 (make-cue-clef-set type))
255 #(define-music-function (parser location) ()
256 (_i "Unset the current cue clef.")
257 (make-cue-clef-unset))
260 #(define-music-function
261 (parser location what dir main-music) (string? ly:dir? ly:music?)
262 (_i "Insert contents of quote @var{what} corresponding to @var{main-music},
263 in a CueVoice oriented by @var{dir}.")
264 (make-music 'QuoteMusic
266 'quoted-context-type 'Voice
267 'quoted-context-id "cue"
268 'quoted-music-name what
269 'quoted-voice-direction dir))
272 #(define-music-function
273 (parser location what dir clef main-music) (string? ly:dir? string? ly:music?)
274 (_i "Insert contents of quote @var{what} corresponding to @var{main-music},
275 in a CueVoice oriented by @var{dir}.")
276 (make-music 'QuoteMusic
278 'quoted-context-type 'Voice
279 'quoted-context-id "cue"
280 'quoted-music-name what
281 'quoted-music-clef clef
282 'quoted-voice-direction dir))
287 #(define-music-function (parser location music) (ly:music?)
288 (_i "Display the LilyPond input representation of @var{music}
291 (display-lily-music music parser)
295 #(define-music-function (parser location music) (ly:music?)
296 (_i "Display the internal representation of @var{music} to the console.")
298 (display-scheme-music music)
304 #(define-music-function (parser location music) (ly:music?)
305 (_i "Terminate the next spanner prematurely after exactly one note
306 without the need of a specific end spanner.")
307 (if (memq (ly:music-property music 'name) '(EventChord NoteEvent))
308 (let* ((start-span-evs (filter (lambda (ev)
309 (equal? (ly:music-property ev 'span-direction)
311 (extract-typed-music music 'span-event)))
314 (let ((c (music-clone m)))
315 (set! (ly:music-property c 'span-direction) STOP)
318 (end-ev-chord (make-music 'EventChord
319 'elements stop-span-evs))
320 (total (make-music 'SequentialMusic
321 'elements (list music
326 (ly:input-message location (_ "argument endSpanners is not an EventChord: ~a") music)
330 #(define-music-function (parser location music) (ly:music?)
331 (_i "Compatibility function wrapping @code{EventChord} around
332 isolated rhythmic events occuring since version 2.15.28, after
333 expanding repeat chords @samp{q}.")
334 (event-chord-wrap! music parser))
337 #(define-music-function (parser location factor argument) (ly:moment? ly:music?)
338 (_i "Adjust durations of music in @var{argument} by rational @var{factor}.")
339 (let ((orig-duration (ly:music-length argument))
340 (multiplier (ly:make-moment 1 1)))
344 (if (< 0 (ly:moment-main-denominator (ly:music-length mus)))
346 (ly:music-compress mus multiplier)
347 (set! multiplier (ly:moment-mul factor multiplier)))))
348 (extract-named-music argument '(EventChord NoteEvent RestEvent SkipEvent)))
351 (ly:moment-div orig-duration (ly:music-length argument)))
356 #(define-music-function (parser location mark offset grob-name footnote music)
357 ((markup?) number-pair? (symbol?) markup? (ly:music?))
358 (_i "Make the markup @var{footnote} a footnote on @var{music}. The
359 footnote is marked with a markup @var{mark} moved by @var{offset} with
360 respect to the marked music.
362 If @var{mark} is not given or specified as @var{\\default}, it is
363 replaced by an automatically generated sequence number. If a symbol
364 @var{grob-name} is specified, then grobs of that type will be marked
365 if they have @var{music} as their ultimate cause; by default all grobs
366 having @var{music} as their @emph{direct} cause will be marked,
367 similar to the way @code{\\tweak} works.
369 If @var{music} is given as @code{\\default}, a footnote event
370 affecting @emph{all} grobs matching @var{grob-name} at a given time
371 step is generated. This may be required for creating footnotes on
372 time signatures, clefs, and other items not cooperating with
375 Like with @code{\\tweak}, if you use a footnote on a following
376 post-event, the @code{\\footnote} command itself needs to be attached
377 to the preceding note or rest as a post-event with @code{-}.")
378 (let ((mus (make-music
380 'X-offset (car offset)
381 'Y-offset (cdr offset)
382 'automatically-numbered (not mark)
383 'text (or mark (make-null-markup))
384 'footnote-text footnote
385 'symbol (or grob-name '()))))
387 (set! (ly:music-property music 'tweaks)
389 (cons grob-name 'footnote-music)
392 (ly:music-property music 'tweaks)))
396 (ly:input-warning location
397 (_ "\\footnote requires music or grob-name"))
398 (make-music 'Music)))))
401 #(def-grace-function startGraceMusic stopGraceMusic
402 (_i "Insert @var{music} as grace notes."))
405 #(define-scheme-function (parser location descriptions) (list?)
406 (_i "Create a context modification from @var{descriptions}, a list
407 in the format of @code{all-grob-descriptions}.")
410 (list 'assign (car p) (list (cdr p))))
413 harmonicByFret = #(define-music-function (parser location fret music) (number? ly:music?)
414 (_i "Convert @var{music} into mixed harmonics; the resulting notes resemble
415 harmonics played on a fretted instrument by touching the strings at @var{fret}.")
417 \set harmonicDots = ##t
418 \override TabNoteHead #'stencil = #(tab-note-head::print-custom-fret-label (number->string fret))
419 \override NoteHead #'Y-extent = #(ly:make-unpure-pure-container ly:grob::stencil-height
420 (lambda (grob start end)
421 (ly:grob::stencil-height grob)))
422 \override NoteHead #'stencil = #(lambda (grob) (ly:grob-set-property! grob 'style 'harmonic-mixed)
423 (ly:note-head::print grob))
425 (calc-harmonic-pitch (fret->pitch (number->string fret)) music))
427 \revert TabNoteHead #'stencil
428 \revert NoteHead #'Y-extent
429 \revert NoteHead #'stencil
432 harmonicByRatio = #(define-music-function (parser location ratio music) (number? ly:music?)
433 (_i "Convert @var{music} into mixed harmonics; the resulting notes resemble
434 harmonics played on a fretted instrument by touching the strings at the point
435 given through @var{ratio}.")
437 \set harmonicDots = ##t
438 \override TabNoteHead #'stencil = #(tab-note-head::print-custom-fret-label (ratio->fret ratio))
439 \override NoteHead #'Y-extent = #(ly:make-unpure-pure-container ly:grob::stencil-height
440 (lambda (grob start end)
441 (ly:grob::stencil-height grob)))
442 \override NoteHead #'stencil = #(lambda (grob) (ly:grob-set-property! grob 'style 'harmonic-mixed)
443 (ly:note-head::print grob))
445 (calc-harmonic-pitch (ratio->pitch ratio) music))
447 \revert TabNoteHead #'stencil
448 \revert NoteHead #'Y-extent
449 \revert NoteHead #'stencil
453 #(define-music-function
454 (parser location name) (string?)
455 (_i "Switch instrument to @var{name}, which must be predefined with
456 @code{\\addInstrumentDefinition}.")
457 (let* ((handle (assoc name instrument-definitions))
458 (instrument-def (if handle (cdr handle) '())))
461 (ly:input-warning location "No such instrument: ~a" name))
463 (make-music 'SimultaneousMusic
475 #(define-music-function (parser location tag music) (symbol? ly:music?)
476 (_i "Include only elements of @var{music} that are tagged with @var{tag}.")
479 (let* ((tags (ly:music-property m 'tags))
480 (res (memq tag tags)))
487 #(define-music-function (parser location tonic pitch-alist)
488 ((ly:pitch? '()) (list? '()))
489 (_i "Set key to @var{tonic} and scale @var{pitch-alist}.
490 If both are null, just generate @code{KeyChangeEvent}.")
491 (cond ((null? tonic) (make-music 'KeyChangeEvent))
493 (ly:parser-error parser (_ "second argument must be pitch list")
495 (make-music 'SequentialMusic 'void #t))
498 (make-music 'KeyChangeEvent
499 'tonic (ly:make-pitch 0 0 0)
500 'pitch-alist pitch-alist)
504 #(define-music-function (parser location music) (ly:music?)
505 (_i "Remove cue notes from @var{music}.")
508 (if (and (string? (ly:music-property mus 'quoted-music-name))
509 (string=? (ly:music-property mus 'quoted-context-id "") "cue"))
510 (ly:music-property mus 'element)
517 #(define-music-function (parser location label) (symbol?)
518 (_i "Create @var{label} as a bookmarking label.")
519 (make-music 'EventChord
522 'elements (list (make-music 'LabelEvent
523 'page-label label))))
527 #(define-void-function (parser location language) (string?)
528 (_i "Set note names for language @var{language}.")
529 (note-names-language parser language))
531 languageSaveAndChange =
532 #(define-void-function (parser location language) (string?)
533 (_i "Store the previous pitchnames alist, and set a new one.")
534 (set! previous-pitchnames pitchnames)
535 (note-names-language parser language))
538 #(define-void-function (parser location) ()
539 (_i "Restore a previously-saved pitchnames alist.")
540 (if previous-pitchnames
542 (set! pitchnames previous-pitchnames)
543 (ly:parser-set-note-names parser pitchnames))
544 (ly:input-warning location (_ "No other language was defined previously. Ignoring."))))
548 #(define-music-function (parser location arg) (ly:music?)
549 (_i "Display chords in @var{arg} as clusters.")
550 (music-map note-to-cluster arg))
553 #(define-music-function (parser location around to scale music)
554 (ly:pitch? ly:pitch? ly:music? ly:music?)
555 (_i "Invert @var{music} about @var{around} using @var{scale} and
556 transpose from @var{around} to @var{to}.")
557 (let ((inverter (make-modal-inverter around to scale)))
558 (change-pitches music inverter)
562 #(define-music-function (parser location from to scale music)
563 (ly:pitch? ly:pitch? ly:music? ly:music?)
564 (_i "Transpose @var{music} from pitch @var{from} to pitch @var{to}
566 (let ((transposer (make-modal-transposer from to scale)))
567 (change-pitches music transposer)
571 #(define-music-function
572 (parser location around to music) (ly:pitch? ly:pitch? ly:music?)
573 (_i "Invert @var{music} about @var{around} and
574 transpose from @var{around} to @var{to}.")
575 (music-invert around to music))
578 #(define-music-function
579 (parser location label) ((scheme? '()))
580 "Make the music for the \\mark command."
581 (let* ((set (and (integer? label)
582 (context-spec-music (make-property-set 'rehearsalMark label)
584 (ev (make-music 'MarkEvent
588 (make-sequential-music (list set ev))
590 (set! (ly:music-property ev 'label) label)
594 #(define-music-function (parser location proc mus) (procedure? ly:music?)
595 (_i "Apply @var{proc} to @var{mus} and all of the music it contains.")
596 (music-map proc mus))
598 %% noPageBreak and noPageTurn are music functions (not music indentifiers),
599 %% because music identifiers are not allowed at top-level.
601 #(define-music-function (location parser) ()
602 (_i "Forbid a page break. May be used at toplevel (i.e., between scores or
603 markups), or inside a score.")
604 (make-music 'EventChord
606 'page-break-permission 'forbid
607 'elements (list (make-music 'PageBreakEvent
608 'break-permission '()))))
611 #(define-music-function (location parser) ()
612 (_i "Forbid a page turn. May be used at toplevel (i.e., between scores or
613 markups), or inside a score.")
614 (make-music 'EventChord
616 'page-turn-permission 'forbid
617 'elements (list (make-music 'PageTurnEvent
618 'break-permission '()))))
623 #(define-music-function (parser location pitch) (ly:pitch?)
625 (make-music 'RelativeOctaveCheck
629 #(define-music-function (parser location music) (ly:music?)
630 (_i "Set @code{once} to @code{#t} on all layout instruction events in @var{music}.")
633 (cond ((music-is-of-type? m 'layout-instruction-event)
634 (set! (ly:music-property m 'once) #t))
635 ((ly:duration? (ly:music-property m 'duration))
636 (ly:music-warning m (_ "Cannot apply \\once to timed music"))))
641 #(define-music-function (parser location octave) (integer?)
642 (_i "Set the octavation.")
643 (make-music 'OttavaMusic
644 'ottava-number octave))
646 overrideTimeSignatureSettings =
647 #(define-music-function
648 (parser location time-signature base-moment beat-structure beam-exceptions)
649 (pair? pair? cheap-list? cheap-list?)
651 (_i "Override @code{timeSignatureSettings}
652 for time signatures of @var{time-signature} to have settings
653 of @var{base-moment}, @var{beat-structure}, and @var{beam-exceptions}.")
655 ;; TODO -- add warning if largest value of grouping is
656 ;; greater than time-signature.
657 (let ((setting (make-setting base-moment beat-structure beam-exceptions)))
658 (override-time-signature-setting time-signature setting)))
661 #(define-music-function (parser location name property value)
662 (string? symbol? scheme?)
664 (_i "Set @var{property} to @var{value} in all grobs named @var{name}.
665 The @var{name} argument is a string of the form @code{\"Context.GrobName\"}
666 or @code{\"GrobName\"}.")
668 (let ((name-components (string-split name #\.))
669 (context-name 'Bottom)
672 (if (> 2 (length name-components))
673 (set! grob-name (string->symbol (car name-components)))
675 (set! grob-name (string->symbol (list-ref name-components 1)))
676 (set! context-name (string->symbol (list-ref name-components 0)))))
678 (make-music 'ApplyOutputEvent
679 'context-type context-name
681 (lambda (grob orig-context context)
683 (cdr (assoc 'name (ly:grob-property grob 'meta)))
685 (set! (ly:grob-property grob property) value))))))
689 %% pageBreak and pageTurn are music functions (iso music indentifiers),
690 %% because music identifiers are not allowed at top-level.
692 #(define-music-function (location parser) ()
693 (_i "Force a page break. May be used at toplevel (i.e., between scores or
694 markups), or inside a score.")
695 (make-music 'EventChord
697 'line-break-permission 'force
698 'page-break-permission 'force
699 'elements (list (make-music 'LineBreakEvent
700 'break-permission 'force)
701 (make-music 'PageBreakEvent
702 'break-permission 'force))))
705 #(define-music-function (location parser) ()
706 (_i "Force a page turn between two scores or top-level markups.")
707 (make-music 'EventChord
709 'line-break-permission 'force
710 'page-break-permission 'force
711 'page-turn-permission 'force
712 'elements (list (make-music 'LineBreakEvent
713 'break-permission 'force)
714 (make-music 'PageBreakEvent
715 'break-permission 'force)
716 (make-music 'PageTurnEvent
717 'break-permission 'force))))
720 #(define-void-function (parser location voice-ids music) (list? ly:music?)
721 (_i "Define parallel music sequences, separated by '|' (bar check signs),
722 and assign them to the identifiers provided in @var{voice-ids}.
724 @var{voice-ids}: a list of music identifiers (symbols containing only letters)
726 @var{music}: a music sequence, containing BarChecks as limiting expressions.
731 \\parallelMusic #'(A B C) {
741 (let* ((voices (apply circular-list (make-list (length voice-ids) (list))))
742 (current-voices voices)
743 (current-sequence (list))
748 (define (push-music m)
749 "Push the music expression into the current sequence"
750 (set! current-sequence (cons m current-sequence)))
751 (define (change-voice)
752 "Stores the previously built sequence into the current voice and
753 change to the following voice."
754 (list-set! current-voices 0 (cons (make-music 'SequentialMusic
755 'elements (reverse! current-sequence))
756 (car current-voices)))
757 (set! current-sequence (list))
758 (set! current-voices (cdr current-voices)))
759 (define (bar-check? m)
760 "Checks whether m is a bar check."
761 (eq? (ly:music-property m 'name) 'BarCheck))
762 (define (music-origin music)
763 "Recursively search an origin location stored in music."
764 (cond ((null? music) #f)
765 ((not (null? (ly:music-property music 'origin)))
766 (ly:music-property music 'origin))
767 (else (or (music-origin (ly:music-property music 'element))
768 (let ((origins (remove not (map music-origin
769 (ly:music-property music 'elements)))))
770 (and (not (null? origins)) (car origins)))))))
771 (while (music-is-of-type? music 'music-wrapper-music)
773 (set! music (ly:music-property wrapper 'element)))
775 (set! (ly:music-property wrapper 'element)
776 (make-music 'SequentialMusic
779 (make-music 'SequentialMusic
782 ;; first, split the music and fill in voices
783 ;; We flatten direct layers of SequentialMusic since they are
784 ;; pretty much impossible to avoid when writing music functions.
785 (let rec ((music music))
786 (for-each (lambda (m)
787 (if (eq? (ly:music-property m 'name) 'SequentialMusic)
791 (if (bar-check? m) (change-voice)))))
792 (ly:music-property music 'elements)))
793 (if (not (null? current-sequence)) (change-voice))
794 ;; un-circularize `voices' and reorder the voices
795 (set! voices (map-in-order (lambda (dummy seqs)
799 ;; set origin location of each sequence in each voice
800 ;; for better type error tracking
801 (for-each (lambda (voice)
802 (for-each (lambda (seq)
803 (set! (ly:music-property seq 'origin)
804 (or (music-origin seq) location)))
808 ;; check sequence length
809 (apply for-each (lambda* (#:rest seqs)
810 (let ((moment-reference (ly:music-length (car seqs))))
811 (for-each (lambda (seq moment)
812 (if (not (equal? moment moment-reference))
813 (ly:music-warning seq
814 "Bars in parallel music don't have the same length")))
815 seqs (map-in-order ly:music-length seqs))))
818 ;; bind voice identifiers to the voices
819 (for-each (lambda (voice-id voice)
820 (ly:parser-define! parser voice-id
821 (let ((v (ly:music-deep-copy original)))
822 (set! (ly:music-property
823 (car (extract-named-music
830 #(define-music-function (parser loc arg) (ly:music?)
831 (_i "Tag @var{arg} to be parenthesized.")
833 (if (memq 'event-chord (ly:music-property arg 'types))
834 ;; arg is an EventChord -> set the parenthesize property
835 ;; on all child notes and rests
838 (if (or (memq 'note-event (ly:music-property ev 'types))
839 (memq 'rest-event (ly:music-property ev 'types)))
840 (set! (ly:music-property ev 'parenthesize) #t)))
841 (ly:music-property arg 'elements))
842 ;; No chord, simply set property for this expression:
843 (set! (ly:music-property arg 'parenthesize) #t))
847 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
848 (_i "Take the music in @var{part1} and @var{part2} and typeset so
849 that they share a staff.")
850 (make-part-combine-music parser
851 (list part1 part2) #f))
854 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
855 (_i "Take the music in @var{part1} and @var{part2} and typeset so
856 that they share a staff with stems directed upward.")
857 (make-part-combine-music parser
858 (list part1 part2) UP))
861 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
862 (_i "Take the music in @var{part1} and @var{part2} and typeset so
863 that they share a staff with stems directed downward.")
864 (make-part-combine-music parser
865 (list part1 part2) DOWN))
868 #(define-music-function (location parser type once) (symbol-or-boolean? boolean?)
869 (_i "Override the part-combiner.")
870 (make-music 'EventChord
871 'elements (list (make-music 'PartCombineForceEvent
874 partcombineApart = \partcombineForce #'apart ##f
875 partcombineApartOnce = \partcombineForce #'apart ##t
876 partcombineChords = \partcombineForce #'chords ##f
877 partcombineChordsOnce = \partcombineForce #'chords ##t
878 partcombineUnisono = \partcombineForce #'unisono ##f
879 partcombineUnisonoOnce = \partcombineForce #'unisono ##t
880 partcombineSoloI = \partcombineForce #'solo1 ##f
881 partcombineSoloIOnce = \partcombineForce #'solo1 ##t
882 partcombineSoloII = \partcombineForce #'solo2 ##f
883 partcombineSoloIIOnce = \partcombineForce #'solo2 ##t
884 partcombineAutomatic = \partcombineForce ##f ##f
885 partcombineAutomaticOnce = \partcombineForce ##f ##t
888 #(define-music-function (parser location dur) (ly:duration?)
889 (_i "Make a partial measure.")
891 ;; We use `descend-to-context' here instead of `context-spec-music' to
892 ;; ensure \partial still works if the Timing_translator is moved
894 (context-spec-music (make-music 'PartialSet
896 'partial-duration dur)
901 #(define-music-function
902 (parser location main-note secondary-note)
903 (ly:music? ly:music?)
904 (_i "Print a trill with @var{main-note} as the main note of the trill and
905 print @var{secondary-note} as a stemless note head in parentheses.")
906 (let* ((get-notes (lambda (ev-chord)
907 (extract-named-music ev-chord 'NoteEvent)))
908 (sec-note-events (get-notes secondary-note))
909 (trill-events (extract-named-music main-note 'TrillSpanEvent)))
910 (if (pair? sec-note-events)
912 (let* ((trill-pitch (ly:music-property (car sec-note-events) 'pitch))
913 (forced (ly:music-property (car sec-note-events) 'force-accidental)))
915 (if (ly:pitch? trill-pitch)
916 (for-each (lambda (m)
917 (ly:music-set-property! m 'pitch trill-pitch)) trill-events)
919 (ly:input-warning location (_ "Second argument of \\pitchedTrill should be single note: "))
920 (display sec-note-events)))
923 (for-each (lambda (m)
924 (ly:music-set-property! m 'force-accidental forced))
929 #(define-music-function (parser location tag more music)
930 (symbol? ly:music? ly:music?)
931 (_i "Add @var{more} to the front of @code{elements} of all music
932 expressions in @var{music} that are tagged with @var{tag}.")
933 (music-map (lambda (m)
934 (if (memq tag (ly:music-property m 'tags))
935 (set! (ly:music-property m 'elements)
936 (cons more (ly:music-property m 'elements))))
941 #(define-music-function (parser location what main-music) (string? ly:music?)
942 (_i "Indicate a section of music to be quoted. @var{what} indicates the name
943 of the quoted voice, as specified in an @code{\\addQuote} command.
944 @var{main-music} is used to indicate the length of music to be quoted;
945 usually contains spacers or multi-measure rests.")
946 (make-music 'QuoteMusic
948 'quoted-music-name what))
951 #(define-music-function (parser location pitch music)
952 ((ly:pitch? (ly:make-pitch 0 0 0)) ly:music?)
953 (_i "Make @var{music} relative to @var{pitch} (default @code{c'}).")
954 (ly:make-music-relative! music pitch)
955 (make-music 'RelativeOctaveMusic
959 #(define-music-function (parser location tag music) (symbol? ly:music?)
960 (_i "Remove elements of @var{music} that are tagged with @var{tag}.")
963 (let* ((tags (ly:music-property m 'tags))
964 (res (memq tag tags)))
968 resetRelativeOctave =
969 #(define-music-function (parser location pitch) (ly:pitch?)
970 (_i "Set the octave inside a \\relative section.")
972 (make-music 'SequentialMusic
973 'to-relative-callback
974 (lambda (music last-pitch) pitch)))
977 #(define-music-function (parser location music)
979 (_i "Return @var{music} in reverse order.")
980 (retrograde-music music))
982 revertTimeSignatureSettings =
983 #(define-music-function
984 (parser location time-signature)
987 (_i "Revert @code{timeSignatureSettings}
988 for time signatures of @var{time-signature}.")
989 (revert-time-signature-setting time-signature))
992 #(define-event-function (parser location finger) (number-or-string?)
993 (_i "Apply @var{finger} as a fingering indication.")
998 (if (string? finger) 'text 'digit)
1002 #(define-music-function (parser location fraction music)
1003 (fraction? ly:music?)
1004 (_i "Multiply the duration of events in @var{music} by @var{fraction}.")
1005 (ly:music-compress music
1006 (ly:make-moment (car fraction) (cdr fraction))))
1009 #(define-scheme-function (parser location ctx music)
1010 ((symbol?) ly:music?)
1011 (_i "Take the layout instruction events from @var{music}, optionally
1012 restricted to those applying to context type @var{ctx}, and return
1013 a context modification duplicating their effect.")
1014 (let ((mods (ly:make-context-mod)))
1016 (if (music-is-of-type? m 'layout-instruction-event)
1019 (case (ly:music-property m 'name)
1022 (ly:music-property m 'symbol)
1023 (ly:music-property m 'value)))
1026 (ly:music-property m 'symbol)))
1029 (ly:music-property m 'symbol)
1030 (ly:music-property m 'grob-value)
1031 (ly:music-property m 'grob-property-path)))
1034 (ly:music-property m 'symbol)
1035 (ly:music-property m 'grob-property-path)))))
1036 (case (ly:music-property m 'name)
1038 (ly:add-context-mod mods
1040 (ly:music-property m 'procedure))))
1041 ((ContextSpeccedMusic)
1043 (eq? ctx (ly:music-property m 'context-type)))
1044 (musicop (ly:music-property m 'element))))
1046 (let ((callback (ly:music-property m 'elements-callback)))
1047 (if (procedure? callback)
1048 (for-each musicop (callback m))))))))
1053 #(define-music-function (parser location grob offsets)
1055 (_i "Offset control-points of @var{grob} by @var{offsets}. The argument
1056 is a list of number pairs or list of such lists. Each element of a pair
1057 represents an offset to one of the coordinates of a control-point.")
1058 (define ((shape-curve offsets) grob)
1059 (let* ((orig (ly:grob-original grob))
1060 (siblings (if (ly:spanner? grob)
1061 (ly:spanner-broken-into orig) '()))
1062 (total-found (length siblings))
1063 (function (assoc-get 'control-points
1064 (reverse (ly:grob-basic-properties grob))))
1065 (coords (function grob)))
1067 (define (offset-control-points offsets)
1071 (lambda (x y) (coord-translate x y))
1074 (define (helper sibs offs)
1076 (if (eq? (car sibs) grob)
1077 (offset-control-points (car offs))
1078 (helper (cdr sibs) (cdr offs)))
1081 ;; we work with lists of lists
1082 (if (or (null? offsets)
1083 (not (list? (car offsets))))
1084 (set! offsets (list offsets)))
1086 (if (>= total-found 2)
1087 (helper siblings offsets)
1088 (offset-control-points (car offsets)))))
1091 \once \override $grob #'control-points = #(shape-curve offsets)
1095 #(define-music-function (parser location dur dots arg)
1096 (integer? integer? ly:music?)
1097 (_i "Change the duration of @var{arg} by adding @var{dur} to the
1098 @code{durlog} of @var{arg} and @var{dots} to the @code{dots} of @var{arg}.")
1102 (shift-one-duration-log x dur dots)) arg))
1105 #(define-music-function (parser location dur) (ly:duration?)
1106 (_i "Skip forward by @var{dur}.")
1107 (make-music 'SkipMusic
1112 #(def-grace-function startSlashedGraceMusic stopSlashedGraceMusic
1113 (_i "Create slashed graces (slashes through stems, but no slur) from
1114 the following music expression"))
1117 #(define-music-function (parser location parameters) (list?)
1118 (_i "Set the system stretch, by reading the 'system-stretch property of
1119 the `parameters' assoc list.")
1121 \overrideProperty #"Score.NonMusicalPaperColumn"
1122 #'line-break-system-details
1123 #(list (cons 'alignment-extra-space (cdr (assoc 'system-stretch parameters)))
1124 (cons 'system-Y-extent (cdr (assoc 'system-Y-extent parameters))))
1128 #(define-music-function (parser location style heads music)
1129 (symbol? list-or-symbol? ly:music?)
1130 (_i "Set @var{heads} in @var{music} to @var{style}.")
1131 (style-note-heads heads style music))
1134 #(define-music-function (parser location tag arg) (symbol? ly:music?)
1136 (_i "Add @var{tag} to the @code{tags} property of @var{arg}.")
1139 (ly:music-property arg 'tags)
1141 (ly:music-property arg 'tags)))
1145 #(define-music-function (parser location beat-structure fraction)
1146 ((number-list? '()) fraction?)
1147 (_i "Set @var{fraction} as time signature, with optional
1148 number list @var{beat-structure} before it.")
1149 (make-music 'TimeSignatureMusic
1150 'numerator (car fraction)
1151 'denominator (cdr fraction)
1152 'beat-structure beat-structure))
1155 #(define-music-function (parser location fraction music)
1156 (fraction? ly:music?)
1157 (_i "Scale @var{music} in time by @var{fraction}.")
1158 (make-music 'TimeScaledMusic
1159 'element (ly:music-compress music (ly:make-moment (car fraction) (cdr fraction)))
1160 'numerator (car fraction)
1161 'denominator (cdr fraction)))
1164 #(define-music-function
1165 (parser location from to music)
1166 (ly:pitch? ly:pitch? ly:music?)
1168 (_i "Transpose @var{music} from pitch @var{from} to pitch @var{to}.")
1169 (make-music 'TransposedMusic
1170 'element (ly:music-transpose music (ly:pitch-diff to from))))
1172 transposedCueDuring =
1173 #(define-music-function
1174 (parser location what dir pitch main-music)
1175 (string? ly:dir? ly:pitch? ly:music?)
1177 (_i "Insert notes from the part @var{what} into a voice called @code{cue},
1178 using the transposition defined by @var{pitch}. This happens
1179 simultaneously with @var{main-music}, which is usually a rest. The
1180 argument @var{dir} determines whether the cue notes should be notated
1181 as a first or second voice.")
1183 (make-music 'QuoteMusic
1185 'quoted-context-type 'Voice
1186 'quoted-context-id "cue"
1187 'quoted-music-name what
1188 'quoted-voice-direction dir
1189 'quoted-transposition pitch))
1192 #(define-music-function (parser location pitch) (ly:pitch?)
1193 (_i "Set instrument transposition")
1196 (make-property-set 'instrumentTransposition
1197 (ly:pitch-negate pitch))
1201 #(define-music-function (parser location grob prop value music)
1202 ((string?) symbol? scheme? ly:music?)
1203 (_i "Add a tweak to the following @var{music}.
1204 Layout objects created by @var{music} get their property @var{prop}
1205 set to @var{value}. If @var{grob} is specified, like with
1207 \\tweak Accidental #'color #red cis'
1209 an indirectly created grob (@samp{Accidental} is caused by
1210 @samp{NoteHead}) can be tweaked; otherwise only directly created grobs
1212 (if (not (object-property prop 'backend-type?))
1214 (ly:input-warning location (_ "cannot find property type-check for ~a") prop)
1215 (ly:warning (_ "doing assignment anyway"))))
1217 (ly:music-property music 'tweaks)
1218 (acons (if grob (cons (string->symbol grob) prop) prop)
1220 (ly:music-property music 'tweaks)))
1224 #(define-music-function (parser location music) (ly:music?)
1225 (_i "Force any @code{\\repeat volta}, @code{\\repeat tremolo} or
1226 @code{\\repeat percent} commands in @var{music} to be interpreted
1227 as @code{\\repeat unfold}.")
1228 (unfold-repeats music))
1231 #(define-void-function (parser location arg) (scheme?)
1232 (_i "Accept a scheme argument, return a void expression.
1233 Use this if you want to have a scheme expression evaluated
1234 because of its side-effects, but its value ignored."))
1237 #(define-music-function (parser location sym val music)
1238 (symbol? scheme? ly:music?)
1239 (_i "Set @var{sym} to @var{val} in @var{music}.")
1241 (set! (ly:music-property music sym) val)