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