6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 %% this file is alphabetically sorted.
8 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 #(use-modules (srfi srfi-1))
15 #(def-grace-function startAcciaccaturaMusic stopAcciaccaturaMusic)
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))
27 #(define-music-function
28 (parser location main grace)
32 ((main-length (ly:music-length main))
33 (fraction (ly:parser-lookup parser 'afterGraceFraction)))
35 (make-simultaneous-music
38 (make-sequential-music
41 (make-music 'SkipMusic
42 'duration (ly:make-duration
44 (* (ly:moment-main-numerator main-length)
46 (* (ly:moment-main-denominator main-length)
48 (make-music 'GraceMusic
52 #(define-music-function (parser location func music) (procedure? ly:music?)
57 #(define-music-function (parser location ctx proc) (symbol? procedure?)
58 (make-music 'ApplyOutputEvent
64 #(def-grace-function startAppoggiaturaMusic stopAppoggiaturaMusic)
68 % for regression testing purposes.
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
75 (list chain-grob-member-functions `(,cons 0 0))
76 (check-quant-callbacks l r))))))
78 % for regression testing purposes.
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
85 (list chain-grob-member-functions `(,cons 0 0))
86 (check-slope-callbacks comp))))))
91 #(define-music-function (parser location music) (ly:music?)
92 (make-autochange-music parser music))
95 #(define-music-function (parser location proc) (procedure?)
96 (make-music 'ApplyContext
102 #(define-music-function (parser location offset text) (number-pair? markup?)
104 (make-music 'AnnotateOutputEvent
105 'X-offset (car offset)
106 'Y-offset (cdr offset)
110 #(define-music-function (parser location grob-name offset text) (symbol? number-pair? markup?)
112 (make-music 'AnnotateOutputEvent
114 'X-offset (car offset)
115 'Y-offset (cdr offset)
119 #(define-music-function (parser location type)
122 (make-property-set 'whichBar type)
127 #(define-music-function (parser location n) (integer?)
128 (make-music 'ApplyContext
133 ((cbn (ly:context-property c 'currentBarNumber)))
134 (if (and (number? cbn) (not (= cbn n)))
135 (ly:input-message location "Barcheck failed got ~a expect ~a"
141 #(define-music-function (parser location) ()
142 (make-music 'EventChord
144 'elements (list (make-music 'BreathingEvent))))
147 #(define-music-function (parser location delta) (real?)
149 (make-music 'BendAfterEvent
153 #(define-music-function (parser location type)
155 (_i "Set the current clef.")
157 (make-clef-set type))
161 #(define-music-function
162 (parser location fraction music) (number-pair? ly:music?)
163 (ly:music-compress music (ly:make-moment (car fraction) (cdr fraction))))
167 #(define-music-function
168 (parser location what dir main-music)
169 (string? ly:dir? ly:music?)
170 (make-music 'QuoteMusic
172 'quoted-context-type 'Voice
173 'quoted-context-id "cue"
174 'quoted-music-name what
175 'quoted-voice-direction dir
179 #(define-music-function (parser location music) (ly:music?)
181 (display-lily-music music parser)
185 #(define-music-function (parser location music) (ly:music?)
187 (display-scheme-music music)
192 #(define-music-function (parser location music) (ly:music?)
193 (if (eq? (ly:music-property music 'name) 'EventChord)
195 ((elts (ly:music-property music 'elements))
196 (start-span-evs (filter (lambda (ev)
197 (and (music-has-type ev 'span-event)
198 (equal? (ly:music-property ev 'span-direction)
203 (let* ((c (music-clone m)))
204 (set! (ly:music-property c 'span-direction) STOP)
207 (end-ev-chord (make-music 'EventChord
208 'elements stop-span-evs))
209 (total (make-music 'SequentialMusic
210 'elements (list music
214 (ly:input-message location (_ "argument endSpanners is not an EventChord: ~a" music))))
217 #(define-music-function (parser location factor argument) (ly:moment? ly:music?)
218 (_i "Rearrange durations in ARGUMENT so there is an
219 acceleration/deceleration. ")
222 ((orig-duration (ly:music-length argument))
223 (multiplier (ly:make-moment 1 1)))
227 (if (and (eq? (ly:music-property mus 'name) 'EventChord)
228 (< 0 (ly:moment-main-denominator (ly:music-length mus))))
230 (ly:music-compress mus multiplier)
231 (set! multiplier (ly:moment-mul factor multiplier)))
238 (ly:moment-div orig-duration (ly:music-length argument)))
243 #(def-grace-function startGraceMusic stopGraceMusic)
246 "instrument-definitions" = #'()
248 addInstrumentDefinition =
249 #(define-music-function
250 (parser location name lst) (string? list?)
252 (set! instrument-definitions (acons name lst instrument-definitions))
254 (make-music 'SequentialMusic 'void #t))
258 #(define-music-function
259 (parser location name) (string?)
261 ((handle (assoc name instrument-definitions))
262 (instrument-def (if handle (cdr handle) '()))
266 (ly:input-message "No such instrument: ~a" name))
268 (make-music 'SimultaneousMusic
279 #(define-music-function
280 (parser location tag music) (symbol? ly:music?)
283 (let* ((tags (ly:music-property m 'tags))
284 (res (memq tag tags)))
293 #(define-music-function
294 (parser location music)
298 (if (string? (ly:music-property mus 'quoted-music-name))
299 (ly:music-property mus 'element)
303 #(define-music-function (parser location label) (symbol?)
304 (_i "Place a bookmarking label, either at top-level or inside music.")
305 (make-music 'EventChord
308 'elements (list (make-music 'LabelEvent
309 'page-label label))))
312 #(define-music-function
313 (parser location arg) (ly:music?)
314 (music-map note-to-cluster arg))
317 #(define-music-function (parser location proc mus) (procedure? ly:music?)
318 (music-map proc mus))
323 #(define-music-function (parser location music lyrics) (ly:music? ly:music?)
325 (make-music 'OldLyricCombineMusic
327 'elements (list music lyrics)))
331 #(define-music-function (parser location name property value)
332 (string? symbol? scheme?)
335 (_i "Set @var{property} to @var{value} in all grobs named @var{name}.
336 The @var{name} argument is a string of the form @code{\"Context.GrobName\"}
337 or @code{\"GrobName\"}")
340 ((name-components (string-split name #\.))
341 (context-name 'Bottom)
344 (if (> 2 (length name-components))
345 (set! grob-name (string->symbol (car name-components)))
347 (set! grob-name (string->symbol (list-ref name-components 1)))
348 (set! context-name (string->symbol (list-ref name-components 0)))))
350 (make-music 'ApplyOutputEvent
352 'context-type context-name
354 (lambda (grob orig-context context)
356 (cdr (assoc 'name (ly:grob-property grob 'meta)))
358 (set! (ly:grob-property grob property) value))))))
360 %% These are music functions (iso music indentifiers), because music identifiers
361 %% are not allowed at top-level.
363 #(define-music-function (location parser) ()
364 (_i "Force a page break. May be used at toplevel (ie between scores or
365 markups), or inside a score.")
366 (make-music 'EventChord
368 'line-break-permission 'force
369 'page-break-permission 'force
370 'elements (list (make-music 'LineBreakEvent
371 'break-permission 'force)
372 (make-music 'PageBreakEvent
373 'break-permission 'force))))
376 #(define-music-function (location parser) ()
377 (_i "Forbid a page break. May be used at toplevel (ie between scores or
378 markups), or inside a score.")
379 (make-music 'EventChord
381 'page-break-permission 'forbid
382 'elements (list (make-music 'PageBreakEvent
383 'break-permission '()))))
386 #(define-music-function (location parser) ()
387 (_i "Force a page turn between two scores or top-level markups.")
388 (make-music 'EventChord
390 'line-break-permission 'force
391 'page-break-permission 'force
392 'page-turn-permission 'force
393 'elements (list (make-music 'LineBreakEvent
394 'break-permission 'force)
395 (make-music 'PageBreakEvent
396 'break-permission 'force)
397 (make-music 'PageTurnEvent
398 'break-permission 'force))))
401 #(define-music-function (location parser) ()
402 (_i "Forbid a page turn. May be used at toplevel (ie between scores or
403 markups), or inside a score.")
404 (make-music 'EventChord
406 'page-turn-permission 'forbid
407 'elements (list (make-music 'PageTurnEvent
408 'break-permission '()))))
411 #(define-music-function (location parser) ()
412 (_i "Allow a page turn. May be used at toplevel (ie between scores or
413 markups), or inside a score.")
414 (make-music 'EventChord
416 'page-turn-permission 'allow
417 'elements (list (make-music 'PageTurnEvent
418 'break-permission 'allow))))
421 #(define-music-function
422 (parser location tag music) (symbol? ly:music?)
425 (let* ((tags (ly:music-property m 'tags))
426 (res (memq tag tags)))
432 %% define-music-function in a .scm causes crash.
435 #(define-music-function (parser location pitch-note) (ly:music?)
438 (make-music 'RelativeOctaveCheck
440 'pitch (pitch-of-note pitch-note)
443 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
444 (make-part-combine-music parser
449 #(define-music-function
450 (parser location main-note secondary-note)
451 (ly:music? ly:music?)
453 ((get-notes (lambda (ev-chord)
455 (lambda (m) (eq? 'NoteEvent (ly:music-property m 'name)))
456 (ly:music-property ev-chord 'elements))))
457 (sec-note-events (get-notes secondary-note))
458 (trill-events (filter (lambda (m) (music-has-type m 'trill-span-event))
459 (ly:music-property main-note 'elements)))
462 (if (pair? sec-note-events)
463 (ly:music-property (car sec-note-events) 'pitch)
466 (if (ly:pitch? trill-pitch)
467 (for-each (lambda (m) (ly:music-set-property! m 'pitch trill-pitch))
470 (ly:warning (_ "Second argument of \\pitchedTrill should be single note: "))
471 (display sec-note-events)))
476 #(define-music-function (parser loc arg) (ly:music?)
477 (_i "Tag @var{arg} to be parenthesized.")
479 (set! (ly:music-property arg 'parenthesize) #t)
483 #(use-modules (ice-9 optargs))
486 #(define-music-function (parser location voice-ids music) (list? ly:music?)
487 (_i "Define parallel music sequences, separated by '|' (bar check signs),
488 and assign them to the identifiers provided in @var{voice-ids}.
490 @var{voice-ids}: a list of music identifiers (symbols containing only letters)
492 @var{music}: a music sequence, containing BarChecks as limiting expressions.
497 \\parallelMusic #'(A B C) {
507 (let* ((voices (apply circular-list (make-list (length voice-ids) (list))))
508 (current-voices voices)
509 (current-sequence (list)))
512 (define (push-music m)
513 "Push the music expression into the current sequence"
514 (set! current-sequence (cons m current-sequence)))
515 (define (change-voice)
516 "Stores the previously built sequence into the current voice and
517 change to the following voice."
518 (list-set! current-voices 0 (cons (make-music 'SequentialMusic
519 'elements (reverse! current-sequence))
520 (car current-voices)))
521 (set! current-sequence (list))
522 (set! current-voices (cdr current-voices)))
523 (define (bar-check? m)
524 "Checks whether m is a bar check."
525 (eq? (ly:music-property m 'name) 'BarCheck))
526 (define (music-origin music)
527 "Recursively search an origin location stored in music."
528 (cond ((null? music) #f)
529 ((not (null? (ly:music-property music 'origin)))
530 (ly:music-property music 'origin))
531 (else (or (music-origin (ly:music-property music 'element))
532 (let ((origins (remove not (map music-origin
533 (ly:music-property music 'elements)))))
534 (and (not (null? origins)) (car origins)))))))
536 ;; first, split the music and fill in voices
537 (map-in-order (lambda (m)
539 (if (bar-check? m) (change-voice)))
540 (ly:music-property music 'elements))
541 (if (not (null? current-sequence)) (change-voice))
542 ;; un-circularize `voices' and reorder the voices
543 (set! voices (map-in-order (lambda (dummy seqs)
547 ;; set origin location of each sequence in each voice
548 ;; for better type error tracking
549 (for-each (lambda (voice)
550 (for-each (lambda (seq)
551 (set! (ly:music-property seq 'origin)
552 (or (music-origin seq) location)))
556 ;; check sequence length
557 (apply for-each (lambda* (#:rest seqs)
558 (let ((moment-reference (ly:music-length (car seqs))))
559 (for-each (lambda (seq moment)
560 (if (not (equal? moment moment-reference))
561 (ly:music-message seq
562 "Bars in parallel music don't have the same length")))
563 seqs (map-in-order ly:music-length seqs))))
566 ;; bind voice identifiers to the voices
567 (map (lambda (voice-id voice)
568 (ly:parser-define! parser voice-id
569 (make-music 'SequentialMusic
573 ;; Return an empty sequence. this function is actually a "void" function.
574 (make-music 'SequentialMusic 'void #t))
579 (define-music-function
580 (parser location what main-music)
582 (make-music 'QuoteMusic
584 'quoted-music-name what
589 resetRelativeOctave =
590 #(define-music-function
591 (parser location reference-note)
593 (_i "Set the octave inside a \\relative section.")
596 ((notes (ly:music-property reference-note 'elements))
597 (pitch (ly:music-property (car notes) 'pitch)))
599 (set! (ly:music-property reference-note 'elements) '())
600 (set! (ly:music-property reference-note
601 'to-relative-callback)
602 (lambda (music last-pitch)
610 #(define-music-function (parser location dur dots arg) (integer? integer? ly:music?)
615 (shift-one-duration-log x dur dots)) arg))
618 #(define-music-function (parser location parameters) (list?)
619 (_i "Set the system stretch, by reading the 'system-stretch property of
620 the `parameters' assoc list.")
622 \overrideProperty #"Score.NonMusicalPaperColumn"
623 #'line-break-system-details
624 #$(list (cons 'alignment-extra-space (cdr (assoc 'system-stretch parameters)))
625 (cons 'system-Y-extent (cdr (assoc 'system-Y-extent parameters))))
628 %% Parser used to read page-layout file, and then retreive score tweaks.
629 #(define page-layout-parser #f)
631 includePageLayoutFile =
632 #(define-music-function (parser location) ()
633 (_i "If page breaks and tweak dump is not asked, and the file
634 <basename>-page-layout.ly exists, include it.")
635 (if (not (ly:get-option 'dump-tweaks))
636 (let ((tweak-filename (format #f "~a-page-layout.ly"
637 (ly:parser-output-name parser))))
638 (if (access? tweak-filename R_OK)
640 (ly:message "Including tweak file ~a" tweak-filename)
641 (set! page-layout-parser (ly:parser-clone parser))
642 (ly:parser-parse-string page-layout-parser
643 (format #f "\\include \"~a\""
645 (make-music 'SequentialMusic 'void #t))
649 #(define-music-function (parser location finger) (number-or-string?)
650 (_i "Define a StrokeFingerEvent")
659 (list 'digit finger)))))
662 #(define-music-function (parser location name) (string?)
663 (_i "Include the score tweak, if exists.")
664 (if (and page-layout-parser (not (ly:get-option 'dump-tweaks)))
665 (let ((tweak-music (ly:parser-lookup page-layout-parser
666 (string->symbol name))))
667 (if (ly:music? tweak-music)
669 (make-music 'SequentialMusic)))
670 (make-music 'SequentialMusic)))
672 transposedCueDuring =
673 #(define-music-function
674 (parser location what dir pitch-note main-music)
675 (string? ly:dir? ly:music? ly:music?)
677 (_i "Insert notes from the part @var{what} into a voice called @code{cue},
678 using the transposition defined by @var{pitch-note}. This happens
679 simultaneously with @var{main-music}, which is usually a rest. The
680 argument @var{dir} determines whether the cue notes should be notated
681 as a first or second voice.")
683 (make-music 'QuoteMusic
685 'quoted-context-type 'Voice
686 'quoted-context-id "cue"
687 'quoted-music-name what
688 'quoted-voice-direction dir
689 'quoted-transposition (pitch-of-note pitch-note)
695 #(define-music-function (parser location pitch-note) (ly:music?)
696 (_i "Set instrument transposition")
699 (make-property-set 'instrumentTransposition
700 (ly:pitch-negate (pitch-of-note pitch-note)))
703 tweak = #(define-music-function (parser location sym val arg)
704 (symbol? scheme? ly:music?)
706 (_i "Add @code{sym . val} to the @code{tweaks} property of @var{arg}.")
709 (ly:music-property arg 'tweaks)
711 (ly:music-property arg 'tweaks)))
714 tag = #(define-music-function (parser location tag arg)
717 (_i "Add @var{tag} to the @code{tags} property of @var{arg}.")
720 (ly:music-property arg 'tags)
722 (ly:music-property arg 'tags)))
727 #(define-music-function (parser location music) (ly:music?)
728 (unfold-repeats music))
733 #(define-music-function (parser location sym val music) (symbol? scheme? ly:music?)
734 (_i "Set @var{sym} to @var{val} in @var{music}.")
736 (set! (ly:music-property music sym) val)