]> git.donarmstrong.com Git - lilypond.git/blob - ly/music-functions-init.ly
Make \balloonText into post-event, \balloonGrobText into proper event
[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.11"
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-event-chord
182     (list
183      (make-music 'AnnotateOutputEvent
184                  'symbol grob-name
185                  'X-offset (car offset)
186                  'Y-offset (cdr offset)
187                  'text text))))
188
189 balloonText =
190 #(define-event-function (parser location offset text) (number-pair? markup?)
191    (_i "Attach @var{text} at @var{offset} (use like @code{\\tweak})")
192    (make-music 'AnnotateOutputEvent
193                'X-offset (car offset)
194                'Y-offset (cdr offset)
195                'text text))
196
197 bar =
198 #(define-music-function (parser location type) (string?)
199    (_i "Insert a bar line of type @var{type}")
200    (context-spec-music
201     (make-property-set 'whichBar type)
202     'Timing))
203
204 barNumberCheck =
205 #(define-music-function (parser location n) (integer?)
206    (_i "Print a warning if the current bar number is not @var{n}.")
207    (make-music 'ApplyContext
208                'procedure
209                (lambda (c)
210                  (let ((cbn (ly:context-property c 'currentBarNumber)))
211                    (if (and  (number? cbn) (not (= cbn n)))
212                        (ly:input-warning location
213                                          "Barcheck failed got ~a expect ~a"
214                                          cbn n))))))
215
216 bendAfter =
217 #(define-event-function (parser location delta) (real?)
218    (_i "Create a fall or doit of pitch interval @var{delta}.")
219    (make-music 'BendAfterEvent
220                'delta-step delta))
221
222 bookOutputName =
223 #(define-void-function (parser location newfilename) (string?)
224    (_i "Direct output for the current book block to @var{newfilename}.")
225    (set! (paper-variable parser #f 'output-filename) newfilename))
226
227 bookOutputSuffix =
228 #(define-void-function (parser location newsuffix) (string?)
229    (_i "Set the output filename suffix for the current book block to
230 @var{newsuffix}.")
231    (set! (paper-variable parser #f 'output-suffix) newsuffix))
232
233 %% \breathe is defined as a music function rather than an event identifier to
234 %% ensure it gets useful input location information: as an event identifier,
235 %% it would have to be wrapped in an EventChord to prevent it from being
236 %% treated as a post_event by the parser
237 breathe =
238 #(define-music-function (parser location) ()
239    (_i "Insert a breath mark.")
240    (make-music 'BreathingEvent))
241
242 clef =
243 #(define-music-function (parser location type) (string?)
244    (_i "Set the current clef to @var{type}.")
245    (make-clef-set type))
246
247
248 compoundMeter =
249 #(define-music-function (parser location args) (pair?)
250   (_i "Create compound time signatures. The argument is a Scheme list of
251 lists. Each list describes one fraction, with the last entry being the
252 denominator, while the first entries describe the summands in the
253 enumerator. If the time signature consists of just one fraction,
254 the list can be given directly, i.e. not as a list containing a single list.
255 For example, a time signature of (3+1)/8 + 2/4 would be created as
256 @code{\\compoundMeter #'((3 1 8) (2 4))}, and a time signature of (3+2)/8
257 as @code{\\compoundMeter #'((3 2 8))} or shorter
258 @code{\\compoundMeter #'(3 2 8)}.")
259   (let* ((mlen (calculate-compound-measure-length args))
260          (beat (calculate-compound-base-beat args))
261          (beatGrouping (calculate-compound-beat-grouping args))
262          (timesig (cons (ly:moment-main-numerator mlen)
263                         (ly:moment-main-denominator mlen))))
264   #{
265     \once \override Staff.TimeSignature.stencil = #(lambda (grob)
266       (grob-interpret-markup grob (format-compound-time args)))
267     \set Timing.timeSignatureFraction = #timesig
268     \set Timing.baseMoment = #beat
269     \set Timing.beatStructure = #beatGrouping
270     \set Timing.beamExceptions = #'()
271     \set Timing.measureLength = #mlen
272   #} ))
273
274 crossStaff =
275 #(define-music-function (parser location notes) (ly:music?)
276   (_i "Create cross-staff stems")
277   #{
278   \temporary \override Stem.cross-staff = #cross-staff-connect
279   \temporary \override Flag.style = #'no-flag
280   #notes
281   \revert Stem.cross-staff
282   \revert Flag.style
283 #})
284
285 cueClef =
286 #(define-music-function (parser location type) (string?)
287   (_i "Set the current cue clef to @var{type}.")
288   (make-cue-clef-set type))
289
290 cueClefUnset =
291 #(define-music-function (parser location) ()
292   (_i "Unset the current cue clef.")
293   (make-cue-clef-unset))
294
295 cueDuring =
296 #(define-music-function
297    (parser location what dir main-music) (string? ly:dir? ly:music?)
298    (_i "Insert contents of quote @var{what} corresponding to @var{main-music},
299 in a CueVoice oriented by @var{dir}.")
300    (make-music 'QuoteMusic
301                'element main-music
302                'quoted-context-type 'Voice
303                'quoted-context-id "cue"
304                'quoted-music-name what
305                'quoted-voice-direction dir))
306
307 cueDuringWithClef =
308 #(define-music-function
309    (parser location what dir clef main-music) (string? ly:dir? string? ly:music?)
310    (_i "Insert contents of quote @var{what} corresponding to @var{main-music},
311 in a CueVoice oriented by @var{dir}.")
312    (make-music 'QuoteMusic
313                'element main-music
314                'quoted-context-type 'Voice
315                'quoted-context-id "cue"
316                'quoted-music-name what
317                'quoted-music-clef clef
318                'quoted-voice-direction dir))
319
320
321
322 displayLilyMusic =
323 #(define-music-function (parser location music) (ly:music?)
324    (_i "Display the LilyPond input representation of @var{music}
325 to the console.")
326    (newline)
327    (display-lily-music music parser)
328    music)
329
330 displayMusic =
331 #(define-music-function (parser location music) (ly:music?)
332    (_i "Display the internal representation of @var{music} to the console.")
333    (newline)
334    (display-scheme-music music)
335    music)
336
337
338
339 endSpanners =
340 #(define-music-function (parser location music) (ly:music?)
341    (_i "Terminate the next spanner prematurely after exactly one note
342 without the need of a specific end spanner.")
343    (let* ((start-span-evs (filter (lambda (ev)
344                                     (equal? (ly:music-property ev 'span-direction)
345                                             START))
346                                   (extract-typed-music music 'span-event)))
347           (stop-span-evs
348            (map (lambda (m)
349                   (music-clone m 'span-direction STOP))
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 finger =
385 #(define-event-function (parser location finger) (number-or-markup?)
386    (_i "Apply @var{finger} as a fingering indication.")
387
388    (make-music
389             'FingeringEvent
390             (if (number? finger) 'digit 'text)
391             finger))
392
393 footnote =
394 #(define-music-function (parser location mark offset footnote item)
395    ((markup?) number-pair? markup? symbol-list-or-music?)
396    (_i "Make the markup @var{footnote} a footnote on @var{item}.  The
397 footnote is marked with a markup @var{mark} moved by @var{offset} with
398 respect to the marked music.
399
400 If @var{mark} is not given or specified as @var{\\default}, it is
401 replaced by an automatically generated sequence number.  If @var{item}
402 is a symbol list of form @samp{Grob} or @samp{Context.Grob}, then
403 grobs of that type will be marked at the current time step in the
404 given context (default @code{Bottom}).
405
406 If @var{item} is music, the music will get a footnote attached to a
407 grob immediately attached to the event, like @var{\\tweak} does.  For
408 attaching a footnote to an @emph{indirectly} caused grob, write
409 @code{\\single\\footnote}, use @var{item} to specify the grob, and
410 follow it with the music to annotate.
411
412 Like with @code{\\tweak}, if you use a footnote on a following
413 post-event, the @code{\\footnote} command itself needs to be attached
414 to the preceding note or rest as a post-event with @code{-}.")
415    (let ((mus (make-music
416                'FootnoteEvent
417                'X-offset (car offset)
418                'Y-offset (cdr offset)
419                'automatically-numbered (not mark)
420                'text (or mark (make-null-markup))
421                'footnote-text footnote)))
422      #{ \tweak footnote-music #mus #item #}))
423
424 grace =
425 #(def-grace-function startGraceMusic stopGraceMusic
426    (_i "Insert @var{music} as grace notes."))
427
428 grobdescriptions =
429 #(define-scheme-function (parser location descriptions) (list?)
430    (_i "Create a context modification from @var{descriptions}, a list
431 in the format of @code{all-grob-descriptions}.")
432    (ly:make-context-mod
433     (map (lambda (p)
434            (list 'assign (car p) (list (cdr p))))
435          descriptions)))
436
437 harmonicByFret = #(define-music-function (parser location fret music) (number? ly:music?)
438   (_i "Convert @var{music} into mixed harmonics; the resulting notes resemble
439 harmonics played on a fretted instrument by touching the strings at @var{fret}.")
440   #{
441     \set harmonicDots = ##t
442     \temporary \override TabNoteHead.stencil = #(tab-note-head::print-custom-fret-label (number->string fret))
443     \temporary \override NoteHead.Y-extent = #grob::always-Y-extent-from-stencil
444     \temporary \override NoteHead.stencil = #(lambda (grob) (ly:grob-set-property! grob 'style 'harmonic-mixed)
445                                             (ly:note-head::print grob))
446     #(make-harmonic
447        (calc-harmonic-pitch (fret->pitch (number->string fret)) music))
448     \unset harmonicDots
449     \revert TabNoteHead.stencil
450     \revert NoteHead.Y-extent
451     \revert NoteHead.stencil
452   #})
453
454 harmonicByRatio = #(define-music-function (parser location ratio music) (number? ly:music?)
455     (_i "Convert @var{music} into mixed harmonics; the resulting notes resemble
456 harmonics played on a fretted instrument by touching the strings at the point
457 given through @var{ratio}.")
458   #{
459     \set harmonicDots = ##t
460     \temporary \override TabNoteHead.stencil = #(tab-note-head::print-custom-fret-label (ratio->fret ratio))
461     \temporary \override NoteHead.Y-extent = #(ly:make-unpure-pure-container ly:grob::stencil-height
462                                        (lambda (grob start end)
463                                                (ly:grob::stencil-height grob)))
464     \temporary \override NoteHead.stencil = #(lambda (grob) (ly:grob-set-property! grob 'style 'harmonic-mixed)
465                                             (ly:note-head::print grob))
466     #(make-harmonic
467       (calc-harmonic-pitch (ratio->pitch ratio) music))
468     \unset harmonicDots
469     \revert TabNoteHead.stencil
470     \revert NoteHead.Y-extent
471     \revert NoteHead.stencil
472   #})
473
474 hide =
475 #(define-music-function (parser location item) (symbol-list-or-music?)
476    (_i "Set @var{item}'s @samp{transparent} property to @code{#t},
477 making it invisible while still retaining its dimensions.
478
479 If @var{item} is a symbol list of form @code{GrobName} or
480 @code{Context.GrobName}, the result is an override for the grob name
481 specified by it.  If @var{item} is a music expression, the result is
482 the same music expression with an appropriate tweak applied to it.")
483    (if (ly:music? item)
484        #{ \tweak transparent ##t #item #}
485        #{ \override #item . transparent = ##t #}))
486
487 inStaffSegno =
488 #(define-music-function (parser location) ()
489    (_i "Put the segno variant 'varsegno' at this position into the staff,
490 compatible with the repeat command.")
491    (make-music 'ApplyContext
492                'procedure
493                (lambda (ctx)
494                  (let ((score-ctx (ly:context-find ctx 'Score)))
495                    (if (ly:context? score-ctx)
496                      (let ((old-rc (ly:context-property score-ctx 'repeatCommands '())))
497                        (if (eq? (memq 'segno-display old-rc) #f)
498                          (ly:context-set-property! score-ctx 'repeatCommands (cons 'segno-display old-rc)))))))))
499
500 instrumentSwitch =
501 #(define-music-function
502    (parser location name) (string?)
503    (_i "Switch instrument to @var{name}, which must be predefined with
504 @code{\\addInstrumentDefinition}.")
505    (let* ((handle (assoc name instrument-definitions))
506           (instrument-def (if handle (cdr handle) '())))
507
508      (if (not handle)
509          (ly:input-warning location "No such instrument: ~a" name))
510      (context-spec-music
511       (make-music 'SimultaneousMusic
512                   'elements
513                   (map (lambda (kv)
514                          (make-property-set
515                           (car kv)
516                           (cdr kv)))
517                        instrument-def))
518       'Staff)))
519
520
521
522 keepWithTag =
523 #(define-music-function (parser location tag music)
524    (symbol-list-or-symbol? ly:music?)
525    (_i "Include only elements of @var{music} that are either untagged
526 or tagged with one of the tags in @var{tag}.  @var{tag} may be either
527 a single symbol or a list of symbols.")
528    (music-filter
529     (if (symbol? tag)
530         (lambda (m)
531           (let ((music-tags (ly:music-property m 'tags)))
532             (or (null? music-tags)
533                 (memq tag music-tags))))
534         (lambda (m)
535           (let ((music-tags (ly:music-property m 'tags)))
536             (or (null? music-tags)
537                 (any (lambda (t) (memq t music-tags)) tag)))))
538     music))
539
540 key =
541 #(define-music-function (parser location tonic pitch-alist)
542    ((ly:pitch? '()) (list? '()))
543    (_i "Set key to @var{tonic} and scale @var{pitch-alist}.
544 If both are null, just generate @code{KeyChangeEvent}.")
545    (cond ((null? tonic) (make-music 'KeyChangeEvent))
546          ((null? pitch-alist)
547           (ly:parser-error parser (_ "second argument must be pitch list")
548                            location)
549           (make-music 'SequentialMusic 'void #t))
550          (else
551           (ly:music-transpose
552            (make-music 'KeyChangeEvent
553                 'tonic (ly:make-pitch 0 0 0)
554                 'pitch-alist pitch-alist)
555            tonic))))
556
557 killCues =
558 #(define-music-function (parser location music) (ly:music?)
559    (_i "Remove cue notes from @var{music}.")
560    (music-map
561     (lambda (mus)
562       (if (and (string? (ly:music-property mus 'quoted-music-name))
563                (string=? (ly:music-property mus 'quoted-context-id "") "cue"))
564           (ly:music-property mus 'element)
565           mus))
566     music))
567
568
569
570 label =
571 #(define-music-function (parser location label) (symbol?)
572    (_i "Create @var{label} as a bookmarking label.")
573    (make-music 'EventChord
574                'page-marker #t
575                'page-label label
576                'elements (list (make-music 'LabelEvent
577                                            'page-label label))))
578
579
580 language =
581 #(define-void-function (parser location language) (string?)
582    (_i "Set note names for language @var{language}.")
583    (note-names-language parser language))
584
585 languageSaveAndChange =
586 #(define-void-function (parser location language) (string?)
587   (_i "Store the previous pitchnames alist, and set a new one.")
588   (set! previous-pitchnames pitchnames)
589   (note-names-language parser language))
590
591 languageRestore =
592 #(define-void-function (parser location) ()
593    (_i "Restore a previously-saved pitchnames alist.")
594    (if previous-pitchnames
595        (begin
596         (set! pitchnames previous-pitchnames)
597         (ly:parser-set-note-names parser pitchnames))
598       (ly:input-warning location (_ "No other language was defined previously. Ignoring."))))
599
600
601 makeClusters =
602 #(define-music-function (parser location arg) (ly:music?)
603    (_i "Display chords in @var{arg} as clusters.")
604    (music-map note-to-cluster arg))
605
606 modalInversion =
607 #(define-music-function (parser location around to scale music)
608     (ly:pitch? ly:pitch? ly:music? ly:music?)
609     (_i "Invert @var{music} about @var{around} using @var{scale} and
610 transpose from @var{around} to @var{to}.")
611     (let ((inverter (make-modal-inverter around to scale)))
612       (change-pitches music inverter)
613       music))
614
615 modalTranspose =
616 #(define-music-function (parser location from to scale music)
617     (ly:pitch? ly:pitch? ly:music? ly:music?)
618     (_i "Transpose @var{music} from pitch @var{from} to pitch @var{to}
619 using @var{scale}.")
620     (let ((transposer (make-modal-transposer from to scale)))
621       (change-pitches music transposer)
622       music))
623
624 inversion =
625 #(define-music-function
626    (parser location around to music) (ly:pitch? ly:pitch? ly:music?)
627    (_i "Invert @var{music} about @var{around} and
628 transpose from @var{around} to @var{to}.")
629    (music-invert around to music))
630
631 mark =
632 #(define-music-function
633    (parser location label) ((scheme? '()))
634   "Make the music for the \\mark command."
635   (let* ((set (and (integer? label)
636                    (context-spec-music (make-property-set 'rehearsalMark label)
637                                       'Score)))
638          (ev (make-music 'MarkEvent
639                          'origin location)))
640
641     (if set
642         (make-sequential-music (list set ev))
643         (begin
644           (set! (ly:music-property ev 'label) label)
645           ev))))
646
647 musicMap =
648 #(define-music-function (parser location proc mus) (procedure? ly:music?)
649    (_i "Apply @var{proc} to @var{mus} and all of the music it contains.")
650    (music-map proc mus))
651
652 %% noPageBreak and noPageTurn are music functions (not music indentifiers),
653 %% because music identifiers are not allowed at top-level.
654 noPageBreak =
655 #(define-music-function (location parser) ()
656    (_i "Forbid a page break.  May be used at toplevel (i.e., between scores or
657 markups), or inside a score.")
658    (make-music 'EventChord
659                'page-marker #t
660                'page-break-permission 'forbid
661                'elements (list (make-music 'PageBreakEvent
662                                            'break-permission '()))))
663
664 noPageTurn =
665 #(define-music-function (location parser) ()
666    (_i "Forbid a page turn.  May be used at toplevel (i.e., between scores or
667 markups), or inside a score.")
668    (make-music 'EventChord
669                'page-marker #t
670                'page-turn-permission 'forbid
671                'elements (list (make-music 'PageTurnEvent
672                                            'break-permission '()))))
673
674
675
676 octaveCheck =
677 #(define-music-function (parser location pitch) (ly:pitch?)
678    (_i "Octave check.")
679    (make-music 'RelativeOctaveCheck
680                'pitch pitch))
681
682 omit =
683 #(define-music-function (parser location item) (symbol-list-or-music?)
684    (_i "Set @var{item}'s @samp{stencil} property to @code{#f},
685 effectively omitting it without taking up space.
686
687 If @var{item} is a symbol list of form @code{GrobName} or
688 @code{Context.GrobName}, the result is an override for the grob name
689 specified by it.  If @var{item} is a music expression, the result is
690 the same music expression with an appropriate tweak applied to it.")
691    (if (ly:music? item)
692        #{ \tweak stencil ##f #item #}
693        #{ \override #item . stencil = ##f #}))
694
695 once =
696 #(define-music-function (parser location music) (ly:music?)
697    (_i "Set @code{once} to @code{#t} on all layout instruction events in @var{music}.")
698    (music-map
699     (lambda (m)
700       (cond ((music-is-of-type? m 'layout-instruction-event)
701              (set! (ly:music-property m 'once) #t))
702             ((ly:duration? (ly:music-property m 'duration))
703              (ly:music-warning m (_ "Cannot apply \\once to timed music"))))
704       m)
705     music))
706
707 ottava =
708 #(define-music-function (parser location octave) (integer?)
709    (_i "Set the octavation.")
710    (make-music 'OttavaMusic
711                'ottava-number octave))
712
713 overrideTimeSignatureSettings =
714 #(define-music-function
715    (parser location time-signature base-moment beat-structure beam-exceptions)
716    (pair? pair? cheap-list? cheap-list?)
717
718    (_i "Override @code{timeSignatureSettings}
719 for time signatures of @var{time-signature} to have settings
720 of @var{base-moment}, @var{beat-structure}, and @var{beam-exceptions}.")
721
722    ;; TODO -- add warning if largest value of grouping is
723    ;;       greater than time-signature.
724   (let ((setting (make-setting base-moment beat-structure beam-exceptions)))
725     (override-time-signature-setting time-signature setting)))
726
727 overrideProperty =
728 #(define-music-function (parser location grob-property-path value)
729    (symbol-list? scheme?)
730
731    (_i "Set the grob property specified by @var{grob-property-path} to
732 @var{value}.  @var{grob-property-path} is a symbol list of the form
733 @code{Context.GrobName.property} or @code{GrobName.property}, possibly
734 with subproperties given as well.")
735    (let ((p (check-grob-path grob-property-path parser location
736                              #:default 'Bottom
737                              #:min 3)))
738      (if p
739          (make-music 'ApplyOutputEvent
740                      'context-type (first p)
741                      'procedure
742                      (lambda (grob orig-context context)
743                        (if (equal?
744                             (cdr (assoc 'name (ly:grob-property grob 'meta)))
745                             (second p))
746                            (ly:grob-set-nested-property!
747                             grob (cddr p) value))))
748          (make-music 'Music))))
749
750
751
752
753
754
755 %% pageBreak and pageTurn are music functions (iso music indentifiers),
756 %% because music identifiers are not allowed at top-level.
757 pageBreak =
758 #(define-music-function (location parser) ()
759    (_i "Force a page break.  May be used at toplevel (i.e., between scores or
760 markups), or inside a score.")
761    (make-music 'EventChord
762                'page-marker #t
763                'line-break-permission 'force
764                'page-break-permission 'force
765                'elements (list (make-music 'LineBreakEvent
766                                            'break-permission 'force)
767                                (make-music 'PageBreakEvent
768                                            'break-permission 'force))))
769
770 pageTurn =
771 #(define-music-function (location parser) ()
772    (_i "Force a page turn between two scores or top-level markups.")
773    (make-music 'EventChord
774                'page-marker #t
775                'line-break-permission 'force
776                'page-break-permission 'force
777                'page-turn-permission 'force
778                'elements (list (make-music 'LineBreakEvent
779                                            'break-permission 'force)
780                                (make-music 'PageBreakEvent
781                                            'break-permission 'force)
782                                (make-music 'PageTurnEvent
783                                            'break-permission 'force))))
784
785 parallelMusic =
786 #(define-void-function (parser location voice-ids music) (list? ly:music?)
787    (_i "Define parallel music sequences, separated by '|' (bar check signs),
788 and assign them to the identifiers provided in @var{voice-ids}.
789
790 @var{voice-ids}: a list of music identifiers (symbols containing only letters)
791
792 @var{music}: a music sequence, containing BarChecks as limiting expressions.
793
794 Example:
795
796 @verbatim
797   \\parallelMusic #'(A B C) {
798     c c | d d | e e |
799     d d | e e | f f |
800   }
801 <==>
802   A = { c c | d d | }
803   B = { d d | e e | }
804   C = { e e | f f | }
805 @end verbatim
806 ")
807    (define (bar-check? m)
808      "Checks whether m is a bar check."
809      (eq? (ly:music-property m 'name) 'BarCheck))
810    (define (recurse-and-split music)
811      "This returns either a list of music split along barchecks, or
812 @code{#f}."
813      (let ((elt (ly:music-property music 'element))
814            (elts (ly:music-property music 'elements)))
815        (cond ((ly:music? elt)
816               (let ((lst (recurse-and-split elt)))
817                 (and lst
818                      (map
819                       (lambda (x)
820                         (let ((res (music-clone music 'element x)))
821                           (if (ly:input-location?
822                                (ly:music-property x 'origin))
823                               (set! (ly:music-property res 'origin)
824                                     (ly:music-property x 'origin)))
825                           res))
826                       lst))))
827              ((any bar-check? elts)
828               (let* ((voices (apply circular-list
829                                     (make-list (length voice-ids)
830                                                '())))
831                      (current-voices voices)
832                      (current-sequence '()))
833                 ;;
834                 ;; utilities
835                 (define (push-music m)
836                   "Push the music expression into the current sequence"
837                   (set! current-sequence (cons m current-sequence)))
838                 (define (change-voice)
839                   "Stores the previously built sequence into the current voice and
840        change to the following voice."
841                   (set-car! current-voices
842                             (cons (reverse! current-sequence)
843                                   (car current-voices)))
844                   (set! current-sequence '())
845                   (set! current-voices (cdr current-voices)))
846                 (for-each (lambda (m)
847                             (let ((split? (recurse-and-split m)))
848                               (if split?
849                                   (for-each
850                                    (lambda (m)
851                                      (push-music m)
852                                      (change-voice))
853                                    split?)
854                                   (begin
855                                     (push-music m)
856                                     (if (bar-check? m) (change-voice))))))
857                           elts)
858                 (if (pair? current-sequence) (change-voice))
859                 ;; un-circularize `voices' and reorder the voices
860
861                 (set! voices (map reverse!
862                                   (list-head voices (length voice-ids))))
863
864                 ;; check sequence length
865                 (apply for-each (lambda seqs
866                                   (define (seq-len seq)
867                                     (reduce ly:moment-add
868                                             (ly:make-moment 0)
869                                             (map ly:music-length seq)))
870                                   (let ((moment-reference (seq-len (car seqs))))
871                                     (for-each (lambda (seq)
872                                                 (if (not (equal? (seq-len seq)
873                                                                  moment-reference))
874                                                     (ly:music-warning
875                                                      (if (pair? seq)
876                                                          (last seq)
877                                                          (caar seqs))
878                                                      (_ "Bars in parallel music don't have the same length"))))
879                                               seqs)))
880                        voices)
881                 (map
882                  (lambda (lst)
883                    (set! lst (concatenate! lst))
884                    (let ((res (music-clone music 'elements lst)))
885                      (if (and (pair? lst)
886                               (ly:input-location? (ly:music-property
887                                                    (car lst)
888                                                    'origin)))
889                          (set! (ly:music-property res 'origin)
890                                (ly:music-property (car lst) 'origin)))
891                      res))
892                  voices)))
893              (else #f))))
894    (let ((voices (recurse-and-split music)))
895      (if voices
896          ;;
897          ;; bind voice identifiers to the voices
898          (for-each (lambda (voice-id voice)
899                      (ly:parser-define! parser voice-id voice))
900           voice-ids voices)
901          (ly:music-warning music
902                            (_ "ignoring parallel music without barchecks")))))
903
904 parenthesize =
905 #(define-music-function (parser loc arg) (ly:music?)
906    (_i "Tag @var{arg} to be parenthesized.")
907
908    (if (memq 'event-chord (ly:music-property arg 'types))
909        ;; arg is an EventChord -> set the parenthesize property
910        ;; on all child notes and rests
911        (for-each
912         (lambda (ev)
913           (if (or (memq 'note-event (ly:music-property ev 'types))
914                   (memq 'rest-event (ly:music-property ev 'types)))
915               (set! (ly:music-property ev 'parenthesize) #t)))
916         (ly:music-property arg 'elements))
917        ;; No chord, simply set property for this expression:
918        (set! (ly:music-property arg 'parenthesize) #t))
919    arg)
920
921 partcombine =
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.")
925    (make-part-combine-music parser
926                             (list part1 part2) #f))
927
928 partcombineUp =
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 upward.")
932    (make-part-combine-music parser
933                             (list part1 part2) UP))
934
935 partcombineDown =
936 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
937    (_i "Take the music in @var{part1} and @var{part2} and typeset so
938 that they share a staff with stems directed downward.")
939    (make-part-combine-music parser
940                             (list part1 part2) DOWN))
941
942 partcombineForce =
943 #(define-music-function (location parser type once) (symbol-or-boolean? boolean?)
944    (_i "Override the part-combiner.")
945    (make-music 'EventChord
946                'elements (list (make-music 'PartCombineForceEvent
947                                            'forced-type type
948                                            'once once))))
949 partcombineApart = \partcombineForce #'apart ##f
950 partcombineApartOnce = \partcombineForce #'apart ##t
951 partcombineChords = \partcombineForce #'chords ##f
952 partcombineChordsOnce = \partcombineForce #'chords ##t
953 partcombineUnisono = \partcombineForce #'unisono ##f
954 partcombineUnisonoOnce = \partcombineForce #'unisono ##t
955 partcombineSoloI = \partcombineForce #'solo1 ##f
956 partcombineSoloIOnce = \partcombineForce #'solo1 ##t
957 partcombineSoloII = \partcombineForce #'solo2 ##f
958 partcombineSoloIIOnce = \partcombineForce #'solo2 ##t
959 partcombineAutomatic = \partcombineForce ##f ##f
960 partcombineAutomaticOnce = \partcombineForce ##f ##t
961
962 partial =
963 #(define-music-function (parser location dur) (ly:duration?)
964   (_i "Make a partial measure.")
965
966   ;; We use `descend-to-context' here instead of `context-spec-music' to
967   ;; ensure \partial still works if the Timing_translator is moved
968     (descend-to-context
969      (context-spec-music (make-music 'PartialSet
970                                      'origin location
971                                      'partial-duration dur)
972                          'Timing)
973      'Score))
974
975 pitchedTrill =
976 #(define-music-function
977    (parser location main-note secondary-note)
978    (ly:music? ly:music?)
979    (_i "Print a trill with @var{main-note} as the main note of the trill and
980 print @var{secondary-note} as a stemless note head in parentheses.")
981    (let* ((get-notes (lambda (ev-chord)
982                        (extract-named-music ev-chord 'NoteEvent)))
983           (sec-note-events (get-notes secondary-note))
984           (trill-events (extract-named-music main-note 'TrillSpanEvent)))
985      (if (pair? sec-note-events)
986          (begin
987            (let* ((trill-pitch (ly:music-property (car sec-note-events) 'pitch))
988                   (forced (ly:music-property (car sec-note-events) 'force-accidental)))
989
990              (if (ly:pitch? trill-pitch)
991                  (for-each (lambda (m)
992                              (ly:music-set-property! m 'pitch trill-pitch)) trill-events)
993                  (begin
994                    (ly:input-warning location (_ "Second argument of \\pitchedTrill should be single note: "))
995                    (display sec-note-events)))
996
997              (if (eq? forced #t)
998                  (for-each (lambda (m)
999                              (ly:music-set-property! m 'force-accidental forced))
1000                            trill-events)))))
1001      main-note))
1002
1003 pushToTag =
1004 #(define-music-function (parser location tag more music)
1005    (symbol? ly:music? ly:music?)
1006    (_i "Add @var{more} to the front of @code{elements} of all music
1007 expressions in @var{music} that are tagged with @var{tag}.")
1008    (music-map (lambda (m)
1009                 (if (memq tag (ly:music-property m 'tags))
1010                     (set! (ly:music-property m 'elements)
1011                           (cons more (ly:music-property m 'elements))))
1012                 m)
1013               music))
1014
1015 quoteDuring =
1016 #(define-music-function (parser location what main-music) (string? ly:music?)
1017    (_i "Indicate a section of music to be quoted.  @var{what} indicates the name
1018 of the quoted voice, as specified in an @code{\\addQuote} command.
1019 @var{main-music} is used to indicate the length of music to be quoted;
1020 usually contains spacers or multi-measure rests.")
1021    (make-music 'QuoteMusic
1022                'element main-music
1023                'quoted-music-name what))
1024
1025 relative =
1026 #(define-music-function (parser location pitch music)
1027    ((ly:pitch? (ly:make-pitch 0 0 0)) ly:music?)
1028    (_i "Make @var{music} relative to @var{pitch} (default @code{c'}).")
1029    (ly:make-music-relative! music pitch)
1030    (make-music 'RelativeOctaveMusic
1031                'element music))
1032
1033 removeWithTag =
1034 #(define-music-function (parser location tag music)
1035    (symbol-list-or-symbol? ly:music?)
1036    (_i "Remove elements of @var{music} that are tagged with one of the
1037 tags in @var{tag}.  @var{tag} may be either a single symbol or a list
1038 of symbols.")
1039    (music-filter
1040     (if (symbol? tag)
1041         (lambda (m)
1042           (not (memq tag (ly:music-property m 'tags))))
1043         (lambda (m)
1044           (let ((music-tags (ly:music-property m 'tags)))
1045             (or (null? music-tags)
1046                 (not (any (lambda (t) (memq t music-tags)) tag))))))
1047     music))
1048
1049 resetRelativeOctave =
1050 #(define-music-function (parser location pitch) (ly:pitch?)
1051    (_i "Set the octave inside a \\relative section.")
1052
1053    (make-music 'SequentialMusic
1054                'to-relative-callback
1055                (lambda (music last-pitch) pitch)))
1056
1057 retrograde =
1058 #(define-music-function (parser location music)
1059     (ly:music?)
1060     (_i "Return @var{music} in reverse order.")
1061     (retrograde-music music))
1062
1063 revertTimeSignatureSettings =
1064 #(define-music-function
1065    (parser location time-signature)
1066    (pair?)
1067
1068    (_i "Revert @code{timeSignatureSettings}
1069 for time signatures of @var{time-signature}.")
1070    (revert-time-signature-setting time-signature))
1071
1072 rightHandFinger =
1073 #(define-event-function (parser location finger) (number-or-markup?)
1074    (_i "Apply @var{finger} as a fingering indication.")
1075
1076    (make-music
1077             'StrokeFingerEvent
1078             (if (number? finger) 'digit 'text)
1079             finger))
1080
1081 scaleDurations =
1082 #(define-music-function (parser location fraction music)
1083    (fraction? ly:music?)
1084    (_i "Multiply the duration of events in @var{music} by @var{fraction}.")
1085    (ly:music-compress music
1086                       (ly:make-moment (car fraction) (cdr fraction))))
1087
1088 settingsFrom =
1089 #(define-scheme-function (parser location ctx music)
1090    ((symbol?) ly:music?)
1091    (_i "Take the layout instruction events from @var{music}, optionally
1092 restricted to those applying to context type @var{ctx}, and return
1093 a context modification duplicating their effect.")
1094    (let ((mods (ly:make-context-mod)))
1095      (define (musicop m)
1096        (if (music-is-of-type? m 'layout-instruction-event)
1097            (ly:add-context-mod
1098             mods
1099             (case (ly:music-property m 'name)
1100               ((PropertySet)
1101                (list 'assign
1102                      (ly:music-property m 'symbol)
1103                      (ly:music-property m 'value)))
1104               ((PropertyUnset)
1105                (list 'unset
1106                      (ly:music-property m 'symbol)))
1107               ((OverrideProperty)
1108                (cons* 'push
1109                       (ly:music-property m 'symbol)
1110                       (ly:music-property m 'grob-value)
1111                       (cond
1112                        ((ly:music-property m 'grob-property #f) => list)
1113                        (else
1114                         (ly:music-property m 'grob-property-path)))))
1115               ((RevertProperty)
1116                (cons* 'pop
1117                       (ly:music-property m 'symbol)
1118                       (cond
1119                        ((ly:music-property m 'grob-property #f) => list)
1120                        (else
1121                         (ly:music-property m 'grob-property-path)))))))
1122            (case (ly:music-property m 'name)
1123              ((ApplyContext)
1124               (ly:add-context-mod mods
1125                                   (list 'apply
1126                                         (ly:music-property m 'procedure))))
1127              ((ContextSpeccedMusic)
1128               (if (or (not ctx)
1129                       (eq? ctx (ly:music-property m 'context-type)))
1130                   (musicop (ly:music-property m 'element))))
1131              (else
1132               (let ((callback (ly:music-property m 'elements-callback)))
1133                 (if (procedure? callback)
1134                     (for-each musicop (callback m))))))))
1135      (musicop music)
1136      mods))
1137
1138 shape =
1139 #(define-music-function (parser location offsets item)
1140    (list? symbol-list-or-music?)
1141    (_i "Offset control-points of @var{item} by @var{offsets}.  The
1142 argument is a list of number pairs or list of such lists.  Each
1143 element of a pair represents an offset to one of the coordinates of a
1144 control-point.  If @var{item} is a string, the result is
1145 @code{\\once\\override} for the specified grob type.  If @var{item} is
1146 a music expression, the result is the same music expression with an
1147 appropriate tweak applied.")
1148    (define (shape-curve grob)
1149      (let* ((orig (ly:grob-original grob))
1150             (siblings (if (ly:spanner? grob)
1151                           (ly:spanner-broken-into orig) '()))
1152             (total-found (length siblings))
1153             (function (assoc-get 'control-points
1154                                  (reverse (ly:grob-basic-properties grob))))
1155             (coords (function grob)))
1156
1157        (define (offset-control-points offsets)
1158          (if (null? offsets)
1159              coords
1160              (map
1161                (lambda (x y) (coord-translate x y))
1162                coords offsets)))
1163
1164        (define (helper sibs offs)
1165          (if (pair? offs)
1166              (if (eq? (car sibs) grob)
1167                  (offset-control-points (car offs))
1168                  (helper (cdr sibs) (cdr offs)))
1169              coords))
1170
1171        ;; we work with lists of lists
1172        (if (or (null? offsets)
1173                (not (list? (car offsets))))
1174            (set! offsets (list offsets)))
1175
1176        (if (>= total-found 2)
1177            (helper siblings offsets)
1178            (offset-control-points (car offsets)))))
1179    #{ \tweak control-points #shape-curve #item #})
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    (set! (ly:music-property music 'tweaks)
1197          (fold-some-music
1198           (lambda (m) (eq? (ly:music-property m 'name)
1199                            'OverrideProperty))
1200           (lambda (m tweaks)
1201             (let ((p (cond
1202                       ((ly:music-property m 'grob-property #f) => list)
1203                       (else
1204                        (ly:music-property m 'grob-property-path)))))
1205               (acons (cons (ly:music-property m 'symbol) ;grob name
1206                            (if (pair? (cdr p))
1207                                p ;grob property path
1208                                (car p))) ;grob property
1209                      (ly:music-property m 'grob-value)
1210                      tweaks)))
1211           (ly:music-property music 'tweaks)
1212           overrides))
1213    music)
1214
1215 skip =
1216 #(define-music-function (parser location dur) (ly:duration?)
1217   (_i "Skip forward by @var{dur}.")
1218   (make-music 'SkipMusic
1219               'duration dur))
1220
1221
1222 slashedGrace =
1223 #(def-grace-function startSlashedGraceMusic stopSlashedGraceMusic
1224    (_i "Create slashed graces (slashes through stems, but no slur) from
1225 the following music expression"))
1226
1227 spacingTweaks =
1228 #(define-music-function (parser location parameters) (list?)
1229    (_i "Set the system stretch, by reading the 'system-stretch property of
1230 the `parameters' assoc list.")
1231    #{
1232      \overrideProperty Score.NonMusicalPaperColumn.line-break-system-details
1233      #(list (cons 'alignment-extra-space (cdr (assoc 'system-stretch parameters)))
1234              (cons 'system-Y-extent (cdr (assoc 'system-Y-extent parameters))))
1235    #})
1236
1237 styledNoteHeads =
1238 #(define-music-function (parser location style heads music)
1239    (symbol? symbol-list-or-symbol? ly:music?)
1240    (_i "Set @var{heads} in @var{music} to @var{style}.")
1241    (style-note-heads heads style music))
1242
1243 tag =
1244 #(define-music-function (parser location tag music) (symbol-list-or-symbol? ly:music?)
1245    (_i "Tag the following @var{music} with @var{tag} and return the
1246 result, by adding the single symbol or symbol list @var{tag} to the
1247 @code{tags} property of @var{music}.")
1248
1249    (set!
1250     (ly:music-property music 'tags)
1251     ((if (symbol? tag) cons append)
1252      tag
1253      (ly:music-property music 'tags)))
1254    music)
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                ;; following is inverse of instrumentTransposition for
1343                ;; historical reasons
1344                'quoted-transposition pitch))
1345
1346 transposition =
1347 #(define-music-function (parser location pitch) (ly:pitch?)
1348    (_i "Set instrument transposition")
1349
1350    (context-spec-music
1351     (make-property-set 'instrumentTransposition pitch)
1352     'Staff))
1353
1354 tuplet =
1355 #(define-music-function (parser location ratio tuplet-span music)
1356    (fraction? (ly:duration? '()) ly:music?)
1357    (_i "Scale the given @var{music} to tuplets.  @var{ratio} is a
1358 fraction that specifies how many notes are played in place of the
1359 nominal value: it will be @samp{3/2} for triplets, namely three notes
1360 being played in place of two.  If the optional duration
1361 @var{tuplet-span} is specified, it is used instead of
1362 @code{tupletSpannerDuration} for grouping the tuplets.
1363 For example,
1364 @example
1365 \\tuplet 3/2 4 @{ c8 c c c c c @}
1366 @end example
1367 will result in two groups of three tuplets, each group lasting for a
1368 quarter note.")
1369    (make-music 'TimeScaledMusic
1370                'element (ly:music-compress
1371                          music
1372                          (ly:make-moment (cdr ratio) (car ratio)))
1373                'numerator (cdr ratio)
1374                'denominator (car ratio)
1375                'duration tuplet-span))
1376
1377 tupletSpan =
1378 #(define-music-function (parser location tuplet-span)
1379    ((ly:duration?))
1380    (_i "Set @code{tupletSpannerDuration}, the length into which
1381 @code{\\tuplet} without an explicit @samp{tuplet-span} argument of its
1382 own will group its tuplets, to the duration @var{tuplet-span}.  To
1383 revert to the default of not subdividing the contents of a @code{\\tuplet}
1384 command without explicit @samp{tuplet-span}, use
1385 @example
1386 \\tupletSpan \\default
1387 @end example
1388 ")
1389    (if tuplet-span
1390        #{ \set tupletSpannerDuration = #(ly:duration-length tuplet-span) #}
1391        #{ \unset tupletSpannerDuration #}))
1392
1393 tweak =
1394 #(define-music-function (parser location prop value item)
1395    (symbol-list-or-symbol? scheme? symbol-list-or-music?)
1396    (_i "Add a tweak to the following @var{item}, usually music.
1397 Layout objects created by @var{item} get their property @var{prop}
1398 set to @var{value}.  If @var{prop} has the form @samp{Grob.property}, like with
1399 @example
1400 \\tweak Accidental.color #red cis'
1401 @end example
1402 an indirectly created grob (@samp{Accidental} is caused by
1403 @samp{NoteHead}) can be tweaked; otherwise only directly created grobs
1404 are affected.
1405
1406 As a special case, @var{item} may be a symbol list specifying a grob
1407 path, in which case @code{\\once\\override} is called on it instead of
1408 creating tweaked music.  This is mainly useful when using
1409 @code{\\tweak} as as a component for building other functions.
1410
1411 @var{prop} can contain additional elements in which case a nested
1412 property (inside of an alist) is tweaked.")
1413    (if (ly:music? item)
1414        (let ((p (check-grob-path prop parser location
1415                                  #:start 1
1416                                  #:default #t
1417                                  #:min 2)))
1418          (if p
1419              (set! (ly:music-property item 'tweaks)
1420                    (acons (cond ((pair? (cddr p)) p)
1421                                 ((symbol? (car p))
1422                                  (cons (car p) (cadr p)))
1423                                 (else (cadr p)))
1424                           value
1425                           (ly:music-property item 'tweaks))))
1426          item)
1427        ;; We could just throw this at \override and let it sort this
1428        ;; out on its own, but this way we should get better error
1429        ;; diagnostics.
1430        (let ((a (check-grob-path item parser location
1431                                  #:default 'Bottom #:min 2 #:max 2))
1432              (b (check-grob-path prop parser location
1433                                  #:start 2)))
1434          (if (and a b)
1435              #{ \once\override #(append a b) = #value #}
1436              (make-music 'Music)))))
1437
1438 undo =
1439 #(define-music-function (parser location music)
1440    (ly:music?)
1441    (_i "Convert @code{\\override} and @code{\\set} in @var{music} to
1442 @code{\\revert} and @code{\\unset}, respectively.  Any reverts and
1443 unsets already in @var{music} cause a warning.  Non-property-related music is ignored.")
1444    (define warned #f)
1445    (let loop
1446        ((music music))
1447      (let
1448          ((lst
1449            (fold-some-music
1450             (lambda (m) (or (music-is-of-type? m 'layout-instruction-event)
1451                             (music-is-of-type? m 'context-specification)
1452                             (music-is-of-type? m 'apply-context)
1453                             (music-is-of-type? m 'time-signature-music)))
1454             (lambda (m overrides)
1455               (case (ly:music-property m 'name)
1456                 ((OverrideProperty)
1457                  (cons
1458                   (make-music 'RevertProperty
1459                               'symbol (ly:music-property m 'symbol)
1460                               'grob-property-path
1461                               (cond
1462                                ((ly:music-property m 'grob-property #f) => list)
1463                                (else
1464                                 (ly:music-property m 'grob-property-path))))
1465                   overrides))
1466                 ((PropertySet)
1467                  (cons
1468                   (make-music 'PropertyUnset
1469                               'symbol (ly:music-property m 'symbol))
1470                   overrides))
1471                 ((ContextSpeccedMusic)
1472                  (cons
1473                   (make-music 'ContextSpeccedMusic
1474                               'element (loop (ly:music-property m 'element))
1475                               'context-type (ly:music-property m 'context-type))
1476                   overrides))
1477                 (else
1478                  (if (not warned)
1479                      (begin
1480                        (ly:input-warning location (_ "Cannot revert ~a")
1481                                          (ly:music-property m 'name))
1482                        (set! warned #t)))
1483                  overrides)))
1484             '()
1485             music)))
1486        (cond
1487         ((null? lst) (make-music 'Music))
1488         ((null? (cdr lst)) (car lst))
1489         (else (make-sequential-music lst))))))
1490
1491 unfoldRepeats =
1492 #(define-music-function (parser location music) (ly:music?)
1493    (_i "Force any @code{\\repeat volta}, @code{\\repeat tremolo} or
1494 @code{\\repeat percent} commands in @var{music} to be interpreted
1495 as @code{\\repeat unfold}.")
1496    (unfold-repeats music))
1497
1498 void =
1499 #(define-void-function (parser location arg) (scheme?)
1500    (_i "Accept a scheme argument, return a void expression.
1501 Use this if you want to have a scheme expression evaluated
1502 because of its side-effects, but its value ignored."))
1503
1504 withMusicProperty =
1505 #(define-music-function (parser location sym val music)
1506    (symbol? scheme? ly:music?)
1507    (_i "Set @var{sym} to @var{val} in @var{music}.")
1508
1509    (set! (ly:music-property music sym) val)
1510    music)