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