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 footnote item)
372 ((markup?) number-pair? markup? symbol-list-or-music?)
373 (_i "Make the markup @var{footnote} a footnote on @var{item}. 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 @var{item}
379 is a symbol list of form @samp{Grob} or @samp{Context.Grob}, then
380 grobs of that type will be marked at the current time step in the
381 given context (default @code{Bottom}).
383 If @var{item} is music, the music will get a footnote attached to a
384 grob immediately attached to the event, like @var{\\tweak} does. For
385 attaching a footnote to an @emph{indirectly} caused grob, write
386 @code{\\single\\footnote}, use @var{item} to specify the grob, and
387 follow it with the music to annotate.
389 Like with @code{\\tweak}, if you use a footnote on a following
390 post-event, the @code{\\footnote} command itself needs to be attached
391 to the preceding note or rest as a post-event with @code{-}.")
392 (let ((mus (make-music
394 'X-offset (car offset)
395 'Y-offset (cdr offset)
396 'automatically-numbered (not mark)
397 'text (or mark (make-null-markup))
398 'footnote-text footnote)))
400 #{ \tweak #'footnote-music #mus #item #}
401 #{ \once\override $item #'footnote-music = #mus #})))
404 #(def-grace-function startGraceMusic stopGraceMusic
405 (_i "Insert @var{music} as grace notes."))
408 #(define-scheme-function (parser location descriptions) (list?)
409 (_i "Create a context modification from @var{descriptions}, a list
410 in the format of @code{all-grob-descriptions}.")
413 (list 'assign (car p) (list (cdr p))))
416 harmonicByFret = #(define-music-function (parser location fret music) (number? ly:music?)
417 (_i "Convert @var{music} into mixed harmonics; the resulting notes resemble
418 harmonics played on a fretted instrument by touching the strings at @var{fret}.")
420 \set harmonicDots = ##t
421 \override TabNoteHead #'stencil = #(tab-note-head::print-custom-fret-label (number->string fret))
422 \override NoteHead #'Y-extent = #(ly:make-unpure-pure-container ly:grob::stencil-height
423 (lambda (grob start end)
424 (ly:grob::stencil-height grob)))
425 \override NoteHead #'stencil = #(lambda (grob) (ly:grob-set-property! grob 'style 'harmonic-mixed)
426 (ly:note-head::print grob))
428 (calc-harmonic-pitch (fret->pitch (number->string fret)) music))
430 \revert TabNoteHead #'stencil
431 \revert NoteHead #'Y-extent
432 \revert NoteHead #'stencil
435 harmonicByRatio = #(define-music-function (parser location ratio music) (number? ly:music?)
436 (_i "Convert @var{music} into mixed harmonics; the resulting notes resemble
437 harmonics played on a fretted instrument by touching the strings at the point
438 given through @var{ratio}.")
440 \set harmonicDots = ##t
441 \override TabNoteHead #'stencil = #(tab-note-head::print-custom-fret-label (ratio->fret ratio))
442 \override NoteHead #'Y-extent = #(ly:make-unpure-pure-container ly:grob::stencil-height
443 (lambda (grob start end)
444 (ly:grob::stencil-height grob)))
445 \override NoteHead #'stencil = #(lambda (grob) (ly:grob-set-property! grob 'style 'harmonic-mixed)
446 (ly:note-head::print grob))
448 (calc-harmonic-pitch (ratio->pitch ratio) music))
450 \revert TabNoteHead #'stencil
451 \revert NoteHead #'Y-extent
452 \revert NoteHead #'stencil
456 #(define-music-function (parser location item) (symbol-list-or-music?)
457 (_i "Set @var{item}'s @samp{transparent} property to @code{#t},
458 making it invisible while still retaining its dimensions.
460 If @var{item} is a symbol list of form @code{GrobName} or
461 @code{Context.GrobName}, the result is an override for the grob name
462 specified by it. If @var{item} is a music expression, the result is
463 the same music expression with an appropriate tweak applied to it.")
465 #{ \tweak #'transparent ##t $item #}
466 #{ \override $item #'transparent = ##t #}))
469 #(define-music-function (parser location) ()
470 (_i "Put the segno variant 'varsegno' at this position into the staff,
471 compatible with the repeat command.")
472 (make-music 'ApplyContext
475 (let ((score-ctx (ly:context-find ctx 'Score)))
476 (if (ly:context? score-ctx)
477 (let ((old-rc (ly:context-property score-ctx 'repeatCommands '())))
478 (if (eq? (memq 'segno-display old-rc) #f)
479 (ly:context-set-property! score-ctx 'repeatCommands (cons 'segno-display old-rc)))))))))
482 #(define-music-function
483 (parser location name) (string?)
484 (_i "Switch instrument to @var{name}, which must be predefined with
485 @code{\\addInstrumentDefinition}.")
486 (let* ((handle (assoc name instrument-definitions))
487 (instrument-def (if handle (cdr handle) '())))
490 (ly:input-warning location "No such instrument: ~a" name))
492 (make-music 'SimultaneousMusic
504 #(define-music-function (parser location tag music) (symbol? ly:music?)
505 (_i "Include only elements of @var{music} that are tagged with @var{tag}.")
508 (let* ((tags (ly:music-property m 'tags))
509 (res (memq tag tags)))
516 #(define-music-function (parser location tonic pitch-alist)
517 ((ly:pitch? '()) (list? '()))
518 (_i "Set key to @var{tonic} and scale @var{pitch-alist}.
519 If both are null, just generate @code{KeyChangeEvent}.")
520 (cond ((null? tonic) (make-music 'KeyChangeEvent))
522 (ly:parser-error parser (_ "second argument must be pitch list")
524 (make-music 'SequentialMusic 'void #t))
527 (make-music 'KeyChangeEvent
528 'tonic (ly:make-pitch 0 0 0)
529 'pitch-alist pitch-alist)
533 #(define-music-function (parser location music) (ly:music?)
534 (_i "Remove cue notes from @var{music}.")
537 (if (and (string? (ly:music-property mus 'quoted-music-name))
538 (string=? (ly:music-property mus 'quoted-context-id "") "cue"))
539 (ly:music-property mus 'element)
546 #(define-music-function (parser location label) (symbol?)
547 (_i "Create @var{label} as a bookmarking label.")
548 (make-music 'EventChord
551 'elements (list (make-music 'LabelEvent
552 'page-label label))))
556 #(define-void-function (parser location language) (string?)
557 (_i "Set note names for language @var{language}.")
558 (note-names-language parser language))
560 languageSaveAndChange =
561 #(define-void-function (parser location language) (string?)
562 (_i "Store the previous pitchnames alist, and set a new one.")
563 (set! previous-pitchnames pitchnames)
564 (note-names-language parser language))
567 #(define-void-function (parser location) ()
568 (_i "Restore a previously-saved pitchnames alist.")
569 (if previous-pitchnames
571 (set! pitchnames previous-pitchnames)
572 (ly:parser-set-note-names parser pitchnames))
573 (ly:input-warning location (_ "No other language was defined previously. Ignoring."))))
577 #(define-music-function (parser location arg) (ly:music?)
578 (_i "Display chords in @var{arg} as clusters.")
579 (music-map note-to-cluster arg))
582 #(define-music-function (parser location around to scale music)
583 (ly:pitch? ly:pitch? ly:music? ly:music?)
584 (_i "Invert @var{music} about @var{around} using @var{scale} and
585 transpose from @var{around} to @var{to}.")
586 (let ((inverter (make-modal-inverter around to scale)))
587 (change-pitches music inverter)
591 #(define-music-function (parser location from to scale music)
592 (ly:pitch? ly:pitch? ly:music? ly:music?)
593 (_i "Transpose @var{music} from pitch @var{from} to pitch @var{to}
595 (let ((transposer (make-modal-transposer from to scale)))
596 (change-pitches music transposer)
600 #(define-music-function
601 (parser location around to music) (ly:pitch? ly:pitch? ly:music?)
602 (_i "Invert @var{music} about @var{around} and
603 transpose from @var{around} to @var{to}.")
604 (music-invert around to music))
607 #(define-music-function
608 (parser location label) ((scheme? '()))
609 "Make the music for the \\mark command."
610 (let* ((set (and (integer? label)
611 (context-spec-music (make-property-set 'rehearsalMark label)
613 (ev (make-music 'MarkEvent
617 (make-sequential-music (list set ev))
619 (set! (ly:music-property ev 'label) label)
623 #(define-music-function (parser location proc mus) (procedure? ly:music?)
624 (_i "Apply @var{proc} to @var{mus} and all of the music it contains.")
625 (music-map proc mus))
627 %% noPageBreak and noPageTurn are music functions (not music indentifiers),
628 %% because music identifiers are not allowed at top-level.
630 #(define-music-function (location parser) ()
631 (_i "Forbid a page break. May be used at toplevel (i.e., between scores or
632 markups), or inside a score.")
633 (make-music 'EventChord
635 'page-break-permission 'forbid
636 'elements (list (make-music 'PageBreakEvent
637 'break-permission '()))))
640 #(define-music-function (location parser) ()
641 (_i "Forbid a page turn. May be used at toplevel (i.e., between scores or
642 markups), or inside a score.")
643 (make-music 'EventChord
645 'page-turn-permission 'forbid
646 'elements (list (make-music 'PageTurnEvent
647 'break-permission '()))))
652 #(define-music-function (parser location pitch) (ly:pitch?)
654 (make-music 'RelativeOctaveCheck
658 #(define-music-function (parser location item) (symbol-list-or-music?)
659 (_i "Set @var{item}'s @samp{stencil} property to @code{#f},
660 effectively omitting it without taking up space.
662 If @var{item} is a symbol list of form @code{GrobName} or
663 @code{Context.GrobName}, the result is an override for the grob name
664 specified by it. If @var{item} is a music expression, the result is
665 the same music expression with an appropriate tweak applied to it.")
667 #{ \tweak #'stencil ##f $item #}
668 #{ \override $item #'stencil = ##f #}))
671 #(define-music-function (parser location music) (ly:music?)
672 (_i "Set @code{once} to @code{#t} on all layout instruction events in @var{music}.")
675 (cond ((music-is-of-type? m 'layout-instruction-event)
676 (set! (ly:music-property m 'once) #t))
677 ((ly:duration? (ly:music-property m 'duration))
678 (ly:music-warning m (_ "Cannot apply \\once to timed music"))))
683 #(define-music-function (parser location octave) (integer?)
684 (_i "Set the octavation.")
685 (make-music 'OttavaMusic
686 'ottava-number octave))
688 overrideTimeSignatureSettings =
689 #(define-music-function
690 (parser location time-signature base-moment beat-structure beam-exceptions)
691 (pair? pair? cheap-list? cheap-list?)
693 (_i "Override @code{timeSignatureSettings}
694 for time signatures of @var{time-signature} to have settings
695 of @var{base-moment}, @var{beat-structure}, and @var{beam-exceptions}.")
697 ;; TODO -- add warning if largest value of grouping is
698 ;; greater than time-signature.
699 (let ((setting (make-setting base-moment beat-structure beam-exceptions)))
700 (override-time-signature-setting time-signature setting)))
703 #(define-music-function (parser location name property-path value)
704 (symbol-list? symbol-list-or-symbol? scheme?)
706 (_i "Set @var{property-path} to @var{value} in all grobs named @var{name}.
707 The @var{name} argument is a symbol list of the form @code{Context.GrobName}
708 or @code{GrobName}.")
709 (if (<= 1 (length name) 2)
710 (make-music 'ApplyOutputEvent
711 'context-type (if (null? (cdr name)) 'Bottom
714 (lambda (grob orig-context context)
716 (cdr (assoc 'name (ly:grob-property grob 'meta)))
718 (if (symbol? property-path)
719 (ly:grob-set-property! grob property-path value)
720 (case (length property-path)
723 (ly:grob-set-property!
724 grob (car property-path) value))
726 (ly:grob-set-nested-property!
727 grob property-path value)))))))
729 (ly:parser-error parser (_ "bad grob name") location)
730 (make-music 'Music))))
737 %% pageBreak and pageTurn are music functions (iso music indentifiers),
738 %% because music identifiers are not allowed at top-level.
740 #(define-music-function (location parser) ()
741 (_i "Force a page break. May be used at toplevel (i.e., between scores or
742 markups), or inside a score.")
743 (make-music 'EventChord
745 'line-break-permission 'force
746 'page-break-permission 'force
747 'elements (list (make-music 'LineBreakEvent
748 'break-permission 'force)
749 (make-music 'PageBreakEvent
750 'break-permission 'force))))
753 #(define-music-function (location parser) ()
754 (_i "Force a page turn between two scores or top-level markups.")
755 (make-music 'EventChord
757 'line-break-permission 'force
758 'page-break-permission 'force
759 'page-turn-permission 'force
760 'elements (list (make-music 'LineBreakEvent
761 'break-permission 'force)
762 (make-music 'PageBreakEvent
763 'break-permission 'force)
764 (make-music 'PageTurnEvent
765 'break-permission 'force))))
768 #(define-void-function (parser location voice-ids music) (list? ly:music?)
769 (_i "Define parallel music sequences, separated by '|' (bar check signs),
770 and assign them to the identifiers provided in @var{voice-ids}.
772 @var{voice-ids}: a list of music identifiers (symbols containing only letters)
774 @var{music}: a music sequence, containing BarChecks as limiting expressions.
779 \\parallelMusic #'(A B C) {
789 (let* ((voices (apply circular-list (make-list (length voice-ids) (list))))
790 (current-voices voices)
791 (current-sequence (list))
796 (define (push-music m)
797 "Push the music expression into the current sequence"
798 (set! current-sequence (cons m current-sequence)))
799 (define (change-voice)
800 "Stores the previously built sequence into the current voice and
801 change to the following voice."
802 (list-set! current-voices 0 (cons (make-music 'SequentialMusic
803 'elements (reverse! current-sequence))
804 (car current-voices)))
805 (set! current-sequence (list))
806 (set! current-voices (cdr current-voices)))
807 (define (bar-check? m)
808 "Checks whether m is a bar check."
809 (eq? (ly:music-property m 'name) 'BarCheck))
810 (define (music-origin music)
811 "Recursively search an origin location stored in music."
812 (cond ((null? music) #f)
813 ((not (null? (ly:music-property music 'origin)))
814 (ly:music-property music 'origin))
815 (else (or (music-origin (ly:music-property music 'element))
816 (let ((origins (remove not (map music-origin
817 (ly:music-property music 'elements)))))
818 (and (not (null? origins)) (car origins)))))))
819 (while (music-is-of-type? music 'music-wrapper-music)
821 (set! music (ly:music-property wrapper 'element)))
823 (set! (ly:music-property wrapper 'element)
824 (make-music 'SequentialMusic
827 (make-music 'SequentialMusic
830 ;; first, split the music and fill in voices
831 ;; We flatten direct layers of SequentialMusic since they are
832 ;; pretty much impossible to avoid when writing music functions.
833 (let rec ((music music))
834 (for-each (lambda (m)
835 (if (eq? (ly:music-property m 'name) 'SequentialMusic)
839 (if (bar-check? m) (change-voice)))))
840 (ly:music-property music 'elements)))
841 (if (not (null? current-sequence)) (change-voice))
842 ;; un-circularize `voices' and reorder the voices
843 (set! voices (map-in-order (lambda (dummy seqs)
847 ;; set origin location of each sequence in each voice
848 ;; for better type error tracking
849 (for-each (lambda (voice)
850 (for-each (lambda (seq)
851 (set! (ly:music-property seq 'origin)
852 (or (music-origin seq) location)))
856 ;; check sequence length
857 (apply for-each (lambda* (#:rest seqs)
858 (let ((moment-reference (ly:music-length (car seqs))))
859 (for-each (lambda (seq moment)
860 (if (not (equal? moment moment-reference))
861 (ly:music-warning seq
862 "Bars in parallel music don't have the same length")))
863 seqs (map-in-order ly:music-length seqs))))
866 ;; bind voice identifiers to the voices
867 (for-each (lambda (voice-id voice)
868 (ly:parser-define! parser voice-id
869 (let ((v (ly:music-deep-copy original)))
870 (set! (ly:music-property
871 (car (extract-named-music
878 #(define-music-function (parser loc arg) (ly:music?)
879 (_i "Tag @var{arg} to be parenthesized.")
881 (if (memq 'event-chord (ly:music-property arg 'types))
882 ;; arg is an EventChord -> set the parenthesize property
883 ;; on all child notes and rests
886 (if (or (memq 'note-event (ly:music-property ev 'types))
887 (memq 'rest-event (ly:music-property ev 'types)))
888 (set! (ly:music-property ev 'parenthesize) #t)))
889 (ly:music-property arg 'elements))
890 ;; No chord, simply set property for this expression:
891 (set! (ly:music-property arg 'parenthesize) #t))
895 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
896 (_i "Take the music in @var{part1} and @var{part2} and typeset so
897 that they share a staff.")
898 (make-part-combine-music parser
899 (list part1 part2) #f))
902 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
903 (_i "Take the music in @var{part1} and @var{part2} and typeset so
904 that they share a staff with stems directed upward.")
905 (make-part-combine-music parser
906 (list part1 part2) UP))
909 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
910 (_i "Take the music in @var{part1} and @var{part2} and typeset so
911 that they share a staff with stems directed downward.")
912 (make-part-combine-music parser
913 (list part1 part2) DOWN))
916 #(define-music-function (location parser type once) (symbol-or-boolean? boolean?)
917 (_i "Override the part-combiner.")
918 (make-music 'EventChord
919 'elements (list (make-music 'PartCombineForceEvent
922 partcombineApart = \partcombineForce #'apart ##f
923 partcombineApartOnce = \partcombineForce #'apart ##t
924 partcombineChords = \partcombineForce #'chords ##f
925 partcombineChordsOnce = \partcombineForce #'chords ##t
926 partcombineUnisono = \partcombineForce #'unisono ##f
927 partcombineUnisonoOnce = \partcombineForce #'unisono ##t
928 partcombineSoloI = \partcombineForce #'solo1 ##f
929 partcombineSoloIOnce = \partcombineForce #'solo1 ##t
930 partcombineSoloII = \partcombineForce #'solo2 ##f
931 partcombineSoloIIOnce = \partcombineForce #'solo2 ##t
932 partcombineAutomatic = \partcombineForce ##f ##f
933 partcombineAutomaticOnce = \partcombineForce ##f ##t
936 #(define-music-function (parser location dur) (ly:duration?)
937 (_i "Make a partial measure.")
939 ;; We use `descend-to-context' here instead of `context-spec-music' to
940 ;; ensure \partial still works if the Timing_translator is moved
942 (context-spec-music (make-music 'PartialSet
944 'partial-duration dur)
949 #(define-music-function
950 (parser location main-note secondary-note)
951 (ly:music? ly:music?)
952 (_i "Print a trill with @var{main-note} as the main note of the trill and
953 print @var{secondary-note} as a stemless note head in parentheses.")
954 (let* ((get-notes (lambda (ev-chord)
955 (extract-named-music ev-chord 'NoteEvent)))
956 (sec-note-events (get-notes secondary-note))
957 (trill-events (extract-named-music main-note 'TrillSpanEvent)))
958 (if (pair? sec-note-events)
960 (let* ((trill-pitch (ly:music-property (car sec-note-events) 'pitch))
961 (forced (ly:music-property (car sec-note-events) 'force-accidental)))
963 (if (ly:pitch? trill-pitch)
964 (for-each (lambda (m)
965 (ly:music-set-property! m 'pitch trill-pitch)) trill-events)
967 (ly:input-warning location (_ "Second argument of \\pitchedTrill should be single note: "))
968 (display sec-note-events)))
971 (for-each (lambda (m)
972 (ly:music-set-property! m 'force-accidental forced))
977 #(define-music-function (parser location tag more music)
978 (symbol? ly:music? ly:music?)
979 (_i "Add @var{more} to the front of @code{elements} of all music
980 expressions in @var{music} that are tagged with @var{tag}.")
981 (music-map (lambda (m)
982 (if (memq tag (ly:music-property m 'tags))
983 (set! (ly:music-property m 'elements)
984 (cons more (ly:music-property m 'elements))))
989 #(define-music-function (parser location what main-music) (string? ly:music?)
990 (_i "Indicate a section of music to be quoted. @var{what} indicates the name
991 of the quoted voice, as specified in an @code{\\addQuote} command.
992 @var{main-music} is used to indicate the length of music to be quoted;
993 usually contains spacers or multi-measure rests.")
994 (make-music 'QuoteMusic
996 'quoted-music-name what))
999 #(define-music-function (parser location pitch music)
1000 ((ly:pitch? (ly:make-pitch 0 0 0)) ly:music?)
1001 (_i "Make @var{music} relative to @var{pitch} (default @code{c'}).")
1002 (ly:make-music-relative! music pitch)
1003 (make-music 'RelativeOctaveMusic
1007 #(define-music-function (parser location tag music) (symbol? ly:music?)
1008 (_i "Remove elements of @var{music} that are tagged with @var{tag}.")
1011 (let* ((tags (ly:music-property m 'tags))
1012 (res (memq tag tags)))
1016 resetRelativeOctave =
1017 #(define-music-function (parser location pitch) (ly:pitch?)
1018 (_i "Set the octave inside a \\relative section.")
1020 (make-music 'SequentialMusic
1021 'to-relative-callback
1022 (lambda (music last-pitch) pitch)))
1025 #(define-music-function (parser location music)
1027 (_i "Return @var{music} in reverse order.")
1028 (retrograde-music music))
1030 revertTimeSignatureSettings =
1031 #(define-music-function
1032 (parser location time-signature)
1035 (_i "Revert @code{timeSignatureSettings}
1036 for time signatures of @var{time-signature}.")
1037 (revert-time-signature-setting time-signature))
1040 #(define-event-function (parser location finger) (number-or-string?)
1041 (_i "Apply @var{finger} as a fingering indication.")
1046 (if (string? finger) 'text 'digit)
1050 #(define-music-function (parser location fraction music)
1051 (fraction? ly:music?)
1052 (_i "Multiply the duration of events in @var{music} by @var{fraction}.")
1053 (ly:music-compress music
1054 (ly:make-moment (car fraction) (cdr fraction))))
1057 #(define-scheme-function (parser location ctx music)
1058 ((symbol?) ly:music?)
1059 (_i "Take the layout instruction events from @var{music}, optionally
1060 restricted to those applying to context type @var{ctx}, and return
1061 a context modification duplicating their effect.")
1062 (let ((mods (ly:make-context-mod)))
1064 (if (music-is-of-type? m 'layout-instruction-event)
1067 (case (ly:music-property m 'name)
1070 (ly:music-property m 'symbol)
1071 (ly:music-property m 'value)))
1074 (ly:music-property m 'symbol)))
1077 (ly:music-property m 'symbol)
1078 (ly:music-property m 'grob-value)
1080 ((ly:music-property m 'grob-property #f) => list)
1082 (ly:music-property m 'grob-property-path)))))
1085 (ly:music-property m 'symbol)
1087 ((ly:music-property m 'grob-property #f) => list)
1089 (ly:music-property m 'grob-property-path)))))))
1090 (case (ly:music-property m 'name)
1092 (ly:add-context-mod mods
1094 (ly:music-property m 'procedure))))
1095 ((ContextSpeccedMusic)
1097 (eq? ctx (ly:music-property m 'context-type)))
1098 (musicop (ly:music-property m 'element))))
1100 (let ((callback (ly:music-property m 'elements-callback)))
1101 (if (procedure? callback)
1102 (for-each musicop (callback m))))))))
1107 #(define-music-function (parser location offsets item)
1108 (list? symbol-list-or-music?)
1109 (_i "Offset control-points of @var{item} by @var{offsets}. The
1110 argument is a list of number pairs or list of such lists. Each
1111 element of a pair represents an offset to one of the coordinates of a
1112 control-point. If @var{item} is a string, the result is
1113 @code{\\once\\override} for the specified grob type. If @var{item} is
1114 a music expression, the result is the same music expression with an
1115 appropriate tweak applied.")
1116 (define (shape-curve grob)
1117 (let* ((orig (ly:grob-original grob))
1118 (siblings (if (ly:spanner? grob)
1119 (ly:spanner-broken-into orig) '()))
1120 (total-found (length siblings))
1121 (function (assoc-get 'control-points
1122 (reverse (ly:grob-basic-properties grob))))
1123 (coords (function grob)))
1125 (define (offset-control-points offsets)
1129 (lambda (x y) (coord-translate x y))
1132 (define (helper sibs offs)
1134 (if (eq? (car sibs) grob)
1135 (offset-control-points (car offs))
1136 (helper (cdr sibs) (cdr offs)))
1139 ;; we work with lists of lists
1140 (if (or (null? offsets)
1141 (not (list? (car offsets))))
1142 (set! offsets (list offsets)))
1144 (if (>= total-found 2)
1145 (helper siblings offsets)
1146 (offset-control-points (car offsets)))))
1147 (if (ly:music? item)
1149 \tweak #'control-points #shape-curve $item
1152 \once \override $item #'control-points = #shape-curve
1156 #(define-music-function (parser location dur dots arg)
1157 (integer? integer? ly:music?)
1158 (_i "Change the duration of @var{arg} by adding @var{dur} to the
1159 @code{durlog} of @var{arg} and @var{dots} to the @code{dots} of @var{arg}.")
1163 (shift-one-duration-log x dur dots)) arg))
1166 #(define-music-function (parser location overrides music)
1167 (ly:music? ly:music?)
1168 (_i "Convert @var{overrides} to tweaks and apply them to @var{music}.
1169 This does not convert @code{\\revert}, @code{\\set} or @code{\\unset}
1170 and ignores nested overrides.")
1171 (set! (ly:music-property music 'tweaks)
1173 (lambda (m) (eq? (ly:music-property m 'name)
1177 ((ly:music-property m 'grob-property #f) => list)
1179 (ly:music-property m 'grob-property-path)))))
1181 tweaks ;ignore nested properties
1182 (acons (cons (ly:music-property m 'symbol) ;grob name
1183 (car p)) ;grob property
1184 (ly:music-property m 'grob-value)
1186 (ly:music-property music 'tweaks)
1191 #(define-music-function (parser location dur) (ly:duration?)
1192 (_i "Skip forward by @var{dur}.")
1193 (make-music 'SkipMusic
1198 #(def-grace-function startSlashedGraceMusic stopSlashedGraceMusic
1199 (_i "Create slashed graces (slashes through stems, but no slur) from
1200 the following music expression"))
1203 #(define-music-function (parser location parameters) (list?)
1204 (_i "Set the system stretch, by reading the 'system-stretch property of
1205 the `parameters' assoc list.")
1207 \overrideProperty #"Score.NonMusicalPaperColumn"
1208 #'line-break-system-details
1209 #(list (cons 'alignment-extra-space (cdr (assoc 'system-stretch parameters)))
1210 (cons 'system-Y-extent (cdr (assoc 'system-Y-extent parameters))))
1214 #(define-music-function (parser location style heads music)
1215 (symbol? symbol-list-or-symbol? ly:music?)
1216 (_i "Set @var{heads} in @var{music} to @var{style}.")
1217 (style-note-heads heads style music))
1220 #(define-music-function (parser location tag arg) (symbol? ly:music?)
1222 (_i "Add @var{tag} to the @code{tags} property of @var{arg}.")
1225 (ly:music-property arg 'tags)
1227 (ly:music-property arg 'tags)))
1231 #(define-music-function (parser location music)
1233 (_i "Make any @code{\\override} in @var{music} replace an existing
1234 grob property value only temporarily, restoring the old value when a
1235 corresponding @code{\\revert} is executed. This is achieved by
1236 clearing the @samp{pop-first} property normally set on
1239 An @code{\\override}/@/@code{\\revert} sequence created by using
1240 @code{\\temporary} and @code{\\undo} on the same music containing
1241 overrides will cancel out perfectly or cause a@tie{}warning.
1243 Non-property-related music is ignored, warnings are generated for any
1244 property-changing music that isn't an @code{\\override}.")
1248 (and (or (music-is-of-type? m 'layout-instruction-event)
1249 (music-is-of-type? m 'context-specification)
1250 (music-is-of-type? m 'apply-context)
1251 (music-is-of-type? m 'time-signature-music))
1252 (case (ly:music-property m 'name)
1254 (if (ly:music-property m 'pop-first #f)
1255 (set! (ly:music-property m 'pop-first) '()))
1256 (if (ly:music-property m 'once #f)
1257 (set! (ly:music-property m 'once) '()))
1259 ((ContextSpeccedMusic)
1264 (ly:input-warning location (_ "Cannot make ~a revertible")
1265 (ly:music-property m 'name))
1272 #(define-music-function (parser location beat-structure fraction)
1273 ((number-list? '()) fraction?)
1274 (_i "Set @var{fraction} as time signature, with optional
1275 number list @var{beat-structure} before it.")
1276 (make-music 'TimeSignatureMusic
1277 'numerator (car fraction)
1278 'denominator (cdr fraction)
1279 'beat-structure beat-structure))
1282 #(define-music-function (parser location fraction music)
1283 (fraction? ly:music?)
1284 (_i "Scale @var{music} in time by @var{fraction}.")
1285 (make-music 'TimeScaledMusic
1286 'element (ly:music-compress music (ly:make-moment (car fraction) (cdr fraction)))
1287 'numerator (car fraction)
1288 'denominator (cdr fraction)))
1291 #(define-music-function
1292 (parser location from to music)
1293 (ly:pitch? ly:pitch? ly:music?)
1295 (_i "Transpose @var{music} from pitch @var{from} to pitch @var{to}.")
1296 (make-music 'TransposedMusic
1297 'element (ly:music-transpose music (ly:pitch-diff to from))))
1299 transposedCueDuring =
1300 #(define-music-function
1301 (parser location what dir pitch main-music)
1302 (string? ly:dir? ly:pitch? ly:music?)
1304 (_i "Insert notes from the part @var{what} into a voice called @code{cue},
1305 using the transposition defined by @var{pitch}. This happens
1306 simultaneously with @var{main-music}, which is usually a rest. The
1307 argument @var{dir} determines whether the cue notes should be notated
1308 as a first or second voice.")
1310 (make-music 'QuoteMusic
1312 'quoted-context-type 'Voice
1313 'quoted-context-id "cue"
1314 'quoted-music-name what
1315 'quoted-voice-direction dir
1316 'quoted-transposition pitch))
1319 #(define-music-function (parser location pitch) (ly:pitch?)
1320 (_i "Set instrument transposition")
1323 (make-property-set 'instrumentTransposition
1324 (ly:pitch-negate pitch))
1328 #(define-music-function (parser location prop value music)
1329 (symbol-list-or-symbol? scheme? ly:music?)
1330 (_i "Add a tweak to the following @var{music}.
1331 Layout objects created by @var{music} get their property @var{prop}
1332 set to @var{value}. If @var{prop} has the form @samp{Grob.property}, like with
1334 \\tweak Accidental.color #red cis'
1336 an indirectly created grob (@samp{Accidental} is caused by
1337 @samp{NoteHead}) can be tweaked; otherwise only directly created grobs
1340 (set! prop (list prop)))
1341 (if (and (<= 1 (length prop) 2)
1342 (object-property (last prop) 'backend-type?))
1343 (set! (ly:music-property music 'tweaks)
1344 (acons (apply cons* prop)
1346 (ly:music-property music 'tweaks)))
1347 (ly:input-warning location (_ "cannot find property type-check for ~a") prop))
1351 #(define-music-function (parser location music)
1353 (_i "Convert @code{\\override} and @code{\\set} in @var{music} to
1354 @code{\\revert} and @code{\\unset}, respectively. Any reverts and
1355 unsets already in @var{music} cause a warning. Non-property-related music is ignored.")
1362 (lambda (m) (or (music-is-of-type? m 'layout-instruction-event)
1363 (music-is-of-type? m 'context-specification)
1364 (music-is-of-type? m 'apply-context)
1365 (music-is-of-type? m 'time-signature-music)))
1366 (lambda (m overrides)
1367 (case (ly:music-property m 'name)
1370 (make-music 'RevertProperty
1371 'symbol (ly:music-property m 'symbol)
1374 ((ly:music-property m 'grob-property #f) => list)
1376 (ly:music-property m 'grob-property-path))))
1380 (make-music 'PropertyUnset
1381 'symbol (ly:music-property m 'symbol))
1383 ((ContextSpeccedMusic)
1385 (make-music 'ContextSpeccedMusic
1386 'element (loop (ly:music-property m 'element))
1387 'context-type (ly:music-property m 'context-type))
1392 (ly:input-warning location (_ "Cannot revert ~a")
1393 (ly:music-property m 'name))
1399 ((null? lst) (make-music 'Music))
1400 ((null? (cdr lst)) (car lst))
1401 (else (make-sequential-music lst))))))
1404 #(define-music-function (parser location music) (ly:music?)
1405 (_i "Force any @code{\\repeat volta}, @code{\\repeat tremolo} or
1406 @code{\\repeat percent} commands in @var{music} to be interpreted
1407 as @code{\\repeat unfold}.")
1408 (unfold-repeats music))
1411 #(define-void-function (parser location arg) (scheme?)
1412 (_i "Accept a scheme argument, return a void expression.
1413 Use this if you want to have a scheme expression evaluated
1414 because of its side-effects, but its value ignored."))
1417 #(define-music-function (parser location sym val music)
1418 (symbol? scheme? ly:music?)
1419 (_i "Set @var{sym} to @var{val} in @var{music}.")
1421 (set! (ly:music-property music sym) val)