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