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