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