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