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