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-path value)
716 (symbol-list? symbol-list-or-symbol? scheme?)
718 (_i "Set @var{property-path} 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 (if (symbol? property-path)
731 (ly:grob-set-property! grob property-path value)
732 (case (length property-path)
735 (ly:grob-set-property!
736 grob (car property-path) value))
738 (ly:grob-set-nested-property!
739 grob property-path value)))))))
741 (ly:parser-error parser (_ "bad grob name") location)
742 (make-music 'Music))))
749 %% pageBreak and pageTurn are music functions (iso music indentifiers),
750 %% because music identifiers are not allowed at top-level.
752 #(define-music-function (location parser) ()
753 (_i "Force a page break. May be used at toplevel (i.e., between scores or
754 markups), or inside a score.")
755 (make-music 'EventChord
757 'line-break-permission 'force
758 'page-break-permission 'force
759 'elements (list (make-music 'LineBreakEvent
760 'break-permission 'force)
761 (make-music 'PageBreakEvent
762 'break-permission 'force))))
765 #(define-music-function (location parser) ()
766 (_i "Force a page turn between two scores or top-level markups.")
767 (make-music 'EventChord
769 'line-break-permission 'force
770 'page-break-permission 'force
771 'page-turn-permission 'force
772 'elements (list (make-music 'LineBreakEvent
773 'break-permission 'force)
774 (make-music 'PageBreakEvent
775 'break-permission 'force)
776 (make-music 'PageTurnEvent
777 'break-permission 'force))))
780 #(define-void-function (parser location voice-ids music) (list? ly:music?)
781 (_i "Define parallel music sequences, separated by '|' (bar check signs),
782 and assign them to the identifiers provided in @var{voice-ids}.
784 @var{voice-ids}: a list of music identifiers (symbols containing only letters)
786 @var{music}: a music sequence, containing BarChecks as limiting expressions.
791 \\parallelMusic #'(A B C) {
801 (let* ((voices (apply circular-list (make-list (length voice-ids) (list))))
802 (current-voices voices)
803 (current-sequence (list))
808 (define (push-music m)
809 "Push the music expression into the current sequence"
810 (set! current-sequence (cons m current-sequence)))
811 (define (change-voice)
812 "Stores the previously built sequence into the current voice and
813 change to the following voice."
814 (list-set! current-voices 0 (cons (make-music 'SequentialMusic
815 'elements (reverse! current-sequence))
816 (car current-voices)))
817 (set! current-sequence (list))
818 (set! current-voices (cdr current-voices)))
819 (define (bar-check? m)
820 "Checks whether m is a bar check."
821 (eq? (ly:music-property m 'name) 'BarCheck))
822 (define (music-origin music)
823 "Recursively search an origin location stored in music."
824 (cond ((null? music) #f)
825 ((not (null? (ly:music-property music 'origin)))
826 (ly:music-property music 'origin))
827 (else (or (music-origin (ly:music-property music 'element))
828 (let ((origins (remove not (map music-origin
829 (ly:music-property music 'elements)))))
830 (and (not (null? origins)) (car origins)))))))
831 (while (music-is-of-type? music 'music-wrapper-music)
833 (set! music (ly:music-property wrapper 'element)))
835 (set! (ly:music-property wrapper 'element)
836 (make-music 'SequentialMusic
839 (make-music 'SequentialMusic
842 ;; first, split the music and fill in voices
843 ;; We flatten direct layers of SequentialMusic since they are
844 ;; pretty much impossible to avoid when writing music functions.
845 (let rec ((music music))
846 (for-each (lambda (m)
847 (if (eq? (ly:music-property m 'name) 'SequentialMusic)
851 (if (bar-check? m) (change-voice)))))
852 (ly:music-property music 'elements)))
853 (if (not (null? current-sequence)) (change-voice))
854 ;; un-circularize `voices' and reorder the voices
855 (set! voices (map-in-order (lambda (dummy seqs)
859 ;; set origin location of each sequence in each voice
860 ;; for better type error tracking
861 (for-each (lambda (voice)
862 (for-each (lambda (seq)
863 (set! (ly:music-property seq 'origin)
864 (or (music-origin seq) location)))
868 ;; check sequence length
869 (apply for-each (lambda* (#:rest seqs)
870 (let ((moment-reference (ly:music-length (car seqs))))
871 (for-each (lambda (seq moment)
872 (if (not (equal? moment moment-reference))
873 (ly:music-warning seq
874 "Bars in parallel music don't have the same length")))
875 seqs (map-in-order ly:music-length seqs))))
878 ;; bind voice identifiers to the voices
879 (for-each (lambda (voice-id voice)
880 (ly:parser-define! parser voice-id
881 (let ((v (ly:music-deep-copy original)))
882 (set! (ly:music-property
883 (car (extract-named-music
890 #(define-music-function (parser loc arg) (ly:music?)
891 (_i "Tag @var{arg} to be parenthesized.")
893 (if (memq 'event-chord (ly:music-property arg 'types))
894 ;; arg is an EventChord -> set the parenthesize property
895 ;; on all child notes and rests
898 (if (or (memq 'note-event (ly:music-property ev 'types))
899 (memq 'rest-event (ly:music-property ev 'types)))
900 (set! (ly:music-property ev 'parenthesize) #t)))
901 (ly:music-property arg 'elements))
902 ;; No chord, simply set property for this expression:
903 (set! (ly:music-property arg 'parenthesize) #t))
907 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
908 (_i "Take the music in @var{part1} and @var{part2} and typeset so
909 that they share a staff.")
910 (make-part-combine-music parser
911 (list part1 part2) #f))
914 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
915 (_i "Take the music in @var{part1} and @var{part2} and typeset so
916 that they share a staff with stems directed upward.")
917 (make-part-combine-music parser
918 (list part1 part2) UP))
921 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
922 (_i "Take the music in @var{part1} and @var{part2} and typeset so
923 that they share a staff with stems directed downward.")
924 (make-part-combine-music parser
925 (list part1 part2) DOWN))
928 #(define-music-function (location parser type once) (symbol-or-boolean? boolean?)
929 (_i "Override the part-combiner.")
930 (make-music 'EventChord
931 'elements (list (make-music 'PartCombineForceEvent
934 partcombineApart = \partcombineForce #'apart ##f
935 partcombineApartOnce = \partcombineForce #'apart ##t
936 partcombineChords = \partcombineForce #'chords ##f
937 partcombineChordsOnce = \partcombineForce #'chords ##t
938 partcombineUnisono = \partcombineForce #'unisono ##f
939 partcombineUnisonoOnce = \partcombineForce #'unisono ##t
940 partcombineSoloI = \partcombineForce #'solo1 ##f
941 partcombineSoloIOnce = \partcombineForce #'solo1 ##t
942 partcombineSoloII = \partcombineForce #'solo2 ##f
943 partcombineSoloIIOnce = \partcombineForce #'solo2 ##t
944 partcombineAutomatic = \partcombineForce ##f ##f
945 partcombineAutomaticOnce = \partcombineForce ##f ##t
948 #(define-music-function (parser location dur) (ly:duration?)
949 (_i "Make a partial measure.")
951 ;; We use `descend-to-context' here instead of `context-spec-music' to
952 ;; ensure \partial still works if the Timing_translator is moved
954 (context-spec-music (make-music 'PartialSet
956 'partial-duration dur)
961 #(define-music-function
962 (parser location main-note secondary-note)
963 (ly:music? ly:music?)
964 (_i "Print a trill with @var{main-note} as the main note of the trill and
965 print @var{secondary-note} as a stemless note head in parentheses.")
966 (let* ((get-notes (lambda (ev-chord)
967 (extract-named-music ev-chord 'NoteEvent)))
968 (sec-note-events (get-notes secondary-note))
969 (trill-events (extract-named-music main-note 'TrillSpanEvent)))
970 (if (pair? sec-note-events)
972 (let* ((trill-pitch (ly:music-property (car sec-note-events) 'pitch))
973 (forced (ly:music-property (car sec-note-events) 'force-accidental)))
975 (if (ly:pitch? trill-pitch)
976 (for-each (lambda (m)
977 (ly:music-set-property! m 'pitch trill-pitch)) trill-events)
979 (ly:input-warning location (_ "Second argument of \\pitchedTrill should be single note: "))
980 (display sec-note-events)))
983 (for-each (lambda (m)
984 (ly:music-set-property! m 'force-accidental forced))
989 #(define-music-function (parser location tag more music)
990 (symbol? ly:music? ly:music?)
991 (_i "Add @var{more} to the front of @code{elements} of all music
992 expressions in @var{music} that are tagged with @var{tag}.")
993 (music-map (lambda (m)
994 (if (memq tag (ly:music-property m 'tags))
995 (set! (ly:music-property m 'elements)
996 (cons more (ly:music-property m 'elements))))
1001 #(define-music-function (parser location what main-music) (string? ly:music?)
1002 (_i "Indicate a section of music to be quoted. @var{what} indicates the name
1003 of the quoted voice, as specified in an @code{\\addQuote} command.
1004 @var{main-music} is used to indicate the length of music to be quoted;
1005 usually contains spacers or multi-measure rests.")
1006 (make-music 'QuoteMusic
1008 'quoted-music-name what))
1011 #(define-music-function (parser location pitch music)
1012 ((ly:pitch? (ly:make-pitch 0 0 0)) ly:music?)
1013 (_i "Make @var{music} relative to @var{pitch} (default @code{c'}).")
1014 (ly:make-music-relative! music pitch)
1015 (make-music 'RelativeOctaveMusic
1019 #(define-music-function (parser location tag music) (symbol? ly:music?)
1020 (_i "Remove elements of @var{music} that are tagged with @var{tag}.")
1023 (let* ((tags (ly:music-property m 'tags))
1024 (res (memq tag tags)))
1028 resetRelativeOctave =
1029 #(define-music-function (parser location pitch) (ly:pitch?)
1030 (_i "Set the octave inside a \\relative section.")
1032 (make-music 'SequentialMusic
1033 'to-relative-callback
1034 (lambda (music last-pitch) pitch)))
1037 #(define-music-function (parser location music)
1039 (_i "Return @var{music} in reverse order.")
1040 (retrograde-music music))
1042 revertTimeSignatureSettings =
1043 #(define-music-function
1044 (parser location time-signature)
1047 (_i "Revert @code{timeSignatureSettings}
1048 for time signatures of @var{time-signature}.")
1049 (revert-time-signature-setting time-signature))
1052 #(define-event-function (parser location finger) (number-or-string?)
1053 (_i "Apply @var{finger} as a fingering indication.")
1058 (if (string? finger) 'text 'digit)
1062 #(define-music-function (parser location fraction music)
1063 (fraction? ly:music?)
1064 (_i "Multiply the duration of events in @var{music} by @var{fraction}.")
1065 (ly:music-compress music
1066 (ly:make-moment (car fraction) (cdr fraction))))
1069 #(define-scheme-function (parser location ctx music)
1070 ((symbol?) ly:music?)
1071 (_i "Take the layout instruction events from @var{music}, optionally
1072 restricted to those applying to context type @var{ctx}, and return
1073 a context modification duplicating their effect.")
1074 (let ((mods (ly:make-context-mod)))
1076 (if (music-is-of-type? m 'layout-instruction-event)
1079 (case (ly:music-property m 'name)
1082 (ly:music-property m 'symbol)
1083 (ly:music-property m 'value)))
1086 (ly:music-property m 'symbol)))
1089 (ly:music-property m 'symbol)
1090 (ly:music-property m 'grob-value)
1092 ((ly:music-property m 'grob-property #f) => list)
1094 (ly:music-property m 'grob-property-path)))))
1097 (ly:music-property m 'symbol)
1099 ((ly:music-property m 'grob-property #f) => list)
1101 (ly:music-property m 'grob-property-path)))))))
1102 (case (ly:music-property m 'name)
1104 (ly:add-context-mod mods
1106 (ly:music-property m 'procedure))))
1107 ((ContextSpeccedMusic)
1109 (eq? ctx (ly:music-property m 'context-type)))
1110 (musicop (ly:music-property m 'element))))
1112 (let ((callback (ly:music-property m 'elements-callback)))
1113 (if (procedure? callback)
1114 (for-each musicop (callback m))))))))
1119 #(define-music-function (parser location offsets item)
1120 (list? symbol-list-or-music?)
1121 (_i "Offset control-points of @var{item} by @var{offsets}. The
1122 argument is a list of number pairs or list of such lists. Each
1123 element of a pair represents an offset to one of the coordinates of a
1124 control-point. If @var{item} is a string, the result is
1125 @code{\\once\\override} for the specified grob type. If @var{item} is
1126 a music expression, the result is the same music expression with an
1127 appropriate tweak applied.")
1128 (define (shape-curve grob)
1129 (let* ((orig (ly:grob-original grob))
1130 (siblings (if (ly:spanner? grob)
1131 (ly:spanner-broken-into orig) '()))
1132 (total-found (length siblings))
1133 (function (assoc-get 'control-points
1134 (reverse (ly:grob-basic-properties grob))))
1135 (coords (function grob)))
1137 (define (offset-control-points offsets)
1141 (lambda (x y) (coord-translate x y))
1144 (define (helper sibs offs)
1146 (if (eq? (car sibs) grob)
1147 (offset-control-points (car offs))
1148 (helper (cdr sibs) (cdr offs)))
1151 ;; we work with lists of lists
1152 (if (or (null? offsets)
1153 (not (list? (car offsets))))
1154 (set! offsets (list offsets)))
1156 (if (>= total-found 2)
1157 (helper siblings offsets)
1158 (offset-control-points (car offsets)))))
1159 (if (ly:music? item)
1161 \tweak #'control-points #shape-curve $item
1164 \once \override $item #'control-points = #shape-curve
1168 #(define-music-function (parser location dur dots arg)
1169 (integer? integer? ly:music?)
1170 (_i "Change the duration of @var{arg} by adding @var{dur} to the
1171 @code{durlog} of @var{arg} and @var{dots} to the @code{dots} of @var{arg}.")
1175 (shift-one-duration-log x dur dots)) arg))
1178 #(define-music-function (parser location overrides music)
1179 (ly:music? ly:music?)
1180 (_i "Convert @var{overrides} to tweaks and apply them to @var{music}.
1181 This does not convert @code{\\revert}, @code{\\set} or @code{\\unset}
1182 and ignores nested overrides.")
1183 (set! (ly:music-property music 'tweaks)
1185 (lambda (m) (eq? (ly:music-property m 'name)
1189 ((ly:music-property m 'grob-property #f) => list)
1191 (ly:music-property m 'grob-property-path)))))
1193 tweaks ;ignore nested properties
1194 (acons (cons (ly:music-property m 'symbol) ;grob name
1195 (car p)) ;grob property
1196 (ly:music-property m 'grob-value)
1198 (ly:music-property music 'tweaks)
1203 #(define-music-function (parser location dur) (ly:duration?)
1204 (_i "Skip forward by @var{dur}.")
1205 (make-music 'SkipMusic
1210 #(def-grace-function startSlashedGraceMusic stopSlashedGraceMusic
1211 (_i "Create slashed graces (slashes through stems, but no slur) from
1212 the following music expression"))
1215 #(define-music-function (parser location parameters) (list?)
1216 (_i "Set the system stretch, by reading the 'system-stretch property of
1217 the `parameters' assoc list.")
1219 \overrideProperty #"Score.NonMusicalPaperColumn"
1220 #'line-break-system-details
1221 #(list (cons 'alignment-extra-space (cdr (assoc 'system-stretch parameters)))
1222 (cons 'system-Y-extent (cdr (assoc 'system-Y-extent parameters))))
1226 #(define-music-function (parser location style heads music)
1227 (symbol? symbol-list-or-symbol? ly:music?)
1228 (_i "Set @var{heads} in @var{music} to @var{style}.")
1229 (style-note-heads heads style music))
1232 #(define-music-function (parser location tag arg) (symbol? ly:music?)
1234 (_i "Add @var{tag} to the @code{tags} property of @var{arg}.")
1237 (ly:music-property arg 'tags)
1239 (ly:music-property arg 'tags)))
1243 #(define-music-function (parser location music)
1245 (_i "Make any @code{\\override} in @var{music} replace an existing
1246 grob property value only temporarily, restoring the old value when a
1247 corresponding @code{\\revert} is executed. This is achieved by
1248 clearing the @samp{pop-first} property normally set on
1251 An @code{\\override}/@/@code{\\revert} sequence created by using
1252 @code{\\temporary} and @code{\\undo} on the same music containing
1253 overrides will cancel out perfectly or cause a@tie{}warning.
1255 Non-property-related music is ignored, warnings are generated for any
1256 property-changing music that isn't an @code{\\override}.")
1260 (and (or (music-is-of-type? m 'layout-instruction-event)
1261 (music-is-of-type? m 'context-specification)
1262 (music-is-of-type? m 'apply-context)
1263 (music-is-of-type? m 'time-signature-music))
1264 (case (ly:music-property m 'name)
1266 (if (ly:music-property m 'pop-first #f)
1267 (set! (ly:music-property m 'pop-first) '()))
1268 (if (ly:music-property m 'once #f)
1269 (set! (ly:music-property m 'once) '()))
1271 ((ContextSpeccedMusic)
1276 (ly:input-warning location (_ "Cannot make ~a revertible")
1277 (ly:music-property m 'name))
1284 #(define-music-function (parser location beat-structure fraction)
1285 ((number-list? '()) fraction?)
1286 (_i "Set @var{fraction} as time signature, with optional
1287 number list @var{beat-structure} before it.")
1288 (make-music 'TimeSignatureMusic
1289 'numerator (car fraction)
1290 'denominator (cdr fraction)
1291 'beat-structure beat-structure))
1294 #(define-music-function (parser location fraction music)
1295 (fraction? ly:music?)
1296 (_i "Scale @var{music} in time by @var{fraction}.")
1297 (make-music 'TimeScaledMusic
1298 'element (ly:music-compress music (ly:make-moment (car fraction) (cdr fraction)))
1299 'numerator (car fraction)
1300 'denominator (cdr fraction)))
1303 #(define-music-function
1304 (parser location from to music)
1305 (ly:pitch? ly:pitch? ly:music?)
1307 (_i "Transpose @var{music} from pitch @var{from} to pitch @var{to}.")
1308 (make-music 'TransposedMusic
1309 'element (ly:music-transpose music (ly:pitch-diff to from))))
1311 transposedCueDuring =
1312 #(define-music-function
1313 (parser location what dir pitch main-music)
1314 (string? ly:dir? ly:pitch? ly:music?)
1316 (_i "Insert notes from the part @var{what} into a voice called @code{cue},
1317 using the transposition defined by @var{pitch}. This happens
1318 simultaneously with @var{main-music}, which is usually a rest. The
1319 argument @var{dir} determines whether the cue notes should be notated
1320 as a first or second voice.")
1322 (make-music 'QuoteMusic
1324 'quoted-context-type 'Voice
1325 'quoted-context-id "cue"
1326 'quoted-music-name what
1327 'quoted-voice-direction dir
1328 'quoted-transposition pitch))
1331 #(define-music-function (parser location pitch) (ly:pitch?)
1332 (_i "Set instrument transposition")
1335 (make-property-set 'instrumentTransposition
1336 (ly:pitch-negate pitch))
1340 #(define-music-function (parser location prop value music)
1341 (symbol-list-or-symbol? scheme? ly:music?)
1342 (_i "Add a tweak to the following @var{music}.
1343 Layout objects created by @var{music} get their property @var{prop}
1344 set to @var{value}. If @var{prop} has the form @samp{Grob.property}, like with
1346 \\tweak Accidental.color #red cis'
1348 an indirectly created grob (@samp{Accidental} is caused by
1349 @samp{NoteHead}) can be tweaked; otherwise only directly created grobs
1352 (set! prop (list prop)))
1353 (if (and (<= 1 (length prop) 2)
1354 (object-property (last prop) 'backend-type?))
1355 (set! (ly:music-property music 'tweaks)
1356 (acons (apply cons* prop)
1358 (ly:music-property music 'tweaks)))
1359 (ly:input-warning location (_ "cannot find property type-check for ~a") prop))
1363 #(define-music-function (parser location music)
1365 (_i "Convert @code{\\override} and @code{\\set} in @var{music} to
1366 @code{\\revert} and @code{\\unset}, respectively. Any reverts and
1367 unsets already in @var{music} cause a warning. Non-property-related music is ignored.")
1374 (lambda (m) (or (music-is-of-type? m 'layout-instruction-event)
1375 (music-is-of-type? m 'context-specification)
1376 (music-is-of-type? m 'apply-context)
1377 (music-is-of-type? m 'time-signature-music)))
1378 (lambda (m overrides)
1379 (case (ly:music-property m 'name)
1382 (make-music 'RevertProperty
1383 'symbol (ly:music-property m 'symbol)
1386 ((ly:music-property m 'grob-property #f) => list)
1388 (ly:music-property m 'grob-property-path))))
1392 (make-music 'PropertyUnset
1393 'symbol (ly:music-property m 'symbol))
1395 ((ContextSpeccedMusic)
1397 (make-music 'ContextSpeccedMusic
1398 'element (loop (ly:music-property m 'element))
1399 'context-type (ly:music-property m 'context-type))
1404 (ly:input-warning location (_ "Cannot revert ~a")
1405 (ly:music-property m 'name))
1411 ((null? lst) (make-music 'Music))
1412 ((null? (cdr lst)) (car lst))
1413 (else (make-sequential-music lst))))))
1416 #(define-music-function (parser location music) (ly:music?)
1417 (_i "Force any @code{\\repeat volta}, @code{\\repeat tremolo} or
1418 @code{\\repeat percent} commands in @var{music} to be interpreted
1419 as @code{\\repeat unfold}.")
1420 (unfold-repeats music))
1423 #(define-void-function (parser location arg) (scheme?)
1424 (_i "Accept a scheme argument, return a void expression.
1425 Use this if you want to have a scheme expression evaluated
1426 because of its side-effects, but its value ignored."))
1429 #(define-music-function (parser location sym val music)
1430 (symbol? scheme? ly:music?)
1431 (_i "Set @var{sym} to @var{val} in @var{music}.")
1433 (set! (ly:music-property music sym) val)