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