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