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 (symbol-list? symbol? list?)
91 (_i "Override @var{property} for pieces of broken spanner @var{name} with
93 ;; only apply override if grob is a spanner
95 (assoc-get (last name) all-grob-descriptions)))
97 (member 'spanner-interface
98 (assoc-get 'interfaces
99 (assoc-get 'meta description))))
101 \override $name $property =
102 #(value-for-spanner-piece arg)
105 (ly:input-warning location (_ "not a spanner name, `~a'") name)
106 (make-music 'SequentialMusic 'void #t)))))
109 #(define-music-function (parser location tag more music)
110 (symbol? ly:music? ly:music?)
111 (_i "Append @var{more} to the @code{elements} of all music
112 expressions in @var{music} that are tagged with @var{tag}.")
113 (music-map (lambda (m)
114 (if (memq tag (ly:music-property m 'tags))
115 (set! (ly:music-property m 'elements)
116 (append (ly:music-property m 'elements)
122 #(define-music-function (parser location proc) (procedure?)
123 (_i "Modify context properties with Scheme procedure @var{proc}.")
124 (make-music 'ApplyContext
128 #(define-music-function (parser location func music) (procedure? ly:music?)
129 (_i"Apply procedure @var{func} to @var{music}.")
133 #(define-music-function (parser location ctx proc) (symbol? procedure?)
134 (_i "Apply function @code{proc} to every layout object in context @code{ctx}")
135 (make-music 'ApplyOutputEvent
140 #(def-grace-function startAppoggiaturaMusic stopAppoggiaturaMusic
141 (_i "Create an appoggiatura from @var{music}"))
143 % for regression testing purposes.
145 #(define-music-function (parser location l r) (pair? pair?)
146 (_i "Testing function: check whether the beam quants @var{l} and @var{r} are correct")
147 (make-grob-property-override 'Beam 'positions (check-quant-callbacks l r)))
149 % for regression testing purposes.
151 #(define-music-function (parser location comp) (procedure?)
152 (_i "Testing function: check whether the slope of the beam is the same as @code{comp}")
153 (make-grob-property-override 'Beam 'positions (check-slope-callbacks comp)))
156 #(define-music-function (parser location music) (ly:music?)
157 (_i "Make voices that switch between staves automatically")
158 (make-autochange-music parser music))
163 #(define-music-function (parser location grob-name offset text)
164 (symbol? number-pair? markup?)
165 (_i "Attach @var{text} to @var{grob-name} at offset @var{offset}
166 (use like @code{\\once})")
167 (make-music 'AnnotateOutputEvent
169 'X-offset (car offset)
170 'Y-offset (cdr offset)
174 #(define-music-function (parser location offset text) (number-pair? markup?)
175 (_i "Attach @var{text} at @var{offset} (use like @code{\\tweak})")
176 (make-music 'AnnotateOutputEvent
177 'X-offset (car offset)
178 'Y-offset (cdr offset)
182 #(define-music-function (parser location type) (string?)
183 (_i "Insert a bar line of type @var{type}")
185 (make-property-set 'whichBar type)
189 #(define-music-function (parser location n) (integer?)
190 (_i "Print a warning if the current bar number is not @var{n}.")
191 (make-music 'ApplyContext
194 (let ((cbn (ly:context-property c 'currentBarNumber)))
195 (if (and (number? cbn) (not (= cbn n)))
196 (ly:input-warning location
197 "Barcheck failed got ~a expect ~a"
201 #(define-event-function (parser location delta) (real?)
202 (_i "Create a fall or doit of pitch interval @var{delta}.")
203 (make-music 'BendAfterEvent
207 #(define-void-function (parser location newfilename) (string?)
208 (_i "Direct output for the current book block to @var{newfilename}.")
209 (set! (paper-variable parser #f 'output-filename) newfilename))
212 #(define-void-function (parser location newsuffix) (string?)
213 (_i "Set the output filename suffix for the current book block to
215 (set! (paper-variable parser #f 'output-suffix) newsuffix))
217 %% \breathe is defined as a music function rather than an event identifier to
218 %% ensure it gets useful input location information: as an event identifier,
219 %% it would have to be wrapped in an EventChord to prevent it from being
220 %% treated as a post_event by the parser
222 #(define-music-function (parser location) ()
223 (_i "Insert a breath mark.")
224 (make-music 'BreathingEvent))
227 #(define-music-function (parser location type) (string?)
228 (_i "Set the current clef to @var{type}.")
229 (make-clef-set type))
233 #(define-music-function (parser location args) (pair?)
234 (_i "Create compound time signatures. The argument is a Scheme list of
235 lists. Each list describes one fraction, with the last entry being the
236 denominator, while the first entries describe the summands in the
237 enumerator. If the time signature consists of just one fraction,
238 the list can be given directly, i.e. not as a list containing a single list.
239 For example, a time signature of (3+1)/8 + 2/4 would be created as
240 @code{\\compoundMeter #'((3 1 8) (2 4))}, and a time signature of (3+2)/8
241 as @code{\\compoundMeter #'((3 2 8))} or shorter
242 @code{\\compoundMeter #'(3 2 8)}.")
243 (let* ((mlen (calculate-compound-measure-length args))
244 (beat (calculate-compound-base-beat args))
245 (beatGrouping (calculate-compound-beat-grouping args))
246 (timesig (cons (ly:moment-main-numerator mlen)
247 (ly:moment-main-denominator mlen))))
249 \once \override Staff.TimeSignature #'stencil = #(lambda (grob)
250 (grob-interpret-markup grob (format-compound-time args)))
251 \set Timing.timeSignatureFraction = $timesig
252 \set Timing.baseMoment = $beat
253 \set Timing.beatStructure = $beatGrouping
254 \set Timing.beamExceptions = #'()
255 \set Timing.measureLength = $mlen
259 #(define-music-function (parser location notes) (ly:music?)
260 (_i "Create cross-staff stems")
262 \override Stem #'cross-staff = #cross-staff-connect
263 \override Flag #'style = #'no-flag
265 \revert Stem #'cross-staff
270 #(define-music-function (parser location type) (string?)
271 (_i "Set the current cue clef to @var{type}.")
272 (make-cue-clef-set type))
275 #(define-music-function (parser location) ()
276 (_i "Unset the current cue clef.")
277 (make-cue-clef-unset))
280 #(define-music-function
281 (parser location what dir main-music) (string? ly:dir? ly:music?)
282 (_i "Insert contents of quote @var{what} corresponding to @var{main-music},
283 in a CueVoice oriented by @var{dir}.")
284 (make-music 'QuoteMusic
286 'quoted-context-type 'Voice
287 'quoted-context-id "cue"
288 'quoted-music-name what
289 'quoted-voice-direction dir))
292 #(define-music-function
293 (parser location what dir clef main-music) (string? ly:dir? string? ly:music?)
294 (_i "Insert contents of quote @var{what} corresponding to @var{main-music},
295 in a CueVoice oriented by @var{dir}.")
296 (make-music 'QuoteMusic
298 'quoted-context-type 'Voice
299 'quoted-context-id "cue"
300 'quoted-music-name what
301 'quoted-music-clef clef
302 'quoted-voice-direction dir))
307 #(define-music-function (parser location music) (ly:music?)
308 (_i "Display the LilyPond input representation of @var{music}
311 (display-lily-music music parser)
315 #(define-music-function (parser location music) (ly:music?)
316 (_i "Display the internal representation of @var{music} to the console.")
318 (display-scheme-music music)
324 #(define-music-function (parser location music) (ly:music?)
325 (_i "Terminate the next spanner prematurely after exactly one note
326 without the need of a specific end spanner.")
327 (let* ((start-span-evs (filter (lambda (ev)
328 (equal? (ly:music-property ev 'span-direction)
330 (extract-typed-music music 'span-event)))
333 (let ((c (music-clone m)))
334 (set! (ly:music-property c 'span-direction) STOP)
337 (end-ev-chord (make-music 'EventChord
338 'elements stop-span-evs))
339 (total (make-music 'SequentialMusic
340 'elements (list music
345 #(define-music-function (parser location music) (ly:music?)
346 (_i "Compatibility function wrapping @code{EventChord} around
347 isolated rhythmic events occuring since version 2.15.28, after
348 expanding repeat chords @samp{q}.")
349 (event-chord-wrap! music parser))
352 #(define-music-function (parser location factor argument) (ly:moment? ly:music?)
353 (_i "Adjust durations of music in @var{argument} by rational @var{factor}.")
354 (let ((orig-duration (ly:music-length argument))
355 (multiplier (ly:make-moment 1 1)))
359 (if (< 0 (ly:moment-main-denominator (ly:music-length mus)))
361 (ly:music-compress mus multiplier)
362 (set! multiplier (ly:moment-mul factor multiplier)))))
363 (extract-named-music argument '(EventChord NoteEvent RestEvent SkipEvent)))
366 (ly:moment-div orig-duration (ly:music-length argument)))
371 #(define-music-function (parser location mark offset grob-name footnote music)
372 ((markup?) number-pair? (symbol?) markup? (ly:music?))
373 (_i "Make the markup @var{footnote} a footnote on @var{music}. The
374 footnote is marked with a markup @var{mark} moved by @var{offset} with
375 respect to the marked music.
377 If @var{mark} is not given or specified as @var{\\default}, it is
378 replaced by an automatically generated sequence number. If a symbol
379 @var{grob-name} is specified, then grobs of that type will be marked
380 if they have @var{music} as their ultimate cause; by default all grobs
381 having @var{music} as their @emph{direct} cause will be marked,
382 similar to the way @code{\\tweak} works.
384 If @var{music} is given as @code{\\default}, a footnote event
385 affecting @emph{all} grobs matching @var{grob-name} at a given time
386 step is generated. This may be required for creating footnotes on
387 time signatures, clefs, and other items not cooperating with
390 Like with @code{\\tweak}, if you use a footnote on a following
391 post-event, the @code{\\footnote} command itself needs to be attached
392 to the preceding note or rest as a post-event with @code{-}.")
393 (let ((mus (make-music
395 'X-offset (car offset)
396 'Y-offset (cdr offset)
397 'automatically-numbered (not mark)
398 'text (or mark (make-null-markup))
399 'footnote-text footnote
400 'symbol (or grob-name '()))))
402 (set! (ly:music-property music 'tweaks)
404 (cons grob-name 'footnote-music)
407 (ly:music-property music 'tweaks)))
411 (ly:input-warning location
412 (_ "\\footnote requires music or grob-name"))
413 (make-music 'Music)))))
416 #(def-grace-function startGraceMusic stopGraceMusic
417 (_i "Insert @var{music} as grace notes."))
420 #(define-scheme-function (parser location descriptions) (list?)
421 (_i "Create a context modification from @var{descriptions}, a list
422 in the format of @code{all-grob-descriptions}.")
425 (list 'assign (car p) (list (cdr p))))
428 harmonicByFret = #(define-music-function (parser location fret music) (number? ly:music?)
429 (_i "Convert @var{music} into mixed harmonics; the resulting notes resemble
430 harmonics played on a fretted instrument by touching the strings at @var{fret}.")
432 \set harmonicDots = ##t
433 \override TabNoteHead #'stencil = #(tab-note-head::print-custom-fret-label (number->string fret))
434 \override NoteHead #'Y-extent = #(ly:make-unpure-pure-container ly:grob::stencil-height
435 (lambda (grob start end)
436 (ly:grob::stencil-height grob)))
437 \override NoteHead #'stencil = #(lambda (grob) (ly:grob-set-property! grob 'style 'harmonic-mixed)
438 (ly:note-head::print grob))
440 (calc-harmonic-pitch (fret->pitch (number->string fret)) music))
442 \revert TabNoteHead #'stencil
443 \revert NoteHead #'Y-extent
444 \revert NoteHead #'stencil
447 harmonicByRatio = #(define-music-function (parser location ratio music) (number? ly:music?)
448 (_i "Convert @var{music} into mixed harmonics; the resulting notes resemble
449 harmonics played on a fretted instrument by touching the strings at the point
450 given through @var{ratio}.")
452 \set harmonicDots = ##t
453 \override TabNoteHead #'stencil = #(tab-note-head::print-custom-fret-label (ratio->fret ratio))
454 \override NoteHead #'Y-extent = #(ly:make-unpure-pure-container ly:grob::stencil-height
455 (lambda (grob start end)
456 (ly:grob::stencil-height grob)))
457 \override NoteHead #'stencil = #(lambda (grob) (ly:grob-set-property! grob 'style 'harmonic-mixed)
458 (ly:note-head::print grob))
460 (calc-harmonic-pitch (ratio->pitch ratio) music))
462 \revert TabNoteHead #'stencil
463 \revert NoteHead #'Y-extent
464 \revert NoteHead #'stencil
468 #(define-music-function (parser location item) (symbol-list-or-music?)
469 (_i "Set @var{item}'s @samp{transparent} property to @code{#t},
470 making it invisible while still retaining its dimensions.
472 If @var{item} is a symbol list of form @code{GrobName} or
473 @code{Context.GrobName}, the result is an override for the grob name
474 specified by it. If @var{item} is a music expression, the result is
475 the same music expression with an appropriate tweak applied to it.")
477 #{ \tweak #'transparent ##t $item #}
478 #{ \override $item #'transparent = ##t #}))
481 #(define-music-function (parser location) ()
482 (_i "Put the segno variant 'varsegno' at this position into the staff,
483 compatible with the repeat command.")
484 (make-music 'ApplyContext
487 (let ((score-ctx (ly:context-find ctx 'Score)))
488 (if (ly:context? score-ctx)
489 (let ((old-rc (ly:context-property score-ctx 'repeatCommands '())))
490 (if (eq? (memq 'segno-display old-rc) #f)
491 (ly:context-set-property! score-ctx 'repeatCommands (cons 'segno-display old-rc)))))))))
494 #(define-music-function
495 (parser location name) (string?)
496 (_i "Switch instrument to @var{name}, which must be predefined with
497 @code{\\addInstrumentDefinition}.")
498 (let* ((handle (assoc name instrument-definitions))
499 (instrument-def (if handle (cdr handle) '())))
502 (ly:input-warning location "No such instrument: ~a" name))
504 (make-music 'SimultaneousMusic
516 #(define-music-function (parser location tag music) (symbol? ly:music?)
517 (_i "Include only elements of @var{music} that are tagged with @var{tag}.")
520 (let* ((tags (ly:music-property m 'tags))
521 (res (memq tag tags)))
528 #(define-music-function (parser location tonic pitch-alist)
529 ((ly:pitch? '()) (list? '()))
530 (_i "Set key to @var{tonic} and scale @var{pitch-alist}.
531 If both are null, just generate @code{KeyChangeEvent}.")
532 (cond ((null? tonic) (make-music 'KeyChangeEvent))
534 (ly:parser-error parser (_ "second argument must be pitch list")
536 (make-music 'SequentialMusic 'void #t))
539 (make-music 'KeyChangeEvent
540 'tonic (ly:make-pitch 0 0 0)
541 'pitch-alist pitch-alist)
545 #(define-music-function (parser location music) (ly:music?)
546 (_i "Remove cue notes from @var{music}.")
549 (if (and (string? (ly:music-property mus 'quoted-music-name))
550 (string=? (ly:music-property mus 'quoted-context-id "") "cue"))
551 (ly:music-property mus 'element)
558 #(define-music-function (parser location label) (symbol?)
559 (_i "Create @var{label} as a bookmarking label.")
560 (make-music 'EventChord
563 'elements (list (make-music 'LabelEvent
564 'page-label label))))
568 #(define-void-function (parser location language) (string?)
569 (_i "Set note names for language @var{language}.")
570 (note-names-language parser language))
572 languageSaveAndChange =
573 #(define-void-function (parser location language) (string?)
574 (_i "Store the previous pitchnames alist, and set a new one.")
575 (set! previous-pitchnames pitchnames)
576 (note-names-language parser language))
579 #(define-void-function (parser location) ()
580 (_i "Restore a previously-saved pitchnames alist.")
581 (if previous-pitchnames
583 (set! pitchnames previous-pitchnames)
584 (ly:parser-set-note-names parser pitchnames))
585 (ly:input-warning location (_ "No other language was defined previously. Ignoring."))))
589 #(define-music-function (parser location arg) (ly:music?)
590 (_i "Display chords in @var{arg} as clusters.")
591 (music-map note-to-cluster arg))
594 #(define-music-function (parser location around to scale music)
595 (ly:pitch? ly:pitch? ly:music? ly:music?)
596 (_i "Invert @var{music} about @var{around} using @var{scale} and
597 transpose from @var{around} to @var{to}.")
598 (let ((inverter (make-modal-inverter around to scale)))
599 (change-pitches music inverter)
603 #(define-music-function (parser location from to scale music)
604 (ly:pitch? ly:pitch? ly:music? ly:music?)
605 (_i "Transpose @var{music} from pitch @var{from} to pitch @var{to}
607 (let ((transposer (make-modal-transposer from to scale)))
608 (change-pitches music transposer)
612 #(define-music-function
613 (parser location around to music) (ly:pitch? ly:pitch? ly:music?)
614 (_i "Invert @var{music} about @var{around} and
615 transpose from @var{around} to @var{to}.")
616 (music-invert around to music))
619 #(define-music-function
620 (parser location label) ((scheme? '()))
621 "Make the music for the \\mark command."
622 (let* ((set (and (integer? label)
623 (context-spec-music (make-property-set 'rehearsalMark label)
625 (ev (make-music 'MarkEvent
629 (make-sequential-music (list set ev))
631 (set! (ly:music-property ev 'label) label)
635 #(define-music-function (parser location proc mus) (procedure? ly:music?)
636 (_i "Apply @var{proc} to @var{mus} and all of the music it contains.")
637 (music-map proc mus))
639 %% noPageBreak and noPageTurn are music functions (not music indentifiers),
640 %% because music identifiers are not allowed at top-level.
642 #(define-music-function (location parser) ()
643 (_i "Forbid a page break. May be used at toplevel (i.e., between scores or
644 markups), or inside a score.")
645 (make-music 'EventChord
647 'page-break-permission 'forbid
648 'elements (list (make-music 'PageBreakEvent
649 'break-permission '()))))
652 #(define-music-function (location parser) ()
653 (_i "Forbid a page turn. May be used at toplevel (i.e., between scores or
654 markups), or inside a score.")
655 (make-music 'EventChord
657 'page-turn-permission 'forbid
658 'elements (list (make-music 'PageTurnEvent
659 'break-permission '()))))
664 #(define-music-function (parser location pitch) (ly:pitch?)
666 (make-music 'RelativeOctaveCheck
670 #(define-music-function (parser location item) (symbol-list-or-music?)
671 (_i "Set @var{item}'s @samp{stencil} property to @code{#f},
672 effectively omitting it without taking up space.
674 If @var{item} is a symbol list of form @code{GrobName} or
675 @code{Context.GrobName}, the result is an override for the grob name
676 specified by it. If @var{item} is a music expression, the result is
677 the same music expression with an appropriate tweak applied to it.")
679 #{ \tweak #'stencil ##f $item #}
680 #{ \override $item #'stencil = ##f #}))
683 #(define-music-function (parser location music) (ly:music?)
684 (_i "Set @code{once} to @code{#t} on all layout instruction events in @var{music}.")
687 (cond ((music-is-of-type? m 'layout-instruction-event)
688 (set! (ly:music-property m 'once) #t))
689 ((ly:duration? (ly:music-property m 'duration))
690 (ly:music-warning m (_ "Cannot apply \\once to timed music"))))
695 #(define-music-function (parser location octave) (integer?)
696 (_i "Set the octavation.")
697 (make-music 'OttavaMusic
698 'ottava-number octave))
700 overrideTimeSignatureSettings =
701 #(define-music-function
702 (parser location time-signature base-moment beat-structure beam-exceptions)
703 (pair? pair? cheap-list? cheap-list?)
705 (_i "Override @code{timeSignatureSettings}
706 for time signatures of @var{time-signature} to have settings
707 of @var{base-moment}, @var{beat-structure}, and @var{beam-exceptions}.")
709 ;; TODO -- add warning if largest value of grouping is
710 ;; greater than time-signature.
711 (let ((setting (make-setting base-moment beat-structure beam-exceptions)))
712 (override-time-signature-setting time-signature setting)))
715 #(define-music-function (parser location name property value)
716 (symbol-list? symbol? scheme?)
718 (_i "Set @var{property} to @var{value} in all grobs named @var{name}.
719 The @var{name} argument is a symbol list of the form @code{Context.GrobName}
720 or @code{GrobName}.")
721 (if (<= 1 (length name) 2)
722 (make-music 'ApplyOutputEvent
723 'context-type (if (null? (cdr name)) 'Bottom
726 (lambda (grob orig-context context)
728 (cdr (assoc 'name (ly:grob-property grob 'meta)))
730 (set! (ly:grob-property grob property) value))))
732 (ly:parser-error parser (_ "bad grob name") location)
733 (make-music 'Music))))
740 %% pageBreak and pageTurn are music functions (iso music indentifiers),
741 %% because music identifiers are not allowed at top-level.
743 #(define-music-function (location parser) ()
744 (_i "Force a page break. May be used at toplevel (i.e., between scores or
745 markups), or inside a score.")
746 (make-music 'EventChord
748 'line-break-permission 'force
749 'page-break-permission 'force
750 'elements (list (make-music 'LineBreakEvent
751 'break-permission 'force)
752 (make-music 'PageBreakEvent
753 'break-permission 'force))))
756 #(define-music-function (location parser) ()
757 (_i "Force a page turn between two scores or top-level markups.")
758 (make-music 'EventChord
760 'line-break-permission 'force
761 'page-break-permission 'force
762 'page-turn-permission 'force
763 'elements (list (make-music 'LineBreakEvent
764 'break-permission 'force)
765 (make-music 'PageBreakEvent
766 'break-permission 'force)
767 (make-music 'PageTurnEvent
768 'break-permission 'force))))
771 #(define-void-function (parser location voice-ids music) (list? ly:music?)
772 (_i "Define parallel music sequences, separated by '|' (bar check signs),
773 and assign them to the identifiers provided in @var{voice-ids}.
775 @var{voice-ids}: a list of music identifiers (symbols containing only letters)
777 @var{music}: a music sequence, containing BarChecks as limiting expressions.
782 \\parallelMusic #'(A B C) {
792 (let* ((voices (apply circular-list (make-list (length voice-ids) (list))))
793 (current-voices voices)
794 (current-sequence (list))
799 (define (push-music m)
800 "Push the music expression into the current sequence"
801 (set! current-sequence (cons m current-sequence)))
802 (define (change-voice)
803 "Stores the previously built sequence into the current voice and
804 change to the following voice."
805 (list-set! current-voices 0 (cons (make-music 'SequentialMusic
806 'elements (reverse! current-sequence))
807 (car current-voices)))
808 (set! current-sequence (list))
809 (set! current-voices (cdr current-voices)))
810 (define (bar-check? m)
811 "Checks whether m is a bar check."
812 (eq? (ly:music-property m 'name) 'BarCheck))
813 (define (music-origin music)
814 "Recursively search an origin location stored in music."
815 (cond ((null? music) #f)
816 ((not (null? (ly:music-property music 'origin)))
817 (ly:music-property music 'origin))
818 (else (or (music-origin (ly:music-property music 'element))
819 (let ((origins (remove not (map music-origin
820 (ly:music-property music 'elements)))))
821 (and (not (null? origins)) (car origins)))))))
822 (while (music-is-of-type? music 'music-wrapper-music)
824 (set! music (ly:music-property wrapper 'element)))
826 (set! (ly:music-property wrapper 'element)
827 (make-music 'SequentialMusic
830 (make-music 'SequentialMusic
833 ;; first, split the music and fill in voices
834 ;; We flatten direct layers of SequentialMusic since they are
835 ;; pretty much impossible to avoid when writing music functions.
836 (let rec ((music music))
837 (for-each (lambda (m)
838 (if (eq? (ly:music-property m 'name) 'SequentialMusic)
842 (if (bar-check? m) (change-voice)))))
843 (ly:music-property music 'elements)))
844 (if (not (null? current-sequence)) (change-voice))
845 ;; un-circularize `voices' and reorder the voices
846 (set! voices (map-in-order (lambda (dummy seqs)
850 ;; set origin location of each sequence in each voice
851 ;; for better type error tracking
852 (for-each (lambda (voice)
853 (for-each (lambda (seq)
854 (set! (ly:music-property seq 'origin)
855 (or (music-origin seq) location)))
859 ;; check sequence length
860 (apply for-each (lambda* (#:rest seqs)
861 (let ((moment-reference (ly:music-length (car seqs))))
862 (for-each (lambda (seq moment)
863 (if (not (equal? moment moment-reference))
864 (ly:music-warning seq
865 "Bars in parallel music don't have the same length")))
866 seqs (map-in-order ly:music-length seqs))))
869 ;; bind voice identifiers to the voices
870 (for-each (lambda (voice-id voice)
871 (ly:parser-define! parser voice-id
872 (let ((v (ly:music-deep-copy original)))
873 (set! (ly:music-property
874 (car (extract-named-music
881 #(define-music-function (parser loc arg) (ly:music?)
882 (_i "Tag @var{arg} to be parenthesized.")
884 (if (memq 'event-chord (ly:music-property arg 'types))
885 ;; arg is an EventChord -> set the parenthesize property
886 ;; on all child notes and rests
889 (if (or (memq 'note-event (ly:music-property ev 'types))
890 (memq 'rest-event (ly:music-property ev 'types)))
891 (set! (ly:music-property ev 'parenthesize) #t)))
892 (ly:music-property arg 'elements))
893 ;; No chord, simply set property for this expression:
894 (set! (ly:music-property arg 'parenthesize) #t))
898 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
899 (_i "Take the music in @var{part1} and @var{part2} and typeset so
900 that they share a staff.")
901 (make-part-combine-music parser
902 (list part1 part2) #f))
905 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
906 (_i "Take the music in @var{part1} and @var{part2} and typeset so
907 that they share a staff with stems directed upward.")
908 (make-part-combine-music parser
909 (list part1 part2) UP))
912 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
913 (_i "Take the music in @var{part1} and @var{part2} and typeset so
914 that they share a staff with stems directed downward.")
915 (make-part-combine-music parser
916 (list part1 part2) DOWN))
919 #(define-music-function (location parser type once) (symbol-or-boolean? boolean?)
920 (_i "Override the part-combiner.")
921 (make-music 'EventChord
922 'elements (list (make-music 'PartCombineForceEvent
925 partcombineApart = \partcombineForce #'apart ##f
926 partcombineApartOnce = \partcombineForce #'apart ##t
927 partcombineChords = \partcombineForce #'chords ##f
928 partcombineChordsOnce = \partcombineForce #'chords ##t
929 partcombineUnisono = \partcombineForce #'unisono ##f
930 partcombineUnisonoOnce = \partcombineForce #'unisono ##t
931 partcombineSoloI = \partcombineForce #'solo1 ##f
932 partcombineSoloIOnce = \partcombineForce #'solo1 ##t
933 partcombineSoloII = \partcombineForce #'solo2 ##f
934 partcombineSoloIIOnce = \partcombineForce #'solo2 ##t
935 partcombineAutomatic = \partcombineForce ##f ##f
936 partcombineAutomaticOnce = \partcombineForce ##f ##t
939 #(define-music-function (parser location dur) (ly:duration?)
940 (_i "Make a partial measure.")
942 ;; We use `descend-to-context' here instead of `context-spec-music' to
943 ;; ensure \partial still works if the Timing_translator is moved
945 (context-spec-music (make-music 'PartialSet
947 'partial-duration dur)
952 #(define-music-function
953 (parser location main-note secondary-note)
954 (ly:music? ly:music?)
955 (_i "Print a trill with @var{main-note} as the main note of the trill and
956 print @var{secondary-note} as a stemless note head in parentheses.")
957 (let* ((get-notes (lambda (ev-chord)
958 (extract-named-music ev-chord 'NoteEvent)))
959 (sec-note-events (get-notes secondary-note))
960 (trill-events (extract-named-music main-note 'TrillSpanEvent)))
961 (if (pair? sec-note-events)
963 (let* ((trill-pitch (ly:music-property (car sec-note-events) 'pitch))
964 (forced (ly:music-property (car sec-note-events) 'force-accidental)))
966 (if (ly:pitch? trill-pitch)
967 (for-each (lambda (m)
968 (ly:music-set-property! m 'pitch trill-pitch)) trill-events)
970 (ly:input-warning location (_ "Second argument of \\pitchedTrill should be single note: "))
971 (display sec-note-events)))
974 (for-each (lambda (m)
975 (ly:music-set-property! m 'force-accidental forced))
980 #(define-music-function (parser location tag more music)
981 (symbol? ly:music? ly:music?)
982 (_i "Add @var{more} to the front of @code{elements} of all music
983 expressions in @var{music} that are tagged with @var{tag}.")
984 (music-map (lambda (m)
985 (if (memq tag (ly:music-property m 'tags))
986 (set! (ly:music-property m 'elements)
987 (cons more (ly:music-property m 'elements))))
992 #(define-music-function (parser location what main-music) (string? ly:music?)
993 (_i "Indicate a section of music to be quoted. @var{what} indicates the name
994 of the quoted voice, as specified in an @code{\\addQuote} command.
995 @var{main-music} is used to indicate the length of music to be quoted;
996 usually contains spacers or multi-measure rests.")
997 (make-music 'QuoteMusic
999 'quoted-music-name what))
1002 #(define-music-function (parser location pitch music)
1003 ((ly:pitch? (ly:make-pitch 0 0 0)) ly:music?)
1004 (_i "Make @var{music} relative to @var{pitch} (default @code{c'}).")
1005 (ly:make-music-relative! music pitch)
1006 (make-music 'RelativeOctaveMusic
1010 #(define-music-function (parser location tag music) (symbol? ly:music?)
1011 (_i "Remove elements of @var{music} that are tagged with @var{tag}.")
1014 (let* ((tags (ly:music-property m 'tags))
1015 (res (memq tag tags)))
1019 resetRelativeOctave =
1020 #(define-music-function (parser location pitch) (ly:pitch?)
1021 (_i "Set the octave inside a \\relative section.")
1023 (make-music 'SequentialMusic
1024 'to-relative-callback
1025 (lambda (music last-pitch) pitch)))
1028 #(define-music-function (parser location music)
1030 (_i "Return @var{music} in reverse order.")
1031 (retrograde-music music))
1033 revertTimeSignatureSettings =
1034 #(define-music-function
1035 (parser location time-signature)
1038 (_i "Revert @code{timeSignatureSettings}
1039 for time signatures of @var{time-signature}.")
1040 (revert-time-signature-setting time-signature))
1043 #(define-event-function (parser location finger) (number-or-string?)
1044 (_i "Apply @var{finger} as a fingering indication.")
1049 (if (string? finger) 'text 'digit)
1053 #(define-music-function (parser location fraction music)
1054 (fraction? ly:music?)
1055 (_i "Multiply the duration of events in @var{music} by @var{fraction}.")
1056 (ly:music-compress music
1057 (ly:make-moment (car fraction) (cdr fraction))))
1060 #(define-scheme-function (parser location ctx music)
1061 ((symbol?) ly:music?)
1062 (_i "Take the layout instruction events from @var{music}, optionally
1063 restricted to those applying to context type @var{ctx}, and return
1064 a context modification duplicating their effect.")
1065 (let ((mods (ly:make-context-mod)))
1067 (if (music-is-of-type? m 'layout-instruction-event)
1070 (case (ly:music-property m 'name)
1073 (ly:music-property m 'symbol)
1074 (ly:music-property m 'value)))
1077 (ly:music-property m 'symbol)))
1080 (ly:music-property m 'symbol)
1081 (ly:music-property m 'grob-value)
1083 ((ly:music-property m 'grob-property #f) => list)
1085 (ly:music-property m 'grob-property-path)))))
1088 (ly:music-property m 'symbol)
1090 ((ly:music-property m 'grob-property #f) => list)
1092 (ly:music-property m 'grob-property-path)))))))
1093 (case (ly:music-property m 'name)
1095 (ly:add-context-mod mods
1097 (ly:music-property m 'procedure))))
1098 ((ContextSpeccedMusic)
1100 (eq? ctx (ly:music-property m 'context-type)))
1101 (musicop (ly:music-property m 'element))))
1103 (let ((callback (ly:music-property m 'elements-callback)))
1104 (if (procedure? callback)
1105 (for-each musicop (callback m))))))))
1110 #(define-music-function (parser location offsets item)
1111 (list? symbol-list-or-music?)
1112 (_i "Offset control-points of @var{item} by @var{offsets}. The
1113 argument is a list of number pairs or list of such lists. Each
1114 element of a pair represents an offset to one of the coordinates of a
1115 control-point. If @var{item} is a string, the result is
1116 @code{\\once\\override} for the specified grob type. If @var{item} is
1117 a music expression, the result is the same music expression with an
1118 appropriate tweak applied.")
1119 (define (shape-curve grob)
1120 (let* ((orig (ly:grob-original grob))
1121 (siblings (if (ly:spanner? grob)
1122 (ly:spanner-broken-into orig) '()))
1123 (total-found (length siblings))
1124 (function (assoc-get 'control-points
1125 (reverse (ly:grob-basic-properties grob))))
1126 (coords (function grob)))
1128 (define (offset-control-points offsets)
1132 (lambda (x y) (coord-translate x y))
1135 (define (helper sibs offs)
1137 (if (eq? (car sibs) grob)
1138 (offset-control-points (car offs))
1139 (helper (cdr sibs) (cdr offs)))
1142 ;; we work with lists of lists
1143 (if (or (null? offsets)
1144 (not (list? (car offsets))))
1145 (set! offsets (list offsets)))
1147 (if (>= total-found 2)
1148 (helper siblings offsets)
1149 (offset-control-points (car offsets)))))
1150 (if (ly:music? item)
1152 \tweak #'control-points #shape-curve $item
1155 \once \override $item #'control-points = #shape-curve
1159 #(define-music-function (parser location dur dots arg)
1160 (integer? integer? ly:music?)
1161 (_i "Change the duration of @var{arg} by adding @var{dur} to the
1162 @code{durlog} of @var{arg} and @var{dots} to the @code{dots} of @var{arg}.")
1166 (shift-one-duration-log x dur dots)) arg))
1169 #(define-music-function (parser location overrides music)
1170 (ly:music? ly:music?)
1171 (_i "Convert @var{overrides} to tweaks and apply them to @var{music}.
1172 This does not convert @code{\\revert}, @code{\\set} or @code{\\unset}
1173 and ignores nested overrides.")
1174 (set! (ly:music-property music 'tweaks)
1176 (lambda (m) (eq? (ly:music-property m 'name)
1180 ((ly:music-property m 'grob-property #f) => list)
1182 (ly:music-property m 'grob-property-path)))))
1184 tweaks ;ignore nested properties
1185 (acons (cons (ly:music-property m 'symbol) ;grob name
1186 (car p)) ;grob property
1187 (ly:music-property m 'grob-value)
1189 (ly:music-property music 'tweaks)
1194 #(define-music-function (parser location dur) (ly:duration?)
1195 (_i "Skip forward by @var{dur}.")
1196 (make-music 'SkipMusic
1201 #(def-grace-function startSlashedGraceMusic stopSlashedGraceMusic
1202 (_i "Create slashed graces (slashes through stems, but no slur) from
1203 the following music expression"))
1206 #(define-music-function (parser location parameters) (list?)
1207 (_i "Set the system stretch, by reading the 'system-stretch property of
1208 the `parameters' assoc list.")
1210 \overrideProperty #"Score.NonMusicalPaperColumn"
1211 #'line-break-system-details
1212 #(list (cons 'alignment-extra-space (cdr (assoc 'system-stretch parameters)))
1213 (cons 'system-Y-extent (cdr (assoc 'system-Y-extent parameters))))
1217 #(define-music-function (parser location style heads music)
1218 (symbol? symbol-list-or-symbol? ly:music?)
1219 (_i "Set @var{heads} in @var{music} to @var{style}.")
1220 (style-note-heads heads style music))
1223 #(define-music-function (parser location tag arg) (symbol? ly:music?)
1225 (_i "Add @var{tag} to the @code{tags} property of @var{arg}.")
1228 (ly:music-property arg 'tags)
1230 (ly:music-property arg 'tags)))
1234 #(define-music-function (parser location music)
1236 (_i "Make any @code{\\override} in @var{music} replace an existing
1237 grob property value only temporarily, restoring the old value when a
1238 corresponding @code{\\revert} is executed. This is achieved by
1239 clearing the @samp{pop-first} property normally set on
1242 An @code{\\override}/@/@code{\\revert} sequence created by using
1243 @code{\\temporary} and @code{\\undo} on the same music containing
1244 overrides will cancel out perfectly or cause a@tie{}warning.
1246 Non-property-related music is ignored, warnings are generated for any
1247 property-changing music that isn't an @code{\\override}.")
1251 (and (or (music-is-of-type? m 'layout-instruction-event)
1252 (music-is-of-type? m 'context-specification)
1253 (music-is-of-type? m 'apply-context)
1254 (music-is-of-type? m 'time-signature-music))
1255 (case (ly:music-property m 'name)
1257 (if (ly:music-property m 'pop-first #f)
1258 (set! (ly:music-property m 'pop-first) '()))
1259 (if (ly:music-property m 'once #f)
1260 (set! (ly:music-property m 'once) '()))
1262 ((ContextSpeccedMusic)
1267 (ly:input-warning location (_ "Cannot make ~a revertible")
1268 (ly:music-property m 'name))
1275 #(define-music-function (parser location beat-structure fraction)
1276 ((number-list? '()) fraction?)
1277 (_i "Set @var{fraction} as time signature, with optional
1278 number list @var{beat-structure} before it.")
1279 (make-music 'TimeSignatureMusic
1280 'numerator (car fraction)
1281 'denominator (cdr fraction)
1282 'beat-structure beat-structure))
1285 #(define-music-function (parser location fraction music)
1286 (fraction? ly:music?)
1287 (_i "Scale @var{music} in time by @var{fraction}.")
1288 (make-music 'TimeScaledMusic
1289 'element (ly:music-compress music (ly:make-moment (car fraction) (cdr fraction)))
1290 'numerator (car fraction)
1291 'denominator (cdr fraction)))
1294 #(define-music-function
1295 (parser location from to music)
1296 (ly:pitch? ly:pitch? ly:music?)
1298 (_i "Transpose @var{music} from pitch @var{from} to pitch @var{to}.")
1299 (make-music 'TransposedMusic
1300 'element (ly:music-transpose music (ly:pitch-diff to from))))
1302 transposedCueDuring =
1303 #(define-music-function
1304 (parser location what dir pitch main-music)
1305 (string? ly:dir? ly:pitch? ly:music?)
1307 (_i "Insert notes from the part @var{what} into a voice called @code{cue},
1308 using the transposition defined by @var{pitch}. This happens
1309 simultaneously with @var{main-music}, which is usually a rest. The
1310 argument @var{dir} determines whether the cue notes should be notated
1311 as a first or second voice.")
1313 (make-music 'QuoteMusic
1315 'quoted-context-type 'Voice
1316 'quoted-context-id "cue"
1317 'quoted-music-name what
1318 'quoted-voice-direction dir
1319 'quoted-transposition pitch))
1322 #(define-music-function (parser location pitch) (ly:pitch?)
1323 (_i "Set instrument transposition")
1326 (make-property-set 'instrumentTransposition
1327 (ly:pitch-negate pitch))
1331 #(define-music-function (parser location grob prop value music)
1332 ((string?) symbol? scheme? ly:music?)
1333 (_i "Add a tweak to the following @var{music}.
1334 Layout objects created by @var{music} get their property @var{prop}
1335 set to @var{value}. If @var{grob} is specified, like with
1337 \\tweak Accidental #'color #red cis'
1339 an indirectly created grob (@samp{Accidental} is caused by
1340 @samp{NoteHead}) can be tweaked; otherwise only directly created grobs
1342 (if (not (object-property prop 'backend-type?))
1344 (ly:input-warning location (_ "cannot find property type-check for ~a") prop)
1345 (ly:warning (_ "doing assignment anyway"))))
1347 (ly:music-property music 'tweaks)
1348 (acons (if grob (cons (string->symbol grob) prop) prop)
1350 (ly:music-property music 'tweaks)))
1354 #(define-music-function (parser location music)
1356 (_i "Convert @code{\\override} and @code{\\set} in @var{music} to
1357 @code{\\revert} and @code{\\unset}, respectively. Any reverts and
1358 unsets already in @var{music} cause a warning. Non-property-related music is ignored.")
1365 (lambda (m) (or (music-is-of-type? m 'layout-instruction-event)
1366 (music-is-of-type? m 'context-specification)
1367 (music-is-of-type? m 'apply-context)
1368 (music-is-of-type? m 'time-signature-music)))
1369 (lambda (m overrides)
1370 (case (ly:music-property m 'name)
1373 (make-music 'RevertProperty
1374 'symbol (ly:music-property m 'symbol)
1377 ((ly:music-property m 'grob-property #f) => list)
1379 (ly:music-property m 'grob-property-path))))
1383 (make-music 'PropertyUnset
1384 'symbol (ly:music-property m 'symbol))
1386 ((ContextSpeccedMusic)
1388 (make-music 'ContextSpeccedMusic
1389 'element (loop (ly:music-property m 'element))
1390 'context-type (ly:music-property m 'context-type))
1395 (ly:input-warning location (_ "Cannot revert ~a")
1396 (ly:music-property m 'name))
1402 ((null? lst) (make-music 'Music))
1403 ((null? (cdr lst)) (car lst))
1404 (else (make-sequential-music lst))))))
1407 #(define-music-function (parser location music) (ly:music?)
1408 (_i "Force any @code{\\repeat volta}, @code{\\repeat tremolo} or
1409 @code{\\repeat percent} commands in @var{music} to be interpreted
1410 as @code{\\repeat unfold}.")
1411 (unfold-repeats music))
1414 #(define-void-function (parser location arg) (scheme?)
1415 (_i "Accept a scheme argument, return a void expression.
1416 Use this if you want to have a scheme expression evaluated
1417 because of its side-effects, but its value ignored."))
1420 #(define-music-function (parser location sym val music)
1421 (symbol? scheme? ly:music?)
1422 (_i "Set @var{sym} to @var{val} in @var{music}.")
1424 (set! (ly:music-property music sym) val)