]> git.donarmstrong.com Git - lilypond.git/blob - ly/music-functions-init.ly
Add explicit \finger command for normal fingering events
[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-music 'AnnotateOutputEvent
182                'symbol grob-name
183                'X-offset (car offset)
184                'Y-offset (cdr offset)
185                'text text))
186
187 balloonText =
188 #(define-music-function (parser location offset text) (number-pair? markup?)
189    (_i "Attach @var{text} at @var{offset} (use like @code{\\tweak})")
190    (make-music 'AnnotateOutputEvent
191                'X-offset (car offset)
192                'Y-offset (cdr offset)
193                'text text))
194
195 bar =
196 #(define-music-function (parser location type) (string?)
197    (_i "Insert a bar line of type @var{type}")
198    (context-spec-music
199     (make-property-set 'whichBar type)
200     'Timing))
201
202 barNumberCheck =
203 #(define-music-function (parser location n) (integer?)
204    (_i "Print a warning if the current bar number is not @var{n}.")
205    (make-music 'ApplyContext
206                'procedure
207                (lambda (c)
208                  (let ((cbn (ly:context-property c 'currentBarNumber)))
209                    (if (and  (number? cbn) (not (= cbn n)))
210                        (ly:input-warning location
211                                          "Barcheck failed got ~a expect ~a"
212                                          cbn n))))))
213
214 bendAfter =
215 #(define-event-function (parser location delta) (real?)
216    (_i "Create a fall or doit of pitch interval @var{delta}.")
217    (make-music 'BendAfterEvent
218                'delta-step delta))
219
220 bookOutputName =
221 #(define-void-function (parser location newfilename) (string?)
222    (_i "Direct output for the current book block to @var{newfilename}.")
223    (set! (paper-variable parser #f 'output-filename) newfilename))
224
225 bookOutputSuffix =
226 #(define-void-function (parser location newsuffix) (string?)
227    (_i "Set the output filename suffix for the current book block to
228 @var{newsuffix}.")
229    (set! (paper-variable parser #f 'output-suffix) newsuffix))
230
231 %% \breathe is defined as a music function rather than an event identifier to
232 %% ensure it gets useful input location information: as an event identifier,
233 %% it would have to be wrapped in an EventChord to prevent it from being
234 %% treated as a post_event by the parser
235 breathe =
236 #(define-music-function (parser location) ()
237    (_i "Insert a breath mark.")
238    (make-music 'BreathingEvent))
239
240 clef =
241 #(define-music-function (parser location type) (string?)
242    (_i "Set the current clef to @var{type}.")
243    (make-clef-set type))
244
245
246 compoundMeter =
247 #(define-music-function (parser location args) (pair?)
248   (_i "Create compound time signatures. The argument is a Scheme list of
249 lists. Each list describes one fraction, with the last entry being the
250 denominator, while the first entries describe the summands in the
251 enumerator. If the time signature consists of just one fraction,
252 the list can be given directly, i.e. not as a list containing a single list.
253 For example, a time signature of (3+1)/8 + 2/4 would be created as
254 @code{\\compoundMeter #'((3 1 8) (2 4))}, and a time signature of (3+2)/8
255 as @code{\\compoundMeter #'((3 2 8))} or shorter
256 @code{\\compoundMeter #'(3 2 8)}.")
257   (let* ((mlen (calculate-compound-measure-length args))
258          (beat (calculate-compound-base-beat args))
259          (beatGrouping (calculate-compound-beat-grouping args))
260          (timesig (cons (ly:moment-main-numerator mlen)
261                         (ly:moment-main-denominator mlen))))
262   #{
263     \once \override Staff.TimeSignature.stencil = #(lambda (grob)
264       (grob-interpret-markup grob (format-compound-time args)))
265     \set Timing.timeSignatureFraction = #timesig
266     \set Timing.baseMoment = #beat
267     \set Timing.beatStructure = #beatGrouping
268     \set Timing.beamExceptions = #'()
269     \set Timing.measureLength = #mlen
270   #} ))
271
272 crossStaff =
273 #(define-music-function (parser location notes) (ly:music?)
274   (_i "Create cross-staff stems")
275   #{
276   \temporary \override Stem.cross-staff = #cross-staff-connect
277   \temporary \override Flag.style = #'no-flag
278   #notes
279   \revert Stem.cross-staff
280   \revert Flag.style
281 #})
282
283 cueClef =
284 #(define-music-function (parser location type) (string?)
285   (_i "Set the current cue clef to @var{type}.")
286   (make-cue-clef-set type))
287
288 cueClefUnset =
289 #(define-music-function (parser location) ()
290   (_i "Unset the current cue clef.")
291   (make-cue-clef-unset))
292
293 cueDuring =
294 #(define-music-function
295    (parser location what dir main-music) (string? ly:dir? ly:music?)
296    (_i "Insert contents of quote @var{what} corresponding to @var{main-music},
297 in a CueVoice oriented by @var{dir}.")
298    (make-music 'QuoteMusic
299                'element main-music
300                'quoted-context-type 'Voice
301                'quoted-context-id "cue"
302                'quoted-music-name what
303                'quoted-voice-direction dir))
304
305 cueDuringWithClef =
306 #(define-music-function
307    (parser location what dir clef main-music) (string? ly:dir? string? ly:music?)
308    (_i "Insert contents of quote @var{what} corresponding to @var{main-music},
309 in a CueVoice oriented by @var{dir}.")
310    (make-music 'QuoteMusic
311                'element main-music
312                'quoted-context-type 'Voice
313                'quoted-context-id "cue"
314                'quoted-music-name what
315                'quoted-music-clef clef
316                'quoted-voice-direction dir))
317
318
319
320 displayLilyMusic =
321 #(define-music-function (parser location music) (ly:music?)
322    (_i "Display the LilyPond input representation of @var{music}
323 to the console.")
324    (newline)
325    (display-lily-music music parser)
326    music)
327
328 displayMusic =
329 #(define-music-function (parser location music) (ly:music?)
330    (_i "Display the internal representation of @var{music} to the console.")
331    (newline)
332    (display-scheme-music music)
333    music)
334
335
336
337 endSpanners =
338 #(define-music-function (parser location music) (ly:music?)
339    (_i "Terminate the next spanner prematurely after exactly one note
340 without the need of a specific end spanner.")
341    (let* ((start-span-evs (filter (lambda (ev)
342                                     (equal? (ly:music-property ev 'span-direction)
343                                             START))
344                                   (extract-typed-music music 'span-event)))
345           (stop-span-evs
346            (map (lambda (m)
347                   (music-clone m 'span-direction STOP))
348                 start-span-evs))
349           (end-ev-chord (make-music 'EventChord
350                                     'elements stop-span-evs))
351           (total (make-music 'SequentialMusic
352                              'elements (list music
353                                              end-ev-chord))))
354      total))
355
356 eventChords =
357 #(define-music-function (parser location music) (ly:music?)
358    (_i "Compatibility function wrapping @code{EventChord} around
359 isolated rhythmic events occuring since version 2.15.28, after
360 expanding repeat chords @samp{q}.")
361    (event-chord-wrap! music parser))
362
363 featherDurations=
364 #(define-music-function (parser location factor argument) (ly:moment? ly:music?)
365    (_i "Adjust durations of music in @var{argument} by rational @var{factor}.")
366    (let ((orig-duration (ly:music-length argument))
367          (multiplier (ly:make-moment 1 1)))
368
369      (for-each
370       (lambda (mus)
371         (if (< 0 (ly:moment-main-denominator (ly:music-length mus)))
372             (begin
373               (ly:music-compress mus multiplier)
374               (set! multiplier (ly:moment-mul factor multiplier)))))
375       (extract-named-music argument '(EventChord NoteEvent RestEvent SkipEvent)))
376      (ly:music-compress
377       argument
378       (ly:moment-div orig-duration (ly:music-length argument)))
379
380      argument))
381
382 finger =
383 #(define-event-function (parser location finger) (number-or-markup?)
384    (_i "Apply @var{finger} as a fingering indication.")
385
386    (make-music
387             'FingeringEvent
388             (if (number? finger) 'digit 'text)
389             finger))
390
391 footnote =
392 #(define-music-function (parser location mark offset footnote item)
393    ((markup?) number-pair? markup? symbol-list-or-music?)
394    (_i "Make the markup @var{footnote} a footnote on @var{item}.  The
395 footnote is marked with a markup @var{mark} moved by @var{offset} with
396 respect to the marked music.
397
398 If @var{mark} is not given or specified as @var{\\default}, it is
399 replaced by an automatically generated sequence number.  If @var{item}
400 is a symbol list of form @samp{Grob} or @samp{Context.Grob}, then
401 grobs of that type will be marked at the current time step in the
402 given context (default @code{Bottom}).
403
404 If @var{item} is music, the music will get a footnote attached to a
405 grob immediately attached to the event, like @var{\\tweak} does.  For
406 attaching a footnote to an @emph{indirectly} caused grob, write
407 @code{\\single\\footnote}, use @var{item} to specify the grob, and
408 follow it with the music to annotate.
409
410 Like with @code{\\tweak}, if you use a footnote on a following
411 post-event, the @code{\\footnote} command itself needs to be attached
412 to the preceding note or rest as a post-event with @code{-}.")
413    (let ((mus (make-music
414                'FootnoteEvent
415                'X-offset (car offset)
416                'Y-offset (cdr offset)
417                'automatically-numbered (not mark)
418                'text (or mark (make-null-markup))
419                'footnote-text footnote)))
420      #{ \tweak footnote-music #mus #item #}))
421
422 grace =
423 #(def-grace-function startGraceMusic stopGraceMusic
424    (_i "Insert @var{music} as grace notes."))
425
426 grobdescriptions =
427 #(define-scheme-function (parser location descriptions) (list?)
428    (_i "Create a context modification from @var{descriptions}, a list
429 in the format of @code{all-grob-descriptions}.")
430    (ly:make-context-mod
431     (map (lambda (p)
432            (list 'assign (car p) (list (cdr p))))
433          descriptions)))
434
435 harmonicByFret = #(define-music-function (parser location fret music) (number? ly:music?)
436   (_i "Convert @var{music} into mixed harmonics; the resulting notes resemble
437 harmonics played on a fretted instrument by touching the strings at @var{fret}.")
438   #{
439     \set harmonicDots = ##t
440     \temporary \override TabNoteHead.stencil = #(tab-note-head::print-custom-fret-label (number->string fret))
441     \temporary \override NoteHead.Y-extent = #(ly:make-unpure-pure-container ly:grob::stencil-height
442                                        (lambda (grob start end)
443                                                (ly:grob::stencil-height grob)))
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                '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 tuplet =
1354 #(define-music-function (parser location ratio tuplet-span music)
1355    (fraction? (ly:duration? '()) ly:music?)
1356    (_i "Scale the given @var{music} to tuplets.  @var{ratio} is a
1357 fraction that specifies how many notes are played in place of the
1358 nominal value: it will be @samp{3/2} for triplets, namely three notes
1359 being played in place of two.  If the optional duration
1360 @var{tuplet-span} is specified, it is used instead of
1361 @code{tupletSpannerDuration} for grouping the tuplets.
1362 For example,
1363 @example
1364 \\tuplet 3/2 4 @{ c8 c c c c c @}
1365 @end example
1366 will result in two groups of three tuplets, each group lasting for a
1367 quarter note.")
1368    (make-music 'TimeScaledMusic
1369                'element (ly:music-compress
1370                          music
1371                          (ly:make-moment (cdr ratio) (car ratio)))
1372                'numerator (cdr ratio)
1373                'denominator (car ratio)
1374                'duration tuplet-span))
1375
1376 tupletSpan =
1377 #(define-music-function (parser location tuplet-span)
1378    ((ly:duration?))
1379    (_i "Set @code{tupletSpannerDuration}, the length into which
1380 @code{\\tuplet} without an explicit @samp{tuplet-span} argument of its
1381 own will group its tuplets, to the duration @var{tuplet-span}.  To
1382 revert to the default of not subdividing the contents of a @code{\\tuplet}
1383 command without explicit @samp{tuplet-span}, use
1384 @example
1385 \\tupletSpan \\default
1386 @end example
1387 ")
1388    (if tuplet-span
1389        #{ \set tupletSpannerDuration = #(ly:duration-length tuplet-span) #}
1390        #{ \unset tupletSpannerDuration #}))
1391
1392 tweak =
1393 #(define-music-function (parser location prop value item)
1394    (symbol-list-or-symbol? scheme? symbol-list-or-music?)
1395    (_i "Add a tweak to the following @var{item}, usually music.
1396 Layout objects created by @var{item} get their property @var{prop}
1397 set to @var{value}.  If @var{prop} has the form @samp{Grob.property}, like with
1398 @example
1399 \\tweak Accidental.color #red cis'
1400 @end example
1401 an indirectly created grob (@samp{Accidental} is caused by
1402 @samp{NoteHead}) can be tweaked; otherwise only directly created grobs
1403 are affected.
1404
1405 As a special case, @var{item} may be a symbol list specifying a grob
1406 path, in which case @code{\\once\\override} is called on it instead of
1407 creating tweaked music.  This is mainly useful when using
1408 @code{\\tweak} as as a component for building other functions.
1409
1410 @var{prop} can contain additional elements in which case a nested
1411 property (inside of an alist) is tweaked.")
1412    (if (ly:music? item)
1413        (let ((p (check-grob-path prop parser location
1414                                  #:start 1
1415                                  #:default #t
1416                                  #:min 2)))
1417          (if p
1418              (set! (ly:music-property item 'tweaks)
1419                    (acons (cond ((pair? (cddr p)) p)
1420                                 ((symbol? (car p))
1421                                  (cons (car p) (cadr p)))
1422                                 (else (cadr p)))
1423                           value
1424                           (ly:music-property item 'tweaks))))
1425          item)
1426        ;; We could just throw this at \override and let it sort this
1427        ;; out on its own, but this way we should get better error
1428        ;; diagnostics.
1429        (let ((a (check-grob-path item parser location
1430                                  #:default 'Bottom #:min 2 #:max 2))
1431              (b (check-grob-path prop parser location
1432                                  #:start 2)))
1433          (if (and a b)
1434              #{ \once\override #(append a b) = #value #}
1435              (make-music 'Music)))))
1436
1437 undo =
1438 #(define-music-function (parser location music)
1439    (ly:music?)
1440    (_i "Convert @code{\\override} and @code{\\set} in @var{music} to
1441 @code{\\revert} and @code{\\unset}, respectively.  Any reverts and
1442 unsets already in @var{music} cause a warning.  Non-property-related music is ignored.")
1443    (define warned #f)
1444    (let loop
1445        ((music music))
1446      (let
1447          ((lst
1448            (fold-some-music
1449             (lambda (m) (or (music-is-of-type? m 'layout-instruction-event)
1450                             (music-is-of-type? m 'context-specification)
1451                             (music-is-of-type? m 'apply-context)
1452                             (music-is-of-type? m 'time-signature-music)))
1453             (lambda (m overrides)
1454               (case (ly:music-property m 'name)
1455                 ((OverrideProperty)
1456                  (cons
1457                   (make-music 'RevertProperty
1458                               'symbol (ly:music-property m 'symbol)
1459                               'grob-property-path
1460                               (cond
1461                                ((ly:music-property m 'grob-property #f) => list)
1462                                (else
1463                                 (ly:music-property m 'grob-property-path))))
1464                   overrides))
1465                 ((PropertySet)
1466                  (cons
1467                   (make-music 'PropertyUnset
1468                               'symbol (ly:music-property m 'symbol))
1469                   overrides))
1470                 ((ContextSpeccedMusic)
1471                  (cons
1472                   (make-music 'ContextSpeccedMusic
1473                               'element (loop (ly:music-property m 'element))
1474                               'context-type (ly:music-property m 'context-type))
1475                   overrides))
1476                 (else
1477                  (if (not warned)
1478                      (begin
1479                        (ly:input-warning location (_ "Cannot revert ~a")
1480                                          (ly:music-property m 'name))
1481                        (set! warned #t)))
1482                  overrides)))
1483             '()
1484             music)))
1485        (cond
1486         ((null? lst) (make-music 'Music))
1487         ((null? (cdr lst)) (car lst))
1488         (else (make-sequential-music lst))))))
1489
1490 unfoldRepeats =
1491 #(define-music-function (parser location music) (ly:music?)
1492    (_i "Force any @code{\\repeat volta}, @code{\\repeat tremolo} or
1493 @code{\\repeat percent} commands in @var{music} to be interpreted
1494 as @code{\\repeat unfold}.")
1495    (unfold-repeats music))
1496
1497 void =
1498 #(define-void-function (parser location arg) (scheme?)
1499    (_i "Accept a scheme argument, return a void expression.
1500 Use this if you want to have a scheme expression evaluated
1501 because of its side-effects, but its value ignored."))
1502
1503 withMusicProperty =
1504 #(define-music-function (parser location sym val music)
1505    (symbol? scheme? ly:music?)
1506    (_i "Set @var{sym} to @var{val} in @var{music}.")
1507
1508    (set! (ly:music-property music sym) val)
1509    music)