]> git.donarmstrong.com Git - lilypond.git/blob - ly/music-functions-init.ly
Merge branch 'lilypond/translation' into staging
[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-music-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! book-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! book-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
319
320 featherDurations=
321 #(define-music-function (parser location factor argument) (ly:moment? ly:music?)
322    (_i "Adjust durations of music in @var{argument} by rational @var{factor}.")
323    (let ((orig-duration (ly:music-length argument))
324          (multiplier (ly:make-moment 1 1)))
325
326      (for-each
327       (lambda (mus)
328         (if (< 0 (ly:moment-main-denominator (ly:music-length mus)))
329             (begin
330               (ly:music-compress mus multiplier)
331               (set! multiplier (ly:moment-mul factor multiplier)))))
332       (extract-named-music argument '(EventChord NoteEvent RestEvent SkipEvent)))
333      (ly:music-compress
334       argument
335       (ly:moment-div orig-duration (ly:music-length argument)))
336
337      argument))
338
339 footnote =
340 #(define-music-function (parser location text offset grob-name footnote)
341    ((markup?) number-pair? (symbol? '()) markup?)
342    (_i "Attach @var{text} at @var{offset} with @var{text} referring to
343 @var{footnote}.  If @var{text} is given as @code{\\default}, use
344 autonumbering instead.  Note that, for this to take effect,
345 auto-numbering must be turned on in the paper block.  Otherwise, no
346 number will appear.  Footnotes are applied like articulations.  If a
347 symbol @var{grob-name} is specified, all grobs of that kind at the
348 current time step are affected.")
349    (make-music
350     'FootnoteEvent
351     'X-offset (car offset)
352     'Y-offset (cdr offset)
353     'automatically-numbered (not text)
354     'text (or text (make-null-markup))
355     'footnote-text footnote
356     'symbol grob-name))
357
358 grace =
359 #(def-grace-function startGraceMusic stopGraceMusic
360    (_i "Insert @var{music} as grace notes."))
361
362 grobdescriptions =
363 #(define-scheme-function (parser location descriptions) (list?)
364    (_i "Create a context modification from @var{descriptions}, a list
365 in the format of @code{all-grob-descriptions}.")
366    (ly:make-context-mod
367     (map (lambda (p)
368            (list 'assign (car p) (list (cdr p))))
369          descriptions)))
370
371 harmonicByFret = #(define-music-function (parser location fret music) (number? ly:music?)
372   (_i "Convert @var{music} into harmonics; the resulting notes resemble
373 harmonics played on a fretted instrument by touching the strings above @var{fret}.")
374   (let* ((fret (number->string fret))
375          (pitch (fret->pitch fret)))
376         (make-sequential-music
377          (list
378           #{
379             \override TabNoteHead #'stencil = #(tab-note-head::print-custom-fret-label fret)
380           #}
381           (make-harmonic
382             (calc-harmonic-pitch pitch music))
383           #{
384             \revert TabNoteHead #'stencil
385           #}))))
386
387 harmonicByRatio = #(define-music-function (parser location ratio music) (number? ly:music?)
388     (_i "Convert @var{music} into harmonics; the resulting notes resemble
389 harmonics played on a fretted instrument by touching the strings above the point
390 given through @var{ratio}.")
391   (let ((pitch (ratio->pitch ratio))
392         (fret (ratio->fret ratio)))
393        (make-sequential-music
394         (list
395          #{
396            \override TabNoteHead #'stencil = #(tab-note-head::print-custom-fret-label fret)
397          #}
398          (make-harmonic
399            (calc-harmonic-pitch pitch music))
400          #{
401             \revert TabNoteHead #'stencil
402          #}))))
403
404 instrumentSwitch =
405 #(define-music-function
406    (parser location name) (string?)
407    (_i "Switch instrument to @var{name}, which must be predefined with
408 @code{\\addInstrumentDefinition}.")
409    (let* ((handle (assoc name instrument-definitions))
410           (instrument-def (if handle (cdr handle) '())))
411
412      (if (not handle)
413          (ly:input-warning location "No such instrument: ~a" name))
414      (context-spec-music
415       (make-music 'SimultaneousMusic
416                   'elements
417                   (map (lambda (kv)
418                          (make-property-set
419                           (car kv)
420                           (cdr kv)))
421                        instrument-def))
422       'Staff)))
423
424
425
426 keepWithTag =
427 #(define-music-function (parser location tag music) (symbol? ly:music?)
428    (_i "Include only elements of @var{music} that are tagged with @var{tag}.")
429    (music-filter
430     (lambda (m)
431       (let* ((tags (ly:music-property m 'tags))
432              (res (memq tag tags)))
433         (or
434          (eq? tags '())
435          res)))
436     music))
437
438 key =
439 #(define-music-function (parser location tonic pitch-alist)
440    ((ly:pitch? '()) (list? '()))
441    (_i "Set key to @var{tonic} and scale @var{pitch-alist}.
442 If both are null, just generate @code{KeyChangeEvent}.")
443    (cond ((null? tonic) (make-music 'KeyChangeEvent))
444          ((null? pitch-alist)
445           (ly:parser-error parser (_ "second argument must be pitch list")
446                            location)
447           (make-music 'SequentialMusic 'void #t))
448          (else
449           (ly:music-transpose
450            (make-music 'KeyChangeEvent
451                 'tonic (ly:make-pitch 0 0 0)
452                 'pitch-alist pitch-alist)
453            tonic))))
454
455 killCues =
456 #(define-music-function (parser location music) (ly:music?)
457    (_i "Remove cue notes from @var{music}.")
458    (music-map
459     (lambda (mus)
460       (if (and (string? (ly:music-property mus 'quoted-music-name))
461                (string=? (ly:music-property mus 'quoted-context-id "") "cue"))
462           (ly:music-property mus 'element)
463           mus))
464     music))
465
466
467
468 label =
469 #(define-music-function (parser location label) (symbol?)
470    (_i "Create @var{label} as a bookmarking label.")
471    (make-music 'EventChord
472                'page-marker #t
473                'page-label label
474                'elements (list (make-music 'LabelEvent
475                                            'page-label label))))
476
477
478 language =
479 #(define-void-function (parser location language) (string?)
480    (_i "Set note names for language @var{language}.")
481    (note-names-language parser language))
482
483 languageSaveAndChange =
484 #(define-void-function (parser location language) (string?)
485   (_i "Store the previous pitchnames alist, and set a new one.")
486   (set! previous-pitchnames pitchnames)
487   (note-names-language parser language))
488
489 languageRestore =
490 #(define-void-function (parser location) ()
491    (_i "Restore a previously-saved pitchnames alist.")
492    (if previous-pitchnames
493        (begin
494         (set! pitchnames previous-pitchnames)
495         (ly:parser-set-note-names parser pitchnames))
496       (ly:input-warning location (_ "No other language was defined previously. Ignoring."))))
497
498
499 makeClusters =
500 #(define-music-function (parser location arg) (ly:music?)
501    (_i "Display chords in @var{arg} as clusters.")
502    (music-map note-to-cluster arg))
503
504 modalInversion =
505 #(define-music-function (parser location around to scale music)
506     (ly:pitch? ly:pitch? ly:music? ly:music?)
507     (_i "Invert @var{music} about @var{around} using @var{scale} and
508 transpose from @var{around} to @var{to}.")
509     (let ((inverter (make-modal-inverter around to scale)))
510       (change-pitches music inverter)
511       music))
512
513 modalTranspose =
514 #(define-music-function (parser location from to scale music)
515     (ly:pitch? ly:pitch? ly:music? ly:music?)
516     (_i "Transpose @var{music} from pitch @var{from} to pitch @var{to}
517 using @var{scale}.")
518     (let ((transposer (make-modal-transposer from to scale)))
519       (change-pitches music transposer)
520       music))
521
522 inversion =
523 #(define-music-function
524    (parser location around to music) (ly:pitch? ly:pitch? ly:music?)
525    (_i "Invert @var{music} about @var{around} and
526 transpose from @var{around} to @var{to}.")
527    (music-invert around to music))
528
529 mark =
530 #(define-music-function
531    (parser location label) ((scheme? '()))
532   "Make the music for the \\mark command."
533   (let* ((set (and (integer? label)
534                    (context-spec-music (make-property-set 'rehearsalMark label)
535                                       'Score)))
536          (ev (make-music 'MarkEvent
537                          'origin location)))
538
539     (if set
540         (make-sequential-music (list set ev))
541         (begin
542           (set! (ly:music-property ev 'label) label)
543           ev))))
544
545 musicMap =
546 #(define-music-function (parser location proc mus) (procedure? ly:music?)
547    (_i "Apply @var{proc} to @var{mus} and all of the music it contains.")
548    (music-map proc mus))
549
550 %% noPageBreak and noPageTurn are music functions (not music indentifiers),
551 %% because music identifiers are not allowed at top-level.
552 noPageBreak =
553 #(define-music-function (location parser) ()
554    (_i "Forbid a page break.  May be used at toplevel (i.e., between scores or
555 markups), or inside a score.")
556    (make-music 'EventChord
557                'page-marker #t
558                'page-break-permission 'forbid
559                'elements (list (make-music 'PageBreakEvent
560                                            'break-permission '()))))
561
562 noPageTurn =
563 #(define-music-function (location parser) ()
564    (_i "Forbid a page turn.  May be used at toplevel (i.e., between scores or
565 markups), or inside a score.")
566    (make-music 'EventChord
567                'page-marker #t
568                'page-turn-permission 'forbid
569                'elements (list (make-music 'PageTurnEvent
570                                            'break-permission '()))))
571
572
573
574 octaveCheck =
575 #(define-music-function (parser location pitch) (ly:pitch?)
576    (_i "Octave check.")
577    (make-music 'RelativeOctaveCheck
578                'pitch pitch))
579
580 once =
581 #(define-music-function (parser location music) (ly:music?)
582    (_i "Set @code{once} to @code{#t} on all layout instruction events in @var{music}.")
583    (music-map
584     (lambda (m)
585       (cond ((music-is-of-type? m 'layout-instruction-event)
586              (set! (ly:music-property m 'once) #t))
587             ((ly:duration? (ly:music-property m 'duration))
588              (ly:music-warning m (_ "Cannot apply \\once to timed music"))))
589       m)
590     music))
591
592 ottava =
593 #(define-music-function (parser location octave) (integer?)
594    (_i "Set the octavation.")
595    (make-music 'OttavaMusic
596                'ottava-number octave))
597
598 overrideTimeSignatureSettings =
599 #(define-music-function
600    (parser location time-signature base-moment beat-structure beam-exceptions)
601    (pair? pair? cheap-list? cheap-list?)
602
603    (_i "Override @code{timeSignatureSettings}
604 for time signatures of @var{time-signature} to have settings
605 of @var{base-moment}, @var{beat-structure}, and @var{beam-exceptions}.")
606
607    ;; TODO -- add warning if largest value of grouping is
608    ;;       greater than time-signature.
609   (let ((setting (make-setting base-moment beat-structure beam-exceptions)))
610     (override-time-signature-setting time-signature setting)))
611
612 overrideProperty =
613 #(define-music-function (parser location name property value)
614    (string? symbol? scheme?)
615
616    (_i "Set @var{property} to @var{value} in all grobs named @var{name}.
617 The @var{name} argument is a string of the form @code{\"Context.GrobName\"}
618 or @code{\"GrobName\"}.")
619
620    (let ((name-components (string-split name #\.))
621          (context-name 'Bottom)
622          (grob-name #f))
623
624      (if (> 2 (length name-components))
625          (set! grob-name (string->symbol (car name-components)))
626          (begin
627            (set! grob-name (string->symbol (list-ref name-components 1)))
628            (set! context-name (string->symbol (list-ref name-components 0)))))
629
630      (make-music 'ApplyOutputEvent
631                  'context-type context-name
632                  'procedure
633                  (lambda (grob orig-context context)
634                    (if (equal?
635                         (cdr (assoc 'name (ly:grob-property grob 'meta)))
636                         grob-name)
637                        (set! (ly:grob-property grob property) value))))))
638
639
640
641 %% pageBreak and pageTurn are music functions (iso music indentifiers),
642 %% because music identifiers are not allowed at top-level.
643 pageBreak =
644 #(define-music-function (location parser) ()
645    (_i "Force a page break.  May be used at toplevel (i.e., between scores or
646 markups), or inside a score.")
647    (make-music 'EventChord
648                'page-marker #t
649                'line-break-permission 'force
650                'page-break-permission 'force
651                'elements (list (make-music 'LineBreakEvent
652                                            'break-permission 'force)
653                                (make-music 'PageBreakEvent
654                                            'break-permission 'force))))
655
656 pageTurn =
657 #(define-music-function (location parser) ()
658    (_i "Force a page turn between two scores or top-level markups.")
659    (make-music 'EventChord
660                'page-marker #t
661                'line-break-permission 'force
662                'page-break-permission 'force
663                'page-turn-permission 'force
664                'elements (list (make-music 'LineBreakEvent
665                                            'break-permission 'force)
666                                (make-music 'PageBreakEvent
667                                            'break-permission 'force)
668                                (make-music 'PageTurnEvent
669                                            'break-permission 'force))))
670
671 parallelMusic =
672 #(define-void-function (parser location voice-ids music) (list? ly:music?)
673    (_i "Define parallel music sequences, separated by '|' (bar check signs),
674 and assign them to the identifiers provided in @var{voice-ids}.
675
676 @var{voice-ids}: a list of music identifiers (symbols containing only letters)
677
678 @var{music}: a music sequence, containing BarChecks as limiting expressions.
679
680 Example:
681
682 @verbatim
683   \\parallelMusic #'(A B C) {
684     c c | d d | e e |
685     d d | e e | f f |
686   }
687 <==>
688   A = { c c | d d | }
689   B = { d d | e e | }
690   C = { e e | f f | }
691 @end verbatim
692 ")
693    (let* ((voices (apply circular-list (make-list (length voice-ids) (list))))
694           (current-voices voices)
695           (current-sequence (list))
696           (original music)
697           (wrapper #f))
698      ;;
699      ;; utilities
700      (define (push-music m)
701        "Push the music expression into the current sequence"
702        (set! current-sequence (cons m current-sequence)))
703      (define (change-voice)
704        "Stores the previously built sequence into the current voice and
705        change to the following voice."
706        (list-set! current-voices 0 (cons (make-music 'SequentialMusic
707                                                      'elements (reverse! current-sequence))
708                                          (car current-voices)))
709        (set! current-sequence (list))
710        (set! current-voices (cdr current-voices)))
711      (define (bar-check? m)
712        "Checks whether m is a bar check."
713        (eq? (ly:music-property m 'name) 'BarCheck))
714      (define (music-origin music)
715        "Recursively search an origin location stored in music."
716        (cond ((null? music) #f)
717              ((not (null? (ly:music-property music 'origin)))
718               (ly:music-property music 'origin))
719              (else (or (music-origin (ly:music-property music 'element))
720                        (let ((origins (remove not (map music-origin
721                                                        (ly:music-property music 'elements)))))
722                          (and (not (null? origins)) (car origins)))))))
723      (while (music-is-of-type? music 'music-wrapper-music)
724             (set! wrapper music)
725             (set! music (ly:music-property wrapper 'element)))
726      (if wrapper
727          (set! (ly:music-property wrapper 'element)
728                                   (make-music 'SequentialMusic
729                                               'origin location))
730          (set! original
731                (make-music 'SequentialMusic
732                            'origin location)))
733      ;;
734      ;; first, split the music and fill in voices
735      ;; We flatten direct layers of SequentialMusic since they are
736      ;; pretty much impossible to avoid when writing music functions.
737      (let rec ((music music))
738        (for-each (lambda (m)
739                    (if (eq? (ly:music-property m 'name) 'SequentialMusic)
740                        (rec m)
741                        (begin
742                          (push-music m)
743                          (if (bar-check? m) (change-voice)))))
744                  (ly:music-property music 'elements)))
745      (if (not (null? current-sequence)) (change-voice))
746      ;; un-circularize `voices' and reorder the voices
747      (set! voices (map-in-order (lambda (dummy seqs)
748                                   (reverse! seqs))
749                                 voice-ids voices))
750      ;;
751      ;; set origin location of each sequence in each voice
752      ;; for better type error tracking
753      (for-each (lambda (voice)
754                  (for-each (lambda (seq)
755                              (set! (ly:music-property seq 'origin)
756                                    (or (music-origin seq) location)))
757                            voice))
758                voices)
759      ;;
760      ;; check sequence length
761      (apply for-each (lambda* (#:rest seqs)
762                               (let ((moment-reference (ly:music-length (car seqs))))
763                                 (for-each (lambda (seq moment)
764                                             (if (not (equal? moment moment-reference))
765                                                 (ly:music-warning seq
766                                                                   "Bars in parallel music don't have the same length")))
767                                           seqs (map-in-order ly:music-length seqs))))
768             voices)
769      ;;
770      ;; bind voice identifiers to the voices
771      (for-each (lambda (voice-id voice)
772             (ly:parser-define! parser voice-id
773                                (let ((v (ly:music-deep-copy original)))
774                                  (set! (ly:music-property
775                                         (car (extract-named-music
776                                               v 'SequentialMusic))
777                                         'elements) voice)
778                                  v)))
779           voice-ids voices)))
780
781 parenthesize =
782 #(define-music-function (parser loc arg) (ly:music?)
783    (_i "Tag @var{arg} to be parenthesized.")
784
785    (if (memq 'event-chord (ly:music-property arg 'types))
786        ;; arg is an EventChord -> set the parenthesize property
787        ;; on all child notes and rests
788        (for-each
789         (lambda (ev)
790           (if (or (memq 'note-event (ly:music-property ev 'types))
791                   (memq 'rest-event (ly:music-property ev 'types)))
792               (set! (ly:music-property ev 'parenthesize) #t)))
793         (ly:music-property arg 'elements))
794        ;; No chord, simply set property for this expression:
795        (set! (ly:music-property arg 'parenthesize) #t))
796    arg)
797
798 partcombine =
799 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
800    (_i "Take the music in @var{part1} and @var{part2} and typeset so
801 that they share a staff.")
802    (make-part-combine-music parser
803                             (list part1 part2) #f))
804
805 partcombineUp =
806 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
807    (_i "Take the music in @var{part1} and @var{part2} and typeset so
808 that they share a staff with stems directed upward.")
809    (make-part-combine-music parser
810                             (list part1 part2) UP))
811
812 partcombineDown =
813 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
814    (_i "Take the music in @var{part1} and @var{part2} and typeset so
815 that they share a staff with stems directed downward.")
816    (make-part-combine-music parser
817                             (list part1 part2) DOWN))
818
819 partcombineForce =
820 #(define-music-function (location parser type once) (symbol-or-boolean? boolean?)
821    (_i "Override the part-combiner.")
822    (make-music 'EventChord
823                'elements (list (make-music 'PartCombineForceEvent
824                                            'forced-type type
825                                            'once once))))
826 partcombineApart = \partcombineForce #'apart ##f
827 partcombineApartOnce = \partcombineForce #'apart ##t
828 partcombineChords = \partcombineForce #'chords ##f
829 partcombineChordsOnce = \partcombineForce #'chords ##t
830 partcombineUnisono = \partcombineForce #'unisono ##f
831 partcombineUnisonoOnce = \partcombineForce #'unisono ##t
832 partcombineSoloI = \partcombineForce #'solo1 ##f
833 partcombineSoloIOnce = \partcombineForce #'solo1 ##t
834 partcombineSoloII = \partcombineForce #'solo2 ##f
835 partcombineSoloIIOnce = \partcombineForce #'solo2 ##t
836 partcombineAutomatic = \partcombineForce ##f ##f
837 partcombineAutomaticOnce = \partcombineForce ##f ##t
838
839 partial =
840 #(define-music-function (parser location dur) (ly:duration?)
841   (_i "Make a partial measure.")
842
843   ;; We use `descend-to-context' here instead of `context-spec-music' to
844   ;; ensure \partial still works if the Timing_translator is moved
845     (descend-to-context
846      (context-spec-music (make-music 'PartialSet
847                                      'origin location
848                                      'partial-duration dur)
849                          'Timing)
850      'Score))
851
852 pitchedTrill =
853 #(define-music-function
854    (parser location main-note secondary-note)
855    (ly:music? ly:music?)
856    (_i "Print a trill with @var{main-note} as the main note of the trill and
857 print @var{secondary-note} as a stemless note head in parentheses.")
858    (let* ((get-notes (lambda (ev-chord)
859                        (extract-named-music ev-chord 'NoteEvent)))
860           (sec-note-events (get-notes secondary-note))
861           (trill-events (extract-named-music main-note 'TrillSpanEvent)))
862      (if (pair? sec-note-events)
863          (begin
864            (let* ((trill-pitch (ly:music-property (car sec-note-events) 'pitch))
865                   (forced (ly:music-property (car sec-note-events) 'force-accidental)))
866
867              (if (ly:pitch? trill-pitch)
868                  (for-each (lambda (m)
869                              (ly:music-set-property! m 'pitch trill-pitch)) trill-events)
870                  (begin
871                    (ly:input-warning location (_ "Second argument of \\pitchedTrill should be single note: "))
872                    (display sec-note-events)))
873
874              (if (eq? forced #t)
875                  (for-each (lambda (m)
876                              (ly:music-set-property! m 'force-accidental forced))
877                            trill-events)))))
878      main-note))
879
880 pushToTag =
881 #(define-music-function (parser location tag more music)
882    (symbol? ly:music? ly:music?)
883    (_i "Add @var{more} to the front of @code{elements} of all music
884 expressions in @var{music} that are tagged with @var{tag}.")
885    (music-map (lambda (m)
886                 (if (memq tag (ly:music-property m 'tags))
887                     (set! (ly:music-property m 'elements)
888                           (cons more (ly:music-property m 'elements))))
889                 m)
890               music))
891
892 quoteDuring =
893 #(define-music-function (parser location what main-music) (string? ly:music?)
894    (_i "Indicate a section of music to be quoted.  @var{what} indicates the name
895 of the quoted voice, as specified in an @code{\\addQuote} command.
896 @var{main-music} is used to indicate the length of music to be quoted;
897 usually contains spacers or multi-measure rests.")
898    (make-music 'QuoteMusic
899                'element main-music
900                'quoted-music-name what))
901
902 relative =
903 #(define-music-function (parser location pitch music)
904    ((ly:pitch? (ly:make-pitch 0 0 0)) ly:music?)
905    (_i "Make @var{music} relative to @var{pitch} (default @code{c'}).")
906    (ly:make-music-relative! music pitch)
907    (make-music 'RelativeOctaveMusic
908                'element music))
909
910 removeWithTag =
911 #(define-music-function (parser location tag music) (symbol? ly:music?)
912    (_i "Remove elements of @var{music} that are tagged with @var{tag}.")
913    (music-filter
914     (lambda (m)
915       (let* ((tags (ly:music-property m 'tags))
916              (res (memq tag tags)))
917         (not res)))
918     music))
919
920 resetRelativeOctave =
921 #(define-music-function (parser location pitch) (ly:pitch?)
922    (_i "Set the octave inside a \\relative section.")
923
924    (make-music 'SequentialMusic
925                'to-relative-callback
926                (lambda (music last-pitch) pitch)))
927
928 retrograde =
929 #(define-music-function (parser location music)
930     (ly:music?)
931     (_i "Return @var{music} in reverse order.")
932     (retrograde-music music))
933
934 revertTimeSignatureSettings =
935 #(define-music-function
936    (parser location time-signature)
937    (pair?)
938
939    (_i "Revert @code{timeSignatureSettings}
940 for time signatures of @var{time-signature}.")
941    (revert-time-signature-setting time-signature))
942
943 rightHandFinger =
944 #(define-music-function (parser location finger) (number-or-string?)
945    (_i "Apply @var{finger} as a fingering indication.")
946
947    (make-music
948             'StrokeFingerEvent
949             'origin location
950             (if (string? finger) 'text 'digit)
951             finger))
952
953 scaleDurations =
954 #(define-music-function (parser location fraction music)
955    (fraction? ly:music?)
956    (_i "Multiply the duration of events in @var{music} by @var{fraction}.")
957    (ly:music-compress music
958                       (ly:make-moment (car fraction) (cdr fraction))))
959
960 settingsFrom =
961 #(define-scheme-function (parser location ctx music)
962    ((symbol?) ly:music?)
963    (_i "Take the layout instruction events from @var{music}, optionally
964 restricted to those applying to context type @var{ctx}, and return
965 a context modification duplicating their effect.")
966    (let ((mods (ly:make-context-mod)))
967      (define (musicop m)
968        (if (music-is-of-type? m 'layout-instruction-event)
969            (ly:add-context-mod
970             mods
971             (case (ly:music-property m 'name)
972               ((PropertySet)
973                (list 'assign
974                      (ly:music-property m 'symbol)
975                      (ly:music-property m 'value)))
976               ((PropertyUnset)
977                (list 'unset
978                      (ly:music-property m 'symbol)))
979               ((OverrideProperty)
980                (list 'push
981                      (ly:music-property m 'symbol)
982                      (ly:music-property m 'grob-property-path)
983                      (ly:music-property m 'grob-value)))
984               ((RevertProperty)
985                (list 'pop
986                      (ly:music-property m 'symbol)
987                      (ly:music-property m 'grob-property-path)))))
988            (case (ly:music-property m 'name)
989              ((SequentialMusic SimultaneousMusic)
990               (for-each musicop (ly:music-property m 'elements)))
991              ((ContextSpeccedMusic)
992               (if (or (not ctx)
993                       (eq? ctx (ly:music-property m 'context-type)))
994                   (musicop (ly:music-property m 'element)))))))
995      (musicop music)
996      mods))
997
998 shiftDurations =
999 #(define-music-function (parser location dur dots arg)
1000    (integer? integer? ly:music?)
1001    (_i "Change the duration of @var{arg} by adding @var{dur} to the
1002 @code{durlog} of @var{arg} and @var{dots} to the @code{dots} of @var{arg}.")
1003
1004    (music-map
1005     (lambda (x)
1006       (shift-one-duration-log x dur dots)) arg))
1007
1008 skip =
1009 #(define-music-function (parser location dur) (ly:duration?)
1010   (_i "Skip forward by @var{dur}.")
1011   (make-music 'SkipMusic
1012               'duration dur))
1013
1014
1015 slashedGrace =
1016 #(def-grace-function startSlashedGraceMusic stopSlashedGraceMusic
1017    (_i "Create slashed graces (slashes through stems, but no slur) from
1018 the following music expression"))
1019
1020 spacingTweaks =
1021 #(define-music-function (parser location parameters) (list?)
1022    (_i "Set the system stretch, by reading the 'system-stretch property of
1023 the `parameters' assoc list.")
1024    #{
1025      \overrideProperty #"Score.NonMusicalPaperColumn"
1026      #'line-break-system-details
1027      #(list (cons 'alignment-extra-space (cdr (assoc 'system-stretch parameters)))
1028              (cons 'system-Y-extent (cdr (assoc 'system-Y-extent parameters))))
1029    #})
1030
1031 styledNoteHeads =
1032 #(define-music-function (parser location style heads music)
1033    (symbol? list-or-symbol? ly:music?)
1034    (_i "Set @var{heads} in @var{music} to @var{style}.")
1035    (style-note-heads heads style music))
1036
1037 tag =
1038 #(define-music-function (parser location tag arg) (symbol? ly:music?)
1039
1040    (_i "Add @var{tag} to the @code{tags} property of @var{arg}.")
1041
1042    (set!
1043     (ly:music-property arg 'tags)
1044     (cons tag
1045           (ly:music-property arg 'tags)))
1046    arg)
1047
1048 time =
1049 #(define-music-function (parser location beat-structure fraction)
1050    ((number-list? '()) fraction?)
1051    (_i "Set @var{fraction} as time signature, with optional
1052 number list @var{beat-structure} before it.")
1053   (make-music 'TimeSignatureMusic
1054               'numerator (car fraction)
1055               'denominator (cdr fraction)
1056               'beat-structure beat-structure))
1057
1058 times =
1059 #(define-music-function (parser location fraction music)
1060    (fraction? ly:music?)
1061    (_i "Scale @var{music} in time by @var{fraction}.")
1062   (make-music 'TimeScaledMusic
1063               'element (ly:music-compress music (ly:make-moment (car fraction) (cdr fraction)))
1064               'numerator (car fraction)
1065               'denominator (cdr fraction)))
1066
1067 transpose =
1068 #(define-music-function
1069    (parser location from to music)
1070    (ly:pitch? ly:pitch? ly:music?)
1071
1072    (_i "Transpose @var{music} from pitch @var{from} to pitch @var{to}.")
1073    (make-music 'TransposedMusic
1074                'element (ly:music-transpose music (ly:pitch-diff to from))))
1075
1076 transposedCueDuring =
1077 #(define-music-function
1078    (parser location what dir pitch main-music)
1079    (string? ly:dir? ly:pitch? ly:music?)
1080
1081    (_i "Insert notes from the part @var{what} into a voice called @code{cue},
1082 using the transposition defined by @var{pitch}.  This happens
1083 simultaneously with @var{main-music}, which is usually a rest.  The
1084 argument @var{dir} determines whether the cue notes should be notated
1085 as a first or second voice.")
1086
1087    (make-music 'QuoteMusic
1088                'element main-music
1089                'quoted-context-type 'Voice
1090                'quoted-context-id "cue"
1091                'quoted-music-name what
1092                'quoted-voice-direction dir
1093                'quoted-transposition pitch))
1094
1095 transposition =
1096 #(define-music-function (parser location pitch) (ly:pitch?)
1097    (_i "Set instrument transposition")
1098
1099    (context-spec-music
1100     (make-property-set 'instrumentTransposition
1101                        (ly:pitch-negate pitch))
1102     'Staff))
1103
1104 tweak =
1105 #(define-music-function (parser location sym val arg)
1106    (symbol? scheme? ly:music?)
1107    (_i "Add @code{sym . val} to the @code{tweaks} property of @var{arg}.")
1108
1109    (if (equal? (object-property sym 'backend-type?) #f)
1110        (begin
1111          (ly:input-warning location (_ "cannot find property type-check for ~a") sym)
1112          (ly:warning (_ "doing assignment anyway"))))
1113    (set!
1114     (ly:music-property arg 'tweaks)
1115     (acons sym val
1116            (ly:music-property arg 'tweaks)))
1117    arg)
1118
1119
1120
1121 unfoldRepeats =
1122 #(define-music-function (parser location music) (ly:music?)
1123    (_i "Force any @code{\\repeat volta}, @code{\\repeat tremolo} or
1124 @code{\\repeat percent} commands in @var{music} to be interpreted
1125 as @code{\\repeat unfold}.")
1126    (unfold-repeats music))
1127
1128 void =
1129 #(define-void-function (parser location arg) (scheme?)
1130    (_i "Accept a scheme argument, return a void expression.
1131 Use this if you want to have a scheme expression evaluated
1132 because of its side-effects, but its value ignored."))
1133
1134 withMusicProperty =
1135 #(define-music-function (parser location sym val music)
1136    (symbol? scheme? ly:music?)
1137    (_i "Set @var{sym} to @var{val} in @var{music}.")
1138
1139    (set! (ly:music-property music sym) val)
1140    music)