]> git.donarmstrong.com Git - lilypond.git/blob - ly/music-functions-init.ly
Enhancement: tabalture chord repetition
[lilypond.git] / ly / music-functions-init.ly
1 %%%% This file is part of LilyPond, the GNU music typesetter.
2 %%%%
3 %%%% Copyright (C) 2003--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
4 %%%%                          Jan Nieuwenhuizen <janneke@gnu.org>
5 %%%%
6 %%%% LilyPond is free software: you can redistribute it and/or modify
7 %%%% it under the terms of the GNU General Public License as published by
8 %%%% the Free Software Foundation, either version 3 of the License, or
9 %%%% (at your option) any later version.
10 %%%%
11 %%%% LilyPond is distributed in the hope that it will be useful,
12 %%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
13 %%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 %%%% GNU General Public License for more details.
15 %%%%
16 %%%% You should have received a copy of the GNU General Public License
17 %%%% along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18
19 % -*-Scheme-*-
20
21 \version "2.12.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-music-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    (make-music 'SequentialMusic 'void #t))
46
47 addQuote =
48 #(define-music-function (parser location name music) (string? ly:music?)
49    (_i "Define @var{music} as a quotable music expression named
50 @var{name}")
51    (add-quotable parser name music)
52    (make-music 'SequentialMusic 'void #t))
53
54 %% keep these two together
55 afterGraceFraction = #(cons 6 8)
56 afterGrace =
57 #(define-music-function
58   (parser location main grace)
59   (ly:music? ly:music?)
60   (_i "Create @var{grace} note(s) after a @var{main} music expression.")
61   (let*
62       ((main-length (ly:music-length main))
63        (fraction  (ly:parser-lookup parser 'afterGraceFraction)))
64
65     (make-simultaneous-music
66      (list
67       main
68       (make-sequential-music
69        (list
70
71         (make-music 'SkipMusic
72                     'duration (ly:make-duration
73                                0 0
74                                (* (ly:moment-main-numerator main-length)
75                                   (car fraction))
76                                (* (ly:moment-main-denominator main-length)
77                                   (cdr fraction)) ))
78         (make-music 'GraceMusic
79                     'element grace)))))))
80
81
82 %% music identifiers not allowed at top-level,
83 %% so this is a music-function instead.
84 allowPageTurn =
85 #(define-music-function (location parser) ()
86    (_i "Allow a page turn. May be used at toplevel (ie between scores or
87 markups), or inside a score.")
88    (make-music 'EventChord
89                'page-marker #t
90                'page-turn-permission 'allow
91                'elements (list (make-music 'PageTurnEvent
92                                            'break-permission 'allow))))
93
94 applyContext =
95 #(define-music-function (parser location proc) (procedure?)
96   (_i "Modify context properties with Scheme procedure @var{proc}.")
97   (make-music 'ApplyContext
98               'origin location
99               'procedure proc))
100
101 applyMusic =
102 #(define-music-function (parser location func music) (procedure? ly:music?)
103    (_i"Apply procedure @var{func} to @var{music}.")
104   (func music))
105
106 applyOutput =
107 #(define-music-function (parser location ctx proc) (symbol? procedure?)
108   (_i "Apply function @code{proc} to every layout object in context @code{ctx}")
109   (make-music 'ApplyOutputEvent
110               'origin location
111               'procedure proc
112               'context-type ctx))
113
114 appoggiatura =
115 #(def-grace-function startAppoggiaturaMusic stopAppoggiaturaMusic
116   (_i "Create an appoggiatura from @var{music}"))
117
118 % for regression testing purposes.
119 assertBeamQuant =
120 #(define-music-function (parser location l r) (pair? pair?)
121   (_i "Testing function: check whether the beam quants @var{l} and @var{r} are correct")
122   (make-grob-property-override 'Beam 'positions
123    (ly:make-simple-closure
124     (ly:make-simple-closure
125      (append
126       (list chain-grob-member-functions `(,cons 0 0))
127       (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
134    (ly:make-simple-closure
135     (ly:make-simple-closure
136      (append
137       (list chain-grob-member-functions `(,cons 0 0))
138       (check-slope-callbacks comp))))))
139
140 autochange =
141 #(define-music-function (parser location music) (ly:music?)
142   (_i "Make voices that switch between staves automatically")
143   (make-autochange-music parser music))
144
145
146
147 balloonGrobText =
148 #(define-music-function (parser location grob-name offset text)
149                         (symbol? number-pair? markup?)
150   (_i "Attach @var{text} to @var{grob-name} at offset @var{offset}
151 use like @code{\\once})")
152     (make-music 'AnnotateOutputEvent
153                 'symbol grob-name
154                 'X-offset (car offset)
155                 'Y-offset (cdr offset)
156                 'text text))
157
158 balloonText =
159 #(define-music-function (parser location offset text) (number-pair? markup?)
160   (_i "Attach @var{text} at @var{offset} (use like @code{\\tweak})")
161     (make-music 'AnnotateOutputEvent
162                 'X-offset (car offset)
163                 'Y-offset (cdr offset)
164                 'text text))
165
166 bar =
167 #(define-music-function (parser location type) (string?)
168   (_i "Insert a bar line of type @var{type}")
169    (context-spec-music
170     (make-property-set 'whichBar type)
171     'Timing))
172
173 barNumberCheck =
174 #(define-music-function (parser location n) (integer?)
175   (_i "Print a warning if the current bar number is not @var{n}.")
176    (make-music 'ApplyContext
177                'origin location
178                'procedure
179                (lambda (c)
180                  (let*
181                      ((cbn (ly:context-property c 'currentBarNumber)))
182                    (if (and  (number? cbn) (not (= cbn n)))
183                        (ly:input-message location "Barcheck failed got ~a expect ~a"
184                                          cbn n))))))
185
186 bendAfter =
187 #(define-music-function (parser location delta) (real?)
188   (_i "Create a fall or doit of pitch interval @var{delta}.")
189   (make-music 'BendAfterEvent
190               'delta-step delta))
191
192 bookOutputName =
193 #(define-music-function (parser location newfilename) (string?)
194   (_i "Direct output for the current book block to @var{newfilename}.")
195   (set! book-filename newfilename)
196   (make-music 'SequentialMusic 'void #t))
197
198 bookOutputSuffix =
199 #(define-music-function (parser location newsuffix) (string?)
200   (_i "Set the output filename suffix for the current book block to
201 @var{newsuffix}.")
202   (set! book-output-suffix newsuffix)
203   (make-music 'SequentialMusic 'void #t))
204
205 %% why a function?
206 breathe =
207 #(define-music-function (parser location) ()
208   (_i "Insert a breath mark.")
209             (make-music 'EventChord
210               'origin location
211               'elements (list (make-music 'BreathingEvent))))
212
213
214
215 clef =
216 #(define-music-function (parser location type) (string?)
217   (_i "Set the current clef to @var{type}.")
218    (make-clef-set type))
219
220 cueDuring =
221 #(define-music-function
222   (parser location what dir main-music) (string? ly:dir? ly:music?)
223   (_i "Insert contents of quote @var{what} corresponding to @var{main-music},
224 in a CueVoice oriented by @var{dir}.")
225   (make-music 'QuoteMusic
226               'element main-music
227               'quoted-context-type 'Voice
228               'quoted-context-id "cue"
229               'quoted-music-name what
230               'quoted-voice-direction dir
231               'origin location))
232
233
234
235 displayLilyMusic =
236 #(define-music-function (parser location music) (ly:music?)
237   (_i "Display  the LilyPond input representation of @var{music}
238 to the console.")
239    (newline)
240    (display-lily-music music parser)
241    music)
242
243 displayMusic =
244 #(define-music-function (parser location music) (ly:music?)
245   (_i "Display the internal representation of @var{music} to the console.")
246    (newline)
247    (display-scheme-music music)
248    music)
249
250
251
252 endSpanners =
253 #(define-music-function (parser location music) (ly:music?)
254   (_i "Terminate the next spanner prematurely after exactly one note without the need of a specific end spanner.")
255    (if (eq? (ly:music-property music 'name) 'EventChord)
256        (let*
257            ((elts (ly:music-property music 'elements))
258             (start-span-evs (filter (lambda (ev)
259                                 (and (music-has-type ev 'span-event)
260                                      (equal? (ly:music-property ev 'span-direction)
261                                              START)))
262                               elts))
263             (stop-span-evs
264              (map (lambda (m)
265                     (let* ((c (music-clone m)))
266                       (set! (ly:music-property c 'span-direction) STOP)
267                       c))
268                   start-span-evs))
269             (end-ev-chord (make-music 'EventChord
270                                       'elements stop-span-evs))
271             (total (make-music 'SequentialMusic
272                                'elements (list music
273                                                end-ev-chord))))
274          total)
275
276        (ly:input-message location (_ "argument endSpanners is not an EventChord: ~a" music))))
277
278
279
280 featherDurations=
281 #(define-music-function (parser location factor argument) (ly:moment? ly:music?)
282  (_i "Adjust durations of music in @var{argument} by rational @var{factor}. ")
283    (let*
284        ((orig-duration (ly:music-length argument))
285         (multiplier (ly:make-moment 1 1)))
286
287      (music-map
288       (lambda (mus)
289         (if (and (eq? (ly:music-property mus 'name) 'EventChord)
290                  (< 0 (ly:moment-main-denominator (ly:music-length mus))))
291             (begin
292               (ly:music-compress mus multiplier)
293               (set! multiplier (ly:moment-mul factor multiplier)))
294             )
295         mus)
296       argument)
297
298      (ly:music-compress
299       argument
300       (ly:moment-div orig-duration (ly:music-length argument)))
301
302      argument))
303
304
305
306 grace =
307 #(def-grace-function startGraceMusic stopGraceMusic
308    (_i "Insert @var{music} as grace notes."))
309
310
311
312 instrumentSwitch =
313 #(define-music-function
314    (parser location name) (string?)
315    (_i "Switch instrument to @var{name}, which must be predefined with
316 @code{\\addInstrumentDefinition}.")
317    (let*
318        ((handle  (assoc name instrument-definitions))
319         (instrument-def (if handle (cdr handle) '()))
320         )
321
322      (if (not handle)
323          (ly:input-message location "No such instrument: ~a" name))
324      (context-spec-music
325       (make-music 'SimultaneousMusic
326                   'elements
327                   (map (lambda (kv)
328                          (make-property-set
329                           (car kv)
330                           (cdr kv)))
331                        instrument-def))
332       'Staff)))
333
334
335
336 keepWithTag =
337 #(define-music-function
338   (parser location tag music) (symbol? ly:music?)
339   (_i "Include only elements of @var{music} that are tagged with @var{tag}.")
340   (music-filter
341    (lambda (m)
342     (let* ((tags (ly:music-property m 'tags))
343            (res (memq tag tags)))
344      (or
345       (eq? tags '())
346       res)))
347    music))
348
349 killCues =
350 #(define-music-function
351    (parser location music)
352    (ly:music?)
353    (_i "Remove cue notes from @var{music}.")
354    (music-map
355     (lambda (mus)
356       (if (and (string? (ly:music-property mus 'quoted-music-name))
357                (string=? (ly:music-property mus 'quoted-context-id "") "cue"))
358           (ly:music-property mus 'element)
359           mus)) music))
360
361
362
363 label =
364 #(define-music-function (parser location label) (symbol?)
365    (_i "Create @var{label} as a bookmarking label")
366    (make-music 'EventChord
367                'page-marker #t
368                'page-label label
369                'elements (list (make-music 'LabelEvent
370                                            'page-label label))))
371
372
373
374 makeClusters =
375 #(define-music-function
376                 (parser location arg) (ly:music?)
377    (_i "Display chords in @var{arg} as clusters")
378                 (music-map note-to-cluster arg))
379
380 musicMap =
381 #(define-music-function (parser location proc mus) (procedure? ly:music?)
382     (_i "Apply @var{proc} to @var{mus} and all of the music it contains.")
383     (music-map proc mus))
384
385
386
387 %% noPageBreak and noPageTurn are music functions (not music indentifiers),
388 %% because music identifiers are not allowed at top-level.
389 noPageBreak =
390 #(define-music-function (location parser) ()
391    (_i "Forbid a page break. May be used at toplevel (ie between scores or
392 markups), or inside a score.")
393    (make-music 'EventChord
394                'page-marker #t
395                'page-break-permission 'forbid
396                'elements (list (make-music 'PageBreakEvent
397                                            'break-permission '()))))
398
399 noPageTurn =
400 #(define-music-function (location parser) ()
401    (_i "Forbid a page turn. May be used at toplevel (ie between scores or
402 markups), or inside a score.")
403    (make-music 'EventChord
404                'page-marker #t
405                'page-turn-permission 'forbid
406                'elements (list (make-music 'PageTurnEvent
407                                            'break-permission '()))))
408
409
410
411 octaveCheck =
412 #(define-music-function (parser location pitch-note) (ly:music?)
413    (_i "octave check")
414
415    (make-music 'RelativeOctaveCheck
416                'origin location
417                'pitch (pitch-of-note pitch-note)
418            ))
419
420 ottava = #(define-music-function (parser location octave) (number?)
421   (_i "set the octavation ")
422   (make-ottava-set octave))
423
424 overrideBeamSettings =
425 #(define-music-function
426     (parser location
427      context time-signature rule-type grouping-rule)
428     (symbol? pair? symbol? pair?)
429
430  (_i "Override beamSettings in @var{context}
431 for time signatures of @var{time-signature} and rules of type
432 @var{rule-type} to have a grouping rule alist
433 @var{grouping-rule}.
434 @var{rule-type} can be @code{end} or @code{subdivide},
435 with a potential future value of @code{begin}.
436 @var{grouping-rule} is an alist of @var{(beam-type . grouping)}
437 entries.  @var{grouping} is in units of @var{beam-type}.  If
438 @var{beam-type} is @code{*}, grouping is in units of the denominator
439 of @var{time-signature}.")
440
441  ;; TODO -- add warning if largest value of grouping is
442  ;;         greater than time-signature.
443
444 #{
445 #(override-beam-setting
446   $time-signature $rule-type $grouping-rule $context)
447 #})
448
449 overrideProperty =
450 #(define-music-function (parser location name property value)
451    (string? symbol? scheme?)
452
453    (_i "Set @var{property} to @var{value} in all grobs named @var{name}.
454 The @var{name} argument is a string of the form @code{\"Context.GrobName\"}
455 or @code{\"GrobName\"}")
456
457    (let*
458        ((name-components (string-split name #\.))
459         (context-name 'Bottom)
460         (grob-name #f))
461
462      (if (> 2 (length name-components))
463          (set! grob-name (string->symbol (car name-components)))
464          (begin
465            (set! grob-name (string->symbol (list-ref name-components 1)))
466            (set! context-name (string->symbol (list-ref name-components 0)))))
467
468      (make-music 'ApplyOutputEvent
469                  'origin location
470                  'context-type context-name
471                  'procedure
472                  (lambda (grob orig-context context)
473                    (if (equal?
474                         (cdr (assoc 'name (ly:grob-property grob 'meta)))
475                         grob-name)
476                        (set! (ly:grob-property grob property) value))))))
477
478
479
480 %% pageBreak and pageTurn are music functions (iso music indentifiers),
481 %% because music identifiers are not allowed at top-level.
482 pageBreak =
483 #(define-music-function (location parser) ()
484    (_i "Force a page break. May be used at toplevel (i.e. between scores or
485 markups), or inside a score.")
486    (make-music 'EventChord
487                'page-marker #t
488                'line-break-permission 'force
489                'page-break-permission 'force
490                'elements (list (make-music 'LineBreakEvent
491                                            'break-permission 'force)
492                                (make-music 'PageBreakEvent
493                                            'break-permission 'force))))
494
495 pageTurn =
496 #(define-music-function (location parser) ()
497    (_i "Force a page turn between two scores or top-level markups.")
498    (make-music 'EventChord
499                'page-marker #t
500                'line-break-permission 'force
501                'page-break-permission 'force
502                'page-turn-permission 'force
503                'elements (list (make-music 'LineBreakEvent
504                                            'break-permission 'force)
505                                (make-music 'PageBreakEvent
506                                            'break-permission 'force)
507                                (make-music 'PageTurnEvent
508                                            'break-permission 'force))))
509
510 parallelMusic =
511 #(define-music-function (parser location voice-ids music) (list? ly:music?)
512   (_i "Define parallel music sequences, separated by '|' (bar check signs),
513 and assign them to the identifiers provided in @var{voice-ids}.
514
515 @var{voice-ids}: a list of music identifiers (symbols containing only letters)
516
517 @var{music}: a music sequence, containing BarChecks as limiting expressions.
518
519 Example:
520
521 @verbatim
522   \\parallelMusic #'(A B C) {
523     c c | d d | e e |
524     d d | e e | f f |
525   }
526 <==>
527   A = { c c | d d | }
528   B = { d d | e e | }
529   C = { e e | f f | }
530 @end verbatim
531 ")
532   (let* ((voices (apply circular-list (make-list (length voice-ids) (list))))
533          (current-voices voices)
534          (current-sequence (list)))
535     ;;
536     ;; utilities
537     (define (push-music m)
538       "Push the music expression into the current sequence"
539       (set! current-sequence (cons m current-sequence)))
540     (define (change-voice)
541       "Stores the previously built sequence into the current voice and
542        change to the following voice."
543       (list-set! current-voices 0 (cons (make-music 'SequentialMusic
544                                          'elements (reverse! current-sequence))
545                                         (car current-voices)))
546       (set! current-sequence (list))
547       (set! current-voices (cdr current-voices)))
548     (define (bar-check? m)
549       "Checks whether m is a bar check."
550       (eq? (ly:music-property m 'name) 'BarCheck))
551     (define (music-origin music)
552       "Recursively search an origin location stored in music."
553       (cond ((null? music) #f)
554             ((not (null? (ly:music-property music 'origin)))
555              (ly:music-property music 'origin))
556             (else (or (music-origin (ly:music-property music 'element))
557                       (let ((origins (remove not (map music-origin
558                                                       (ly:music-property music 'elements)))))
559                         (and (not (null? origins)) (car origins)))))))
560     ;;
561     ;; first, split the music and fill in voices
562     (map-in-order (lambda (m)
563                     (push-music m)
564                     (if (bar-check? m) (change-voice)))
565                   (ly:music-property music 'elements))
566     (if (not (null? current-sequence)) (change-voice))
567     ;; un-circularize `voices' and reorder the voices
568     (set! voices (map-in-order (lambda (dummy seqs)
569                                  (reverse! seqs))
570                                voice-ids voices))
571     ;;
572     ;; set origin location of each sequence in each voice
573     ;; for better type error tracking
574     (for-each (lambda (voice)
575                 (for-each (lambda (seq)
576                             (set! (ly:music-property seq 'origin)
577                                   (or (music-origin seq) location)))
578                           voice))
579               voices)
580     ;;
581     ;; check sequence length
582     (apply for-each (lambda* (#:rest seqs)
583                       (let ((moment-reference (ly:music-length (car seqs))))
584                         (for-each (lambda (seq moment)
585                                     (if (not (equal? moment moment-reference))
586                                         (ly:music-message seq
587                                          "Bars in parallel music don't have the same length")))
588                           seqs (map-in-order ly:music-length seqs))))
589            voices)
590    ;;
591    ;; bind voice identifiers to the voices
592    (map (lambda (voice-id voice)
593           (ly:parser-define! parser voice-id
594                              (make-music 'SequentialMusic
595                                'origin location
596                                'elements voice)))
597         voice-ids voices))
598  ;; Return an empty sequence. this function is actually a "void" function.
599  (make-music 'SequentialMusic 'void #t))
600
601 parenthesize =
602 #(define-music-function (parser loc arg) (ly:music?)
603    (_i "Tag @var{arg} to be parenthesized.")
604
605    (if (memq 'event-chord (ly:music-property arg 'types))
606      ; arg is an EventChord -> set the parenthesize property on all child notes and rests
607      (map
608        (lambda (ev)
609          (if (or (memq 'note-event (ly:music-property ev 'types))
610                  (memq 'rest-event (ly:music-property ev 'types)))
611            (set! (ly:music-property ev 'parenthesize) #t)))
612        (ly:music-property arg 'elements))
613      ; No chord, simply set property for this expression:
614      (set! (ly:music-property arg 'parenthesize) #t))
615    arg)
616
617 partcombine =
618 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
619    (_i "Take the music in @var{part1} and @var{part2} and typeset so that they share a staff.")
620    (make-part-combine-music parser
621                             (list part1 part2)))
622
623 pitchedTrill =
624 #(define-music-function
625    (parser location main-note secondary-note)
626    (ly:music? ly:music?)
627    (_i "Print a trill with @var{main-note} as the main note of the trill and
628 print @var{secondary-note} as a stemless note head in parentheses.")
629    (let* ((get-notes (lambda (ev-chord)
630                        (filter
631                         (lambda (m) (eq? 'NoteEvent (ly:music-property m 'name)))
632                         (ly:music-property ev-chord 'elements))))
633           (sec-note-events (get-notes secondary-note))
634           (trill-events (filter (lambda (m) (music-has-type m 'trill-span-event))
635                                 (ly:music-property main-note 'elements))))
636
637      (if (pair? sec-note-events)
638          (begin
639            (let* ((trill-pitch (ly:music-property (car sec-note-events) 'pitch))
640                   (forced (ly:music-property (car sec-note-events) 'force-accidental)))
641
642              (if (ly:pitch? trill-pitch)
643                  (for-each (lambda (m)
644                              (ly:music-set-property! m 'pitch trill-pitch)) trill-events)
645                  (begin
646                    (ly:warning (_ "Second argument of \\pitchedTrill should be single note: "))
647                    (display sec-note-events)))
648
649              (if (eq? forced #t)
650                  (for-each (lambda (m)
651                              (ly:music-set-property! m 'force-accidental forced))
652                            trill-events)))))
653      main-note))
654
655 quoteDuring =
656 #(define-music-function
657    (parser location what main-music)
658    (string? ly:music?)
659    (_i "Indicate a section of music to be quoted.  @var{what} indicates the name
660 of the quoted voice, as specified in an @code{\\addQuote} command.
661 @var{main-music} is used to indicate the length of music to be quoted;
662 usually contains spacers or multi-measure rests.")
663    (make-music 'QuoteMusic
664                'element main-music
665                'quoted-music-name what
666                'origin location))
667
668 removeWithTag =
669 #(define-music-function
670   (parser location tag music) (symbol? ly:music?)
671   (_i "Remove elements of @var{music} that are tagged with @var{tag}.")
672   (music-filter
673    (lambda (m)
674     (let* ((tags (ly:music-property m 'tags))
675            (res (memq tag tags)))
676      (not res)))
677  music))
678
679 resetRelativeOctave =
680 #(define-music-function
681     (parser location reference-note)
682     (ly:music?)
683     (_i "Set the octave inside a \\relative section.")
684
685    (let*
686     ((notes (ly:music-property reference-note 'elements))
687      (pitch (ly:music-property (car notes) 'pitch)))
688
689     (set! (ly:music-property reference-note 'elements) '())
690     (set! (ly:music-property reference-note
691        'to-relative-callback)
692        (lambda (music last-pitch)
693         pitch))
694
695     reference-note))
696
697 revertBeamSettings =
698 #(define-music-function
699     (parser location
700      context time-signature rule-type)
701     (symbol? pair? symbol?)
702
703  (_i "Revert beam settings in @var{context} for time signatures of
704 @var{time-signature} and groups of type
705 @var{group-type}.  @var{group-type} can be @code{end}
706 or @code{subdivide}.")
707 #{
708   #(revert-beam-setting $time-signature $rule-type $context)
709 #})
710
711 rightHandFinger =
712 #(define-music-function (parser location finger) (number-or-string?)
713    (_i "Apply @var{finger} as a fingering indication.")
714
715    (apply make-music
716           (append
717            (list
718             'StrokeFingerEvent
719             'origin location)
720            (if  (string? finger)
721                 (list 'text finger)
722                 (list 'digit finger)))))
723
724
725
726 scaleDurations =
727 #(define-music-function (parser location fraction music) (number-pair? ly:music?)
728    (_i "Multiply the duration of events in @var{music} by @var{fraction}.")
729    (ly:music-compress music
730                       (ly:make-moment (car fraction) (cdr fraction))))
731
732 setBeatGrouping =
733 #(define-music-function (parser location grouping) (pair?)
734    (_i "Set the beat grouping in the current time signature to
735 @var{grouping}.")
736    (define (default-group-setting c)
737     (let* ((context-time-signature
738             (ly:context-property c 'timeSignatureFraction))
739            (time-signature (if (null? context-time-signature)
740                                '(4 . 4)
741                                context-time-signature)))
742       (override-property-setting
743        c
744        'beamSettings
745        (list time-signature 'end)
746        (list  (cons '* grouping)))))
747
748    (context-spec-music
749      (make-apply-context default-group-setting)
750      'Score))
751
752 shiftDurations =
753 #(define-music-function (parser location dur dots arg) (integer? integer? ly:music?)
754    (_i "Scale @var{arg} up by a factor of @var{2^dur*(2-(1/2)^dots)}.")
755
756    (music-map
757     (lambda (x)
758       (shift-one-duration-log x dur dots)) arg))
759
760 spacingTweaks =
761 #(define-music-function (parser location parameters) (list?)
762    (_i "Set the system stretch, by reading the 'system-stretch property of
763 the `parameters' assoc list.")
764    #{
765       \overrideProperty #"Score.NonMusicalPaperColumn"
766         #'line-break-system-details
767         #$(list (cons 'alignment-extra-space (cdr (assoc 'system-stretch parameters)))
768                 (cons 'system-Y-extent (cdr (assoc 'system-Y-extent parameters))))
769    #})
770
771 styledNoteHeads =
772 #(define-music-function
773    (parser location style heads music)
774    (symbol? list-or-symbol? ly:music?)
775    (_i "Set @var{heads} in @var{music} to @var{style}.")
776    (style-note-heads heads style music))
777
778 tabChordRepetition =
779 #(define-music-function (parser location) ()
780    (_i "Include the string information in a chord repetition.")
781    (ly:parser-set-repetition-function parser tab-repeat-chord)
782    (make-music 'SequentialMusic 'void #t))
783
784 tag =
785 #(define-music-function (parser location tag arg)
786    (symbol? ly:music?)
787
788    (_i "Add @var{tag} to the @code{tags} property of @var{arg}.")
789
790    (set!
791     (ly:music-property arg 'tags)
792     (cons tag
793           (ly:music-property arg 'tags)))
794    arg)
795
796 transposedCueDuring =
797 #(define-music-function
798   (parser location what dir pitch-note main-music)
799   (string? ly:dir? ly:music? ly:music?)
800
801   (_i "Insert notes from the part @var{what} into a voice called @code{cue},
802 using the transposition defined by @var{pitch-note}.  This happens
803 simultaneously with @var{main-music}, which is usually a rest.  The
804 argument @var{dir} determines whether the cue notes should be notated
805 as a first or second voice.")
806
807   (make-music 'QuoteMusic
808               'element main-music
809               'quoted-context-type 'Voice
810               'quoted-context-id "cue"
811               'quoted-music-name what
812               'quoted-voice-direction dir
813               'quoted-transposition (pitch-of-note pitch-note)
814               'origin location))
815
816 transposition =
817 #(define-music-function (parser location pitch-note) (ly:music?)
818    (_i "Set instrument transposition")
819
820    (context-spec-music
821     (make-property-set 'instrumentTransposition
822                        (ly:pitch-negate (pitch-of-note pitch-note)))
823         'Staff))
824
825 tweak =
826 #(define-music-function (parser location sym val arg)
827    (symbol? scheme? ly:music?)
828    (_i "Add @code{sym . val} to the @code{tweaks} property of @var{arg}.")
829
830    (if (equal? (object-property sym 'backend-type?) #f)
831        (begin
832          (ly:warning (_ "cannot find property type-check for ~a") sym)
833          (ly:warning (_ "doing assignment anyway"))))
834    (set!
835     (ly:music-property arg 'tweaks)
836     (acons sym val
837            (ly:music-property arg 'tweaks)))
838    arg)
839
840
841
842 unfoldRepeats =
843 #(define-music-function (parser location music) (ly:music?)
844    (_i "Force any @code{\\repeat volta}, @code{\\repeat tremolo} or
845 @code{\\repeat percent} commands in @var{music} to be interpreted
846 as @code{\\repeat unfold}.")
847    (unfold-repeats music))
848
849
850
851 withMusicProperty =
852 #(define-music-function (parser location sym val music) (symbol? scheme? ly:music?)
853    (_i "Set @var{sym} to @var{val} in @var{music}.")
854
855    (set! (ly:music-property music sym) val)
856    music)