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