]> git.donarmstrong.com Git - lilypond.git/blob - ly/music-functions-init.ly
Merge branch 'master' of git+ssh://git.sv.gnu.org/srv/git/lilypond
[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          (begin
387            (if (ly:get-option 'verbose)
388                (ly:message (_ "Using ~a note names...") str))
389            (ly:parser-set-note-names parser (eval-string extract-alist)))
390          (ly:error (_ "Cannot process ~a as a language file.
391 Use \\include \"~a\" instead.") file-name file-name))
392      make-void-music))
393
394
395 makeClusters =
396 #(define-music-function (parser location arg) (ly:music?)
397    (_i "Display chords in @var{arg} as clusters.")
398    (music-map note-to-cluster arg))
399
400 musicMap =
401 #(define-music-function (parser location proc mus) (procedure? ly:music?)
402    (_i "Apply @var{proc} to @var{mus} and all of the music it contains.")
403    (music-map proc mus))
404
405
406
407 %% noPageBreak and noPageTurn are music functions (not music indentifiers),
408 %% because music identifiers are not allowed at top-level.
409 noPageBreak =
410 #(define-music-function (location parser) ()
411    (_i "Forbid a page break.  May be used at toplevel (i.e., between scores or
412 markups), or inside a score.")
413    (make-music 'EventChord
414                'page-marker #t
415                'page-break-permission 'forbid
416                'elements (list (make-music 'PageBreakEvent
417                                            'break-permission '()))))
418
419 noPageTurn =
420 #(define-music-function (location parser) ()
421    (_i "Forbid a page turn.  May be used at toplevel (i.e., between scores or
422 markups), or inside a score.")
423    (make-music 'EventChord
424                'page-marker #t
425                'page-turn-permission 'forbid
426                'elements (list (make-music 'PageTurnEvent
427                                            'break-permission '()))))
428
429
430
431 octaveCheck =
432 #(define-music-function (parser location pitch-note) (ly:music?)
433    (_i "Octave check.")
434    (make-music 'RelativeOctaveCheck
435                'origin location
436                'pitch (pitch-of-note pitch-note)))
437
438 ottava =
439 #(define-music-function (parser location octave) (integer?)
440    (_i "Set the octavation.")
441    (make-music 'OttavaMusic
442                'ottava-number octave))
443
444 overrideTimeSignatureSettings =
445 #(define-music-function
446    (parser location context time-signature base-moment beat-structure beam-exceptions)
447    (symbol? pair? pair? cheap-list? cheap-list?)
448
449    (_i "Override @code{timeSignatureSettings} in @var{context}
450 for time signatures of @var{time-signature} to have settings
451 of @var{base-moment}, @var{beat-structure}, and @var{beam-exceptions}.")
452
453    ;; TODO -- add warning if largest value of grouping is
454    ;;       greater than time-signature.
455   (let ((setting (make-setting base-moment beat-structure beam-exceptions)))
456     (override-time-signature-setting time-signature setting context)))
457
458 overrideProperty =
459 #(define-music-function (parser location name property value)
460    (string? symbol? scheme?)
461
462    (_i "Set @var{property} to @var{value} in all grobs named @var{name}.
463 The @var{name} argument is a string of the form @code{\"Context.GrobName\"}
464 or @code{\"GrobName\"}.")
465
466    (let ((name-components (string-split name #\.))
467          (context-name 'Bottom)
468          (grob-name #f))
469
470      (if (> 2 (length name-components))
471          (set! grob-name (string->symbol (car name-components)))
472          (begin
473            (set! grob-name (string->symbol (list-ref name-components 1)))
474            (set! context-name (string->symbol (list-ref name-components 0)))))
475
476      (make-music 'ApplyOutputEvent
477                  'origin location
478                  'context-type context-name
479                  'procedure
480                  (lambda (grob orig-context context)
481                    (if (equal?
482                         (cdr (assoc 'name (ly:grob-property grob 'meta)))
483                         grob-name)
484                        (set! (ly:grob-property grob property) value))))))
485
486
487
488 %% pageBreak and pageTurn are music functions (iso music indentifiers),
489 %% because music identifiers are not allowed at top-level.
490 pageBreak =
491 #(define-music-function (location parser) ()
492    (_i "Force a page break.  May be used at toplevel (i.e., between scores or
493 markups), or inside a score.")
494    (make-music 'EventChord
495                'page-marker #t
496                'line-break-permission 'force
497                'page-break-permission 'force
498                'elements (list (make-music 'LineBreakEvent
499                                            'break-permission 'force)
500                                (make-music 'PageBreakEvent
501                                            'break-permission 'force))))
502
503 pageTurn =
504 #(define-music-function (location parser) ()
505    (_i "Force a page turn between two scores or top-level markups.")
506    (make-music 'EventChord
507                'page-marker #t
508                'line-break-permission 'force
509                'page-break-permission 'force
510                'page-turn-permission 'force
511                'elements (list (make-music 'LineBreakEvent
512                                            'break-permission 'force)
513                                (make-music 'PageBreakEvent
514                                            'break-permission 'force)
515                                (make-music 'PageTurnEvent
516                                            'break-permission 'force))))
517
518 parallelMusic =
519 #(define-music-function (parser location voice-ids music) (list? ly:music?)
520    (_i "Define parallel music sequences, separated by '|' (bar check signs),
521 and assign them to the identifiers provided in @var{voice-ids}.
522
523 @var{voice-ids}: a list of music identifiers (symbols containing only letters)
524
525 @var{music}: a music sequence, containing BarChecks as limiting expressions.
526
527 Example:
528
529 @verbatim
530   \\parallelMusic #'(A B C) {
531     c c | d d | e e |
532     d d | e e | f f |
533   }
534 <==>
535   A = { c c | d d | }
536   B = { d d | e e | }
537   C = { e e | f f | }
538 @end verbatim
539 ")
540    (let* ((voices (apply circular-list (make-list (length voice-ids) (list))))
541           (current-voices voices)
542           (current-sequence (list)))
543      ;;
544      ;; utilities
545      (define (push-music m)
546        "Push the music expression into the current sequence"
547        (set! current-sequence (cons m current-sequence)))
548      (define (change-voice)
549        "Stores the previously built sequence into the current voice and
550        change to the following voice."
551        (list-set! current-voices 0 (cons (make-music 'SequentialMusic
552                                                      'elements (reverse! current-sequence))
553                                          (car current-voices)))
554        (set! current-sequence (list))
555        (set! current-voices (cdr current-voices)))
556      (define (bar-check? m)
557        "Checks whether m is a bar check."
558        (eq? (ly:music-property m 'name) 'BarCheck))
559      (define (music-origin music)
560        "Recursively search an origin location stored in music."
561        (cond ((null? music) #f)
562              ((not (null? (ly:music-property music 'origin)))
563               (ly:music-property music 'origin))
564              (else (or (music-origin (ly:music-property music 'element))
565                        (let ((origins (remove not (map music-origin
566                                                        (ly:music-property music 'elements)))))
567                          (and (not (null? origins)) (car origins)))))))
568      ;;
569      ;; first, split the music and fill in voices
570      (map-in-order (lambda (m)
571                      (push-music m)
572                      (if (bar-check? m) (change-voice)))
573                    (ly:music-property music 'elements))
574      (if (not (null? current-sequence)) (change-voice))
575      ;; un-circularize `voices' and reorder the voices
576      (set! voices (map-in-order (lambda (dummy seqs)
577                                   (reverse! seqs))
578                                 voice-ids voices))
579      ;;
580      ;; set origin location of each sequence in each voice
581      ;; for better type error tracking
582      (for-each (lambda (voice)
583                  (for-each (lambda (seq)
584                              (set! (ly:music-property seq 'origin)
585                                    (or (music-origin seq) location)))
586                            voice))
587                voices)
588      ;;
589      ;; check sequence length
590      (apply for-each (lambda* (#:rest seqs)
591                               (let ((moment-reference (ly:music-length (car seqs))))
592                                 (for-each (lambda (seq moment)
593                                             (if (not (equal? moment moment-reference))
594                                                 (ly:music-message seq
595                                                                   "Bars in parallel music don't have the same length")))
596                                           seqs (map-in-order ly:music-length seqs))))
597             voices)
598      ;;
599      ;; bind voice identifiers to the voices
600      (map (lambda (voice-id voice)
601             (ly:parser-define! parser voice-id
602                                (make-music 'SequentialMusic
603                                            'origin location
604                                            'elements voice)))
605           voice-ids voices))
606    ;; Return an empty sequence.  This function is actually a "void" function.
607    (make-music 'SequentialMusic 'void #t))
608
609 parenthesize =
610 #(define-music-function (parser loc arg) (ly:music?)
611    (_i "Tag @var{arg} to be parenthesized.")
612
613    (if (memq 'event-chord (ly:music-property arg 'types))
614        ;; arg is an EventChord -> set the parenthesize property
615        ;; on all child notes and rests
616        (map
617         (lambda (ev)
618           (if (or (memq 'note-event (ly:music-property ev 'types))
619                   (memq 'rest-event (ly:music-property ev 'types)))
620               (set! (ly:music-property ev 'parenthesize) #t)))
621         (ly:music-property arg 'elements))
622        ;; No chord, simply set property for this expression:
623        (set! (ly:music-property arg 'parenthesize) #t))
624    arg)
625
626 partcombine =
627 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
628    (_i "Take the music in @var{part1} and @var{part2} and typeset so
629 that they share a staff.")
630    (make-part-combine-music parser
631                             (list part1 part2)))
632
633 #(define (symbol-or-boolean? x) (or (symbol? x) (boolean? x)))
634 partcombineForce =
635 #(define-music-function (location parser type once) (symbol-or-boolean? boolean?)
636    (_i "Override the part-combiner.")
637    (make-music 'EventChord
638                'elements (list (make-music 'PartCombineForceEvent
639                                            'forced-type type
640                                            'once once))))
641 partcombineApart = \partcombineForce #'apart ##f
642 partcombineApartOnce = \partcombineForce #'apart ##t
643 partcombineChords = \partcombineForce #'chords ##f
644 partcombineChordsOnce = \partcombineForce #'chords ##t
645 partcombineUnisono = \partcombineForce #'unisono ##f
646 partcombineUnisonoOnce = \partcombineForce #'unisono ##t
647 partcombineSoloI = \partcombineForce #'solo1 ##f
648 partcombineSoloIOnce = \partcombineForce #'solo1 ##t
649 partcombineSoloII = \partcombineForce #'solo2 ##f
650 partcombineSoloIIOnce = \partcombineForce #'solo2 ##t
651 partcombineAutomatic = \partcombineForce ##f ##f
652 partcombineAutomaticOnce = \partcombineForce ##f ##t
653
654
655 pitchedTrill =
656 #(define-music-function
657    (parser location main-note secondary-note)
658    (ly:music? ly:music?)
659    (_i "Print a trill with @var{main-note} as the main note of the trill and
660 print @var{secondary-note} as a stemless note head in parentheses.")
661    (let* ((get-notes (lambda (ev-chord)
662                        (filter
663                         (lambda (m) (eq? 'NoteEvent (ly:music-property m 'name)))
664                         (ly:music-property ev-chord 'elements))))
665           (sec-note-events (get-notes secondary-note))
666           (trill-events (filter (lambda (m) (music-has-type m 'trill-span-event))
667                                 (ly:music-property main-note 'elements))))
668
669      (if (pair? sec-note-events)
670          (begin
671            (let* ((trill-pitch (ly:music-property (car sec-note-events) 'pitch))
672                   (forced (ly:music-property (car sec-note-events) 'force-accidental)))
673
674              (if (ly:pitch? trill-pitch)
675                  (for-each (lambda (m)
676                              (ly:music-set-property! m 'pitch trill-pitch)) trill-events)
677                  (begin
678                    (ly:warning (_ "Second argument of \\pitchedTrill should be single note: "))
679                    (display sec-note-events)))
680
681              (if (eq? forced #t)
682                  (for-each (lambda (m)
683                              (ly:music-set-property! m 'force-accidental forced))
684                            trill-events)))))
685      main-note))
686
687 quoteDuring =
688 #(define-music-function (parser location what main-music) (string? ly:music?)
689    (_i "Indicate a section of music to be quoted.  @var{what} indicates the name
690 of the quoted voice, as specified in an @code{\\addQuote} command.
691 @var{main-music} is used to indicate the length of music to be quoted;
692 usually contains spacers or multi-measure rests.")
693    (make-music 'QuoteMusic
694                'element main-music
695                'quoted-music-name what
696                'origin location))
697
698 removeWithTag =
699 #(define-music-function (parser location tag music) (symbol? ly:music?)
700    (_i "Remove elements of @var{music} that are tagged with @var{tag}.")
701    (music-filter
702     (lambda (m)
703       (let* ((tags (ly:music-property m 'tags))
704              (res (memq tag tags)))
705         (not res)))
706     music))
707
708 resetRelativeOctave =
709 #(define-music-function (parser location reference-note) (ly:music?)
710    (_i "Set the octave inside a \\relative section.")
711
712    (let* ((notes (ly:music-property reference-note 'elements))
713           (pitch (ly:music-property (car notes) 'pitch)))
714
715      (set! (ly:music-property reference-note 'elements) '())
716      (set! (ly:music-property reference-note 'to-relative-callback)
717            (lambda (music last-pitch)
718              pitch))
719
720      reference-note))
721
722 revertTimeSignatureSettings =
723 #(define-music-function
724    (parser location context time-signature)
725    (symbol? pair?)
726
727    (_i "Revert @code{timeSignatureSettings} in @var{context}
728 for time signatures of @var{time-signature}.")
729      (revert-time-signature-setting time-signature context))
730
731 rightHandFinger =
732 #(define-music-function (parser location finger) (number-or-string?)
733    (_i "Apply @var{finger} as a fingering indication.")
734
735    (apply make-music
736           (append
737            (list
738             'StrokeFingerEvent
739             'origin location)
740            (if  (string? finger)
741                 (list 'text finger)
742                 (list 'digit finger)))))
743
744
745
746 scaleDurations =
747 #(define-music-function (parser location fraction music)
748    (number-pair? ly:music?)
749    (_i "Multiply the duration of events in @var{music} by @var{fraction}.")
750    (ly:music-compress music
751                       (ly:make-moment (car fraction) (cdr fraction))))
752
753 shiftDurations =
754 #(define-music-function (parser location dur dots arg)
755    (integer? integer? ly:music?)
756    (_i "Scale @var{arg} up by a factor of @var{2^dur*(2-(1/2)^dots)}.")
757
758    (music-map
759     (lambda (x)
760       (shift-one-duration-log x dur dots)) arg))
761
762 spacingTweaks =
763 #(define-music-function (parser location parameters) (list?)
764    (_i "Set the system stretch, by reading the 'system-stretch property of
765 the `parameters' assoc list.")
766    #{
767      \overrideProperty #"Score.NonMusicalPaperColumn"
768      #'line-break-system-details
769      #$(list (cons 'alignment-extra-space (cdr (assoc 'system-stretch parameters)))
770              (cons 'system-Y-extent (cdr (assoc 'system-Y-extent parameters))))
771    #})
772
773 styledNoteHeads =
774 #(define-music-function (parser location style heads music)
775    (symbol? list-or-symbol? ly:music?)
776    (_i "Set @var{heads} in @var{music} to @var{style}.")
777    (style-note-heads heads style music))
778
779
780
781 tabChordRepetition =
782 #(define-music-function (parser location) ()
783    (_i "Include the string information in a chord repetition.")
784    (ly:parser-set-repetition-function parser tab-repeat-chord)
785    (make-music 'SequentialMusic 'void #t))
786
787 tag =
788 #(define-music-function (parser location tag arg) (symbol? ly:music?)
789
790    (_i "Add @var{tag} to the @code{tags} property of @var{arg}.")
791
792    (set!
793     (ly:music-property arg 'tags)
794     (cons tag
795           (ly:music-property arg 'tags)))
796    arg)
797
798 transposedCueDuring =
799 #(define-music-function
800    (parser location what dir pitch-note main-music)
801    (string? ly:dir? ly:music? ly:music?)
802
803    (_i "Insert notes from the part @var{what} into a voice called @code{cue},
804 using the transposition defined by @var{pitch-note}.  This happens
805 simultaneously with @var{main-music}, which is usually a rest.  The
806 argument @var{dir} determines whether the cue notes should be notated
807 as a first or second voice.")
808
809    (make-music 'QuoteMusic
810                'element main-music
811                'quoted-context-type 'Voice
812                'quoted-context-id "cue"
813                'quoted-music-name what
814                'quoted-voice-direction dir
815                'quoted-transposition (pitch-of-note pitch-note)
816                'origin location))
817
818 transposition =
819 #(define-music-function (parser location pitch-note) (ly:music?)
820    (_i "Set instrument transposition")
821
822    (context-spec-music
823     (make-property-set 'instrumentTransposition
824                        (ly:pitch-negate (pitch-of-note pitch-note)))
825     'Staff))
826
827 tweak =
828 #(define-music-function (parser location sym val arg)
829    (symbol? scheme? ly:music?)
830    (_i "Add @code{sym . val} to the @code{tweaks} property of @var{arg}.")
831
832    (if (equal? (object-property sym 'backend-type?) #f)
833        (begin
834          (ly:warning (_ "cannot find property type-check for ~a") sym)
835          (ly:warning (_ "doing assignment anyway"))))
836    (set!
837     (ly:music-property arg 'tweaks)
838     (acons sym val
839            (ly:music-property arg 'tweaks)))
840    arg)
841
842
843
844 unfoldRepeats =
845 #(define-music-function (parser location music) (ly:music?)
846    (_i "Force any @code{\\repeat volta}, @code{\\repeat tremolo} or
847 @code{\\repeat percent} commands in @var{music} to be interpreted
848 as @code{\\repeat unfold}.")
849    (unfold-repeats music))
850
851
852
853 withMusicProperty =
854 #(define-music-function (parser location sym val music)
855    (symbol? scheme? ly:music?)
856    (_i "Set @var{sym} to @var{val} in @var{music}.")
857
858    (set! (ly:music-property music sym) val)
859    music)