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