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