staff-symbol-referencer.cc: Junk redundant functions.
[lilypond.git] / ly / music-functions-init.ly
blob10af2cfefb8f720f02b034d67d9894b0e08a02b4
1 % -*-Scheme-*-
3 \version "2.10.0"
6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 %% this file is alphabetically sorted.
8 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10 %% need SRFI-1 filter
12 #(use-modules (srfi srfi-1))
14 acciaccatura =
15 #(def-grace-function startAcciaccaturaMusic stopAcciaccaturaMusic)
17 addQuote =
18 #(define-music-function (parser location name music) (string? ly:music?)
19 (_i "Add a piece of music to be quoted ")
20 (add-quotable parser name music)
21 (make-music 'SequentialMusic 'void #t))
23 afterGraceFraction =
24 #(cons 6 8)
26 afterGrace =
27 #(define-music-function
28 (parser location main grace)
29 (ly:music? ly:music?)
31 (let*
32 ((main-length (ly:music-length main))
33 (fraction (ly:parser-lookup parser 'afterGraceFraction)))
35 (make-simultaneous-music
36 (list
37 main
38 (make-sequential-music
39 (list
41 (make-music 'SkipMusic
42 'duration (ly:make-duration
43 0 0
44 (* (ly:moment-main-numerator main-length)
45 (car fraction))
46 (* (ly:moment-main-denominator main-length)
47 (cdr fraction)) ))
48 (make-music 'GraceMusic
49 'element grace)))))))
51 applyMusic =
52 #(define-music-function (parser location func music) (procedure? ly:music?)
53 (func music))
56 applyOutput =
57 #(define-music-function (parser location ctx proc) (symbol? procedure?)
58 (make-music 'ApplyOutputEvent
59 'origin location
60 'procedure proc
61 'context-type ctx))
63 appoggiatura =
64 #(def-grace-function startAppoggiaturaMusic stopAppoggiaturaMusic)
68 % for regression testing purposes.
69 assertBeamQuant =
70 #(define-music-function (parser location l r) (pair? pair?)
71 (make-grob-property-override 'Beam 'positions
72 (ly:make-simple-closure
73 (ly:make-simple-closure
74 (append
75 (list chain-grob-member-functions `(,cons 0 0))
76 (check-quant-callbacks l r))))))
78 % for regression testing purposes.
79 assertBeamSlope =
80 #(define-music-function (parser location comp) (procedure?)
81 (make-grob-property-override 'Beam 'positions
82 (ly:make-simple-closure
83 (ly:make-simple-closure
84 (append
85 (list chain-grob-member-functions `(,cons 0 0))
86 (check-slope-callbacks comp))))))
90 autochange =
91 #(define-music-function (parser location music) (ly:music?)
92 (make-autochange-music parser music))
94 applyContext =
95 #(define-music-function (parser location proc) (procedure?)
96 (make-music 'ApplyContext
97 'origin location
98 'procedure proc))
101 balloonGrobText =
102 #(define-music-function (parser location grob-name offset text) (symbol? number-pair? markup?)
104 (make-music 'AnnotateOutputEvent
105 'symbol grob-name
106 'X-offset (car offset)
107 'Y-offset (cdr offset)
108 'text text))
110 balloonText =
111 #(define-music-function (parser location offset text) (number-pair? markup?)
113 (make-music 'AnnotateOutputEvent
114 'X-offset (car offset)
115 'Y-offset (cdr offset)
116 'text text))
119 bar =
120 #(define-music-function (parser location type)
121 (string?)
122 (context-spec-music
123 (make-property-set 'whichBar type)
124 'Timing))
127 barNumberCheck =
128 #(define-music-function (parser location n) (integer?)
129 (make-music 'ApplyContext
130 'origin location
131 'procedure
132 (lambda (c)
133 (let*
134 ((cbn (ly:context-property c 'currentBarNumber)))
135 (if (and (number? cbn) (not (= cbn n)))
136 (ly:input-message location "Barcheck failed got ~a expect ~a"
137 cbn n))))))
140 bendAfter =
141 #(define-music-function (parser location delta) (real?)
143 (make-music 'BendAfterEvent
144 'delta-step delta))
146 %% why a function?
147 breathe =
148 #(define-music-function (parser location) ()
149 (make-music 'EventChord
150 'origin location
151 'elements (list (make-music 'BreathingEvent))))
154 clef =
155 #(define-music-function (parser location type)
156 (string?)
157 (_i "Set the current clef.")
159 (make-clef-set type))
162 cueDuring =
163 #(define-music-function
164 (parser location what dir main-music)
165 (string? ly:dir? ly:music?)
166 (make-music 'QuoteMusic
167 'element main-music
168 'quoted-context-type 'Voice
169 'quoted-context-id "cue"
170 'quoted-music-name what
171 'quoted-voice-direction dir
172 'origin location))
174 displayLilyMusic =
175 #(define-music-function (parser location music) (ly:music?)
176 (newline)
177 (display-lily-music music parser)
178 music)
180 displayMusic =
181 #(define-music-function (parser location music) (ly:music?)
182 (newline)
183 (display-scheme-music music)
184 music)
187 endSpanners =
188 #(define-music-function (parser location music) (ly:music?)
189 (if (eq? (ly:music-property music 'name) 'EventChord)
190 (let*
191 ((elts (ly:music-property music 'elements))
192 (start-span-evs (filter (lambda (ev)
193 (and (music-has-type ev 'span-event)
194 (equal? (ly:music-property ev 'span-direction)
195 START)))
196 elts))
197 (stop-span-evs
198 (map (lambda (m)
199 (let* ((c (music-clone m)))
200 (set! (ly:music-property c 'span-direction) STOP)
202 start-span-evs))
203 (end-ev-chord (make-music 'EventChord
204 'elements stop-span-evs))
205 (total (make-music 'SequentialMusic
206 'elements (list music
207 end-ev-chord))))
208 total)
210 (ly:input-message location (_ "argument endSpanners is not an EventChord: ~a" music))))
212 featherDurations=
213 #(define-music-function (parser location factor argument) (ly:moment? ly:music?)
214 (_i "Rearrange durations in ARGUMENT so there is an
215 acceleration/deceleration. ")
217 (let*
218 ((orig-duration (ly:music-length argument))
219 (multiplier (ly:make-moment 1 1)))
221 (music-map
222 (lambda (mus)
223 (if (and (eq? (ly:music-property mus 'name) 'EventChord)
224 (< 0 (ly:moment-main-denominator (ly:music-length mus))))
225 (begin
226 (ly:music-compress mus multiplier)
227 (set! multiplier (ly:moment-mul factor multiplier)))
229 mus)
230 argument)
232 (ly:music-compress
233 argument
234 (ly:moment-div orig-duration (ly:music-length argument)))
236 argument))
238 grace =
239 #(def-grace-function startGraceMusic stopGraceMusic)
242 "instrument-definitions" = #'()
244 addInstrumentDefinition =
245 #(define-music-function
246 (parser location name lst) (string? list?)
248 (set! instrument-definitions (acons name lst instrument-definitions))
250 (make-music 'SequentialMusic 'void #t))
253 instrumentSwitch =
254 #(define-music-function
255 (parser location name) (string?)
256 (let*
257 ((handle (assoc name instrument-definitions))
258 (instrument-def (if handle (cdr handle) '()))
261 (if (not handle)
262 (ly:input-message "No such instrument: ~a" name))
263 (context-spec-music
264 (make-music 'SimultaneousMusic
265 'elements
266 (map (lambda (kv)
267 (make-property-set
268 (car kv)
269 (cdr kv)))
270 instrument-def))
271 'Staff)))
274 %% Parser used to read page-layout file, and then retreive score tweaks.
275 #(define page-layout-parser #f)
277 includePageLayoutFile =
278 #(define-music-function (parser location) ()
279 (_i "If page breaks and tweak dump is not asked, and the file
280 <basename>-page-layout.ly exists, include it.")
281 (if (not (ly:get-option 'dump-tweaks))
282 (let ((tweak-filename (format #f "~a-page-layout.ly"
283 (ly:parser-output-name parser))))
284 (if (access? tweak-filename R_OK)
285 (begin
286 (ly:message "Including tweak file ~a" tweak-filename)
287 (set! page-layout-parser (ly:parser-clone parser))
288 (ly:parser-parse-string page-layout-parser
289 (format #f "\\include \"~a\""
290 tweak-filename))))))
291 (make-music 'SequentialMusic 'void #t))
295 keepWithTag =
296 #(define-music-function
297 (parser location tag music) (symbol? ly:music?)
298 (music-filter
299 (lambda (m)
300 (let* ((tags (ly:music-property m 'tags))
301 (res (memq tag tags)))
303 (eq? tags '())
304 res)))
305 music))
307 removeWithTag =
308 #(define-music-function
309 (parser location tag music) (symbol? ly:music?)
310 (music-filter
311 (lambda (m)
312 (let* ((tags (ly:music-property m 'tags))
313 (res (memq tag tags)))
314 (not res)))
315 music))
317 killCues =
318 #(define-music-function
319 (parser location music)
320 (ly:music?)
321 (music-map
322 (lambda (mus)
323 (if (string? (ly:music-property mus 'quoted-music-name))
324 (ly:music-property mus 'element)
325 mus)) music))
327 label =
328 #(define-music-function (parser location label) (symbol?)
329 (_i "Place a bookmarking label, either at top-level or inside music.")
330 (make-music 'EventChord
331 'page-marker #t
332 'page-label label
333 'elements (list (make-music 'LabelEvent
334 'page-label label))))
336 makeClusters =
337 #(define-music-function
338 (parser location arg) (ly:music?)
339 (music-map note-to-cluster arg))
341 musicMap =
342 #(define-music-function (parser location proc mus) (procedure? ly:music?)
343 (music-map proc mus))
347 oldaddlyrics =
348 #(define-music-function (parser location music lyrics) (ly:music? ly:music?)
350 (make-music 'OldLyricCombineMusic
351 'origin location
352 'elements (list music lyrics)))
355 overrideProperty =
356 #(define-music-function (parser location name property value)
357 (string? symbol? scheme?)
360 (_i "Set @var{property} to @var{value} in all grobs named @var{name}.
361 The @var{name} argument is a string of the form @code{\"Context.GrobName\"}
362 or @code{\"GrobName\"}")
364 (let*
365 ((name-components (string-split name #\.))
366 (context-name 'Bottom)
367 (grob-name #f))
369 (if (> 2 (length name-components))
370 (set! grob-name (string->symbol (car name-components)))
371 (begin
372 (set! grob-name (string->symbol (list-ref name-components 1)))
373 (set! context-name (string->symbol (list-ref name-components 0)))))
375 (make-music 'ApplyOutputEvent
376 'origin location
377 'context-type context-name
378 'procedure
379 (lambda (grob orig-context context)
380 (if (equal?
381 (cdr (assoc 'name (ly:grob-property grob 'meta)))
382 grob-name)
383 (set! (ly:grob-property grob property) value))))))
385 %% These are music functions (iso music indentifiers), because music identifiers
386 %% are not allowed at top-level.
387 pageBreak =
388 #(define-music-function (location parser) ()
389 (_i "Force a page break. May be used at toplevel (ie between scores or
390 markups), or inside a score.")
391 (make-music 'EventChord
392 'page-marker #t
393 'line-break-permission 'force
394 'page-break-permission 'force
395 'elements (list (make-music 'LineBreakEvent
396 'break-permission 'force)
397 (make-music 'PageBreakEvent
398 'break-permission 'force))))
400 noPageBreak =
401 #(define-music-function (location parser) ()
402 (_i "Forbid a page break. May be used at toplevel (ie between scores or
403 markups), or inside a score.")
404 (make-music 'EventChord
405 'page-marker #t
406 'page-break-permission 'forbid
407 'elements (list (make-music 'PageBreakEvent
408 'break-permission '()))))
410 pageTurn =
411 #(define-music-function (location parser) ()
412 (_i "Force a page turn between two scores or top-level markups.")
413 (make-music 'EventChord
414 'page-marker #t
415 'line-break-permission 'force
416 'page-break-permission 'force
417 'page-turn-permission 'force
418 'elements (list (make-music 'LineBreakEvent
419 'break-permission 'force)
420 (make-music 'PageBreakEvent
421 'break-permission 'force)
422 (make-music 'PageTurnEvent
423 'break-permission 'force))))
425 noPageTurn =
426 #(define-music-function (location parser) ()
427 (_i "Forbid a page turn. May be used at toplevel (ie between scores or
428 markups), or inside a score.")
429 (make-music 'EventChord
430 'page-marker #t
431 'page-turn-permission 'forbid
432 'elements (list (make-music 'PageTurnEvent
433 'break-permission '()))))
435 allowPageTurn =
436 #(define-music-function (location parser) ()
437 (_i "Allow a page turn. May be used at toplevel (ie between scores or
438 markups), or inside a score.")
439 (make-music 'EventChord
440 'page-marker #t
441 'page-turn-permission 'allow
442 'elements (list (make-music 'PageTurnEvent
443 'break-permission 'allow))))
445 %% Todo:
446 %% doing
447 %% define-music-function in a .scm causes crash.
449 octaveCheck =
450 #(define-music-function (parser location pitch-note) (ly:music?)
451 (_i "octave check")
453 (make-music 'RelativeOctaveCheck
454 'origin location
455 'pitch (pitch-of-note pitch-note)
458 ottava = #(define-music-function (parser location octave) (number?)
459 (_i "set the octavation ")
460 (make-ottava-set octave))
462 partcombine =
463 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
464 (make-part-combine-music parser
465 (list part1 part2)))
468 pitchedTrill =
469 #(define-music-function
470 (parser location main-note secondary-note)
471 (ly:music? ly:music?)
472 (let*
473 ((get-notes (lambda (ev-chord)
474 (filter
475 (lambda (m) (eq? 'NoteEvent (ly:music-property m 'name)))
476 (ly:music-property ev-chord 'elements))))
477 (sec-note-events (get-notes secondary-note))
478 (trill-events (filter (lambda (m) (music-has-type m 'trill-span-event))
479 (ly:music-property main-note 'elements))))
481 (if (pair? sec-note-events)
482 (begin
483 (let*
484 ((trill-pitch (ly:music-property (car sec-note-events) 'pitch))
485 (forced (ly:music-property (car sec-note-events ) 'force-accidental)))
487 (if (ly:pitch? trill-pitch)
488 (for-each (lambda (m) (ly:music-set-property! m 'pitch trill-pitch))
489 trill-events)
490 (begin
491 (ly:warning (_ "Second argument of \\pitchedTrill should be single note: "))
492 (display sec-note-events)))
494 (if (eq? forced #t)
495 (for-each (lambda (m) (ly:music-set-property! m 'force-accidental forced))
496 trill-events)))))
497 main-note))
501 %% for lambda*
502 #(use-modules (ice-9 optargs))
504 parallelMusic =
505 #(define-music-function (parser location voice-ids music) (list? ly:music?)
506 (_i "Define parallel music sequences, separated by '|' (bar check signs),
507 and assign them to the identifiers provided in @var{voice-ids}.
509 @var{voice-ids}: a list of music identifiers (symbols containing only letters)
511 @var{music}: a music sequence, containing BarChecks as limiting expressions.
513 Example:
515 @verbatim
516 \\parallelMusic #'(A B C) {
517 c c | d d | e e |
518 d d | e e | f f |
520 <==>
521 A = { c c | d d | }
522 B = { d d | e e | }
523 C = { e e | f f | }
524 @end verbatim
526 (let* ((voices (apply circular-list (make-list (length voice-ids) (list))))
527 (current-voices voices)
528 (current-sequence (list)))
530 ;; utilities
531 (define (push-music m)
532 "Push the music expression into the current sequence"
533 (set! current-sequence (cons m current-sequence)))
534 (define (change-voice)
535 "Stores the previously built sequence into the current voice and
536 change to the following voice."
537 (list-set! current-voices 0 (cons (make-music 'SequentialMusic
538 'elements (reverse! current-sequence))
539 (car current-voices)))
540 (set! current-sequence (list))
541 (set! current-voices (cdr current-voices)))
542 (define (bar-check? m)
543 "Checks whether m is a bar check."
544 (eq? (ly:music-property m 'name) 'BarCheck))
545 (define (music-origin music)
546 "Recursively search an origin location stored in music."
547 (cond ((null? music) #f)
548 ((not (null? (ly:music-property music 'origin)))
549 (ly:music-property music 'origin))
550 (else (or (music-origin (ly:music-property music 'element))
551 (let ((origins (remove not (map music-origin
552 (ly:music-property music 'elements)))))
553 (and (not (null? origins)) (car origins)))))))
555 ;; first, split the music and fill in voices
556 (map-in-order (lambda (m)
557 (push-music m)
558 (if (bar-check? m) (change-voice)))
559 (ly:music-property music 'elements))
560 (if (not (null? current-sequence)) (change-voice))
561 ;; un-circularize `voices' and reorder the voices
562 (set! voices (map-in-order (lambda (dummy seqs)
563 (reverse! seqs))
564 voice-ids voices))
566 ;; set origin location of each sequence in each voice
567 ;; for better type error tracking
568 (for-each (lambda (voice)
569 (for-each (lambda (seq)
570 (set! (ly:music-property seq 'origin)
571 (or (music-origin seq) location)))
572 voice))
573 voices)
575 ;; check sequence length
576 (apply for-each (lambda* (#:rest seqs)
577 (let ((moment-reference (ly:music-length (car seqs))))
578 (for-each (lambda (seq moment)
579 (if (not (equal? moment moment-reference))
580 (ly:music-message seq
581 "Bars in parallel music don't have the same length")))
582 seqs (map-in-order ly:music-length seqs))))
583 voices)
585 ;; bind voice identifiers to the voices
586 (map (lambda (voice-id voice)
587 (ly:parser-define! parser voice-id
588 (make-music 'SequentialMusic
589 'origin location
590 'elements voice)))
591 voice-ids voices))
592 ;; Return an empty sequence. this function is actually a "void" function.
593 (make-music 'SequentialMusic 'void #t))
597 parenthesize =
598 #(define-music-function (parser loc arg) (ly:music?)
599 (_i "Tag @var{arg} to be parenthesized.")
601 (if (memq 'event-chord (ly:music-property arg 'types))
602 ; arg is an EventChord -> set the parenthesize property on all child notes and rests
603 (map
604 (lambda (ev)
605 (if (or (memq 'note-event (ly:music-property ev 'types))
606 (memq 'rest-event (ly:music-property ev 'types)))
607 (set! (ly:music-property ev 'parenthesize) #t)))
608 (ly:music-property arg 'elements))
609 ; No chord, simply set property for this expression:
610 (set! (ly:music-property arg 'parenthesize) #t))
611 arg)
614 quoteDuring = #
615 (define-music-function
616 (parser location what main-music)
617 (string? ly:music?)
618 (make-music 'QuoteMusic
619 'element main-music
620 'quoted-music-name what
621 'origin location))
625 resetRelativeOctave =
626 #(define-music-function
627 (parser location reference-note)
628 (ly:music?)
629 (_i "Set the octave inside a \\relative section.")
631 (let*
632 ((notes (ly:music-property reference-note 'elements))
633 (pitch (ly:music-property (car notes) 'pitch)))
635 (set! (ly:music-property reference-note 'elements) '())
636 (set! (ly:music-property reference-note
637 'to-relative-callback)
638 (lambda (music last-pitch)
639 pitch))
641 reference-note))
644 scaleDurations =
645 #(define-music-function
646 (parser location fraction music) (number-pair? ly:music?)
647 (ly:music-compress music (ly:make-moment (car fraction) (cdr fraction))))
651 shiftDurations =
652 #(define-music-function (parser location dur dots arg) (integer? integer? ly:music?)
653 (_i "")
655 (music-map
656 (lambda (x)
657 (shift-one-duration-log x dur dots)) arg))
659 spacingTweaks =
660 #(define-music-function (parser location parameters) (list?)
661 (_i "Set the system stretch, by reading the 'system-stretch property of
662 the `parameters' assoc list.")
664 \overrideProperty #"Score.NonMusicalPaperColumn"
665 #'line-break-system-details
666 #$(list (cons 'alignment-extra-space (cdr (assoc 'system-stretch parameters)))
667 (cons 'system-Y-extent (cdr (assoc 'system-Y-extent parameters))))
671 rightHandFinger =
672 #(define-music-function (parser location finger) (number-or-string?)
673 (_i "Define a StrokeFingerEvent")
675 (apply make-music
676 (append
677 (list
678 'StrokeFingerEvent
679 'origin location)
680 (if (string? finger)
681 (list 'text finger)
682 (list 'digit finger)))))
684 scoreTweak =
685 #(define-music-function (parser location name) (string?)
686 (_i "Include the score tweak, if exists.")
687 (if (and page-layout-parser (not (ly:get-option 'dump-tweaks)))
688 (let ((tweak-music (ly:parser-lookup page-layout-parser
689 (string->symbol name))))
690 (if (ly:music? tweak-music)
691 tweak-music
692 (make-music 'SequentialMusic)))
693 (make-music 'SequentialMusic)))
696 tag = #(define-music-function (parser location tag arg)
697 (symbol? ly:music?)
699 (_i "Add @var{tag} to the @code{tags} property of @var{arg}.")
701 (set!
702 (ly:music-property arg 'tags)
703 (cons tag
704 (ly:music-property arg 'tags)))
705 arg)
709 transposedCueDuring =
710 #(define-music-function
711 (parser location what dir pitch-note main-music)
712 (string? ly:dir? ly:music? ly:music?)
714 (_i "Insert notes from the part @var{what} into a voice called @code{cue},
715 using the transposition defined by @var{pitch-note}. This happens
716 simultaneously with @var{main-music}, which is usually a rest. The
717 argument @var{dir} determines whether the cue notes should be notated
718 as a first or second voice.")
720 (make-music 'QuoteMusic
721 'element main-music
722 'quoted-context-type 'Voice
723 'quoted-context-id "cue"
724 'quoted-music-name what
725 'quoted-voice-direction dir
726 'quoted-transposition (pitch-of-note pitch-note)
727 'origin location))
731 transposition =
732 #(define-music-function (parser location pitch-note) (ly:music?)
733 (_i "Set instrument transposition")
735 (context-spec-music
736 (make-property-set 'instrumentTransposition
737 (ly:pitch-negate (pitch-of-note pitch-note)))
738 'Staff))
740 tweak = #(define-music-function (parser location sym val arg)
741 (symbol? scheme? ly:music?)
743 (_i "Add @code{sym . val} to the @code{tweaks} property of @var{arg}.")
745 (set!
746 (ly:music-property arg 'tweaks)
747 (acons sym val
748 (ly:music-property arg 'tweaks)))
749 arg)
753 unfoldRepeats =
754 #(define-music-function (parser location music) (ly:music?)
755 (unfold-repeats music))
759 withMusicProperty =
760 #(define-music-function (parser location sym val music) (symbol? scheme? ly:music?)
761 (_i "Set @var{sym} to @var{val} in @var{music}.")
763 (set! (ly:music-property music sym) val)
764 music)