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