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