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