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 name property arg)
90 (string? scheme? list?)
91 (_i "Override @var{property} for pieces of broken spanner @var{name} with
93 (let* ((name (string-delete name char-set:blank)) ; remove any spaces
94 (name-components (string-split name #\.))
95 (context-name "Bottom")
98 (if (> 2 (length name-components))
99 (set! grob-name (car name-components))
101 (set! grob-name (cadr name-components))
102 (set! context-name (car name-components))))
104 ;; only apply override if grob is a spanner
106 (assoc-get (string->symbol grob-name) all-grob-descriptions)))
108 (member 'spanner-interface
109 (assoc-get 'interfaces
110 (assoc-get 'meta description))))
112 \override $context-name . $grob-name $property =
113 #(value-for-spanner-piece arg)
116 (ly:input-warning location (_ "not a spanner name, `~a'") grob-name)
117 (make-music 'SequentialMusic 'void #t))))))
120 #(define-music-function (parser location tag more music)
121 (symbol? ly:music? ly:music?)
122 (_i "Append @var{more} to the @code{elements} of all music
123 expressions in @var{music} that are tagged with @var{tag}.")
124 (music-map (lambda (m)
125 (if (memq tag (ly:music-property m 'tags))
126 (set! (ly:music-property m 'elements)
127 (append (ly:music-property m 'elements)
133 #(define-music-function (parser location proc) (procedure?)
134 (_i "Modify context properties with Scheme procedure @var{proc}.")
135 (make-music 'ApplyContext
139 #(define-music-function (parser location func music) (procedure? ly:music?)
140 (_i"Apply procedure @var{func} to @var{music}.")
144 #(define-music-function (parser location ctx proc) (symbol? procedure?)
145 (_i "Apply function @code{proc} to every layout object in context @code{ctx}")
146 (make-music 'ApplyOutputEvent
151 #(def-grace-function startAppoggiaturaMusic stopAppoggiaturaMusic
152 (_i "Create an appoggiatura from @var{music}"))
154 % for regression testing purposes.
156 #(define-music-function (parser location l r) (pair? pair?)
157 (_i "Testing function: check whether the beam quants @var{l} and @var{r} are correct")
158 (make-grob-property-override 'Beam 'positions (check-quant-callbacks l r)))
160 % for regression testing purposes.
162 #(define-music-function (parser location comp) (procedure?)
163 (_i "Testing function: check whether the slope of the beam is the same as @code{comp}")
164 (make-grob-property-override 'Beam 'positions (check-slope-callbacks comp)))
167 #(define-music-function (parser location music) (ly:music?)
168 (_i "Make voices that switch between staves automatically")
169 (make-autochange-music parser music))
174 #(define-music-function (parser location grob-name offset text)
175 (symbol? number-pair? markup?)
176 (_i "Attach @var{text} to @var{grob-name} at offset @var{offset}
177 (use like @code{\\once})")
178 (make-music 'AnnotateOutputEvent
180 'X-offset (car offset)
181 'Y-offset (cdr offset)
185 #(define-music-function (parser location offset text) (number-pair? markup?)
186 (_i "Attach @var{text} at @var{offset} (use like @code{\\tweak})")
187 (make-music 'AnnotateOutputEvent
188 'X-offset (car offset)
189 'Y-offset (cdr offset)
193 #(define-music-function (parser location type) (string?)
194 (_i "Insert a bar line of type @var{type}")
196 (make-property-set 'whichBar type)
200 #(define-music-function (parser location n) (integer?)
201 (_i "Print a warning if the current bar number is not @var{n}.")
202 (make-music 'ApplyContext
205 (let ((cbn (ly:context-property c 'currentBarNumber)))
206 (if (and (number? cbn) (not (= cbn n)))
207 (ly:input-warning location
208 "Barcheck failed got ~a expect ~a"
212 #(define-event-function (parser location delta) (real?)
213 (_i "Create a fall or doit of pitch interval @var{delta}.")
214 (make-music 'BendAfterEvent
218 #(define-void-function (parser location newfilename) (string?)
219 (_i "Direct output for the current book block to @var{newfilename}.")
220 (set! (paper-variable parser #f 'output-filename) newfilename))
223 #(define-void-function (parser location newsuffix) (string?)
224 (_i "Set the output filename suffix for the current book block to
226 (set! (paper-variable parser #f 'output-suffix) newsuffix))
228 %% \breathe is defined as a music function rather than an event identifier to
229 %% ensure it gets useful input location information: as an event identifier,
230 %% it would have to be wrapped in an EventChord to prevent it from being
231 %% treated as a post_event by the parser
233 #(define-music-function (parser location) ()
234 (_i "Insert a breath mark.")
235 (make-music 'BreathingEvent))
238 #(define-music-function (parser location type) (string?)
239 (_i "Set the current clef to @var{type}.")
240 (make-clef-set type))
244 #(define-music-function (parser location args) (pair?)
245 (_i "Create compound time signatures. The argument is a Scheme list of
246 lists. Each list describes one fraction, with the last entry being the
247 denominator, while the first entries describe the summands in the
248 enumerator. If the time signature consists of just one fraction,
249 the list can be given directly, i.e. not as a list containing a single list.
250 For example, a time signature of (3+1)/8 + 2/4 would be created as
251 @code{\\compoundMeter #'((3 1 8) (2 4))}, and a time signature of (3+2)/8
252 as @code{\\compoundMeter #'((3 2 8))} or shorter
253 @code{\\compoundMeter #'(3 2 8)}.")
254 (let* ((mlen (calculate-compound-measure-length args))
255 (beat (calculate-compound-base-beat args))
256 (beatGrouping (calculate-compound-beat-grouping args))
257 (timesig (cons (ly:moment-main-numerator mlen)
258 (ly:moment-main-denominator mlen))))
260 \once \override Staff.TimeSignature #'stencil = #(lambda (grob)
261 (grob-interpret-markup grob (format-compound-time args)))
262 \set Timing.timeSignatureFraction = $timesig
263 \set Timing.baseMoment = $beat
264 \set Timing.beatStructure = $beatGrouping
265 \set Timing.beamExceptions = #'()
266 \set Timing.measureLength = $mlen
270 #(define-music-function (parser location notes) (ly:music?)
271 (_i "Create cross-staff stems")
273 \override Stem #'cross-staff = #cross-staff-connect
274 \override Flag #'style = #'no-flag
276 \revert Stem #'cross-staff
281 #(define-music-function (parser location type) (string?)
282 (_i "Set the current cue clef to @var{type}.")
283 (make-cue-clef-set type))
286 #(define-music-function (parser location) ()
287 (_i "Unset the current cue clef.")
288 (make-cue-clef-unset))
291 #(define-music-function
292 (parser location what dir main-music) (string? ly:dir? ly:music?)
293 (_i "Insert contents of quote @var{what} corresponding to @var{main-music},
294 in a CueVoice oriented by @var{dir}.")
295 (make-music 'QuoteMusic
297 'quoted-context-type 'Voice
298 'quoted-context-id "cue"
299 'quoted-music-name what
300 'quoted-voice-direction dir))
303 #(define-music-function
304 (parser location what dir clef main-music) (string? ly:dir? string? ly:music?)
305 (_i "Insert contents of quote @var{what} corresponding to @var{main-music},
306 in a CueVoice oriented by @var{dir}.")
307 (make-music 'QuoteMusic
309 'quoted-context-type 'Voice
310 'quoted-context-id "cue"
311 'quoted-music-name what
312 'quoted-music-clef clef
313 'quoted-voice-direction dir))
318 #(define-music-function (parser location music) (ly:music?)
319 (_i "Display the LilyPond input representation of @var{music}
322 (display-lily-music music parser)
326 #(define-music-function (parser location music) (ly:music?)
327 (_i "Display the internal representation of @var{music} to the console.")
329 (display-scheme-music music)
335 #(define-music-function (parser location music) (ly:music?)
336 (_i "Terminate the next spanner prematurely after exactly one note
337 without the need of a specific end spanner.")
338 (let* ((start-span-evs (filter (lambda (ev)
339 (equal? (ly:music-property ev 'span-direction)
341 (extract-typed-music music 'span-event)))
344 (let ((c (music-clone m)))
345 (set! (ly:music-property c 'span-direction) STOP)
348 (end-ev-chord (make-music 'EventChord
349 'elements stop-span-evs))
350 (total (make-music 'SequentialMusic
351 'elements (list music
356 #(define-music-function (parser location music) (ly:music?)
357 (_i "Compatibility function wrapping @code{EventChord} around
358 isolated rhythmic events occuring since version 2.15.28, after
359 expanding repeat chords @samp{q}.")
360 (event-chord-wrap! music parser))
363 #(define-music-function (parser location factor argument) (ly:moment? ly:music?)
364 (_i "Adjust durations of music in @var{argument} by rational @var{factor}.")
365 (let ((orig-duration (ly:music-length argument))
366 (multiplier (ly:make-moment 1 1)))
370 (if (< 0 (ly:moment-main-denominator (ly:music-length mus)))
372 (ly:music-compress mus multiplier)
373 (set! multiplier (ly:moment-mul factor multiplier)))))
374 (extract-named-music argument '(EventChord NoteEvent RestEvent SkipEvent)))
377 (ly:moment-div orig-duration (ly:music-length argument)))
382 #(define-music-function (parser location mark offset grob-name footnote music)
383 ((markup?) number-pair? (symbol?) markup? (ly:music?))
384 (_i "Make the markup @var{footnote} a footnote on @var{music}. The
385 footnote is marked with a markup @var{mark} moved by @var{offset} with
386 respect to the marked music.
388 If @var{mark} is not given or specified as @var{\\default}, it is
389 replaced by an automatically generated sequence number. If a symbol
390 @var{grob-name} is specified, then grobs of that type will be marked
391 if they have @var{music} as their ultimate cause; by default all grobs
392 having @var{music} as their @emph{direct} cause will be marked,
393 similar to the way @code{\\tweak} works.
395 If @var{music} is given as @code{\\default}, a footnote event
396 affecting @emph{all} grobs matching @var{grob-name} at a given time
397 step is generated. This may be required for creating footnotes on
398 time signatures, clefs, and other items not cooperating with
401 Like with @code{\\tweak}, if you use a footnote on a following
402 post-event, the @code{\\footnote} command itself needs to be attached
403 to the preceding note or rest as a post-event with @code{-}.")
404 (let ((mus (make-music
406 'X-offset (car offset)
407 'Y-offset (cdr offset)
408 'automatically-numbered (not mark)
409 'text (or mark (make-null-markup))
410 'footnote-text footnote
411 'symbol (or grob-name '()))))
413 (set! (ly:music-property music 'tweaks)
415 (cons grob-name 'footnote-music)
418 (ly:music-property music 'tweaks)))
422 (ly:input-warning location
423 (_ "\\footnote requires music or grob-name"))
424 (make-music 'Music)))))
427 #(def-grace-function startGraceMusic stopGraceMusic
428 (_i "Insert @var{music} as grace notes."))
431 #(define-scheme-function (parser location descriptions) (list?)
432 (_i "Create a context modification from @var{descriptions}, a list
433 in the format of @code{all-grob-descriptions}.")
436 (list 'assign (car p) (list (cdr p))))
439 harmonicByFret = #(define-music-function (parser location fret music) (number? ly:music?)
440 (_i "Convert @var{music} into mixed harmonics; the resulting notes resemble
441 harmonics played on a fretted instrument by touching the strings at @var{fret}.")
443 \set harmonicDots = ##t
444 \override TabNoteHead #'stencil = #(tab-note-head::print-custom-fret-label (number->string fret))
445 \override NoteHead #'Y-extent = #(ly:make-unpure-pure-container ly:grob::stencil-height
446 (lambda (grob start end)
447 (ly:grob::stencil-height grob)))
448 \override NoteHead #'stencil = #(lambda (grob) (ly:grob-set-property! grob 'style 'harmonic-mixed)
449 (ly:note-head::print grob))
451 (calc-harmonic-pitch (fret->pitch (number->string fret)) music))
453 \revert TabNoteHead #'stencil
454 \revert NoteHead #'Y-extent
455 \revert NoteHead #'stencil
458 harmonicByRatio = #(define-music-function (parser location ratio music) (number? ly:music?)
459 (_i "Convert @var{music} into mixed harmonics; the resulting notes resemble
460 harmonics played on a fretted instrument by touching the strings at the point
461 given through @var{ratio}.")
463 \set harmonicDots = ##t
464 \override TabNoteHead #'stencil = #(tab-note-head::print-custom-fret-label (ratio->fret ratio))
465 \override NoteHead #'Y-extent = #(ly:make-unpure-pure-container ly:grob::stencil-height
466 (lambda (grob start end)
467 (ly:grob::stencil-height grob)))
468 \override NoteHead #'stencil = #(lambda (grob) (ly:grob-set-property! grob 'style 'harmonic-mixed)
469 (ly:note-head::print grob))
471 (calc-harmonic-pitch (ratio->pitch ratio) music))
473 \revert TabNoteHead #'stencil
474 \revert NoteHead #'Y-extent
475 \revert NoteHead #'stencil
479 #(define-music-function (parser location item) (string-or-music?)
480 (_i "Set @var{item}'s @samp{transparent} property to @code{#t},
481 making it invisible while still retaining its dimensions.
483 If @var{item} is a string, the result is an override for the grob name
484 specified by it. If @var{item} is a music expression, the result is
485 the same music expression with an appropriate tweak applied to it.")
487 #{ \override $item #'transparent = ##t #}
488 #{ \tweak #'transparent ##t $item #}))
491 #(define-music-function (parser location) ()
492 (_i "Put the segno variant 'varsegno' at this position into the staff,
493 compatible with the repeat command.")
494 (make-music 'ApplyContext
497 (let ((score-ctx (ly:context-find ctx 'Score)))
498 (if (ly:context? score-ctx)
499 (let ((old-rc (ly:context-property score-ctx 'repeatCommands '())))
500 (if (eq? (memq 'segno-display old-rc) #f)
501 (ly:context-set-property! score-ctx 'repeatCommands (cons 'segno-display old-rc)))))))))
504 #(define-music-function
505 (parser location name) (string?)
506 (_i "Switch instrument to @var{name}, which must be predefined with
507 @code{\\addInstrumentDefinition}.")
508 (let* ((handle (assoc name instrument-definitions))
509 (instrument-def (if handle (cdr handle) '())))
512 (ly:input-warning location "No such instrument: ~a" name))
514 (make-music 'SimultaneousMusic
526 #(define-music-function (parser location tag music) (symbol? ly:music?)
527 (_i "Include only elements of @var{music} that are tagged with @var{tag}.")
530 (let* ((tags (ly:music-property m 'tags))
531 (res (memq tag tags)))
538 #(define-music-function (parser location tonic pitch-alist)
539 ((ly:pitch? '()) (list? '()))
540 (_i "Set key to @var{tonic} and scale @var{pitch-alist}.
541 If both are null, just generate @code{KeyChangeEvent}.")
542 (cond ((null? tonic) (make-music 'KeyChangeEvent))
544 (ly:parser-error parser (_ "second argument must be pitch list")
546 (make-music 'SequentialMusic 'void #t))
549 (make-music 'KeyChangeEvent
550 'tonic (ly:make-pitch 0 0 0)
551 'pitch-alist pitch-alist)
555 #(define-music-function (parser location music) (ly:music?)
556 (_i "Remove cue notes from @var{music}.")
559 (if (and (string? (ly:music-property mus 'quoted-music-name))
560 (string=? (ly:music-property mus 'quoted-context-id "") "cue"))
561 (ly:music-property mus 'element)
568 #(define-music-function (parser location label) (symbol?)
569 (_i "Create @var{label} as a bookmarking label.")
570 (make-music 'EventChord
573 'elements (list (make-music 'LabelEvent
574 'page-label label))))
578 #(define-void-function (parser location language) (string?)
579 (_i "Set note names for language @var{language}.")
580 (note-names-language parser language))
582 languageSaveAndChange =
583 #(define-void-function (parser location language) (string?)
584 (_i "Store the previous pitchnames alist, and set a new one.")
585 (set! previous-pitchnames pitchnames)
586 (note-names-language parser language))
589 #(define-void-function (parser location) ()
590 (_i "Restore a previously-saved pitchnames alist.")
591 (if previous-pitchnames
593 (set! pitchnames previous-pitchnames)
594 (ly:parser-set-note-names parser pitchnames))
595 (ly:input-warning location (_ "No other language was defined previously. Ignoring."))))
599 #(define-music-function (parser location arg) (ly:music?)
600 (_i "Display chords in @var{arg} as clusters.")
601 (music-map note-to-cluster arg))
604 #(define-music-function (parser location around to scale music)
605 (ly:pitch? ly:pitch? ly:music? ly:music?)
606 (_i "Invert @var{music} about @var{around} using @var{scale} and
607 transpose from @var{around} to @var{to}.")
608 (let ((inverter (make-modal-inverter around to scale)))
609 (change-pitches music inverter)
613 #(define-music-function (parser location from to scale music)
614 (ly:pitch? ly:pitch? ly:music? ly:music?)
615 (_i "Transpose @var{music} from pitch @var{from} to pitch @var{to}
617 (let ((transposer (make-modal-transposer from to scale)))
618 (change-pitches music transposer)
622 #(define-music-function
623 (parser location around to music) (ly:pitch? ly:pitch? ly:music?)
624 (_i "Invert @var{music} about @var{around} and
625 transpose from @var{around} to @var{to}.")
626 (music-invert around to music))
629 #(define-music-function
630 (parser location label) ((scheme? '()))
631 "Make the music for the \\mark command."
632 (let* ((set (and (integer? label)
633 (context-spec-music (make-property-set 'rehearsalMark label)
635 (ev (make-music 'MarkEvent
639 (make-sequential-music (list set ev))
641 (set! (ly:music-property ev 'label) label)
645 #(define-music-function (parser location proc mus) (procedure? ly:music?)
646 (_i "Apply @var{proc} to @var{mus} and all of the music it contains.")
647 (music-map proc mus))
649 %% noPageBreak and noPageTurn are music functions (not music indentifiers),
650 %% because music identifiers are not allowed at top-level.
652 #(define-music-function (location parser) ()
653 (_i "Forbid a page break. May be used at toplevel (i.e., between scores or
654 markups), or inside a score.")
655 (make-music 'EventChord
657 'page-break-permission 'forbid
658 'elements (list (make-music 'PageBreakEvent
659 'break-permission '()))))
662 #(define-music-function (location parser) ()
663 (_i "Forbid a page turn. May be used at toplevel (i.e., between scores or
664 markups), or inside a score.")
665 (make-music 'EventChord
667 'page-turn-permission 'forbid
668 'elements (list (make-music 'PageTurnEvent
669 'break-permission '()))))
674 #(define-music-function (parser location pitch) (ly:pitch?)
676 (make-music 'RelativeOctaveCheck
680 #(define-music-function (parser location item) (string-or-music?)
681 (_i "Set @var{item}'s @samp{stencil} property to @code{#f},
682 effectively omitting it without taking up space.
684 If @var{item} is a string, the result is an override for the grob name
685 specified by it. If @var{item} is a music expression, the result is
686 the same music expression with an appropriate tweak applied to it.")
688 #{ \override $item #'stencil = ##f #}
689 #{ \tweak #'stencil ##f $item #}))
692 #(define-music-function (parser location music) (ly:music?)
693 (_i "Set @code{once} to @code{#t} on all layout instruction events in @var{music}.")
696 (cond ((music-is-of-type? m 'layout-instruction-event)
697 (set! (ly:music-property m 'once) #t))
698 ((ly:duration? (ly:music-property m 'duration))
699 (ly:music-warning m (_ "Cannot apply \\once to timed music"))))
704 #(define-music-function (parser location octave) (integer?)
705 (_i "Set the octavation.")
706 (make-music 'OttavaMusic
707 'ottava-number octave))
709 overrideTimeSignatureSettings =
710 #(define-music-function
711 (parser location time-signature base-moment beat-structure beam-exceptions)
712 (pair? pair? cheap-list? cheap-list?)
714 (_i "Override @code{timeSignatureSettings}
715 for time signatures of @var{time-signature} to have settings
716 of @var{base-moment}, @var{beat-structure}, and @var{beam-exceptions}.")
718 ;; TODO -- add warning if largest value of grouping is
719 ;; greater than time-signature.
720 (let ((setting (make-setting base-moment beat-structure beam-exceptions)))
721 (override-time-signature-setting time-signature setting)))
724 #(define-music-function (parser location name property value)
725 (string? symbol? scheme?)
727 (_i "Set @var{property} to @var{value} in all grobs named @var{name}.
728 The @var{name} argument is a string of the form @code{\"Context.GrobName\"}
729 or @code{\"GrobName\"}.")
731 (let ((name-components (string-split name #\.))
732 (context-name 'Bottom)
735 (if (> 2 (length name-components))
736 (set! grob-name (string->symbol (car name-components)))
738 (set! grob-name (string->symbol (list-ref name-components 1)))
739 (set! context-name (string->symbol (list-ref name-components 0)))))
741 (make-music 'ApplyOutputEvent
742 'context-type context-name
744 (lambda (grob orig-context context)
746 (cdr (assoc 'name (ly:grob-property grob 'meta)))
748 (set! (ly:grob-property grob property) value))))))
752 %% pageBreak and pageTurn are music functions (iso music indentifiers),
753 %% because music identifiers are not allowed at top-level.
755 #(define-music-function (location parser) ()
756 (_i "Force a page break. May be used at toplevel (i.e., between scores or
757 markups), or inside a score.")
758 (make-music 'EventChord
760 'line-break-permission 'force
761 'page-break-permission 'force
762 'elements (list (make-music 'LineBreakEvent
763 'break-permission 'force)
764 (make-music 'PageBreakEvent
765 'break-permission 'force))))
768 #(define-music-function (location parser) ()
769 (_i "Force a page turn between two scores or top-level markups.")
770 (make-music 'EventChord
772 'line-break-permission 'force
773 'page-break-permission 'force
774 'page-turn-permission 'force
775 'elements (list (make-music 'LineBreakEvent
776 'break-permission 'force)
777 (make-music 'PageBreakEvent
778 'break-permission 'force)
779 (make-music 'PageTurnEvent
780 'break-permission 'force))))
783 #(define-void-function (parser location voice-ids music) (list? ly:music?)
784 (_i "Define parallel music sequences, separated by '|' (bar check signs),
785 and assign them to the identifiers provided in @var{voice-ids}.
787 @var{voice-ids}: a list of music identifiers (symbols containing only letters)
789 @var{music}: a music sequence, containing BarChecks as limiting expressions.
794 \\parallelMusic #'(A B C) {
804 (let* ((voices (apply circular-list (make-list (length voice-ids) (list))))
805 (current-voices voices)
806 (current-sequence (list))
811 (define (push-music m)
812 "Push the music expression into the current sequence"
813 (set! current-sequence (cons m current-sequence)))
814 (define (change-voice)
815 "Stores the previously built sequence into the current voice and
816 change to the following voice."
817 (list-set! current-voices 0 (cons (make-music 'SequentialMusic
818 'elements (reverse! current-sequence))
819 (car current-voices)))
820 (set! current-sequence (list))
821 (set! current-voices (cdr current-voices)))
822 (define (bar-check? m)
823 "Checks whether m is a bar check."
824 (eq? (ly:music-property m 'name) 'BarCheck))
825 (define (music-origin music)
826 "Recursively search an origin location stored in music."
827 (cond ((null? music) #f)
828 ((not (null? (ly:music-property music 'origin)))
829 (ly:music-property music 'origin))
830 (else (or (music-origin (ly:music-property music 'element))
831 (let ((origins (remove not (map music-origin
832 (ly:music-property music 'elements)))))
833 (and (not (null? origins)) (car origins)))))))
834 (while (music-is-of-type? music 'music-wrapper-music)
836 (set! music (ly:music-property wrapper 'element)))
838 (set! (ly:music-property wrapper 'element)
839 (make-music 'SequentialMusic
842 (make-music 'SequentialMusic
845 ;; first, split the music and fill in voices
846 ;; We flatten direct layers of SequentialMusic since they are
847 ;; pretty much impossible to avoid when writing music functions.
848 (let rec ((music music))
849 (for-each (lambda (m)
850 (if (eq? (ly:music-property m 'name) 'SequentialMusic)
854 (if (bar-check? m) (change-voice)))))
855 (ly:music-property music 'elements)))
856 (if (not (null? current-sequence)) (change-voice))
857 ;; un-circularize `voices' and reorder the voices
858 (set! voices (map-in-order (lambda (dummy seqs)
862 ;; set origin location of each sequence in each voice
863 ;; for better type error tracking
864 (for-each (lambda (voice)
865 (for-each (lambda (seq)
866 (set! (ly:music-property seq 'origin)
867 (or (music-origin seq) location)))
871 ;; check sequence length
872 (apply for-each (lambda* (#:rest seqs)
873 (let ((moment-reference (ly:music-length (car seqs))))
874 (for-each (lambda (seq moment)
875 (if (not (equal? moment moment-reference))
876 (ly:music-warning seq
877 "Bars in parallel music don't have the same length")))
878 seqs (map-in-order ly:music-length seqs))))
881 ;; bind voice identifiers to the voices
882 (for-each (lambda (voice-id voice)
883 (ly:parser-define! parser voice-id
884 (let ((v (ly:music-deep-copy original)))
885 (set! (ly:music-property
886 (car (extract-named-music
893 #(define-music-function (parser loc arg) (ly:music?)
894 (_i "Tag @var{arg} to be parenthesized.")
896 (if (memq 'event-chord (ly:music-property arg 'types))
897 ;; arg is an EventChord -> set the parenthesize property
898 ;; on all child notes and rests
901 (if (or (memq 'note-event (ly:music-property ev 'types))
902 (memq 'rest-event (ly:music-property ev 'types)))
903 (set! (ly:music-property ev 'parenthesize) #t)))
904 (ly:music-property arg 'elements))
905 ;; No chord, simply set property for this expression:
906 (set! (ly:music-property arg 'parenthesize) #t))
910 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
911 (_i "Take the music in @var{part1} and @var{part2} and typeset so
912 that they share a staff.")
913 (make-part-combine-music parser
914 (list part1 part2) #f))
917 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
918 (_i "Take the music in @var{part1} and @var{part2} and typeset so
919 that they share a staff with stems directed upward.")
920 (make-part-combine-music parser
921 (list part1 part2) UP))
924 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
925 (_i "Take the music in @var{part1} and @var{part2} and typeset so
926 that they share a staff with stems directed downward.")
927 (make-part-combine-music parser
928 (list part1 part2) DOWN))
931 #(define-music-function (location parser type once) (symbol-or-boolean? boolean?)
932 (_i "Override the part-combiner.")
933 (make-music 'EventChord
934 'elements (list (make-music 'PartCombineForceEvent
937 partcombineApart = \partcombineForce #'apart ##f
938 partcombineApartOnce = \partcombineForce #'apart ##t
939 partcombineChords = \partcombineForce #'chords ##f
940 partcombineChordsOnce = \partcombineForce #'chords ##t
941 partcombineUnisono = \partcombineForce #'unisono ##f
942 partcombineUnisonoOnce = \partcombineForce #'unisono ##t
943 partcombineSoloI = \partcombineForce #'solo1 ##f
944 partcombineSoloIOnce = \partcombineForce #'solo1 ##t
945 partcombineSoloII = \partcombineForce #'solo2 ##f
946 partcombineSoloIIOnce = \partcombineForce #'solo2 ##t
947 partcombineAutomatic = \partcombineForce ##f ##f
948 partcombineAutomaticOnce = \partcombineForce ##f ##t
951 #(define-music-function (parser location dur) (ly:duration?)
952 (_i "Make a partial measure.")
954 ;; We use `descend-to-context' here instead of `context-spec-music' to
955 ;; ensure \partial still works if the Timing_translator is moved
957 (context-spec-music (make-music 'PartialSet
959 'partial-duration dur)
964 #(define-music-function
965 (parser location main-note secondary-note)
966 (ly:music? ly:music?)
967 (_i "Print a trill with @var{main-note} as the main note of the trill and
968 print @var{secondary-note} as a stemless note head in parentheses.")
969 (let* ((get-notes (lambda (ev-chord)
970 (extract-named-music ev-chord 'NoteEvent)))
971 (sec-note-events (get-notes secondary-note))
972 (trill-events (extract-named-music main-note 'TrillSpanEvent)))
973 (if (pair? sec-note-events)
975 (let* ((trill-pitch (ly:music-property (car sec-note-events) 'pitch))
976 (forced (ly:music-property (car sec-note-events) 'force-accidental)))
978 (if (ly:pitch? trill-pitch)
979 (for-each (lambda (m)
980 (ly:music-set-property! m 'pitch trill-pitch)) trill-events)
982 (ly:input-warning location (_ "Second argument of \\pitchedTrill should be single note: "))
983 (display sec-note-events)))
986 (for-each (lambda (m)
987 (ly:music-set-property! m 'force-accidental forced))
992 #(define-music-function (parser location tag more music)
993 (symbol? ly:music? ly:music?)
994 (_i "Add @var{more} to the front of @code{elements} of all music
995 expressions in @var{music} that are tagged with @var{tag}.")
996 (music-map (lambda (m)
997 (if (memq tag (ly:music-property m 'tags))
998 (set! (ly:music-property m 'elements)
999 (cons more (ly:music-property m 'elements))))
1004 #(define-music-function (parser location what main-music) (string? ly:music?)
1005 (_i "Indicate a section of music to be quoted. @var{what} indicates the name
1006 of the quoted voice, as specified in an @code{\\addQuote} command.
1007 @var{main-music} is used to indicate the length of music to be quoted;
1008 usually contains spacers or multi-measure rests.")
1009 (make-music 'QuoteMusic
1011 'quoted-music-name what))
1014 #(define-music-function (parser location pitch music)
1015 ((ly:pitch? (ly:make-pitch 0 0 0)) ly:music?)
1016 (_i "Make @var{music} relative to @var{pitch} (default @code{c'}).")
1017 (ly:make-music-relative! music pitch)
1018 (make-music 'RelativeOctaveMusic
1022 #(define-music-function (parser location tag music) (symbol? ly:music?)
1023 (_i "Remove elements of @var{music} that are tagged with @var{tag}.")
1026 (let* ((tags (ly:music-property m 'tags))
1027 (res (memq tag tags)))
1031 resetRelativeOctave =
1032 #(define-music-function (parser location pitch) (ly:pitch?)
1033 (_i "Set the octave inside a \\relative section.")
1035 (make-music 'SequentialMusic
1036 'to-relative-callback
1037 (lambda (music last-pitch) pitch)))
1040 #(define-music-function (parser location music)
1042 (_i "Return @var{music} in reverse order.")
1043 (retrograde-music music))
1045 revertTimeSignatureSettings =
1046 #(define-music-function
1047 (parser location time-signature)
1050 (_i "Revert @code{timeSignatureSettings}
1051 for time signatures of @var{time-signature}.")
1052 (revert-time-signature-setting time-signature))
1055 #(define-event-function (parser location finger) (number-or-string?)
1056 (_i "Apply @var{finger} as a fingering indication.")
1061 (if (string? finger) 'text 'digit)
1065 #(define-music-function (parser location fraction music)
1066 (fraction? ly:music?)
1067 (_i "Multiply the duration of events in @var{music} by @var{fraction}.")
1068 (ly:music-compress music
1069 (ly:make-moment (car fraction) (cdr fraction))))
1072 #(define-scheme-function (parser location ctx music)
1073 ((symbol?) ly:music?)
1074 (_i "Take the layout instruction events from @var{music}, optionally
1075 restricted to those applying to context type @var{ctx}, and return
1076 a context modification duplicating their effect.")
1077 (let ((mods (ly:make-context-mod)))
1079 (if (music-is-of-type? m 'layout-instruction-event)
1082 (case (ly:music-property m 'name)
1085 (ly:music-property m 'symbol)
1086 (ly:music-property m 'value)))
1089 (ly:music-property m 'symbol)))
1092 (ly:music-property m 'symbol)
1093 (ly:music-property m 'grob-value)
1095 ((ly:music-property m 'grob-property #f) => list)
1097 (ly:music-property m 'grob-property-path)))))
1100 (ly:music-property m 'symbol)
1102 ((ly:music-property m 'grob-property #f) => list)
1104 (ly:music-property m 'grob-property-path)))))))
1105 (case (ly:music-property m 'name)
1107 (ly:add-context-mod mods
1109 (ly:music-property m 'procedure))))
1110 ((ContextSpeccedMusic)
1112 (eq? ctx (ly:music-property m 'context-type)))
1113 (musicop (ly:music-property m 'element))))
1115 (let ((callback (ly:music-property m 'elements-callback)))
1116 (if (procedure? callback)
1117 (for-each musicop (callback m))))))))
1122 #(define-music-function (parser location grob offsets)
1124 (_i "Offset control-points of @var{grob} by @var{offsets}. The argument
1125 is a list of number pairs or list of such lists. Each element of a pair
1126 represents an offset to one of the coordinates of a control-point.")
1127 (define ((shape-curve offsets) grob)
1128 (let* ((orig (ly:grob-original grob))
1129 (siblings (if (ly:spanner? grob)
1130 (ly:spanner-broken-into orig) '()))
1131 (total-found (length siblings))
1132 (function (assoc-get 'control-points
1133 (reverse (ly:grob-basic-properties grob))))
1134 (coords (function grob)))
1136 (define (offset-control-points offsets)
1140 (lambda (x y) (coord-translate x y))
1143 (define (helper sibs offs)
1145 (if (eq? (car sibs) grob)
1146 (offset-control-points (car offs))
1147 (helper (cdr sibs) (cdr offs)))
1150 ;; we work with lists of lists
1151 (if (or (null? offsets)
1152 (not (list? (car offsets))))
1153 (set! offsets (list offsets)))
1155 (if (>= total-found 2)
1156 (helper siblings offsets)
1157 (offset-control-points (car offsets)))))
1160 \once \override $grob #'control-points = #(shape-curve offsets)
1164 #(define-music-function (parser location dur dots arg)
1165 (integer? integer? ly:music?)
1166 (_i "Change the duration of @var{arg} by adding @var{dur} to the
1167 @code{durlog} of @var{arg} and @var{dots} to the @code{dots} of @var{arg}.")
1171 (shift-one-duration-log x dur dots)) arg))
1174 #(define-music-function (parser location overrides music)
1175 (ly:music? ly:music?)
1176 (_i "Convert @var{overrides} to tweaks and apply them to @var{music}.
1177 This does not convert @code{\\revert}, @code{\\set} or @code{\\unset}
1178 and ignores nested overrides.")
1179 (set! (ly:music-property music 'tweaks)
1181 (lambda (m) (eq? (ly:music-property m 'name)
1185 ((ly:music-property m 'grob-property #f) => list)
1187 (ly:music-property m 'grob-property-path)))))
1189 tweaks ;ignore nested properties
1190 (acons (cons (ly:music-property m 'symbol) ;grob name
1191 (car p)) ;grob property
1192 (ly:music-property m 'grob-value)
1194 (ly:music-property music 'tweaks)
1199 #(define-music-function (parser location dur) (ly:duration?)
1200 (_i "Skip forward by @var{dur}.")
1201 (make-music 'SkipMusic
1206 #(def-grace-function startSlashedGraceMusic stopSlashedGraceMusic
1207 (_i "Create slashed graces (slashes through stems, but no slur) from
1208 the following music expression"))
1211 #(define-music-function (parser location parameters) (list?)
1212 (_i "Set the system stretch, by reading the 'system-stretch property of
1213 the `parameters' assoc list.")
1215 \overrideProperty #"Score.NonMusicalPaperColumn"
1216 #'line-break-system-details
1217 #(list (cons 'alignment-extra-space (cdr (assoc 'system-stretch parameters)))
1218 (cons 'system-Y-extent (cdr (assoc 'system-Y-extent parameters))))
1222 #(define-music-function (parser location style heads music)
1223 (symbol? list-or-symbol? ly:music?)
1224 (_i "Set @var{heads} in @var{music} to @var{style}.")
1225 (style-note-heads heads style music))
1228 #(define-music-function (parser location tag arg) (symbol? ly:music?)
1230 (_i "Add @var{tag} to the @code{tags} property of @var{arg}.")
1233 (ly:music-property arg 'tags)
1235 (ly:music-property arg 'tags)))
1239 #(define-music-function (parser location beat-structure fraction)
1240 ((number-list? '()) fraction?)
1241 (_i "Set @var{fraction} as time signature, with optional
1242 number list @var{beat-structure} before it.")
1243 (make-music 'TimeSignatureMusic
1244 'numerator (car fraction)
1245 'denominator (cdr fraction)
1246 'beat-structure beat-structure))
1249 #(define-music-function (parser location fraction music)
1250 (fraction? ly:music?)
1251 (_i "Scale @var{music} in time by @var{fraction}.")
1252 (make-music 'TimeScaledMusic
1253 'element (ly:music-compress music (ly:make-moment (car fraction) (cdr fraction)))
1254 'numerator (car fraction)
1255 'denominator (cdr fraction)))
1258 #(define-music-function
1259 (parser location from to music)
1260 (ly:pitch? ly:pitch? ly:music?)
1262 (_i "Transpose @var{music} from pitch @var{from} to pitch @var{to}.")
1263 (make-music 'TransposedMusic
1264 'element (ly:music-transpose music (ly:pitch-diff to from))))
1266 transposedCueDuring =
1267 #(define-music-function
1268 (parser location what dir pitch main-music)
1269 (string? ly:dir? ly:pitch? ly:music?)
1271 (_i "Insert notes from the part @var{what} into a voice called @code{cue},
1272 using the transposition defined by @var{pitch}. This happens
1273 simultaneously with @var{main-music}, which is usually a rest. The
1274 argument @var{dir} determines whether the cue notes should be notated
1275 as a first or second voice.")
1277 (make-music 'QuoteMusic
1279 'quoted-context-type 'Voice
1280 'quoted-context-id "cue"
1281 'quoted-music-name what
1282 'quoted-voice-direction dir
1283 'quoted-transposition pitch))
1286 #(define-music-function (parser location pitch) (ly:pitch?)
1287 (_i "Set instrument transposition")
1290 (make-property-set 'instrumentTransposition
1291 (ly:pitch-negate pitch))
1295 #(define-music-function (parser location grob prop value music)
1296 ((string?) symbol? scheme? ly:music?)
1297 (_i "Add a tweak to the following @var{music}.
1298 Layout objects created by @var{music} get their property @var{prop}
1299 set to @var{value}. If @var{grob} is specified, like with
1301 \\tweak Accidental #'color #red cis'
1303 an indirectly created grob (@samp{Accidental} is caused by
1304 @samp{NoteHead}) can be tweaked; otherwise only directly created grobs
1306 (if (not (object-property prop 'backend-type?))
1308 (ly:input-warning location (_ "cannot find property type-check for ~a") prop)
1309 (ly:warning (_ "doing assignment anyway"))))
1311 (ly:music-property music 'tweaks)
1312 (acons (if grob (cons (string->symbol grob) prop) prop)
1314 (ly:music-property music 'tweaks)))
1318 #(define-music-function (parser location music) (ly:music?)
1319 (_i "Force any @code{\\repeat volta}, @code{\\repeat tremolo} or
1320 @code{\\repeat percent} commands in @var{music} to be interpreted
1321 as @code{\\repeat unfold}.")
1322 (unfold-repeats music))
1325 #(define-void-function (parser location arg) (scheme?)
1326 (_i "Accept a scheme argument, return a void expression.
1327 Use this if you want to have a scheme expression evaluated
1328 because of its side-effects, but its value ignored."))
1331 #(define-music-function (parser location sym val music)
1332 (symbol? scheme? ly:music?)
1333 (_i "Set @var{sym} to @var{val} in @var{music}.")
1335 (set! (ly:music-property music sym) val)