7 #(use-modules (srfi srfi-1))
8 %% FIXME: guile-1.7 required?
9 %#(use-modules (scm display-lily))invalid module name for use-syntax ((srfi srfi-39))
11 #(use-modules (scm display-lily))
12 #(display-lily-init parser)
16 #(def-grace-function startAcciaccaturaMusic stopAcciaccaturaMusic)
19 #(define-music-function (parser location name music) (string? ly:music?)
20 "Add a piece of music to be quoted "
21 (add-quotable name music)
22 (make-music 'SequentialMusic 'void #t))
29 #(define-music-function
30 (parser location main grace)
34 ((main-length (ly:music-length main))
35 (fraction (ly:parser-lookup parser 'afterGraceFraction)))
37 (make-simultaneous-music
40 (make-sequential-music
43 (make-music 'SkipMusic
44 'duration (ly:make-duration
46 (* (ly:moment-main-numerator main-length)
48 (* (ly:moment-main-denominator main-length)
50 (make-music 'GraceMusic
54 #(define-music-function (parser location func music) (procedure? ly:music?)
59 #(define-music-function (parser location ctx proc) (symbol? procedure?)
60 (make-music 'ApplyOutputEvent
66 #(def-grace-function startAppoggiaturaMusic stopAppoggiaturaMusic)
70 % for regression testing purposes.
72 #(define-music-function (parser location l r) (pair? pair?)
73 (make-grob-property-override 'Beam 'positions
74 (ly:make-simple-closure
75 (ly:make-simple-closure
77 (list chain-grob-member-functions `(,cons 0 0))
78 (check-quant-callbacks l r))))))
80 % for regression testing purposes.
82 #(define-music-function (parser location comp) (procedure?)
83 (make-grob-property-override 'Beam 'positions
84 (ly:make-simple-closure
85 (ly:make-simple-closure
87 (list chain-grob-member-functions `(,cons 0 0))
88 (check-slope-callbacks comp))))))
93 #(define-music-function (parser location music) (ly:music?)
94 (make-autochange-music music))
97 #(define-music-function (parser location proc) (procedure?)
98 (make-music 'ApplyContext
103 #(define-music-function (parser location type)
106 (make-property-set 'whichBar type)
111 #(define-music-function (parser location n) (integer?)
112 (make-music 'ApplyContext
117 ((cbn (ly:context-property c 'currentBarNumber)))
118 (if (and (number? cbn) (not (= cbn n)))
119 (ly:input-message location "Barcheck failed got ~a expect ~a"
125 #(define-music-function (parser location) ()
126 (make-music 'EventChord
128 'elements (list (make-music 'BreathingEvent))))
131 #(define-music-function (parser location delta) (integer?)
133 (make-music 'BendAfterEvent
137 #(define-music-function (parser location type)
140 "Set the current clef."
142 (make-clef-set type))
146 #(define-music-function
147 (parser location fraction music) (number-pair? ly:music?)
148 (ly:music-compress music (ly:make-moment (car fraction) (cdr fraction))))
152 #(define-music-function
153 (parser location what dir main-music)
154 (string? ly:dir? ly:music?)
155 (make-music 'QuoteMusic
157 'quoted-context-type 'Voice
158 'quoted-context-id "cue"
159 'quoted-music-name what
160 'quoted-voice-direction dir
165 #(define-music-function (parser location music) (ly:music?)
166 (display-lily-music music)
170 #(define-music-function (parser location music) (ly:music?)
171 (display-scheme-music music)
175 #(define-music-function (parser location factor argument) (ly:moment? ly:music?)
177 "Rearrange durations in ARGUMENT so there is an
178 acceleration/deceleration. "
181 ((orig-duration (ly:music-length argument))
182 (multiplier (ly:make-moment 1 1)))
186 (if (and (eq? (ly:music-property mus 'name) 'EventChord)
187 (< 0 (ly:moment-main-denominator (ly:music-length mus))))
189 (ly:music-compress mus multiplier)
190 (set! multiplier (ly:moment-mul factor multiplier)))
197 (ly:moment-div orig-duration (ly:music-length argument)))
202 #(def-grace-function startGraceMusic stopGraceMusic)
205 "instrument-definitions" = #'()
207 addInstrumentDefinition =
208 #(define-music-function
209 (parser location name lst) (string? list?)
211 (set! instrument-definitions (acons name lst instrument-definitions))
213 (make-music 'SequentialMusic 'void #t))
217 #(define-music-function
218 (parser location name) (string?)
220 ((handle (assoc name instrument-definitions))
221 (instrument-def (if handle (cdr handle) '()))
225 (ly:input-message "No such instrument: ~a" name))
227 (make-music 'SimultaneousMusic
238 #(define-music-function
239 (parser location tag music) (symbol? ly:music?)
242 (let* ((tags (ly:music-property m 'tags))
243 (res (memq tag tags)))
252 #(define-music-function
253 (parser location music)
257 (if (string? (ly:music-property mus 'quoted-music-name))
258 (ly:music-property mus 'element)
263 #(define-music-function
264 (parser location arg) (ly:music?)
265 (music-map note-to-cluster arg))
268 #(define-music-function (parser location proc mus) (procedure? ly:music?)
269 (music-map proc mus))
274 #(define-music-function (parser location music lyrics) (ly:music? ly:music?)
276 (make-music 'OldLyricCombineMusic
278 'elements (list music lyrics)))
282 #(define-music-function (parser location name property value)
283 (string? symbol? scheme?)
286 "Set @var{property} to @var{value} in all grobs named @var{name}.
287 The @var{name} argument is a string of the form @code{\"Context.GrobName\"}
288 or @code{\"GrobName\"}"
291 ((name-components (string-split name #\.))
292 (context-name 'Bottom)
295 (if (> 2 (length name-components))
296 (set! grob-name (string->symbol (car name-components)))
298 (set! grob-name (string->symbol (list-ref name-components 1)))
299 (set! context-name (string->symbol (list-ref name-components 0)))))
301 (make-music 'ApplyOutputEvent
303 'context-type context-name
305 (lambda (grob orig-context context)
307 (cdr (assoc 'name (ly:grob-property grob 'meta)))
309 (set! (ly:grob-property grob property) value))))))
313 #(define-music-function
314 (parser location tag music) (symbol? ly:music?)
317 (let* ((tags (ly:music-property m 'tags))
318 (res (memq tag tags)))
324 %% define-music-function in a .scm causes crash.
327 #(define-music-function (parser location pitch-note) (ly:music?)
330 (make-music 'RelativeOctaveCheck
332 'pitch (pitch-of-note pitch-note)
335 #(define-music-function (parser location part1 part2) (ly:music? ly:music?)
336 (make-part-combine-music (list part1 part2)))
340 #(define-music-function
341 (parser location main-note secondary-note)
342 (ly:music? ly:music?)
344 ((get-notes (lambda (ev-chord)
346 (lambda (m) (eq? 'NoteEvent (ly:music-property m 'name)))
347 (ly:music-property ev-chord 'elements))))
348 (sec-note-events (get-notes secondary-note))
349 (trill-events (filter (lambda (m) (memq 'trill-span-event (ly:music-property m 'types)))
350 (ly:music-property main-note 'elements)))
353 (if (pair? sec-note-events)
354 (ly:music-property (car sec-note-events) 'pitch)
357 (if (ly:pitch? trill-pitch)
358 (for-each (lambda (m) (ly:music-set-property! m 'pitch trill-pitch))
361 (ly:warning (_ "Second argument of \\pitchedTrill should be single note: "))
362 (display sec-note-events)))
367 #(define-music-function (parser loc arg) (ly:music?)
368 "Tag @var{arg} to be parenthesized."
370 (set! (ly:music-property arg 'parenthesize) #t)
374 #(use-modules (ice-9 optargs))
377 #(define-music-function (parser location voice-ids music) (list? ly:music?)
378 "Define parallel music sequences, separated by '|' (bar check signs),
379 and assign them to the identifiers provided in @var{voice-ids}.
381 @var{voice-ids}: a list of music identifiers (symbols containing only letters)
383 @var{music}: a music sequence, containing BarChecks as limiting expressions.
386 \\parallelMusic #'(A B C) {
395 (let* ((voices (apply circular-list (make-list (length voice-ids) (list))))
396 (current-voices voices)
397 (current-sequence (list)))
400 (define (push-music m)
401 "Push the music expression into the current sequence"
402 (set! current-sequence (cons m current-sequence)))
403 (define (change-voice)
404 "Stores the previously built sequence into the current voice and
405 change to the following voice."
406 (list-set! current-voices 0 (cons (make-music 'SequentialMusic
407 'elements (reverse! current-sequence))
408 (car current-voices)))
409 (set! current-sequence (list))
410 (set! current-voices (cdr current-voices)))
411 (define (bar-check? m)
412 "Checks whether m is a bar check."
413 (eq? (ly:music-property m 'name) 'BarCheck))
414 (define (music-origin music)
415 "Recursively search an origin location stored in music."
416 (cond ((null? music) #f)
417 ((not (null? (ly:music-property music 'origin)))
418 (ly:music-property music 'origin))
419 (else (or (music-origin (ly:music-property music 'element))
420 (let ((origins (remove not (map music-origin
421 (ly:music-property music 'elements)))))
422 (and (not (null? origins)) (car origins)))))))
424 ;; first, split the music and fill in voices
425 (map-in-order (lambda (m)
427 (if (bar-check? m) (change-voice)))
428 (ly:music-property music 'elements))
429 (if (not (null? current-sequence)) (change-voice))
430 ;; un-circularize `voices' and reorder the voices
431 (set! voices (map-in-order (lambda (dummy seqs)
435 ;; set origin location of each sequence in each voice
436 ;; for better type error tracking
437 (for-each (lambda (voice)
438 (for-each (lambda (seq)
439 (set! (ly:music-property seq 'origin)
440 (or (music-origin seq) location)))
444 ;; check sequence length
445 (apply for-each (lambda* (#:rest seqs)
446 (let ((moment-reference (ly:music-length (car seqs))))
447 (for-each (lambda (seq moment)
448 (if (not (equal? moment moment-reference))
449 (ly:music-message seq
450 "Bars in parallel music don't have the same length")))
451 seqs (map-in-order ly:music-length seqs))))
454 ;; bind voice identifiers to the voices
455 (map (lambda (voice-id voice)
456 (ly:parser-define! parser voice-id
457 (make-music 'SequentialMusic
461 ;; Return an empty sequence. this function is actually a "void" function.
462 (make-music 'SequentialMusic 'void #t))
467 (define-music-function
468 (parser location what main-music)
470 (make-music 'QuoteMusic
472 'quoted-music-name what
477 resetRelativeOctave =
478 #(define-music-function
479 (parser location reference-note)
481 "Set the octave inside a \\relative section."
484 ((notes (ly:music-property reference-note 'elements))
485 (pitch (ly:music-property (car notes) 'pitch)))
487 (set! (ly:music-property reference-note 'elements) '())
488 (set! (ly:music-property reference-note
489 'to-relative-callback)
490 (lambda (music last-pitch)
498 #(define-music-function (parser location dur dots arg) (integer? integer? ly:music?)
504 (shift-one-duration-log x dur dots)) arg))
507 #(define-music-function (parser location parameters) (list?)
508 "Set the system stretch, by reading the 'system-stretch property of
509 the `parameters' assoc list."
511 \overrideProperty #"Score.NonMusicalPaperColumn"
512 #'line-break-system-details
513 #$(list (cons 'alignment-extra-space (cdr (assoc 'system-stretch parameters))))
516 %% Parser used to read page-layout file, and then retreive score tweaks.
517 #(define page-layout-parser #f)
519 includePageLayoutFile =
520 #(define-music-function (parser location) ()
521 "If page breaks and tweak dump is not asked, and the file
522 <basename>-page-layout.ly exists, include it."
523 (if (not (ly:get-option 'dump-tweaks))
524 (let ((tweak-filename (format #f "~a-page-layout.ly"
525 (ly:parser-output-name parser))))
526 (if (access? tweak-filename R_OK)
528 (ly:message "Including tweak file ~a" tweak-filename)
529 (set! page-layout-parser (ly:clone-parser parser))
530 (ly:parser-parse-string page-layout-parser
531 (format #f "\\include \"~a\""
533 (make-music 'SequentialMusic 'void #t))
536 #(define-music-function (parser location name) (string?)
537 "Include the score tweak, if exists."
538 (if (and page-layout-parser (not (ly:get-option 'dump-tweaks)))
539 (let ((tweak-music (ly:parser-lookup page-layout-parser
540 (string->symbol name))))
541 (if (ly:music? tweak-music)
543 (make-music 'SequentialMusic)))
544 (make-music 'SequentialMusic)))
546 transposedCueDuring =
547 #(define-music-function
548 (parser location what dir pitch-note main-music)
549 (string? ly:dir? ly:music? ly:music?)
551 "Insert notes from the part @var{what} into a voice called @code{cue},
552 using the transposition defined by @var{pitch-note}. This happens
553 simultaneously with @var{main-music}, which is usually a rest. The
554 argument @var{dir} determines whether the cue notes should be notated
555 as a first or second voice."
557 (make-music 'QuoteMusic
559 'quoted-context-type 'Voice
560 'quoted-context-id "cue"
561 'quoted-music-name what
562 'quoted-voice-direction dir
563 'quoted-transposition (pitch-of-note pitch-note)
569 #(define-music-function (parser location pitch-note) (ly:music?)
570 "Set instrument transposition"
573 (make-property-set 'instrumentTransposition
574 (ly:pitch-diff (ly:make-pitch 0 0 0) (pitch-of-note pitch-note)))
578 tweak = #(define-music-function (parser location sym val arg)
579 (symbol? scheme? ly:music?)
581 "Add @code{sym . val} to the @code{tweaks} property of @var{arg}."
585 (ly:music-property arg 'tweaks)
587 (ly:music-property arg 'tweaks)))
590 tag = #(define-music-function (parser location tag arg)
593 "Add @var{tag} to the @code{tags} property of @var{arg}."
596 (ly:music-property arg 'tags)
598 (ly:music-property arg 'tags)))
603 #(define-music-function (parser location music) (ly:music?)
604 (unfold-repeats music))
609 #(define-music-function (parser location sym val music) (symbol? scheme? ly:music?)
610 "Set @var{sym} to @var{val} in @var{music}."
612 (set! (ly:music-property music sym) val)