]> git.donarmstrong.com Git - lilypond.git/blob - ly/music-functions-init.ly
Let \parallelMusic deal with barchecks at arbitrary depth
[lilypond.git] / ly / music-functions-init.ly
1 %%%% -*- Mode: Scheme -*-
2
3 %%%% This file is part of LilyPond, the GNU music typesetter.
4 %%%%
5 %%%% Copyright (C) 2003--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 %%%%                          Jan Nieuwenhuizen <janneke@gnu.org>
7 %%%%
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.
12 %%%%
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.
17 %%%%
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/>.
20
21 \version "2.17.6"
22
23
24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25 %% this file is alphabetically sorted.
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27
28 %% need SRFI-1 for filter; optargs for lambda*
29 #(use-modules (srfi srfi-1)
30               (ice-9 optargs))
31
32 %% TODO: using define-music-function in a .scm causes crash.
33
34 acciaccatura =
35 #(def-grace-function startAcciaccaturaMusic stopAcciaccaturaMusic
36    (_i "Create an acciaccatura from the following music expression"))
37
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)))
45
46 addQuote =
47 #(define-void-function (parser location name music) (string? ly:music?)
48    (_i "Define @var{music} as a quotable music expression named
49 @var{name}")
50    (add-quotable parser name music))
51
52 %% keep these two together
53 afterGraceFraction = #(cons 6 8)
54 afterGrace =
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
60       (list
61        main
62        (make-sequential-music
63         (list
64
65          (make-music 'SkipMusic
66                      'duration (ly:make-duration
67                                 0 0
68                                 (* (ly:moment-main-numerator main-length)
69                                    (car fraction))
70                                 (* (ly:moment-main-denominator main-length)
71                                    (cdr fraction))))
72          (make-music 'GraceMusic
73                      'element grace)))))))
74
75
76 %% music identifiers not allowed at top-level,
77 %% so this is a music-function instead.
78 allowPageTurn =
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
83                'page-marker #t
84                'page-turn-permission 'allow
85                'elements (list (make-music 'PageTurnEvent
86                                            'break-permission 'allow))))
87
88 alterBroken =
89 #(define-music-function (parser location property arg item)
90   (symbol-list-or-symbol? list? symbol-list-or-music?)
91   (_i "Override @var{property} for pieces of broken spanner @var{item}
92 with values @var{arg}.  @var{item} may either be music in the form of
93 a starting spanner event, or a symbol list in the form
94 @samp{Context.Grob} or just @samp{Grob}.  Iff @var{item} is in the
95 form of a spanner event, @var{property} may also have the form
96 @samp{Grob.property} for specifying a directed tweak.")
97   (if (ly:music? item)
98       (if (eq? (ly:music-property item 'span-direction) START)
99           #{ \tweak #property #(value-for-spanner-piece arg) #item #}
100           (begin
101             (ly:music-warning item (_ "not a spanner"))
102             item))
103       (let* ((p (check-grob-path item parser location
104                                  #:default 'Bottom
105                                  #:min 2
106                                  #:max 2))
107              (name (and p (second p)))
108              (description
109               (and name (assoc-get name all-grob-descriptions))))
110         (if (and description
111                  (member 'spanner-interface
112                          (assoc-get 'interfaces
113                                     (assoc-get 'meta description))))
114             #{
115               \override #item . #property =
116               #(value-for-spanner-piece arg)
117             #}
118             (begin
119               (ly:input-warning location (_ "not a spanner name, `~a'") name)
120               (make-music 'Music))))))
121
122 appendToTag =
123 #(define-music-function (parser location tag more music)
124    (symbol? ly:music? ly:music?)
125    (_i "Append @var{more} to the @code{elements} of all music
126 expressions in @var{music} that are tagged with @var{tag}.")
127    (music-map (lambda (m)
128                 (if (memq tag (ly:music-property m 'tags))
129                     (set! (ly:music-property m 'elements)
130                           (append (ly:music-property m 'elements)
131                                   (list more))))
132                 m)
133               music))
134
135 applyContext =
136 #(define-music-function (parser location proc) (procedure?)
137    (_i "Modify context properties with Scheme procedure @var{proc}.")
138    (make-music 'ApplyContext
139                'procedure proc))
140
141 applyMusic =
142 #(define-music-function (parser location func music) (procedure? ly:music?)
143    (_i"Apply procedure @var{func} to @var{music}.")
144    (func music))
145
146 applyOutput =
147 #(define-music-function (parser location ctx proc) (symbol? procedure?)
148    (_i "Apply function @code{proc} to every layout object in context @code{ctx}")
149    (make-music 'ApplyOutputEvent
150                'procedure proc
151                'context-type ctx))
152
153 appoggiatura =
154 #(def-grace-function startAppoggiaturaMusic stopAppoggiaturaMusic
155    (_i "Create an appoggiatura from @var{music}"))
156
157 % for regression testing purposes.
158 assertBeamQuant =
159 #(define-music-function (parser location l r) (pair? pair?)
160    (_i "Testing function: check whether the beam quants @var{l} and @var{r} are correct")
161    (make-grob-property-override 'Beam 'positions (check-quant-callbacks l r)))
162
163 % for regression testing purposes.
164 assertBeamSlope =
165 #(define-music-function (parser location comp) (procedure?)
166    (_i "Testing function: check whether the slope of the beam is the same as @code{comp}")
167    (make-grob-property-override 'Beam 'positions (check-slope-callbacks comp)))
168
169 autochange =
170 #(define-music-function (parser location music) (ly:music?)
171    (_i "Make voices that switch between staves automatically")
172    (make-autochange-music parser music))
173
174
175
176 balloonGrobText =
177 #(define-music-function (parser location grob-name offset text)
178    (symbol? number-pair? markup?)
179    (_i "Attach @var{text} to @var{grob-name} at offset @var{offset}
180  (use like @code{\\once})")
181    (make-music 'AnnotateOutputEvent
182                'symbol grob-name
183                'X-offset (car offset)
184                'Y-offset (cdr offset)
185                'text text))
186
187 balloonText =
188 #(define-music-function (parser location offset text) (number-pair? markup?)
189    (_i "Attach @var{text} at @var{offset} (use like @code{\\tweak})")
190    (make-music 'AnnotateOutputEvent
191                'X-offset (car offset)
192                'Y-offset (cdr offset)
193                'text text))
194
195 bar =
196 #(define-music-function (parser location type) (string?)
197    (_i "Insert a bar line of type @var{type}")
198    (context-spec-music
199     (make-property-set 'whichBar type)
200     'Timing))
201
202 barNumberCheck =
203 #(define-music-function (parser location n) (integer?)
204    (_i "Print a warning if the current bar number is not @var{n}.")
205    (make-music 'ApplyContext
206                'procedure
207                (lambda (c)
208                  (let ((cbn (ly:context-property c 'currentBarNumber)))
209                    (if (and  (number? cbn) (not (= cbn n)))
210                        (ly:input-warning location
211                                          "Barcheck failed got ~a expect ~a"
212                                          cbn n))))))
213
214 bendAfter =
215 #(define-event-function (parser location delta) (real?)
216    (_i "Create a fall or doit of pitch interval @var{delta}.")
217    (make-music 'BendAfterEvent
218                'delta-step delta))
219
220 bookOutputName =
221 #(define-void-function (parser location newfilename) (string?)
222    (_i "Direct output for the current book block to @var{newfilename}.")
223    (set! (paper-variable parser #f 'output-filename) newfilename))
224
225 bookOutputSuffix =
226 #(define-void-function (parser location newsuffix) (string?)
227    (_i "Set the output filename suffix for the current book block to
228 @var{newsuffix}.")
229    (set! (paper-variable parser #f 'output-suffix) newsuffix))
230
231 %% \breathe is defined as a music function rather than an event identifier to
232 %% ensure it gets useful input location information: as an event identifier,
233 %% it would have to be wrapped in an EventChord to prevent it from being
234 %% treated as a post_event by the parser
235 breathe =
236 #(define-music-function (parser location) ()
237    (_i "Insert a breath mark.")
238    (make-music 'BreathingEvent))
239
240 clef =
241 #(define-music-function (parser location type) (string?)
242    (_i "Set the current clef to @var{type}.")
243    (make-clef-set type))
244
245
246 compoundMeter =
247 #(define-music-function (parser location args) (pair?)
248   (_i "Create compound time signatures. The argument is a Scheme list of
249 lists. Each list describes one fraction, with the last entry being the
250 denominator, while the first entries describe the summands in the
251 enumerator. If the time signature consists of just one fraction,
252 the list can be given directly, i.e. not as a list containing a single list.
253 For example, a time signature of (3+1)/8 + 2/4 would be created as
254 @code{\\compoundMeter #'((3 1 8) (2 4))}, and a time signature of (3+2)/8
255 as @code{\\compoundMeter #'((3 2 8))} or shorter
256 @code{\\compoundMeter #'(3 2 8)}.")
257   (let* ((mlen (calculate-compound-measure-length args))
258          (beat (calculate-compound-base-beat args))
259          (beatGrouping (calculate-compound-beat-grouping args))
260          (timesig (cons (ly:moment-main-numerator mlen)
261                         (ly:moment-main-denominator mlen))))
262   #{
263     \once \override Staff.TimeSignature.stencil = #(lambda (grob)
264       (grob-interpret-markup grob (format-compound-time args)))
265     \set Timing.timeSignatureFraction = #timesig
266     \set Timing.baseMoment = #beat
267     \set Timing.beatStructure = #beatGrouping
268     \set Timing.beamExceptions = #'()
269     \set Timing.measureLength = #mlen
270   #} ))
271
272 crossStaff =
273 #(define-music-function (parser location notes) (ly:music?)
274   (_i "Create cross-staff stems")
275   #{
276   \temporary \override Stem.cross-staff = #cross-staff-connect
277   \temporary \override Flag.style = #'no-flag
278   #notes
279   \revert Stem.cross-staff
280   \revert Flag.style
281 #})
282
283 cueClef =
284 #(define-music-function (parser location type) (string?)
285   (_i "Set the current cue clef to @var{type}.")
286   (make-cue-clef-set type))
287
288 cueClefUnset =
289 #(define-music-function (parser location) ()
290   (_i "Unset the current cue clef.")
291   (make-cue-clef-unset))
292
293 cueDuring =
294 #(define-music-function
295    (parser location what dir main-music) (string? ly:dir? ly:music?)
296    (_i "Insert contents of quote @var{what} corresponding to @var{main-music},
297 in a CueVoice oriented by @var{dir}.")
298    (make-music 'QuoteMusic
299                'element main-music
300                'quoted-context-type 'Voice
301                'quoted-context-id "cue"
302                'quoted-music-name what
303                'quoted-voice-direction dir))
304
305 cueDuringWithClef =
306 #(define-music-function
307    (parser location what dir clef main-music) (string? ly:dir? string? ly:music?)
308    (_i "Insert contents of quote @var{what} corresponding to @var{main-music},
309 in a CueVoice oriented by @var{dir}.")
310    (make-music 'QuoteMusic
311                'element main-music
312                'quoted-context-type 'Voice
313                'quoted-context-id "cue"
314                'quoted-music-name what
315                'quoted-music-clef clef
316                'quoted-voice-direction dir))
317
318
319
320 displayLilyMusic =
321 #(define-music-function (parser location music) (ly:music?)
322    (_i "Display the LilyPond input representation of @var{music}
323 to the console.")
324    (newline)
325    (display-lily-music music parser)
326    music)
327
328 displayMusic =
329 #(define-music-function (parser location music) (ly:music?)
330    (_i "Display the internal representation of @var{music} to the console.")
331    (newline)
332    (display-scheme-music music)
333    music)
334
335
336
337 endSpanners =
338 #(define-music-function (parser location music) (ly:music?)
339    (_i "Terminate the next spanner prematurely after exactly one note
340 without the need of a specific end spanner.")
341    (let* ((start-span-evs (filter (lambda (ev)
342                                     (equal? (ly:music-property ev 'span-direction)
343                                             START))
344                                   (extract-typed-music music 'span-event)))
345           (stop-span-evs
346            (map (lambda (m)
347                   (music-clone m 'span-direction STOP))
348                 start-span-evs))
349           (end-ev-chord (make-music 'EventChord
350                                     'elements stop-span-evs))
351           (total (make-music 'SequentialMusic
352                              'elements (list music
353                                              end-ev-chord))))
354      total))
355
356 eventChords =
357 #(define-music-function (parser location music) (ly:music?)
358    (_i "Compatibility function wrapping @code{EventChord} around
359 isolated rhythmic events occuring since version 2.15.28, after
360 expanding repeat chords @samp{q}.")
361    (event-chord-wrap! music parser))
362
363 featherDurations=
364 #(define-music-function (parser location factor argument) (ly:moment? ly:music?)
365    (_i "Adjust durations of music in @var{argument} by rational @var{factor}.")
366    (let ((orig-duration (ly:music-length argument))
367          (multiplier (ly:make-moment 1 1)))
368
369      (for-each
370       (lambda (mus)
371         (if (< 0 (ly:moment-main-denominator (ly:music-length mus)))
372             (begin
373               (ly:music-compress mus multiplier)
374               (set! multiplier (ly:moment-mul factor multiplier)))))
375       (extract-named-music argument '(EventChord NoteEvent RestEvent SkipEvent)))
376      (ly:music-compress
377       argument
378       (ly:moment-div orig-duration (ly:music-length argument)))
379
380      argument))
381
382 footnote =
383 #(define-music-function (parser location mark offset footnote item)
384    ((markup?) number-pair? markup? symbol-list-or-music?)
385    (_i "Make the markup @var{footnote} a footnote on @var{item}.  The
386 footnote is marked with a markup @var{mark} moved by @var{offset} with
387 respect to the marked music.
388
389 If @var{mark} is not given or specified as @var{\\default}, it is
390 replaced by an automatically generated sequence number.  If @var{item}
391 is a symbol list of form @samp{Grob} or @samp{Context.Grob}, then
392 grobs of that type will be marked at the current time step in the
393 given context (default @code{Bottom}).
394
395 If @var{item} is music, the music will get a footnote attached to a
396 grob immediately attached to the event, like @var{\\tweak} does.  For
397 attaching a footnote to an @emph{indirectly} caused grob, write
398 @code{\\single\\footnote}, use @var{item} to specify the grob, and
399 follow it with the music to annotate.
400
401 Like with @code{\\tweak}, if you use a footnote on a following
402 post-event, the @code{\\footnote} command itself needs to be attached
403 to the preceding note or rest as a post-event with @code{-}.")
404    (let ((mus (make-music
405                'FootnoteEvent
406                'X-offset (car offset)
407                'Y-offset (cdr offset)
408                'automatically-numbered (not mark)
409                'text (or mark (make-null-markup))
410                'footnote-text footnote)))
411      #{ \tweak footnote-music #mus #item #}))
412
413 grace =
414 #(def-grace-function startGraceMusic stopGraceMusic
415    (_i "Insert @var{music} as grace notes."))
416
417 grobdescriptions =
418 #(define-scheme-function (parser location descriptions) (list?)
419    (_i "Create a context modification from @var{descriptions}, a list
420 in the format of @code{all-grob-descriptions}.")
421    (ly:make-context-mod
422     (map (lambda (p)
423            (list 'assign (car p) (list (cdr p))))
424          descriptions)))
425
426 harmonicByFret = #(define-music-function (parser location fret music) (number? ly:music?)
427   (_i "Convert @var{music} into mixed harmonics; the resulting notes resemble
428 harmonics played on a fretted instrument by touching the strings at @var{fret}.")
429   #{
430     \set harmonicDots = ##t
431     \temporary \override TabNoteHead.stencil = #(tab-note-head::print-custom-fret-label (number->string fret))
432     \temporary \override NoteHead.Y-extent = #(ly:make-unpure-pure-container ly:grob::stencil-height
433                                        (lambda (grob start end)
434                                                (ly:grob::stencil-height grob)))
435     \temporary \override NoteHead.stencil = #(lambda (grob) (ly:grob-set-property! grob 'style 'harmonic-mixed)
436                                             (ly:note-head::print grob))
437     #(make-harmonic
438        (calc-harmonic-pitch (fret->pitch (number->string fret)) music))
439     \unset harmonicDots
440     \revert TabNoteHead.stencil
441     \revert NoteHead.Y-extent
442     \revert NoteHead.stencil
443   #})
444
445 harmonicByRatio = #(define-music-function (parser location ratio music) (number? ly:music?)
446     (_i "Convert @var{music} into mixed harmonics; the resulting notes resemble
447 harmonics played on a fretted instrument by touching the strings at the point
448 given through @var{ratio}.")
449   #{
450     \set harmonicDots = ##t
451     \temporary \override TabNoteHead.stencil = #(tab-note-head::print-custom-fret-label (ratio->fret ratio))
452     \temporary \override NoteHead.Y-extent = #(ly:make-unpure-pure-container ly:grob::stencil-height
453                                        (lambda (grob start end)
454                                                (ly:grob::stencil-height grob)))
455     \temporary \override NoteHead.stencil = #(lambda (grob) (ly:grob-set-property! grob 'style 'harmonic-mixed)
456                                             (ly:note-head::print grob))
457     #(make-harmonic
458       (calc-harmonic-pitch (ratio->pitch ratio) music))
459     \unset harmonicDots
460     \revert TabNoteHead.stencil
461     \revert NoteHead.Y-extent
462     \revert NoteHead.stencil
463   #})
464
465 hide =
466 #(define-music-function (parser location item) (symbol-list-or-music?)
467    (_i "Set @var{item}'s @samp{transparent} property to @code{#t},
468 making it invisible while still retaining its dimensions.
469
470 If @var{item} is a symbol list of form @code{GrobName} or
471 @code{Context.GrobName}, the result is an override for the grob name
472 specified by it.  If @var{item} is a music expression, the result is
473 the same music expression with an appropriate tweak applied to it.")
474    (if (ly:music? item)
475        #{ \tweak transparent ##t #item #}
476        #{ \override #item . transparent = ##t #}))
477
478 inStaffSegno =
479 #(define-music-function (parser location) ()
480    (_i "Put the segno variant 'varsegno' at this position into the staff,
481 compatible with the repeat command.")
482    (make-music 'ApplyContext
483                'procedure
484                (lambda (ctx)
485                  (let ((score-ctx (ly:context-find ctx 'Score)))
486                    (if (ly:context? score-ctx)
487                      (let ((old-rc (ly:context-property score-ctx 'repeatCommands '())))
488                        (if (eq? (memq 'segno-display old-rc) #f)
489                          (ly:context-set-property! score-ctx 'repeatCommands (cons 'segno-display old-rc)))))))))
490
491 instrumentSwitch =
492 #(define-music-function
493    (parser location name) (string?)
494    (_i "Switch instrument to @var{name}, which must be predefined with
495 @code{\\addInstrumentDefinition}.")
496    (let* ((handle (assoc name instrument-definitions))
497           (instrument-def (if handle (cdr handle) '())))
498
499      (if (not handle)
500          (ly:input-warning location "No such instrument: ~a" name))
501      (context-spec-music
502       (make-music 'SimultaneousMusic
503                   'elements
504                   (map (lambda (kv)
505                          (make-property-set
506                           (car kv)
507                           (cdr kv)))
508                        instrument-def))
509       'Staff)))
510
511
512
513 keepWithTag =
514 #(define-music-function (parser location tag music)
515    (symbol-list-or-symbol? ly:music?)
516    (_i "Include only elements of @var{music} that are either untagged
517 or tagged with one of the tags in @var{tag}.  @var{tag} may be either
518 a single symbol or a list of symbols.")
519    (music-filter
520     (if (symbol? tag)
521         (lambda (m)
522           (let ((music-tags (ly:music-property m 'tags)))
523             (or (null? music-tags)
524                 (memq tag music-tags))))
525         (lambda (m)
526           (let ((music-tags (ly:music-property m 'tags)))
527             (or (null? music-tags)
528                 (any (lambda (t) (memq t music-tags)) tag)))))
529     music))
530
531 key =
532 #(define-music-function (parser location tonic pitch-alist)
533    ((ly:pitch? '()) (list? '()))
534    (_i "Set key to @var{tonic} and scale @var{pitch-alist}.
535 If both are null, just generate @code{KeyChangeEvent}.")
536    (cond ((null? tonic) (make-music 'KeyChangeEvent))
537          ((null? pitch-alist)
538           (ly:parser-error parser (_ "second argument must be pitch list")
539                            location)
540           (make-music 'SequentialMusic 'void #t))
541          (else
542           (ly:music-transpose
543            (make-music 'KeyChangeEvent
544                 'tonic (ly:make-pitch 0 0 0)
545                 'pitch-alist pitch-alist)
546            tonic))))
547
548 killCues =
549 #(define-music-function (parser location music) (ly:music?)
550    (_i "Remove cue notes from @var{music}.")
551    (music-map
552     (lambda (mus)
553       (if (and (string? (ly:music-property mus 'quoted-music-name))
554                (string=? (ly:music-property mus 'quoted-context-id "") "cue"))
555           (ly:music-property mus 'element)
556           mus))
557     music))
558
559
560
561 label =
562 #(define-music-function (parser location label) (symbol?)
563    (_i "Create @var{label} as a bookmarking label.")
564    (make-music 'EventChord
565                'page-marker #t
566                'page-label label
567                'elements (list (make-music 'LabelEvent
568                                            'page-label label))))
569
570
571 language =
572 #(define-void-function (parser location language) (string?)
573    (_i "Set note names for language @var{language}.")
574    (note-names-language parser language))
575
576 languageSaveAndChange =
577 #(define-void-function (parser location language) (string?)
578   (_i "Store the previous pitchnames alist, and set a new one.")
579   (set! previous-pitchnames pitchnames)
580   (note-names-language parser language))
581
582 languageRestore =
583 #(define-void-function (parser location) ()
584    (_i "Restore a previously-saved pitchnames alist.")
585    (if previous-pitchnames
586        (begin
587         (set! pitchnames previous-pitchnames)
588         (ly:parser-set-note-names parser pitchnames))
589       (ly:input-warning location (_ "No other language was defined previously. Ignoring."))))
590
591
592 makeClusters =
593 #(define-music-function (parser location arg) (ly:music?)
594    (_i "Display chords in @var{arg} as clusters.")
595    (music-map note-to-cluster arg))
596
597 modalInversion =
598 #(define-music-function (parser location around to scale music)
599     (ly:pitch? ly:pitch? ly:music? ly:music?)
600     (_i "Invert @var{music} about @var{around} using @var{scale} and
601 transpose from @var{around} to @var{to}.")
602     (let ((inverter (make-modal-inverter around to scale)))
603       (change-pitches music inverter)
604       music))
605
606 modalTranspose =
607 #(define-music-function (parser location from to scale music)
608     (ly:pitch? ly:pitch? ly:music? ly:music?)
609     (_i "Transpose @var{music} from pitch @var{from} to pitch @var{to}
610 using @var{scale}.")
611     (let ((transposer (make-modal-transposer from to scale)))
612       (change-pitches music transposer)
613       music))
614
615 inversion =
616 #(define-music-function
617    (parser location around to music) (ly:pitch? ly:pitch? ly:music?)
618    (_i "Invert @var{music} about @var{around} and
619 transpose from @var{around} to @var{to}.")
620    (music-invert around to music))
621
622 mark =
623 #(define-music-function
624    (parser location label) ((scheme? '()))
625   "Make the music for the \\mark command."
626   (let* ((set (and (integer? label)
627                    (context-spec-music (make-property-set 'rehearsalMark label)
628                                       'Score)))
629          (ev (make-music 'MarkEvent
630                          'origin location)))
631
632     (if set
633         (make-sequential-music (list set ev))
634         (begin
635           (set! (ly:music-property ev 'label) label)
636           ev))))
637
638 musicMap =
639 #(define-music-function (parser location proc mus) (procedure? ly:music?)
640    (_i "Apply @var{proc} to @var{mus} and all of the music it contains.")
641    (music-map proc mus))
642
643 %% noPageBreak and noPageTurn are music functions (not music indentifiers),
644 %% because music identifiers are not allowed at top-level.
645 noPageBreak =
646 #(define-music-function (location parser) ()
647    (_i "Forbid a page break.  May be used at toplevel (i.e., between scores or
648 markups), or inside a score.")
649    (make-music 'EventChord
650                'page-marker #t
651                'page-break-permission 'forbid
652                'elements (list (make-music 'PageBreakEvent
653                                            'break-permission '()))))
654
655 noPageTurn =
656 #(define-music-function (location parser) ()
657    (_i "Forbid a page turn.  May be used at toplevel (i.e., between scores or
658 markups), or inside a score.")
659    (make-music 'EventChord
660                'page-marker #t
661                'page-turn-permission 'forbid
662                'elements (list (make-music 'PageTurnEvent
663                                            'break-permission '()))))
664
665
666
667 octaveCheck =
668 #(define-music-function (parser location pitch) (ly:pitch?)
669    (_i "Octave check.")
670    (make-music 'RelativeOctaveCheck
671                'pitch pitch))
672
673 omit =
674 #(define-music-function (parser location item) (symbol-list-or-music?)
675    (_i "Set @var{item}'s @samp{stencil} property to @code{#f},
676 effectively omitting it without taking up space.
677
678 If @var{item} is a symbol list of form @code{GrobName} or
679 @code{Context.GrobName}, the result is an override for the grob name
680 specified by it.  If @var{item} is a music expression, the result is
681 the same music expression with an appropriate tweak applied to it.")
682    (if (ly:music? item)
683        #{ \tweak stencil ##f #item #}
684        #{ \override #item . stencil = ##f #}))
685
686 once =
687 #(define-music-function (parser location music) (ly:music?)
688    (_i "Set @code{once} to @code{#t} on all layout instruction events in @var{music}.")
689    (music-map
690     (lambda (m)
691       (cond ((music-is-of-type? m 'layout-instruction-event)
692              (set! (ly:music-property m 'once) #t))
693             ((ly:duration? (ly:music-property m 'duration))
694              (ly:music-warning m (_ "Cannot apply \\once to timed music"))))
695       m)
696     music))
697
698 ottava =
699 #(define-music-function (parser location octave) (integer?)
700    (_i "Set the octavation.")
701    (make-music 'OttavaMusic
702                'ottava-number octave))
703
704 overrideTimeSignatureSettings =
705 #(define-music-function
706    (parser location time-signature base-moment beat-structure beam-exceptions)
707    (pair? pair? cheap-list? cheap-list?)
708
709    (_i "Override @code{timeSignatureSettings}
710 for time signatures of @var{time-signature} to have settings
711 of @var{base-moment}, @var{beat-structure}, and @var{beam-exceptions}.")
712
713    ;; TODO -- add warning if largest value of grouping is
714    ;;       greater than time-signature.
715   (let ((setting (make-setting base-moment beat-structure beam-exceptions)))
716     (override-time-signature-setting time-signature setting)))
717
718 overrideProperty =
719 #(define-music-function (parser location grob-property-path value)
720    (symbol-list? scheme?)
721
722    (_i "Set the grob property specified by @var{grob-property-path} to
723 @var{value}.  @var{grob-property-path} is a symbol list of the form
724 @code{Context.GrobName.property} or @code{GrobName.property}, possibly
725 with subproperties given as well.")
726    (let ((p (check-grob-path grob-property-path parser location
727                              #:default 'Bottom
728                              #:min 3)))
729      (if p
730          (make-music 'ApplyOutputEvent
731                      'context-type (first p)
732                      'procedure
733                      (lambda (grob orig-context context)
734                        (if (equal?
735                             (cdr (assoc 'name (ly:grob-property grob 'meta)))
736                             (second p))
737                            (ly:grob-set-nested-property!
738                             grob (cddr p) value))))
739          (make-music 'Music))))
740
741
742
743
744
745
746 %% pageBreak and pageTurn are music functions (iso music indentifiers),
747 %% because music identifiers are not allowed at top-level.
748 pageBreak =
749 #(define-music-function (location parser) ()
750    (_i "Force a page break.  May be used at toplevel (i.e., between scores or
751 markups), or inside a score.")
752    (make-music 'EventChord
753                'page-marker #t
754                'line-break-permission 'force
755                'page-break-permission 'force
756                'elements (list (make-music 'LineBreakEvent
757                                            'break-permission 'force)
758                                (make-music 'PageBreakEvent
759                                            'break-permission 'force))))
760
761 pageTurn =
762 #(define-music-function (location parser) ()
763    (_i "Force a page turn between two scores or top-level markups.")
764    (make-music 'EventChord
765                'page-marker #t
766                'line-break-permission 'force
767                'page-break-permission 'force
768                'page-turn-permission 'force
769                'elements (list (make-music 'LineBreakEvent
770                                            'break-permission 'force)
771                                (make-music 'PageBreakEvent
772                                            'break-permission 'force)
773                                (make-music 'PageTurnEvent
774                                            'break-permission 'force))))
775
776 parallelMusic =
777 #(define-void-function (parser location voice-ids music) (list? ly:music?)
778    (_i "Define parallel music sequences, separated by '|' (bar check signs),
779 and assign them to the identifiers provided in @var{voice-ids}.
780
781 @var{voice-ids}: a list of music identifiers (symbols containing only letters)
782
783 @var{music}: a music sequence, containing BarChecks as limiting expressions.
784
785 Example:
786
787 @verbatim
788   \\parallelMusic #'(A B C) {
789     c c | d d | e e |
790     d d | e e | f f |
791   }
792 <==>
793   A = { c c | d d | }
794   B = { d d | e e | }
795   C = { e e | f f | }
796 @end verbatim
797 ")
798    (define (bar-check? m)
799      "Checks whether m is a bar check."
800      (eq? (ly:music-property m 'name) 'BarCheck))
801    (define (recurse-and-split music)
802      "This returns either a list of music split along barchecks, or
803 @code{#f}."
804      (let ((elt (ly:music-property music 'element))
805            (elts (ly:music-property music 'elements)))
806        (cond ((ly:music? elt)
807               (let ((lst (recurse-and-split elt)))
808                 (and lst
809                      (map
810                       (lambda (x)
811                         (let ((res (music-clone music 'element x)))
812                           (if (ly:input-location?
813                                (ly:music-property x 'origin))
814                               (set! (ly:music-property res 'origin)
815                                     (ly:music-property x 'origin)))
816                           res))
817                       lst))))
818              ((any bar-check? elts)
819               (let* ((voices (apply circular-list
820                                     (make-list (length voice-ids)
821                                                '())))
822                      (current-voices voices)
823                      (current-sequence '()))
824                 ;;
825                 ;; utilities
826                 (define (push-music m)
827                   "Push the music expression into the current sequence"
828                   (set! current-sequence (cons m current-sequence)))
829                 (define (change-voice)
830                   "Stores the previously built sequence into the current voice and
831        change to the following voice."
832                   (set-car! current-voices
833                             (cons (reverse! current-sequence)
834                                   (car current-voices)))
835                   (set! current-sequence '())
836                   (set! current-voices (cdr current-voices)))
837                 (for-each (lambda (m)
838                             (let ((split? (recurse-and-split m)))
839                               (if split?
840                                   (for-each
841                                    (lambda (m)
842                                      (push-music m)
843                                      (change-voice))
844                                    split?)
845                                   (begin
846                                     (push-music m)
847                                     (if (bar-check? m) (change-voice))))))
848                           elts)
849                 (if (pair? current-sequence) (change-voice))
850                 ;; un-circularize `voices' and reorder the voices
851
852                 (set! voices (map reverse!
853                                   (list-head voices (length voice-ids))))
854
855                 ;; check sequence length
856                 (apply for-each (lambda seqs
857                                   (define (seq-len seq)
858                                     (reduce ly:moment-add
859                                             (ly:make-moment 0)
860                                             (map ly:music-length seq)))
861                                   (let ((moment-reference (seq-len (car seqs))))
862                                     (for-each (lambda (seq)
863                                                 (if (not (equal? (seq-len seq)
864                                                                  moment-reference))
865                                                     (ly:music-warning
866                                                      (if (pair? seq)
867                                                          (last seq)
868                                                          (caar seqs))
869                                                      (_ "Bars in parallel music don't have the same length"))))
870                                               seqs)))
871                        voices)
872                 (map
873                  (lambda (lst)
874                    (set! lst (concatenate! lst))
875                    (let ((res (music-clone music 'elements lst)))
876                      (if (and (pair? lst)
877                               (ly:input-location? (ly:music-property
878                                                    (car lst)
879                                                    'origin)))
880                          (set! (ly:music-property res 'origin)
881                                (ly:music-property (car lst) 'origin)))
882                      res))
883                  voices)))
884              (else #f))))
885    (let ((voices (recurse-and-split music)))
886      (if voices
887          ;;
888          ;; bind voice identifiers to the voices
889          (for-each (lambda (voice-id voice)
890                      (ly:parser-define! parser voice-id voice))
891           voice-ids voices)
892          (ly:music-warning music
893                            (_ "ignoring parallel music without barchecks")))))
894
895 parenthesize =
896 #(define-music-function (parser loc arg) (ly:music?)
897    (_i "Tag @var{arg} to be parenthesized.")
898
899    (if (memq 'event-chord (ly:music-property arg 'types))
900        ;; arg is an EventChord -> set the parenthesize property
901        ;; on all child notes and rests
902        (for-each
903         (lambda (ev)
904           (if (or (memq 'note-event (ly:music-property ev 'types))
905                   (memq 'rest-event (ly:music-property ev 'types)))
906               (set! (ly:music-property ev 'parenthesize) #t)))
907         (ly:music-property arg 'elements))
908        ;; No chord, simply set property for this expression:
909        (set! (ly:music-property arg 'parenthesize) #t))
910    arg)
911
912 partcombine =
913 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
914    (_i "Take the music in @var{part1} and @var{part2} and typeset so
915 that they share a staff.")
916    (make-part-combine-music parser
917                             (list part1 part2) #f))
918
919 partcombineUp =
920 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
921    (_i "Take the music in @var{part1} and @var{part2} and typeset so
922 that they share a staff with stems directed upward.")
923    (make-part-combine-music parser
924                             (list part1 part2) UP))
925
926 partcombineDown =
927 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
928    (_i "Take the music in @var{part1} and @var{part2} and typeset so
929 that they share a staff with stems directed downward.")
930    (make-part-combine-music parser
931                             (list part1 part2) DOWN))
932
933 partcombineForce =
934 #(define-music-function (location parser type once) (symbol-or-boolean? boolean?)
935    (_i "Override the part-combiner.")
936    (make-music 'EventChord
937                'elements (list (make-music 'PartCombineForceEvent
938                                            'forced-type type
939                                            'once once))))
940 partcombineApart = \partcombineForce #'apart ##f
941 partcombineApartOnce = \partcombineForce #'apart ##t
942 partcombineChords = \partcombineForce #'chords ##f
943 partcombineChordsOnce = \partcombineForce #'chords ##t
944 partcombineUnisono = \partcombineForce #'unisono ##f
945 partcombineUnisonoOnce = \partcombineForce #'unisono ##t
946 partcombineSoloI = \partcombineForce #'solo1 ##f
947 partcombineSoloIOnce = \partcombineForce #'solo1 ##t
948 partcombineSoloII = \partcombineForce #'solo2 ##f
949 partcombineSoloIIOnce = \partcombineForce #'solo2 ##t
950 partcombineAutomatic = \partcombineForce ##f ##f
951 partcombineAutomaticOnce = \partcombineForce ##f ##t
952
953 partial =
954 #(define-music-function (parser location dur) (ly:duration?)
955   (_i "Make a partial measure.")
956
957   ;; We use `descend-to-context' here instead of `context-spec-music' to
958   ;; ensure \partial still works if the Timing_translator is moved
959     (descend-to-context
960      (context-spec-music (make-music 'PartialSet
961                                      'origin location
962                                      'partial-duration dur)
963                          'Timing)
964      'Score))
965
966 pitchedTrill =
967 #(define-music-function
968    (parser location main-note secondary-note)
969    (ly:music? ly:music?)
970    (_i "Print a trill with @var{main-note} as the main note of the trill and
971 print @var{secondary-note} as a stemless note head in parentheses.")
972    (let* ((get-notes (lambda (ev-chord)
973                        (extract-named-music ev-chord 'NoteEvent)))
974           (sec-note-events (get-notes secondary-note))
975           (trill-events (extract-named-music main-note 'TrillSpanEvent)))
976      (if (pair? sec-note-events)
977          (begin
978            (let* ((trill-pitch (ly:music-property (car sec-note-events) 'pitch))
979                   (forced (ly:music-property (car sec-note-events) 'force-accidental)))
980
981              (if (ly:pitch? trill-pitch)
982                  (for-each (lambda (m)
983                              (ly:music-set-property! m 'pitch trill-pitch)) trill-events)
984                  (begin
985                    (ly:input-warning location (_ "Second argument of \\pitchedTrill should be single note: "))
986                    (display sec-note-events)))
987
988              (if (eq? forced #t)
989                  (for-each (lambda (m)
990                              (ly:music-set-property! m 'force-accidental forced))
991                            trill-events)))))
992      main-note))
993
994 pushToTag =
995 #(define-music-function (parser location tag more music)
996    (symbol? ly:music? ly:music?)
997    (_i "Add @var{more} to the front of @code{elements} of all music
998 expressions in @var{music} that are tagged with @var{tag}.")
999    (music-map (lambda (m)
1000                 (if (memq tag (ly:music-property m 'tags))
1001                     (set! (ly:music-property m 'elements)
1002                           (cons more (ly:music-property m 'elements))))
1003                 m)
1004               music))
1005
1006 quoteDuring =
1007 #(define-music-function (parser location what main-music) (string? ly:music?)
1008    (_i "Indicate a section of music to be quoted.  @var{what} indicates the name
1009 of the quoted voice, as specified in an @code{\\addQuote} command.
1010 @var{main-music} is used to indicate the length of music to be quoted;
1011 usually contains spacers or multi-measure rests.")
1012    (make-music 'QuoteMusic
1013                'element main-music
1014                'quoted-music-name what))
1015
1016 relative =
1017 #(define-music-function (parser location pitch music)
1018    ((ly:pitch? (ly:make-pitch 0 0 0)) ly:music?)
1019    (_i "Make @var{music} relative to @var{pitch} (default @code{c'}).")
1020    (ly:make-music-relative! music pitch)
1021    (make-music 'RelativeOctaveMusic
1022                'element music))
1023
1024 removeWithTag =
1025 #(define-music-function (parser location tag music)
1026    (symbol-list-or-symbol? ly:music?)
1027    (_i "Remove elements of @var{music} that are tagged with one of the
1028 tags in @var{tag}.  @var{tag} may be either a single symbol or a list
1029 of symbols.")
1030    (music-filter
1031     (if (symbol? tag)
1032         (lambda (m)
1033           (not (memq tag (ly:music-property m 'tags))))
1034         (lambda (m)
1035           (let ((music-tags (ly:music-property m 'tags)))
1036             (or (null? music-tags)
1037                 (not (any (lambda (t) (memq t music-tags)) tag))))))
1038     music))
1039
1040 resetRelativeOctave =
1041 #(define-music-function (parser location pitch) (ly:pitch?)
1042    (_i "Set the octave inside a \\relative section.")
1043
1044    (make-music 'SequentialMusic
1045                'to-relative-callback
1046                (lambda (music last-pitch) pitch)))
1047
1048 retrograde =
1049 #(define-music-function (parser location music)
1050     (ly:music?)
1051     (_i "Return @var{music} in reverse order.")
1052     (retrograde-music music))
1053
1054 revertTimeSignatureSettings =
1055 #(define-music-function
1056    (parser location time-signature)
1057    (pair?)
1058
1059    (_i "Revert @code{timeSignatureSettings}
1060 for time signatures of @var{time-signature}.")
1061    (revert-time-signature-setting time-signature))
1062
1063 rightHandFinger =
1064 #(define-event-function (parser location finger) (number-or-string?)
1065    (_i "Apply @var{finger} as a fingering indication.")
1066
1067    (make-music
1068             'StrokeFingerEvent
1069             'origin location
1070             (if (string? finger) 'text 'digit)
1071             finger))
1072
1073 scaleDurations =
1074 #(define-music-function (parser location fraction music)
1075    (fraction? ly:music?)
1076    (_i "Multiply the duration of events in @var{music} by @var{fraction}.")
1077    (ly:music-compress music
1078                       (ly:make-moment (car fraction) (cdr fraction))))
1079
1080 settingsFrom =
1081 #(define-scheme-function (parser location ctx music)
1082    ((symbol?) ly:music?)
1083    (_i "Take the layout instruction events from @var{music}, optionally
1084 restricted to those applying to context type @var{ctx}, and return
1085 a context modification duplicating their effect.")
1086    (let ((mods (ly:make-context-mod)))
1087      (define (musicop m)
1088        (if (music-is-of-type? m 'layout-instruction-event)
1089            (ly:add-context-mod
1090             mods
1091             (case (ly:music-property m 'name)
1092               ((PropertySet)
1093                (list 'assign
1094                      (ly:music-property m 'symbol)
1095                      (ly:music-property m 'value)))
1096               ((PropertyUnset)
1097                (list 'unset
1098                      (ly:music-property m 'symbol)))
1099               ((OverrideProperty)
1100                (cons* 'push
1101                       (ly:music-property m 'symbol)
1102                       (ly:music-property m 'grob-value)
1103                       (cond
1104                        ((ly:music-property m 'grob-property #f) => list)
1105                        (else
1106                         (ly:music-property m 'grob-property-path)))))
1107               ((RevertProperty)
1108                (cons* 'pop
1109                       (ly:music-property m 'symbol)
1110                       (cond
1111                        ((ly:music-property m 'grob-property #f) => list)
1112                        (else
1113                         (ly:music-property m 'grob-property-path)))))))
1114            (case (ly:music-property m 'name)
1115              ((ApplyContext)
1116               (ly:add-context-mod mods
1117                                   (list 'apply
1118                                         (ly:music-property m 'procedure))))
1119              ((ContextSpeccedMusic)
1120               (if (or (not ctx)
1121                       (eq? ctx (ly:music-property m 'context-type)))
1122                   (musicop (ly:music-property m 'element))))
1123              (else
1124               (let ((callback (ly:music-property m 'elements-callback)))
1125                 (if (procedure? callback)
1126                     (for-each musicop (callback m))))))))
1127      (musicop music)
1128      mods))
1129
1130 shape =
1131 #(define-music-function (parser location offsets item)
1132    (list? symbol-list-or-music?)
1133    (_i "Offset control-points of @var{item} by @var{offsets}.  The
1134 argument is a list of number pairs or list of such lists.  Each
1135 element of a pair represents an offset to one of the coordinates of a
1136 control-point.  If @var{item} is a string, the result is
1137 @code{\\once\\override} for the specified grob type.  If @var{item} is
1138 a music expression, the result is the same music expression with an
1139 appropriate tweak applied.")
1140    (define (shape-curve grob)
1141      (let* ((orig (ly:grob-original grob))
1142             (siblings (if (ly:spanner? grob)
1143                           (ly:spanner-broken-into orig) '()))
1144             (total-found (length siblings))
1145             (function (assoc-get 'control-points
1146                                  (reverse (ly:grob-basic-properties grob))))
1147             (coords (function grob)))
1148
1149        (define (offset-control-points offsets)
1150          (if (null? offsets)
1151              coords
1152              (map
1153                (lambda (x y) (coord-translate x y))
1154                coords offsets)))
1155
1156        (define (helper sibs offs)
1157          (if (pair? offs)
1158              (if (eq? (car sibs) grob)
1159                  (offset-control-points (car offs))
1160                  (helper (cdr sibs) (cdr offs)))
1161              coords))
1162
1163        ;; we work with lists of lists
1164        (if (or (null? offsets)
1165                (not (list? (car offsets))))
1166            (set! offsets (list offsets)))
1167
1168        (if (>= total-found 2)
1169            (helper siblings offsets)
1170            (offset-control-points (car offsets)))))
1171    #{ \tweak control-points #shape-curve #item #})
1172
1173 shiftDurations =
1174 #(define-music-function (parser location dur dots arg)
1175    (integer? integer? ly:music?)
1176    (_i "Change the duration of @var{arg} by adding @var{dur} to the
1177 @code{durlog} of @var{arg} and @var{dots} to the @code{dots} of @var{arg}.")
1178
1179    (music-map
1180     (lambda (x)
1181       (shift-one-duration-log x dur dots)) arg))
1182
1183 single =
1184 #(define-music-function (parser location overrides music)
1185    (ly:music? ly:music?)
1186    (_i "Convert @var{overrides} to tweaks and apply them to @var{music}.
1187 This does not convert @code{\\revert}, @code{\\set} or @code{\\unset}.")
1188    (set! (ly:music-property music 'tweaks)
1189          (fold-some-music
1190           (lambda (m) (eq? (ly:music-property m 'name)
1191                            'OverrideProperty))
1192           (lambda (m tweaks)
1193             (let ((p (cond
1194                       ((ly:music-property m 'grob-property #f) => list)
1195                       (else
1196                        (ly:music-property m 'grob-property-path)))))
1197               (acons (cons (ly:music-property m 'symbol) ;grob name
1198                            (if (pair? (cdr p))
1199                                p ;grob property path
1200                                (car p))) ;grob property
1201                      (ly:music-property m 'grob-value)
1202                      tweaks)))
1203           (ly:music-property music 'tweaks)
1204           overrides))
1205    music)
1206
1207 skip =
1208 #(define-music-function (parser location dur) (ly:duration?)
1209   (_i "Skip forward by @var{dur}.")
1210   (make-music 'SkipMusic
1211               'duration dur))
1212
1213
1214 slashedGrace =
1215 #(def-grace-function startSlashedGraceMusic stopSlashedGraceMusic
1216    (_i "Create slashed graces (slashes through stems, but no slur) from
1217 the following music expression"))
1218
1219 spacingTweaks =
1220 #(define-music-function (parser location parameters) (list?)
1221    (_i "Set the system stretch, by reading the 'system-stretch property of
1222 the `parameters' assoc list.")
1223    #{
1224      \overrideProperty Score.NonMusicalPaperColumn.line-break-system-details
1225      #(list (cons 'alignment-extra-space (cdr (assoc 'system-stretch parameters)))
1226              (cons 'system-Y-extent (cdr (assoc 'system-Y-extent parameters))))
1227    #})
1228
1229 styledNoteHeads =
1230 #(define-music-function (parser location style heads music)
1231    (symbol? symbol-list-or-symbol? ly:music?)
1232    (_i "Set @var{heads} in @var{music} to @var{style}.")
1233    (style-note-heads heads style music))
1234
1235 tag =
1236 #(define-music-function (parser location tag music) (symbol-list-or-symbol? ly:music?)
1237    (_i "Tag the following @var{music} with @var{tag} and return the
1238 result, by adding the single symbol or symbol list @var{tag} to the
1239 @code{tags} property of @var{music}.")
1240
1241    (set!
1242     (ly:music-property music 'tags)
1243     ((if (symbol? tag) cons append)
1244      tag
1245      (ly:music-property music 'tags)))
1246    music)
1247
1248 temporary =
1249 #(define-music-function (parser location music)
1250    (ly:music?)
1251    (_i "Make any @code{\\override} in @var{music} replace an existing
1252 grob property value only temporarily, restoring the old value when a
1253 corresponding @code{\\revert} is executed.  This is achieved by
1254 clearing the @samp{pop-first} property normally set on
1255 @code{\\override}s.
1256
1257 An @code{\\override}/@/@code{\\revert} sequence created by using
1258 @code{\\temporary} and @code{\\undo} on the same music containing
1259 overrides will cancel out perfectly or cause a@tie{}warning.
1260
1261 Non-property-related music is ignored, warnings are generated for any
1262 property-changing music that isn't an @code{\\override}.")
1263    (define warned #f)
1264    (for-some-music
1265     (lambda (m)
1266       (and (or (music-is-of-type? m 'layout-instruction-event)
1267                (music-is-of-type? m 'context-specification)
1268                (music-is-of-type? m 'apply-context)
1269                (music-is-of-type? m 'time-signature-music))
1270            (case (ly:music-property m 'name)
1271              ((OverrideProperty)
1272               (if (ly:music-property m 'pop-first #f)
1273                   (set! (ly:music-property m 'pop-first) '()))
1274               (if (ly:music-property m 'once #f)
1275                   (set! (ly:music-property m 'once) '()))
1276               #t)
1277              ((ContextSpeccedMusic)
1278               #f)
1279              (else
1280               (if (not warned)
1281                   (begin
1282                     (ly:input-warning location (_ "Cannot make ~a revertible")
1283                                       (ly:music-property m 'name))
1284                     (set! warned #t)))
1285               #t))))
1286     music)
1287    music)
1288
1289 time =
1290 #(define-music-function (parser location beat-structure fraction)
1291    ((number-list? '()) fraction?)
1292    (_i "Set @var{fraction} as time signature, with optional
1293 number list @var{beat-structure} before it.")
1294   (make-music 'TimeSignatureMusic
1295               'numerator (car fraction)
1296               'denominator (cdr fraction)
1297               'beat-structure beat-structure))
1298
1299 times =
1300 #(define-music-function (parser location fraction music)
1301    (fraction? ly:music?)
1302    (_i "Scale @var{music} in time by @var{fraction}.")
1303   (make-music 'TimeScaledMusic
1304               'element (ly:music-compress music (ly:make-moment (car fraction) (cdr fraction)))
1305               'numerator (car fraction)
1306               'denominator (cdr fraction)))
1307
1308 transpose =
1309 #(define-music-function
1310    (parser location from to music)
1311    (ly:pitch? ly:pitch? ly:music?)
1312
1313    (_i "Transpose @var{music} from pitch @var{from} to pitch @var{to}.")
1314    (make-music 'TransposedMusic
1315                'element (ly:music-transpose music (ly:pitch-diff to from))))
1316
1317 transposedCueDuring =
1318 #(define-music-function
1319    (parser location what dir pitch main-music)
1320    (string? ly:dir? ly:pitch? ly:music?)
1321
1322    (_i "Insert notes from the part @var{what} into a voice called @code{cue},
1323 using the transposition defined by @var{pitch}.  This happens
1324 simultaneously with @var{main-music}, which is usually a rest.  The
1325 argument @var{dir} determines whether the cue notes should be notated
1326 as a first or second voice.")
1327
1328    (make-music 'QuoteMusic
1329                'element main-music
1330                'quoted-context-type 'Voice
1331                'quoted-context-id "cue"
1332                'quoted-music-name what
1333                'quoted-voice-direction dir
1334                'quoted-transposition pitch))
1335
1336 transposition =
1337 #(define-music-function (parser location pitch) (ly:pitch?)
1338    (_i "Set instrument transposition")
1339
1340    (context-spec-music
1341     (make-property-set 'instrumentTransposition
1342                        (ly:pitch-negate pitch))
1343     'Staff))
1344
1345 tweak =
1346 #(define-music-function (parser location prop value item)
1347    (symbol-list-or-symbol? scheme? symbol-list-or-music?)
1348    (_i "Add a tweak to the following @var{item}, usually music.
1349 Layout objects created by @var{item} get their property @var{prop}
1350 set to @var{value}.  If @var{prop} has the form @samp{Grob.property}, like with
1351 @example
1352 \\tweak Accidental.color #red cis'
1353 @end example
1354 an indirectly created grob (@samp{Accidental} is caused by
1355 @samp{NoteHead}) can be tweaked; otherwise only directly created grobs
1356 are affected.
1357
1358 As a special case, @var{item} may be a symbol list specifying a grob
1359 path, in which case @code{\\once\\override} is called on it instead of
1360 creating tweaked music.  This is mainly useful when using
1361 @code{\\tweak} as as a component for building other functions.
1362
1363 @var{prop} can contain additional elements in which case a nested
1364 property (inside of an alist) is tweaked.")
1365    (if (ly:music? item)
1366        (let ((p (check-grob-path prop parser location
1367                                  #:start 1
1368                                  #:default #t
1369                                  #:min 2)))
1370          (if p
1371              (set! (ly:music-property item 'tweaks)
1372                    (acons (cond ((pair? (cddr p)) p)
1373                                 ((symbol? (car p))
1374                                  (cons (car p) (cadr p)))
1375                                 (else (cadr p)))
1376                           value
1377                           (ly:music-property item 'tweaks))))
1378          item)
1379        ;; We could just throw this at \override and let it sort this
1380        ;; out on its own, but this way we should get better error
1381        ;; diagnostics.
1382        (let ((a (check-grob-path item parser location
1383                                  #:default 'Bottom #:min 2 #:max 2))
1384              (b (check-grob-path prop parser location
1385                                  #:start 2)))
1386          (if (and a b)
1387              #{ \once\override #(append a b) = #value #}
1388              (make-music 'Music)))))
1389
1390 undo =
1391 #(define-music-function (parser location music)
1392    (ly:music?)
1393    (_i "Convert @code{\\override} and @code{\\set} in @var{music} to
1394 @code{\\revert} and @code{\\unset}, respectively.  Any reverts and
1395 unsets already in @var{music} cause a warning.  Non-property-related music is ignored.")
1396    (define warned #f)
1397    (let loop
1398        ((music music))
1399      (let
1400          ((lst
1401            (fold-some-music
1402             (lambda (m) (or (music-is-of-type? m 'layout-instruction-event)
1403                             (music-is-of-type? m 'context-specification)
1404                             (music-is-of-type? m 'apply-context)
1405                             (music-is-of-type? m 'time-signature-music)))
1406             (lambda (m overrides)
1407               (case (ly:music-property m 'name)
1408                 ((OverrideProperty)
1409                  (cons
1410                   (make-music 'RevertProperty
1411                               'symbol (ly:music-property m 'symbol)
1412                               'grob-property-path
1413                               (cond
1414                                ((ly:music-property m 'grob-property #f) => list)
1415                                (else
1416                                 (ly:music-property m 'grob-property-path))))
1417                   overrides))
1418                 ((PropertySet)
1419                  (cons
1420                   (make-music 'PropertyUnset
1421                               'symbol (ly:music-property m 'symbol))
1422                   overrides))
1423                 ((ContextSpeccedMusic)
1424                  (cons
1425                   (make-music 'ContextSpeccedMusic
1426                               'element (loop (ly:music-property m 'element))
1427                               'context-type (ly:music-property m 'context-type))
1428                   overrides))
1429                 (else
1430                  (if (not warned)
1431                      (begin
1432                        (ly:input-warning location (_ "Cannot revert ~a")
1433                                          (ly:music-property m 'name))
1434                        (set! warned #t)))
1435                  overrides)))
1436             '()
1437             music)))
1438        (cond
1439         ((null? lst) (make-music 'Music))
1440         ((null? (cdr lst)) (car lst))
1441         (else (make-sequential-music lst))))))
1442
1443 unfoldRepeats =
1444 #(define-music-function (parser location music) (ly:music?)
1445    (_i "Force any @code{\\repeat volta}, @code{\\repeat tremolo} or
1446 @code{\\repeat percent} commands in @var{music} to be interpreted
1447 as @code{\\repeat unfold}.")
1448    (unfold-repeats music))
1449
1450 void =
1451 #(define-void-function (parser location arg) (scheme?)
1452    (_i "Accept a scheme argument, return a void expression.
1453 Use this if you want to have a scheme expression evaluated
1454 because of its side-effects, but its value ignored."))
1455
1456 withMusicProperty =
1457 #(define-music-function (parser location sym val music)
1458    (symbol? scheme? ly:music?)
1459    (_i "Set @var{sym} to @var{val} in @var{music}.")
1460
1461    (set! (ly:music-property music sym) val)
1462    music)