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