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