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 property arg item)
90 (symbol-list-or-symbol? list? symbol-list-or-music?)
91 (_i "Override @var{property} for pieces of broken spanner @var{item}
92 with values @var{arg}. @var{item} may either be music in the form of
93 a starting spanner event, or a symbol list in the form
94 @samp{Context.Grob} or just @samp{Grob}. Iff @var{item} is in the
95 form of a spanner event, @var{property} may also have the form
96 @samp{Grob.property} for specifying a directed tweak.")
98 (if (eq? (ly:music-property item 'span-direction) START)
99 #{ \tweak #property #(value-for-spanner-piece arg) #item #}
101 (ly:music-warning item (_ "not a spanner"))
103 (let* ((p (check-grob-path item parser location
107 (name (and p (second p)))
109 (and name (assoc-get name all-grob-descriptions))))
111 (member 'spanner-interface
112 (assoc-get 'interfaces
113 (assoc-get 'meta description))))
115 \override #item . #property =
116 #(value-for-spanner-piece arg)
119 (ly:input-warning location (_ "not a spanner name, `~a'") name)
120 (make-music 'Music))))))
123 #(define-music-function (parser location tag more music)
124 (symbol? ly:music? ly:music?)
125 (_i "Append @var{more} to the @code{elements} of all music
126 expressions in @var{music} that are tagged with @var{tag}.")
127 (music-map (lambda (m)
128 (if (memq tag (ly:music-property m 'tags))
129 (set! (ly:music-property m 'elements)
130 (append (ly:music-property m 'elements)
136 #(define-music-function (parser location proc) (procedure?)
137 (_i "Modify context properties with Scheme procedure @var{proc}.")
138 (make-music 'ApplyContext
142 #(define-music-function (parser location func music) (procedure? ly:music?)
143 (_i"Apply procedure @var{func} to @var{music}.")
147 #(define-music-function (parser location ctx proc) (symbol? procedure?)
148 (_i "Apply function @code{proc} to every layout object in context @code{ctx}")
149 (make-music 'ApplyOutputEvent
154 #(def-grace-function startAppoggiaturaMusic stopAppoggiaturaMusic
155 (_i "Create an appoggiatura from @var{music}"))
157 % for regression testing purposes.
159 #(define-music-function (parser location l r) (pair? pair?)
160 (_i "Testing function: check whether the beam quants @var{l} and @var{r} are correct")
161 (make-grob-property-override 'Beam 'positions (check-quant-callbacks l r)))
163 % for regression testing purposes.
165 #(define-music-function (parser location comp) (procedure?)
166 (_i "Testing function: check whether the slope of the beam is the same as @code{comp}")
167 (make-grob-property-override 'Beam 'positions (check-slope-callbacks comp)))
170 #(define-music-function (parser location music) (ly:music?)
171 (_i "Make voices that switch between staves automatically")
172 (make-autochange-music parser music))
177 #(define-music-function (parser location grob-name offset text)
178 (symbol? number-pair? markup?)
179 (_i "Attach @var{text} to @var{grob-name} at offset @var{offset}
180 (use like @code{\\once})")
183 (make-music 'AnnotateOutputEvent
185 'X-offset (car offset)
186 'Y-offset (cdr offset)
190 #(define-event-function (parser location offset text) (number-pair? markup?)
191 (_i "Attach @var{text} at @var{offset} (use like @code{\\tweak})")
192 (make-music 'AnnotateOutputEvent
193 'X-offset (car offset)
194 'Y-offset (cdr offset)
198 #(define-music-function (parser location type) (string?)
199 (_i "Insert a bar line of type @var{type}")
201 (make-property-set 'whichBar type)
205 #(define-music-function (parser location n) (integer?)
206 (_i "Print a warning if the current bar number is not @var{n}.")
207 (make-music 'ApplyContext
210 (let ((cbn (ly:context-property c 'currentBarNumber)))
211 (if (and (number? cbn) (not (= cbn n)))
212 (ly:input-warning location
213 "Barcheck failed got ~a expect ~a"
217 #(define-event-function (parser location delta) (real?)
218 (_i "Create a fall or doit of pitch interval @var{delta}.")
219 (make-music 'BendAfterEvent
223 #(define-void-function (parser location newfilename) (string?)
224 (_i "Direct output for the current book block to @var{newfilename}.")
225 (set! (paper-variable parser #f 'output-filename) newfilename))
228 #(define-void-function (parser location newsuffix) (string?)
229 (_i "Set the output filename suffix for the current book block to
231 (set! (paper-variable parser #f 'output-suffix) newsuffix))
233 %% \breathe is defined as a music function rather than an event identifier to
234 %% ensure it gets useful input location information: as an event identifier,
235 %% it would have to be wrapped in an EventChord to prevent it from being
236 %% treated as a post_event by the parser
238 #(define-music-function (parser location) ()
239 (_i "Insert a breath mark.")
240 (make-music 'BreathingEvent))
243 #(define-music-function (parser location type) (string?)
244 (_i "Set the current clef to @var{type}.")
245 (make-clef-set type))
249 #(define-music-function (parser location args) (pair?)
250 (_i "Create compound time signatures. The argument is a Scheme list of
251 lists. Each list describes one fraction, with the last entry being the
252 denominator, while the first entries describe the summands in the
253 enumerator. If the time signature consists of just one fraction,
254 the list can be given directly, i.e. not as a list containing a single list.
255 For example, a time signature of (3+1)/8 + 2/4 would be created as
256 @code{\\compoundMeter #'((3 1 8) (2 4))}, and a time signature of (3+2)/8
257 as @code{\\compoundMeter #'((3 2 8))} or shorter
258 @code{\\compoundMeter #'(3 2 8)}.")
259 (let* ((mlen (calculate-compound-measure-length args))
260 (beat (calculate-compound-base-beat args))
261 (beatGrouping (calculate-compound-beat-grouping args))
262 (timesig (cons (ly:moment-main-numerator mlen)
263 (ly:moment-main-denominator mlen))))
265 \once \override Staff.TimeSignature.stencil = #(lambda (grob)
266 (grob-interpret-markup grob (format-compound-time args)))
267 \set Timing.timeSignatureFraction = #timesig
268 \set Timing.baseMoment = #beat
269 \set Timing.beatStructure = #beatGrouping
270 \set Timing.beamExceptions = #'()
271 \set Timing.measureLength = #mlen
275 #(define-music-function (parser location notes) (ly:music?)
276 (_i "Create cross-staff stems")
278 \temporary \override Stem.cross-staff = #cross-staff-connect
279 \temporary \override Flag.style = #'no-flag
281 \revert Stem.cross-staff
286 #(define-music-function (parser location type) (string?)
287 (_i "Set the current cue clef to @var{type}.")
288 (make-cue-clef-set type))
291 #(define-music-function (parser location) ()
292 (_i "Unset the current cue clef.")
293 (make-cue-clef-unset))
296 #(define-music-function
297 (parser location what dir main-music) (string? ly:dir? ly:music?)
298 (_i "Insert contents of quote @var{what} corresponding to @var{main-music},
299 in a CueVoice oriented by @var{dir}.")
300 (make-music 'QuoteMusic
302 'quoted-context-type 'Voice
303 'quoted-context-id "cue"
304 'quoted-music-name what
305 'quoted-voice-direction dir))
308 #(define-music-function
309 (parser location what dir clef main-music) (string? ly:dir? string? ly:music?)
310 (_i "Insert contents of quote @var{what} corresponding to @var{main-music},
311 in a CueVoice oriented by @var{dir}.")
312 (make-music 'QuoteMusic
314 'quoted-context-type 'Voice
315 'quoted-context-id "cue"
316 'quoted-music-name what
317 'quoted-music-clef clef
318 'quoted-voice-direction dir))
323 #(define-music-function (parser location music) (ly:music?)
324 (_i "Display the LilyPond input representation of @var{music}
327 (display-lily-music music parser)
331 #(define-music-function (parser location music) (ly:music?)
332 (_i "Display the internal representation of @var{music} to the console.")
334 (display-scheme-music music)
340 #(define-music-function (parser location music) (ly:music?)
341 (_i "Terminate the next spanner prematurely after exactly one note
342 without the need of a specific end spanner.")
343 (let* ((start-span-evs (filter (lambda (ev)
344 (equal? (ly:music-property ev 'span-direction)
346 (extract-typed-music music 'span-event)))
349 (music-clone m 'span-direction STOP))
351 (end-ev-chord (make-music 'EventChord
352 'elements stop-span-evs))
353 (total (make-music 'SequentialMusic
354 'elements (list music
359 #(define-music-function (parser location music) (ly:music?)
360 (_i "Compatibility function wrapping @code{EventChord} around
361 isolated rhythmic events occuring since version 2.15.28, after
362 expanding repeat chords @samp{q}.")
363 (event-chord-wrap! music parser))
366 #(define-music-function (parser location factor argument) (ly:moment? ly:music?)
367 (_i "Adjust durations of music in @var{argument} by rational @var{factor}.")
368 (let ((orig-duration (ly:music-length argument))
369 (multiplier (ly:make-moment 1 1)))
373 (if (< 0 (ly:moment-main-denominator (ly:music-length mus)))
375 (ly:music-compress mus multiplier)
376 (set! multiplier (ly:moment-mul factor multiplier)))))
377 (extract-named-music argument '(EventChord NoteEvent RestEvent SkipEvent)))
380 (ly:moment-div orig-duration (ly:music-length argument)))
385 #(define-event-function (parser location finger) (number-or-markup?)
386 (_i "Apply @var{finger} as a fingering indication.")
390 (if (number? finger) 'digit 'text)
394 #(define-music-function (parser location mark offset footnote item)
395 ((markup?) number-pair? markup? symbol-list-or-music?)
396 (_i "Make the markup @var{footnote} a footnote on @var{item}. The
397 footnote is marked with a markup @var{mark} moved by @var{offset} with
398 respect to the marked music.
400 If @var{mark} is not given or specified as @var{\\default}, it is
401 replaced by an automatically generated sequence number. If @var{item}
402 is a symbol list of form @samp{Grob} or @samp{Context.Grob}, then
403 grobs of that type will be marked at the current time step in the
404 given context (default @code{Bottom}).
406 If @var{item} is music, the music will get a footnote attached to a
407 grob immediately attached to the event, like @var{\\tweak} does. For
408 attaching a footnote to an @emph{indirectly} caused grob, write
409 @code{\\single\\footnote}, use @var{item} to specify the grob, and
410 follow it with the music to annotate.
412 Like with @code{\\tweak}, if you use a footnote on a following
413 post-event, the @code{\\footnote} command itself needs to be attached
414 to the preceding note or rest as a post-event with @code{-}.")
415 (let ((mus (make-music
417 'X-offset (car offset)
418 'Y-offset (cdr offset)
419 'automatically-numbered (not mark)
420 'text (or mark (make-null-markup))
421 'footnote-text footnote)))
422 #{ \tweak footnote-music #mus #item #}))
425 #(def-grace-function startGraceMusic stopGraceMusic
426 (_i "Insert @var{music} as grace notes."))
429 #(define-scheme-function (parser location descriptions) (list?)
430 (_i "Create a context modification from @var{descriptions}, a list
431 in the format of @code{all-grob-descriptions}.")
434 (list 'assign (car p) (list (cdr p))))
437 harmonicByFret = #(define-music-function (parser location fret music) (number? ly:music?)
438 (_i "Convert @var{music} into mixed harmonics; the resulting notes resemble
439 harmonics played on a fretted instrument by touching the strings at @var{fret}.")
441 \set harmonicDots = ##t
442 \temporary \override TabNoteHead.stencil = #(tab-note-head::print-custom-fret-label (number->string fret))
443 \temporary \override NoteHead.Y-extent = #grob::always-Y-extent-from-stencil
444 \temporary \override NoteHead.stencil = #(lambda (grob) (ly:grob-set-property! grob 'style 'harmonic-mixed)
445 (ly:note-head::print grob))
447 (calc-harmonic-pitch (fret->pitch (number->string fret)) music))
449 \revert TabNoteHead.stencil
450 \revert NoteHead.Y-extent
451 \revert NoteHead.stencil
454 harmonicByRatio = #(define-music-function (parser location ratio music) (number? ly:music?)
455 (_i "Convert @var{music} into mixed harmonics; the resulting notes resemble
456 harmonics played on a fretted instrument by touching the strings at the point
457 given through @var{ratio}.")
459 \set harmonicDots = ##t
460 \temporary \override TabNoteHead.stencil = #(tab-note-head::print-custom-fret-label (ratio->fret ratio))
461 \temporary \override NoteHead.Y-extent = #(ly:make-unpure-pure-container ly:grob::stencil-height
462 (lambda (grob start end)
463 (ly:grob::stencil-height grob)))
464 \temporary \override NoteHead.stencil = #(lambda (grob) (ly:grob-set-property! grob 'style 'harmonic-mixed)
465 (ly:note-head::print grob))
467 (calc-harmonic-pitch (ratio->pitch ratio) music))
469 \revert TabNoteHead.stencil
470 \revert NoteHead.Y-extent
471 \revert NoteHead.stencil
475 #(define-music-function (parser location item) (symbol-list-or-music?)
476 (_i "Set @var{item}'s @samp{transparent} property to @code{#t},
477 making it invisible while still retaining its dimensions.
479 If @var{item} is a symbol list of form @code{GrobName} or
480 @code{Context.GrobName}, the result is an override for the grob name
481 specified by it. If @var{item} is a music expression, the result is
482 the same music expression with an appropriate tweak applied to it.")
484 #{ \tweak transparent ##t #item #}
485 #{ \override #item . transparent = ##t #}))
488 #(define-music-function (parser location) ()
489 (_i "Put the segno variant 'varsegno' at this position into the staff,
490 compatible with the repeat command.")
491 (make-music 'ApplyContext
494 (let ((score-ctx (ly:context-find ctx 'Score)))
495 (if (ly:context? score-ctx)
496 (let ((old-rc (ly:context-property score-ctx 'repeatCommands '())))
497 (if (eq? (memq 'segno-display old-rc) #f)
498 (ly:context-set-property! score-ctx 'repeatCommands (cons 'segno-display old-rc)))))))))
501 #(define-music-function
502 (parser location name) (string?)
503 (_i "Switch instrument to @var{name}, which must be predefined with
504 @code{\\addInstrumentDefinition}.")
505 (let* ((handle (assoc name instrument-definitions))
506 (instrument-def (if handle (cdr handle) '())))
509 (ly:input-warning location "No such instrument: ~a" name))
511 (make-music 'SimultaneousMusic
523 #(define-music-function (parser location tag music)
524 (symbol-list-or-symbol? ly:music?)
525 (_i "Include only elements of @var{music} that are either untagged
526 or tagged with one of the tags in @var{tag}. @var{tag} may be either
527 a single symbol or a list of symbols.")
531 (let ((music-tags (ly:music-property m 'tags)))
532 (or (null? music-tags)
533 (memq tag music-tags))))
535 (let ((music-tags (ly:music-property m 'tags)))
536 (or (null? music-tags)
537 (any (lambda (t) (memq t music-tags)) tag)))))
541 #(define-music-function (parser location tonic pitch-alist)
542 ((ly:pitch? '()) (list? '()))
543 (_i "Set key to @var{tonic} and scale @var{pitch-alist}.
544 If both are null, just generate @code{KeyChangeEvent}.")
545 (cond ((null? tonic) (make-music 'KeyChangeEvent))
547 (ly:parser-error parser (_ "second argument must be pitch list")
549 (make-music 'SequentialMusic 'void #t))
552 (make-music 'KeyChangeEvent
553 'tonic (ly:make-pitch 0 0 0)
554 'pitch-alist pitch-alist)
558 #(define-music-function (parser location music) (ly:music?)
559 (_i "Remove cue notes from @var{music}.")
562 (if (and (string? (ly:music-property mus 'quoted-music-name))
563 (string=? (ly:music-property mus 'quoted-context-id "") "cue"))
564 (ly:music-property mus 'element)
571 #(define-music-function (parser location label) (symbol?)
572 (_i "Create @var{label} as a bookmarking label.")
573 (make-music 'EventChord
576 'elements (list (make-music 'LabelEvent
577 'page-label label))))
581 #(define-void-function (parser location language) (string?)
582 (_i "Set note names for language @var{language}.")
583 (note-names-language parser language))
585 languageSaveAndChange =
586 #(define-void-function (parser location language) (string?)
587 (_i "Store the previous pitchnames alist, and set a new one.")
588 (set! previous-pitchnames pitchnames)
589 (note-names-language parser language))
592 #(define-void-function (parser location) ()
593 (_i "Restore a previously-saved pitchnames alist.")
594 (if previous-pitchnames
596 (set! pitchnames previous-pitchnames)
597 (ly:parser-set-note-names parser pitchnames))
598 (ly:input-warning location (_ "No other language was defined previously. Ignoring."))))
602 #(define-music-function (parser location arg) (ly:music?)
603 (_i "Display chords in @var{arg} as clusters.")
604 (music-map note-to-cluster arg))
607 #(define-music-function (parser location around to scale music)
608 (ly:pitch? ly:pitch? ly:music? ly:music?)
609 (_i "Invert @var{music} about @var{around} using @var{scale} and
610 transpose from @var{around} to @var{to}.")
611 (let ((inverter (make-modal-inverter around to scale)))
612 (change-pitches music inverter)
616 #(define-music-function (parser location from to scale music)
617 (ly:pitch? ly:pitch? ly:music? ly:music?)
618 (_i "Transpose @var{music} from pitch @var{from} to pitch @var{to}
620 (let ((transposer (make-modal-transposer from to scale)))
621 (change-pitches music transposer)
625 #(define-music-function
626 (parser location around to music) (ly:pitch? ly:pitch? ly:music?)
627 (_i "Invert @var{music} about @var{around} and
628 transpose from @var{around} to @var{to}.")
629 (music-invert around to music))
632 #(define-music-function
633 (parser location label) ((scheme? '()))
634 "Make the music for the \\mark command."
635 (let* ((set (and (integer? label)
636 (context-spec-music (make-property-set 'rehearsalMark label)
638 (ev (make-music 'MarkEvent
642 (make-sequential-music (list set ev))
644 (set! (ly:music-property ev 'label) label)
648 #(define-music-function (parser location proc mus) (procedure? ly:music?)
649 (_i "Apply @var{proc} to @var{mus} and all of the music it contains.")
650 (music-map proc mus))
652 %% noPageBreak and noPageTurn are music functions (not music indentifiers),
653 %% because music identifiers are not allowed at top-level.
655 #(define-music-function (location parser) ()
656 (_i "Forbid a page break. May be used at toplevel (i.e., between scores or
657 markups), or inside a score.")
658 (make-music 'EventChord
660 'page-break-permission 'forbid
661 'elements (list (make-music 'PageBreakEvent
662 'break-permission '()))))
665 #(define-music-function (location parser) ()
666 (_i "Forbid a page turn. May be used at toplevel (i.e., between scores or
667 markups), or inside a score.")
668 (make-music 'EventChord
670 'page-turn-permission 'forbid
671 'elements (list (make-music 'PageTurnEvent
672 'break-permission '()))))
677 #(define-music-function (parser location pitch) (ly:pitch?)
679 (make-music 'RelativeOctaveCheck
683 #(define-music-function (parser location item) (symbol-list-or-music?)
684 (_i "Set @var{item}'s @samp{stencil} property to @code{#f},
685 effectively omitting it without taking up space.
687 If @var{item} is a symbol list of form @code{GrobName} or
688 @code{Context.GrobName}, the result is an override for the grob name
689 specified by it. If @var{item} is a music expression, the result is
690 the same music expression with an appropriate tweak applied to it.")
692 #{ \tweak stencil ##f #item #}
693 #{ \override #item . stencil = ##f #}))
696 #(define-music-function (parser location music) (ly:music?)
697 (_i "Set @code{once} to @code{#t} on all layout instruction events in @var{music}.")
700 (cond ((music-is-of-type? m 'layout-instruction-event)
701 (set! (ly:music-property m 'once) #t))
702 ((ly:duration? (ly:music-property m 'duration))
703 (ly:music-warning m (_ "Cannot apply \\once to timed music"))))
708 #(define-music-function (parser location octave) (integer?)
709 (_i "Set the octavation.")
710 (make-music 'OttavaMusic
711 'ottava-number octave))
713 overrideTimeSignatureSettings =
714 #(define-music-function
715 (parser location time-signature base-moment beat-structure beam-exceptions)
716 (pair? pair? cheap-list? cheap-list?)
718 (_i "Override @code{timeSignatureSettings}
719 for time signatures of @var{time-signature} to have settings
720 of @var{base-moment}, @var{beat-structure}, and @var{beam-exceptions}.")
722 ;; TODO -- add warning if largest value of grouping is
723 ;; greater than time-signature.
724 (let ((setting (make-setting base-moment beat-structure beam-exceptions)))
725 (override-time-signature-setting time-signature setting)))
728 #(define-music-function (parser location grob-property-path value)
729 (symbol-list? scheme?)
731 (_i "Set the grob property specified by @var{grob-property-path} to
732 @var{value}. @var{grob-property-path} is a symbol list of the form
733 @code{Context.GrobName.property} or @code{GrobName.property}, possibly
734 with subproperties given as well.")
735 (let ((p (check-grob-path grob-property-path parser location
739 (make-music 'ApplyOutputEvent
740 'context-type (first p)
742 (lambda (grob orig-context context)
744 (cdr (assoc 'name (ly:grob-property grob 'meta)))
746 (ly:grob-set-nested-property!
747 grob (cddr p) value))))
748 (make-music 'Music))))
755 %% pageBreak and pageTurn are music functions (iso music indentifiers),
756 %% because music identifiers are not allowed at top-level.
758 #(define-music-function (location parser) ()
759 (_i "Force a page break. May be used at toplevel (i.e., between scores or
760 markups), or inside a score.")
761 (make-music 'EventChord
763 'line-break-permission 'force
764 'page-break-permission 'force
765 'elements (list (make-music 'LineBreakEvent
766 'break-permission 'force)
767 (make-music 'PageBreakEvent
768 'break-permission 'force))))
771 #(define-music-function (location parser) ()
772 (_i "Force a page turn between two scores or top-level markups.")
773 (make-music 'EventChord
775 'line-break-permission 'force
776 'page-break-permission 'force
777 'page-turn-permission 'force
778 'elements (list (make-music 'LineBreakEvent
779 'break-permission 'force)
780 (make-music 'PageBreakEvent
781 'break-permission 'force)
782 (make-music 'PageTurnEvent
783 'break-permission 'force))))
786 #(define-void-function (parser location voice-ids music) (list? ly:music?)
787 (_i "Define parallel music sequences, separated by '|' (bar check signs),
788 and assign them to the identifiers provided in @var{voice-ids}.
790 @var{voice-ids}: a list of music identifiers (symbols containing only letters)
792 @var{music}: a music sequence, containing BarChecks as limiting expressions.
797 \\parallelMusic #'(A B C) {
807 (define (bar-check? m)
808 "Checks whether m is a bar check."
809 (eq? (ly:music-property m 'name) 'BarCheck))
810 (define (recurse-and-split music)
811 "This returns either a list of music split along barchecks, or
813 (let ((elt (ly:music-property music 'element))
814 (elts (ly:music-property music 'elements)))
815 (cond ((ly:music? elt)
816 (let ((lst (recurse-and-split elt)))
820 (let ((res (music-clone music 'element x)))
821 (if (ly:input-location?
822 (ly:music-property x 'origin))
823 (set! (ly:music-property res 'origin)
824 (ly:music-property x 'origin)))
827 ((any bar-check? elts)
828 (let* ((voices (apply circular-list
829 (make-list (length voice-ids)
831 (current-voices voices)
832 (current-sequence '()))
835 (define (push-music m)
836 "Push the music expression into the current sequence"
837 (set! current-sequence (cons m current-sequence)))
838 (define (change-voice)
839 "Stores the previously built sequence into the current voice and
840 change to the following voice."
841 (set-car! current-voices
842 (cons (reverse! current-sequence)
843 (car current-voices)))
844 (set! current-sequence '())
845 (set! current-voices (cdr current-voices)))
846 (for-each (lambda (m)
847 (let ((split? (recurse-and-split m)))
856 (if (bar-check? m) (change-voice))))))
858 (if (pair? current-sequence) (change-voice))
859 ;; un-circularize `voices' and reorder the voices
861 (set! voices (map reverse!
862 (list-head voices (length voice-ids))))
864 ;; check sequence length
865 (apply for-each (lambda seqs
866 (define (seq-len seq)
867 (reduce ly:moment-add
869 (map ly:music-length seq)))
870 (let ((moment-reference (seq-len (car seqs))))
871 (for-each (lambda (seq)
872 (if (not (equal? (seq-len seq)
878 (_ "Bars in parallel music don't have the same length"))))
883 (set! lst (concatenate! lst))
884 (let ((res (music-clone music 'elements lst)))
886 (ly:input-location? (ly:music-property
889 (set! (ly:music-property res 'origin)
890 (ly:music-property (car lst) 'origin)))
894 (let ((voices (recurse-and-split music)))
897 ;; bind voice identifiers to the voices
898 (for-each (lambda (voice-id voice)
899 (ly:parser-define! parser voice-id voice))
901 (ly:music-warning music
902 (_ "ignoring parallel music without barchecks")))))
905 #(define-music-function (parser loc arg) (ly:music?)
906 (_i "Tag @var{arg} to be parenthesized.")
908 (if (memq 'event-chord (ly:music-property arg 'types))
909 ;; arg is an EventChord -> set the parenthesize property
910 ;; on all child notes and rests
913 (if (or (memq 'note-event (ly:music-property ev 'types))
914 (memq 'rest-event (ly:music-property ev 'types)))
915 (set! (ly:music-property ev 'parenthesize) #t)))
916 (ly:music-property arg 'elements))
917 ;; No chord, simply set property for this expression:
918 (set! (ly:music-property arg 'parenthesize) #t))
922 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
923 (_i "Take the music in @var{part1} and @var{part2} and typeset so
924 that they share a staff.")
925 (make-part-combine-music parser
926 (list part1 part2) #f))
929 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
930 (_i "Take the music in @var{part1} and @var{part2} and typeset so
931 that they share a staff with stems directed upward.")
932 (make-part-combine-music parser
933 (list part1 part2) UP))
936 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
937 (_i "Take the music in @var{part1} and @var{part2} and typeset so
938 that they share a staff with stems directed downward.")
939 (make-part-combine-music parser
940 (list part1 part2) DOWN))
943 #(define-music-function (location parser type once) (symbol-or-boolean? boolean?)
944 (_i "Override the part-combiner.")
945 (make-music 'EventChord
946 'elements (list (make-music 'PartCombineForceEvent
949 partcombineApart = \partcombineForce #'apart ##f
950 partcombineApartOnce = \partcombineForce #'apart ##t
951 partcombineChords = \partcombineForce #'chords ##f
952 partcombineChordsOnce = \partcombineForce #'chords ##t
953 partcombineUnisono = \partcombineForce #'unisono ##f
954 partcombineUnisonoOnce = \partcombineForce #'unisono ##t
955 partcombineSoloI = \partcombineForce #'solo1 ##f
956 partcombineSoloIOnce = \partcombineForce #'solo1 ##t
957 partcombineSoloII = \partcombineForce #'solo2 ##f
958 partcombineSoloIIOnce = \partcombineForce #'solo2 ##t
959 partcombineAutomatic = \partcombineForce ##f ##f
960 partcombineAutomaticOnce = \partcombineForce ##f ##t
963 #(define-music-function (parser location dur) (ly:duration?)
964 (_i "Make a partial measure.")
966 ;; We use `descend-to-context' here instead of `context-spec-music' to
967 ;; ensure \partial still works if the Timing_translator is moved
969 (context-spec-music (make-music 'PartialSet
971 'partial-duration dur)
976 #(define-music-function
977 (parser location main-note secondary-note)
978 (ly:music? ly:music?)
979 (_i "Print a trill with @var{main-note} as the main note of the trill and
980 print @var{secondary-note} as a stemless note head in parentheses.")
981 (let* ((get-notes (lambda (ev-chord)
982 (extract-named-music ev-chord 'NoteEvent)))
983 (sec-note-events (get-notes secondary-note))
984 (trill-events (extract-named-music main-note 'TrillSpanEvent)))
985 (if (pair? sec-note-events)
987 (let* ((trill-pitch (ly:music-property (car sec-note-events) 'pitch))
988 (forced (ly:music-property (car sec-note-events) 'force-accidental)))
990 (if (ly:pitch? trill-pitch)
991 (for-each (lambda (m)
992 (ly:music-set-property! m 'pitch trill-pitch)) trill-events)
994 (ly:input-warning location (_ "Second argument of \\pitchedTrill should be single note: "))
995 (display sec-note-events)))
998 (for-each (lambda (m)
999 (ly:music-set-property! m 'force-accidental forced))
1004 #(define-music-function (parser location tag more music)
1005 (symbol? ly:music? ly:music?)
1006 (_i "Add @var{more} to the front of @code{elements} of all music
1007 expressions in @var{music} that are tagged with @var{tag}.")
1008 (music-map (lambda (m)
1009 (if (memq tag (ly:music-property m 'tags))
1010 (set! (ly:music-property m 'elements)
1011 (cons more (ly:music-property m 'elements))))
1016 #(define-music-function (parser location what main-music) (string? ly:music?)
1017 (_i "Indicate a section of music to be quoted. @var{what} indicates the name
1018 of the quoted voice, as specified in an @code{\\addQuote} command.
1019 @var{main-music} is used to indicate the length of music to be quoted;
1020 usually contains spacers or multi-measure rests.")
1021 (make-music 'QuoteMusic
1023 'quoted-music-name what))
1026 #(define-music-function (parser location pitch music)
1027 ((ly:pitch? (ly:make-pitch 0 0 0)) ly:music?)
1028 (_i "Make @var{music} relative to @var{pitch} (default @code{c'}).")
1029 (ly:make-music-relative! music pitch)
1030 (make-music 'RelativeOctaveMusic
1034 #(define-music-function (parser location tag music)
1035 (symbol-list-or-symbol? ly:music?)
1036 (_i "Remove elements of @var{music} that are tagged with one of the
1037 tags in @var{tag}. @var{tag} may be either a single symbol or a list
1042 (not (memq tag (ly:music-property m 'tags))))
1044 (let ((music-tags (ly:music-property m 'tags)))
1045 (or (null? music-tags)
1046 (not (any (lambda (t) (memq t music-tags)) tag))))))
1049 resetRelativeOctave =
1050 #(define-music-function (parser location pitch) (ly:pitch?)
1051 (_i "Set the octave inside a \\relative section.")
1053 (make-music 'SequentialMusic
1054 'to-relative-callback
1055 (lambda (music last-pitch) pitch)))
1058 #(define-music-function (parser location music)
1060 (_i "Return @var{music} in reverse order.")
1061 (retrograde-music music))
1063 revertTimeSignatureSettings =
1064 #(define-music-function
1065 (parser location time-signature)
1068 (_i "Revert @code{timeSignatureSettings}
1069 for time signatures of @var{time-signature}.")
1070 (revert-time-signature-setting time-signature))
1073 #(define-event-function (parser location finger) (number-or-markup?)
1074 (_i "Apply @var{finger} as a fingering indication.")
1078 (if (number? finger) 'digit 'text)
1082 #(define-music-function (parser location fraction music)
1083 (fraction? ly:music?)
1084 (_i "Multiply the duration of events in @var{music} by @var{fraction}.")
1085 (ly:music-compress music
1086 (ly:make-moment (car fraction) (cdr fraction))))
1089 #(define-scheme-function (parser location ctx music)
1090 ((symbol?) ly:music?)
1091 (_i "Take the layout instruction events from @var{music}, optionally
1092 restricted to those applying to context type @var{ctx}, and return
1093 a context modification duplicating their effect.")
1094 (let ((mods (ly:make-context-mod)))
1096 (if (music-is-of-type? m 'layout-instruction-event)
1099 (case (ly:music-property m 'name)
1102 (ly:music-property m 'symbol)
1103 (ly:music-property m 'value)))
1106 (ly:music-property m 'symbol)))
1109 (ly:music-property m 'symbol)
1110 (ly:music-property m 'grob-value)
1112 ((ly:music-property m 'grob-property #f) => list)
1114 (ly:music-property m 'grob-property-path)))))
1117 (ly:music-property m 'symbol)
1119 ((ly:music-property m 'grob-property #f) => list)
1121 (ly:music-property m 'grob-property-path)))))))
1122 (case (ly:music-property m 'name)
1124 (ly:add-context-mod mods
1126 (ly:music-property m 'procedure))))
1127 ((ContextSpeccedMusic)
1129 (eq? ctx (ly:music-property m 'context-type)))
1130 (musicop (ly:music-property m 'element))))
1132 (let ((callback (ly:music-property m 'elements-callback)))
1133 (if (procedure? callback)
1134 (for-each musicop (callback m))))))))
1139 #(define-music-function (parser location offsets item)
1140 (list? symbol-list-or-music?)
1141 (_i "Offset control-points of @var{item} by @var{offsets}. The
1142 argument is a list of number pairs or list of such lists. Each
1143 element of a pair represents an offset to one of the coordinates of a
1144 control-point. If @var{item} is a string, the result is
1145 @code{\\once\\override} for the specified grob type. If @var{item} is
1146 a music expression, the result is the same music expression with an
1147 appropriate tweak applied.")
1148 (define (shape-curve grob)
1149 (let* ((orig (ly:grob-original grob))
1150 (siblings (if (ly:spanner? grob)
1151 (ly:spanner-broken-into orig) '()))
1152 (total-found (length siblings))
1153 (function (assoc-get 'control-points
1154 (reverse (ly:grob-basic-properties grob))))
1155 (coords (function grob)))
1157 (define (offset-control-points offsets)
1161 (lambda (x y) (coord-translate x y))
1164 (define (helper sibs offs)
1166 (if (eq? (car sibs) grob)
1167 (offset-control-points (car offs))
1168 (helper (cdr sibs) (cdr offs)))
1171 ;; we work with lists of lists
1172 (if (or (null? offsets)
1173 (not (list? (car offsets))))
1174 (set! offsets (list offsets)))
1176 (if (>= total-found 2)
1177 (helper siblings offsets)
1178 (offset-control-points (car offsets)))))
1179 #{ \tweak control-points #shape-curve #item #})
1182 #(define-music-function (parser location dur dots arg)
1183 (integer? integer? ly:music?)
1184 (_i "Change the duration of @var{arg} by adding @var{dur} to the
1185 @code{durlog} of @var{arg} and @var{dots} to the @code{dots} of @var{arg}.")
1189 (shift-one-duration-log x dur dots)) arg))
1192 #(define-music-function (parser location overrides music)
1193 (ly:music? ly:music?)
1194 (_i "Convert @var{overrides} to tweaks and apply them to @var{music}.
1195 This does not convert @code{\\revert}, @code{\\set} or @code{\\unset}.")
1196 (set! (ly:music-property music 'tweaks)
1198 (lambda (m) (eq? (ly:music-property m 'name)
1202 ((ly:music-property m 'grob-property #f) => list)
1204 (ly:music-property m 'grob-property-path)))))
1205 (acons (cons (ly:music-property m 'symbol) ;grob name
1207 p ;grob property path
1208 (car p))) ;grob property
1209 (ly:music-property m 'grob-value)
1211 (ly:music-property music 'tweaks)
1216 #(define-music-function (parser location dur) (ly:duration?)
1217 (_i "Skip forward by @var{dur}.")
1218 (make-music 'SkipMusic
1223 #(def-grace-function startSlashedGraceMusic stopSlashedGraceMusic
1224 (_i "Create slashed graces (slashes through stems, but no slur) from
1225 the following music expression"))
1228 #(define-music-function (parser location parameters) (list?)
1229 (_i "Set the system stretch, by reading the 'system-stretch property of
1230 the `parameters' assoc list.")
1232 \overrideProperty Score.NonMusicalPaperColumn.line-break-system-details
1233 #(list (cons 'alignment-extra-space (cdr (assoc 'system-stretch parameters)))
1234 (cons 'system-Y-extent (cdr (assoc 'system-Y-extent parameters))))
1238 #(define-music-function (parser location style heads music)
1239 (symbol? symbol-list-or-symbol? ly:music?)
1240 (_i "Set @var{heads} in @var{music} to @var{style}.")
1241 (style-note-heads heads style music))
1244 #(define-music-function (parser location tag music) (symbol-list-or-symbol? ly:music?)
1245 (_i "Tag the following @var{music} with @var{tag} and return the
1246 result, by adding the single symbol or symbol list @var{tag} to the
1247 @code{tags} property of @var{music}.")
1250 (ly:music-property music 'tags)
1251 ((if (symbol? tag) cons append)
1253 (ly:music-property music 'tags)))
1257 #(define-music-function (parser location music)
1259 (_i "Make any @code{\\override} in @var{music} replace an existing
1260 grob property value only temporarily, restoring the old value when a
1261 corresponding @code{\\revert} is executed. This is achieved by
1262 clearing the @samp{pop-first} property normally set on
1265 An @code{\\override}/@/@code{\\revert} sequence created by using
1266 @code{\\temporary} and @code{\\undo} on the same music containing
1267 overrides will cancel out perfectly or cause a@tie{}warning.
1269 Non-property-related music is ignored, warnings are generated for any
1270 property-changing music that isn't an @code{\\override}.")
1274 (and (or (music-is-of-type? m 'layout-instruction-event)
1275 (music-is-of-type? m 'context-specification)
1276 (music-is-of-type? m 'apply-context)
1277 (music-is-of-type? m 'time-signature-music))
1278 (case (ly:music-property m 'name)
1280 (if (ly:music-property m 'pop-first #f)
1281 (set! (ly:music-property m 'pop-first) '()))
1282 (if (ly:music-property m 'once #f)
1283 (set! (ly:music-property m 'once) '()))
1285 ((ContextSpeccedMusic)
1290 (ly:input-warning location (_ "Cannot make ~a revertible")
1291 (ly:music-property m 'name))
1298 #(define-music-function (parser location beat-structure fraction)
1299 ((number-list? '()) fraction?)
1300 (_i "Set @var{fraction} as time signature, with optional
1301 number list @var{beat-structure} before it.")
1302 (make-music 'TimeSignatureMusic
1303 'numerator (car fraction)
1304 'denominator (cdr fraction)
1305 'beat-structure beat-structure))
1308 #(define-music-function (parser location fraction music)
1309 (fraction? ly:music?)
1310 (_i "Scale @var{music} in time by @var{fraction}.")
1311 (make-music 'TimeScaledMusic
1312 'element (ly:music-compress music (ly:make-moment (car fraction) (cdr fraction)))
1313 'numerator (car fraction)
1314 'denominator (cdr fraction)))
1317 #(define-music-function
1318 (parser location from to music)
1319 (ly:pitch? ly:pitch? ly:music?)
1321 (_i "Transpose @var{music} from pitch @var{from} to pitch @var{to}.")
1322 (make-music 'TransposedMusic
1323 'element (ly:music-transpose music (ly:pitch-diff to from))))
1325 transposedCueDuring =
1326 #(define-music-function
1327 (parser location what dir pitch main-music)
1328 (string? ly:dir? ly:pitch? ly:music?)
1330 (_i "Insert notes from the part @var{what} into a voice called @code{cue},
1331 using the transposition defined by @var{pitch}. This happens
1332 simultaneously with @var{main-music}, which is usually a rest. The
1333 argument @var{dir} determines whether the cue notes should be notated
1334 as a first or second voice.")
1336 (make-music 'QuoteMusic
1338 'quoted-context-type 'Voice
1339 'quoted-context-id "cue"
1340 'quoted-music-name what
1341 'quoted-voice-direction dir
1342 ;; following is inverse of instrumentTransposition for
1343 ;; historical reasons
1344 'quoted-transposition pitch))
1347 #(define-music-function (parser location pitch) (ly:pitch?)
1348 (_i "Set instrument transposition")
1351 (make-property-set 'instrumentTransposition pitch)
1355 #(define-music-function (parser location ratio tuplet-span music)
1356 (fraction? (ly:duration? '()) ly:music?)
1357 (_i "Scale the given @var{music} to tuplets. @var{ratio} is a
1358 fraction that specifies how many notes are played in place of the
1359 nominal value: it will be @samp{3/2} for triplets, namely three notes
1360 being played in place of two. If the optional duration
1361 @var{tuplet-span} is specified, it is used instead of
1362 @code{tupletSpannerDuration} for grouping the tuplets.
1365 \\tuplet 3/2 4 @{ c8 c c c c c @}
1367 will result in two groups of three tuplets, each group lasting for a
1369 (make-music 'TimeScaledMusic
1370 'element (ly:music-compress
1372 (ly:make-moment (cdr ratio) (car ratio)))
1373 'numerator (cdr ratio)
1374 'denominator (car ratio)
1375 'duration tuplet-span))
1378 #(define-music-function (parser location tuplet-span)
1380 (_i "Set @code{tupletSpannerDuration}, the length into which
1381 @code{\\tuplet} without an explicit @samp{tuplet-span} argument of its
1382 own will group its tuplets, to the duration @var{tuplet-span}. To
1383 revert to the default of not subdividing the contents of a @code{\\tuplet}
1384 command without explicit @samp{tuplet-span}, use
1386 \\tupletSpan \\default
1390 #{ \set tupletSpannerDuration = #(ly:duration-length tuplet-span) #}
1391 #{ \unset tupletSpannerDuration #}))
1394 #(define-music-function (parser location prop value item)
1395 (symbol-list-or-symbol? scheme? symbol-list-or-music?)
1396 (_i "Add a tweak to the following @var{item}, usually music.
1397 Layout objects created by @var{item} get their property @var{prop}
1398 set to @var{value}. If @var{prop} has the form @samp{Grob.property}, like with
1400 \\tweak Accidental.color #red cis'
1402 an indirectly created grob (@samp{Accidental} is caused by
1403 @samp{NoteHead}) can be tweaked; otherwise only directly created grobs
1406 As a special case, @var{item} may be a symbol list specifying a grob
1407 path, in which case @code{\\once\\override} is called on it instead of
1408 creating tweaked music. This is mainly useful when using
1409 @code{\\tweak} as as a component for building other functions.
1411 @var{prop} can contain additional elements in which case a nested
1412 property (inside of an alist) is tweaked.")
1413 (if (ly:music? item)
1414 (let ((p (check-grob-path prop parser location
1419 (set! (ly:music-property item 'tweaks)
1420 (acons (cond ((pair? (cddr p)) p)
1422 (cons (car p) (cadr p)))
1425 (ly:music-property item 'tweaks))))
1427 ;; We could just throw this at \override and let it sort this
1428 ;; out on its own, but this way we should get better error
1430 (let ((a (check-grob-path item parser location
1431 #:default 'Bottom #:min 2 #:max 2))
1432 (b (check-grob-path prop parser location
1435 #{ \once\override #(append a b) = #value #}
1436 (make-music 'Music)))))
1439 #(define-music-function (parser location music)
1441 (_i "Convert @code{\\override} and @code{\\set} in @var{music} to
1442 @code{\\revert} and @code{\\unset}, respectively. Any reverts and
1443 unsets already in @var{music} cause a warning. Non-property-related music is ignored.")
1450 (lambda (m) (or (music-is-of-type? m 'layout-instruction-event)
1451 (music-is-of-type? m 'context-specification)
1452 (music-is-of-type? m 'apply-context)
1453 (music-is-of-type? m 'time-signature-music)))
1454 (lambda (m overrides)
1455 (case (ly:music-property m 'name)
1458 (make-music 'RevertProperty
1459 'symbol (ly:music-property m 'symbol)
1462 ((ly:music-property m 'grob-property #f) => list)
1464 (ly:music-property m 'grob-property-path))))
1468 (make-music 'PropertyUnset
1469 'symbol (ly:music-property m 'symbol))
1471 ((ContextSpeccedMusic)
1473 (make-music 'ContextSpeccedMusic
1474 'element (loop (ly:music-property m 'element))
1475 'context-type (ly:music-property m 'context-type))
1480 (ly:input-warning location (_ "Cannot revert ~a")
1481 (ly:music-property m 'name))
1487 ((null? lst) (make-music 'Music))
1488 ((null? (cdr lst)) (car lst))
1489 (else (make-sequential-music lst))))))
1492 #(define-music-function (parser location music) (ly:music?)
1493 (_i "Force any @code{\\repeat volta}, @code{\\repeat tremolo} or
1494 @code{\\repeat percent} commands in @var{music} to be interpreted
1495 as @code{\\repeat unfold}.")
1496 (unfold-repeats music))
1499 #(define-void-function (parser location arg) (scheme?)
1500 (_i "Accept a scheme argument, return a void expression.
1501 Use this if you want to have a scheme expression evaluated
1502 because of its side-effects, but its value ignored."))
1505 #(define-music-function (parser location sym val music)
1506 (symbol? scheme? ly:music?)
1507 (_i "Set @var{sym} to @var{val} in @var{music}.")
1509 (set! (ly:music-property music sym) val)