1 ;;; define-music-display-methods.scm -- data for displaying music
2 ;;; expressions using LilyPond notation.
4 ;;; Copyright (C) 2005--2015 Nicolas Sceaux <nicolas.sceaux@free.fr>
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9 ;;; Display method implementation
12 (define-module (scm display-lily))
17 (define (scheme-expr->lily-string scm-arg)
18 (cond ((or (number? scm-arg)
21 (format #f "~s" scm-arg))
22 ((or (symbol? scm-arg)
24 (format #f "'~s" scm-arg))
27 (or (procedure-name scm-arg)
28 (with-output-to-string
30 (pretty-print (procedure-source scm-arg)))))))
33 (with-output-to-string
35 (display-scheme-music scm-arg)))))))
40 (define-public (markup->lily-string markup-expr)
41 "Return a string describing, in LilyPond syntax, the given markup
43 (define (proc->command proc)
44 (let ((cmd-markup (symbol->string (procedure-name proc))))
45 (substring cmd-markup 0 (- (string-length cmd-markup)
46 (string-length "-markup")))))
47 (define (arg->string arg)
50 ((markup? arg) ;; a markup
51 (markup->lily-string-aux arg))
52 ((and (pair? arg) (every markup? arg)) ;; a markup list
53 (format #f "{~{ ~a~}}" (map-in-order markup->lily-string-aux arg)))
54 (else ;; a scheme argument
55 (format #f "#~a" (scheme-expr->lily-string arg)))))
56 (define (markup->lily-string-aux expr)
59 (let ((cmd (car expr))
61 (if (eqv? cmd simple-markup) ;; a simple markup
62 (format #f "~s" (car args))
63 (format #f "\\~a~{ ~a~}"
65 (map-in-order arg->string args))))))
66 (cond ((string? markup-expr)
67 (format #f "~s" markup-expr))
68 ((eqv? (car markup-expr) simple-markup)
69 (format #f "~s" (second markup-expr)))
71 (format #f "\\markup ~a"
72 (markup->lily-string-aux markup-expr)))))
78 ;; It is a pity that there is no rassoc in Scheme.
79 (define* (rassoc item alist #:optional (test equal?))
80 (do ((alist alist (cdr alist))
82 ((or result (null? alist)) result)
83 (if (and (car alist) (test item (cdar alist)))
84 (set! result (car alist)))))
86 (define-public (note-name->lily-string ly-pitch)
87 ;; here we define a custom pitch= function, since we do not want to
88 ;; test whether octaves are also equal. (otherwise, we would be using equal?)
89 (define (pitch= pitch1 pitch2)
90 (and (= (ly:pitch-notename pitch1) (ly:pitch-notename pitch2))
91 (= (ly:pitch-alteration pitch1) (ly:pitch-alteration pitch2))))
92 (let* ((result (rassoc ly-pitch pitchnames pitch=)))
93 (and result (car result))))
95 (define-public (octave->lily-string pitch)
96 (let ((octave (ly:pitch-octave pitch)))
98 (make-string (1+ octave) #\'))
100 (make-string (1- (* -1 octave)) #\,))
106 (define*-public (duration->lily-string ly-duration #:key
108 (time-scale (*time-scale*)))
109 (let ((log2 (ly:duration-log ly-duration))
110 (dots (ly:duration-dot-count ly-duration))
111 (scale (ly:duration-scale ly-duration)))
112 (if (or force-duration (not (*omit-duration*)))
113 (string-append (case log2
117 (else (number->string (expt 2 log2))))
118 (make-string dots #\.)
119 (let ((end-scale (/ scale time-scale)))
120 (if (= end-scale 1) ""
121 (format #f "*~a" end-scale))))
128 (define post-event? (music-type-predicate 'post-event))
130 (define* (event-direction->lily-string event #:optional (required #t))
131 (let ((direction (ly:music-property event 'direction)))
132 (cond ((or (not direction) (null? direction) (= CENTER direction))
133 (if required "-" ""))
134 ((= UP direction) "^")
135 ((= DOWN direction) "_")
138 (define-macro (define-post-event-display-method type vars direction-required str)
139 `(define-display-method ,type ,vars
141 (event-direction->lily-string ,(car vars) ,direction-required)
144 (define-macro (define-span-event-display-method type vars direction-required str-start str-stop)
145 `(define-display-method ,type ,vars
147 (event-direction->lily-string ,(car vars) ,direction-required)
148 (if (= START (ly:music-property ,(car vars) 'span-direction))
152 (define-display-method HyphenEvent (event)
154 (define-display-method ExtenderEvent (event)
156 (define-display-method TieEvent (event)
158 (define-display-method BeamForbidEvent (event)
160 (define-display-method StringNumberEvent (event)
161 (format #f "\\~a" (ly:music-property event 'string-number)))
164 (define-display-method TremoloEvent (event)
165 (let ((tremolo-type (ly:music-property event 'tremolo-type 8)))
166 (format #f ":~a" tremolo-type)))
168 (define-display-method ArticulationEvent (event) #t
169 (let* ((articulation (ly:music-property event 'articulation-type))
171 (case (string->symbol articulation)
175 ((staccatissimo) "!")
180 (format #f "~a~:[\\~;~]~a"
181 (event-direction->lily-string event shorthand)
183 (or shorthand articulation))))
185 (define-post-event-display-method FingeringEvent (event) #t
186 (ly:music-property event 'digit))
188 (define-post-event-display-method TextScriptEvent (event) #t
189 (markup->lily-string (ly:music-property event 'text)))
191 (define-post-event-display-method MultiMeasureTextEvent (event) #t
192 (markup->lily-string (ly:music-property event 'text)))
194 (define-post-event-display-method BendAfterEvent (event) #f
195 (format #f "\\bendAfter #~a " (ly:music-property event 'delta-step)))
197 (define-post-event-display-method HarmonicEvent (event) #f "\\harmonic")
198 (define-post-event-display-method GlissandoEvent (event) #f "\\glissando")
199 (define-post-event-display-method ArpeggioEvent (event) #f "\\arpeggio")
200 (define-post-event-display-method AbsoluteDynamicEvent (event) #f
201 (format #f "\\~a" (ly:music-property event 'text)))
203 (define-post-event-display-method StrokeFingerEvent (event) #f
204 (format #f "\\rightHandFinger #~a " (ly:music-property event 'digit)))
206 (define-span-event-display-method BeamEvent (event) #f "[" "]")
207 (define-span-event-display-method SlurEvent (event) #f "(" ")")
208 (define-span-event-display-method CrescendoEvent (event) #f "\\<" "\\!")
209 (define-span-event-display-method DecrescendoEvent (event) #f "\\>" "\\!")
210 (define-span-event-display-method EpisemaEvent (event) #f "\\episemInitium" "\\episemFinis")
211 (define-span-event-display-method PhrasingSlurEvent (event) #f "\\(" "\\)")
212 (define-span-event-display-method SustainEvent (event) #f "\\sustainOn" "\\sustainOff")
213 (define-span-event-display-method SostenutoEvent (event) #f "\\sostenutoOn" "\\sostenutoOff")
214 (define-span-event-display-method TextSpanEvent (event) #f "\\startTextSpan" "\\stopTextSpan")
215 (define-span-event-display-method TrillSpanEvent (event) #f "\\startTrillSpan" "\\stopTrillSpan")
216 (define-span-event-display-method StaffSpanEvent (event) #f "\\startStaff" "\\stopStaff")
217 (define-span-event-display-method NoteGroupingEvent (event) #f "\\startGroup" "\\stopGroup")
218 (define-span-event-display-method UnaCordaEvent (event) #f "\\unaCorda" "\\treCorde")
224 (define-display-method GraceMusic (expr)
225 (format #f "\\grace ~a"
226 (music->lily-string (ly:music-property expr 'element))))
228 ;; \acciaccatura \appoggiatura \grace
229 ;; TODO: it would be better to compare ?start and ?stop
230 ;; with startAppoggiaturaMusic and stopAppoggiaturaMusic,
231 ;; using a custom music equality predicate.
232 (define-extra-display-method GraceMusic (expr)
233 "Display method for appoggiatura."
234 (with-music-match (expr (music
241 ;; we check whether ?start and ?stop look like
242 ;; startAppoggiaturaMusic stopAppoggiaturaMusic
243 (and (with-music-match (?start (music
250 span-direction START))))))
252 (with-music-match (?stop (music
259 span-direction STOP))))))
260 (format #f "\\appoggiatura ~a" (music->lily-string ?music))))))
263 (define-extra-display-method GraceMusic (expr)
264 "Display method for acciaccatura."
265 (with-music-match (expr (music
272 ;; we check whether ?start and ?stop look like
273 ;; startAcciaccaturaMusic stopAcciaccaturaMusic
274 (and (with-music-match (?start (music
281 span-direction START)))
286 grob-property-path '(stroke-style)
290 (with-music-match (?stop (music
296 grob-property-path '(stroke-style)
304 span-direction STOP))))))
305 (format #f "\\acciaccatura ~a" (music->lily-string ?music))))))
307 (define-extra-display-method GraceMusic (expr)
308 "Display method for grace."
309 (with-music-match (expr (music
316 ;; we check whether ?start and ?stop look like
317 ;; startGraceMusic stopGraceMusic
318 (and (null? (ly:music-property ?start 'elements))
319 (null? (ly:music-property ?stop 'elements))
320 (format #f "\\grace ~a" (music->lily-string ?music)))))
326 (define-display-method SequentialMusic (seq)
327 (let ((force-line-break (and (*force-line-break*)
329 (> (length (ly:music-property seq 'elements))
330 (*max-element-number-before-break*))))
331 (elements (ly:music-property seq 'elements))
332 (chord? (make-music-type-predicate 'EventChord))
333 (note-or-chord? (make-music-type-predicate 'EventChord 'NoteEvent
334 'LyricEvent 'RestEvent
336 (cluster? (make-music-type-predicate 'ClusterNoteEvent))
337 (note? (make-music-type-predicate 'NoteEvent)))
338 (format #f "~a~a{~v%~v_~{~a~^ ~}~v%~v_}"
342 (any cluster? (ly:music-property e 'elements)))))
346 (if (*explicit-mode*)
347 ;; if the sequence contains EventChord which contains figures ==> figuremode
348 ;; if the sequence contains EventChord which contains lyrics ==> lyricmode
349 ;; if the sequence contains EventChord which contains drum notes ==> drummode
350 (cond ((any (lambda (chord)
351 (any (make-music-type-predicate 'BassFigureEvent)
352 (ly:music-property chord 'elements)))
353 (filter chord? elements))
355 ((any (lambda (chord)
356 (any (make-music-type-predicate 'LyricEvent)
358 (ly:music-property chord 'elements))))
359 (filter note-or-chord? elements))
361 ((any (lambda (chord)
364 (not (null? (ly:music-property event 'drum-type)))))
366 (ly:music-property chord 'elements))))
367 (filter note-or-chord? elements))
369 (else ;; TODO: other modes?
372 (if force-line-break 1 0)
373 (if force-line-break (+ 2 (*indent*)) 1)
374 (parameterize ((*indent* (+ 2 (*indent*))))
375 (map-in-order (lambda (music)
376 (music->lily-string music))
378 (if force-line-break 1 0)
379 (if force-line-break (*indent*) 1))))
381 (define-display-method SimultaneousMusic (sim)
382 (parameterize ((*indent* (+ 3 (*indent*))))
383 (format #f "<< ~{~a ~}>>"
384 (map-in-order (lambda (music)
385 (music->lily-string music))
386 (ly:music-property sim 'elements)))))
388 (define-extra-display-method SimultaneousMusic (expr)
389 "If `sim' is an \afterGrace expression, return \"\\afterGrace ...\".
390 Otherwise, return #f."
391 ;; TODO: do something with afterGraceFraction?
392 (with-music-match (expr (music 'SimultaneousMusic
393 elements (?before-grace
394 (music 'SequentialMusic
395 elements ((music 'SkipMusic)
398 (format #f "\\afterGrace ~a ~a"
399 (music->lily-string ?before-grace)
400 (music->lily-string ?grace))))
406 (define-display-method EventChord (chord)
407 ;; event_chord : command_element
408 ;; | note_chord_element
410 ;; TODO : tagged post_events
411 ;; post_events : ( post_event | tagged_post_event )*
412 ;; tagged_post_event: '-' \tag embedded_scm post_event
414 (let* ((elements (append (ly:music-property chord 'elements)
415 (ly:music-property chord 'articulations)))
416 (chord-repeat (ly:music-property chord 'duration)))
419 (partition (music-type-predicate 'rhythmic-event)
421 (lambda (chord-elements other-elements)
422 (cond ((pair? chord-elements)
423 ;; note_chord_element :
424 ;; '<' (notepitch | drumpitch)* '>" duration post_events
425 (let ((duration (duration->lily-string (ly:music-property
428 ;; Format duration first so that it does not appear on
430 (format #f "< ~{~a ~}>~a~:{~:[-~;~]~a~^ ~}"
431 (parameterize ((*omit-duration* #t))
434 (music->lily-string music))
437 (map-in-order (lambda (music)
440 (music->lily-string music)))
442 ((ly:duration? chord-repeat)
443 (let ((duration (duration->lily-string chord-repeat)))
444 (format #f "q~a~:{~:[-~;~]~a~^ ~}"
446 (map-in-order (lambda (music)
449 (music->lily-string music)))
452 ((and (= 1 (length other-elements))
453 (not (post-event? (car other-elements))))
454 (format #f (music->lily-string (car other-elements))))
456 (format #f "< >~:{~:[-~;~]~a~^ ~}"
457 (map-in-order (lambda (music)
460 (music->lily-string music)))
461 other-elements))))))))
463 (define-display-method MultiMeasureRestMusic (mmrest)
464 (format #f "R~a~{~a~^ ~}"
465 (duration->lily-string (ly:music-property mmrest 'duration))
466 (map-in-order (lambda (music)
467 (music->lily-string music))
468 (ly:music-property mmrest 'articulations))))
470 (define-display-method SkipMusic (skip)
471 (format #f "\\skip ~a" (duration->lily-string (ly:music-property skip 'duration) #:force-duration #t)))
473 (define-display-method OttavaMusic (ottava)
474 (format #f "\\ottava #~a" (ly:music-property ottava 'ottava-number)))
477 ;;; Notes, rests, skips...
480 (define (simple-note->lily-string event)
481 (format #f "~a~a~a~a~a~a~:{~:[-~;~]~a~}" ; pitchname octave !? octave-check duration optional_rest articulations
482 (note-name->lily-string (ly:music-property event 'pitch))
483 (octave->lily-string (ly:music-property event 'pitch))
484 (let ((forced (ly:music-property event 'force-accidental))
485 (cautionary (ly:music-property event 'cautionary)))
486 (cond ((and (not (null? forced))
488 (not (null? cautionary))
491 ((and (not (null? forced)) forced) "!")
493 (let ((octave-check (ly:music-property event 'absolute-octave)))
494 (if (not (null? octave-check))
495 (format #f "=~a" (cond ((>= octave-check 0)
496 (make-string (1+ octave-check) #\'))
498 (make-string (1- (* -1 octave-check)) #\,))
501 (duration->lily-string (ly:music-property event 'duration))
502 (if ((make-music-type-predicate 'RestEvent) event)
504 (map-in-order (lambda (event)
507 (music->lily-string event)))
508 (ly:music-property event 'articulations))))
510 (define-display-method NoteEvent (note)
511 (cond ((not (null? (ly:music-property note 'pitch))) ;; note
512 (simple-note->lily-string note))
513 ((not (null? (ly:music-property note 'drum-type))) ;; drum
514 (format #f "~a~a~{~a~}" (ly:music-property note 'drum-type)
515 (duration->lily-string (ly:music-property note 'duration))
516 (map-in-order (lambda (event)
517 (music->lily-string event))
518 (ly:music-property note 'articulations))))
521 (format #f "~a~{~a~}"
522 (duration->lily-string (ly:music-property note 'duration)
524 (map-in-order (lambda (event)
525 (music->lily-string event))
526 (ly:music-property note 'articulations))))))
528 (define-display-method ClusterNoteEvent (note)
529 (simple-note->lily-string note))
531 (define-display-method RestEvent (rest)
532 (if (not (null? (ly:music-property rest 'pitch)))
533 (simple-note->lily-string rest)
534 (format #f "r~a~{~a~}"
535 (duration->lily-string (ly:music-property rest 'duration))
536 (map-in-order (lambda (event)
537 (music->lily-string event))
538 (ly:music-property rest 'articulations)))))
540 (define-display-method MultiMeasureRestEvent (rest)
541 (string-append "R" (duration->lily-string (ly:music-property rest 'duration))))
543 (define-display-method SkipEvent (rest)
544 (format #f "s~a~{~a~}"
545 (duration->lily-string (ly:music-property rest 'duration))
546 (map-in-order (lambda (event)
547 (music->lily-string event))
548 (ly:music-property rest 'articulations))))
550 (define-display-method RepeatedChord (chord)
551 (music->lily-string (ly:music-property chord 'element)))
553 (define-display-method MarkEvent (mark)
554 (let ((label (ly:music-property mark 'label)))
557 (format #f "\\mark ~a" (markup->lily-string label)))))
559 (define-display-method KeyChangeEvent (key)
560 (let ((pitch-alist (ly:music-property key 'pitch-alist))
561 (tonic (ly:music-property key 'tonic)))
562 (if (or (null? pitch-alist)
565 (let ((c-pitch-alist (ly:transpose-key-alist pitch-alist
566 (ly:pitch-diff (ly:make-pitch 0 0 0) tonic))))
567 (format #f "\\key ~a \\~a~a"
568 (note-name->lily-string (ly:music-property key 'tonic))
570 (and (equal? (ly:parser-lookup mode) c-pitch-alist)
571 (symbol->string mode)))
572 '(major minor ionian locrian aeolian mixolydian lydian phrygian dorian))
573 (new-line->lily-string))))))
575 (define-display-method RelativeOctaveCheck (octave)
576 (let ((pitch (ly:music-property octave 'pitch)))
577 (format #f "\\octaveCheck ~a~a"
578 (note-name->lily-string pitch)
579 (octave->lily-string pitch))))
581 (define-display-method VoiceSeparator (sep)
584 (define-display-method LigatureEvent (ligature)
585 (if (= START (ly:music-property ligature 'span-direction))
589 (define-display-method BarCheck (check)
590 (format #f "|~a" (new-line->lily-string)))
592 (define-display-method PesOrFlexaEvent (expr)
595 (define-display-method BassFigureEvent (figure)
596 (let ((alteration (ly:music-property figure 'alteration))
597 (fig (ly:music-property figure 'figure))
598 (bracket-start (ly:music-property figure 'bracket-start))
599 (bracket-stop (ly:music-property figure 'bracket-stop)))
601 (format #f "~a~a~a~a"
602 (if (null? bracket-start) "" "[")
603 (cond ((null? fig) "_")
604 ((markup? fig) (second fig)) ;; fig: (<number-markup> "number")
606 (if (null? alteration)
609 ((= alteration DOUBLE-FLAT) "--")
610 ((= alteration FLAT) "-")
611 ((= alteration NATURAL) "!")
612 ((= alteration SHARP) "+")
613 ((= alteration DOUBLE-SHARP) "++")
615 (if (null? bracket-stop) "" "]"))))
617 (define-display-method LyricEvent (lyric)
618 (format #f "~a~{~a~^ ~}"
619 (let ((text (ly:music-property lyric 'text)))
620 (if (or (string? text)
621 (eqv? (first text) simple-markup))
622 ;; a string or a simple markup
623 (let ((string (if (string? text)
626 (if (string-match "(\"| |[0-9])" string)
627 ;; TODO check exactly in which cases double quotes should be used
628 (format #f "~s" string)
630 (markup->lily-string text)))
631 (map-in-order (lambda (m) (music->lily-string m))
632 (ly:music-property lyric 'articulations))))
634 (define-display-method BreathingEvent (event)
641 (define-display-method AutoChangeMusic (m)
642 (format #f "\\autochange ~a"
644 (ly:music-property (ly:music-property m 'element) 'element))))
646 (define-display-method ContextChange (m)
647 (format #f "\\change ~a = \"~a\""
648 (ly:music-property m 'change-to-type)
649 (ly:music-property m 'change-to-id)))
653 (define-display-method TimeScaledMusic (times)
654 (let* ((num (ly:music-property times 'numerator))
655 (den (ly:music-property times 'denominator))
656 (span (ly:music-property times 'duration #f))
657 ;; need to format before changing time scale
659 (and span (duration->lily-string span #:force-duration #t)))
661 (time-scale (*time-scale*)))
663 (parameterize ((*force-line-break* #f)
664 (*time-scale* (* time-scale scale)))
665 (format #f "\\tuplet ~a/~a ~@[~a ~]~a"
669 (music->lily-string (ly:music-property times 'element))))))
672 (define-display-method RelativeOctaveMusic (m)
673 (music->lily-string (ly:music-property m 'element)))
675 (define-display-method TransposedMusic (m)
676 (music->lily-string (ly:music-property m 'element)))
682 (define-display-method AlternativeEvent (alternative) "")
684 (define (repeat->lily-string expr repeat-type)
685 (let* ((main (music->lily-string (ly:music-property expr 'element))))
686 (format #f "\\repeat ~a ~a ~a ~a"
688 (ly:music-property expr 'repeat-count)
690 (let ((alternatives (ly:music-property expr 'elements)))
691 (if (null? alternatives)
693 (format #f "\\alternative { ~{~a ~}}"
694 (map-in-order (lambda (music)
695 (music->lily-string music))
698 (define-display-method VoltaRepeatedMusic (expr)
699 (repeat->lily-string expr "volta"))
701 (define-display-method UnfoldedRepeatedMusic (expr)
702 (repeat->lily-string expr "unfold"))
704 (define-display-method PercentRepeatedMusic (expr)
705 (repeat->lily-string expr "percent"))
707 (define-display-method TremoloRepeatedMusic (expr)
708 (repeat->lily-string expr "tremolo"))
714 (define-display-method ContextSpeccedMusic (expr)
715 (let ((id (ly:music-property expr 'context-id))
716 (create-new (ly:music-property expr 'create-new))
717 (music (ly:music-property expr 'element))
718 (operations (ly:music-property expr 'property-operations))
719 (ctype (ly:music-property expr 'context-type)))
720 (format #f "~a ~a~a~a ~a"
721 (if (and (not (null? create-new)) create-new)
727 (format #f " = ~s" id))
728 (if (null? operations)
730 (format #f " \\with {~{~a~}~%~v_}"
731 (parameterize ((*indent* (+ (*indent*) 2)))
733 (format #f "~%~v_\\~a ~s"
739 (parameterize ((*current-context* ctype))
740 (music->lily-string music)))))
742 ;; special cases: \figures \lyrics \drums
743 (define-extra-display-method ContextSpeccedMusic (expr)
744 (with-music-match (expr (music 'ContextSpeccedMusic
746 property-operations ?op
747 context-type ?context-type
750 (parameterize ((*explicit-mode* #f))
753 (format #f "\\figures ~a" (music->lily-string ?sequence)))
755 (format #f "\\lyrics ~a" (music->lily-string ?sequence)))
757 (format #f "\\drums ~a" (music->lily-string ?sequence)))
762 ;;; Context properties
764 (define-extra-display-method ContextSpeccedMusic (expr)
765 (let ((element (ly:music-property expr 'element))
766 (property-tuning? (make-music-type-predicate 'PropertySet
770 (sequence? (make-music-type-predicate 'SequentialMusic)))
771 (if (and (ly:music? element)
772 (or (property-tuning? element)
773 (and (sequence? element)
774 (every property-tuning? (ly:music-property element 'elements)))))
775 (parameterize ((*current-context* (ly:music-property expr 'context-type)))
776 (music->lily-string element))
779 (define-public (value->lily-string arg)
780 (cond ((ly:music? arg)
781 (music->lily-string arg))
783 (format #f "#~s" arg))
785 (markup->lily-string arg))
787 (format #f "##{ ~a #}" (duration->lily-string arg #:force-duration #t)))
790 (note-name->lily-string arg)
791 (octave->lily-string arg)))
793 (format #f "#~a" (scheme-expr->lily-string arg)))))
795 (define-display-method PropertySet (expr)
796 (let ((property (ly:music-property expr 'symbol))
797 (value (ly:music-property expr 'value))
798 (once (ly:music-property expr 'once)))
799 (format #f "~a\\set ~a~a = ~a~a"
800 (if (and (not (null? once)))
803 (if (eqv? (*current-context*) 'Bottom)
805 (format #f "~a . " (*current-context*)))
807 (value->lily-string value)
808 (new-line->lily-string))))
810 (define-display-method PropertyUnset (expr)
811 (format #f "~a\\unset ~a~a~a"
812 (if (ly:music-property expr 'once #f) "\\once " "")
813 (if (eqv? (*current-context*) 'Bottom)
815 (format #f "~a . " (*current-context*)))
816 (ly:music-property expr 'symbol)
817 (new-line->lily-string)))
819 ;;; Layout properties
821 (define-display-method OverrideProperty (expr)
822 (let* ((symbol (ly:music-property expr 'symbol))
823 (properties (ly:music-property expr 'grob-property-path
824 (list (ly:music-property expr 'grob-property))))
825 (value (ly:music-property expr 'grob-value))
826 (once (ly:music-property expr 'once)))
828 (format #f "~a\\override ~{~a~^.~} = ~a~a"
833 (if (eqv? (*current-context*) 'Bottom)
834 (cons symbol properties)
835 (cons* (*current-context*) symbol properties))
836 (value->lily-string value)
837 (new-line->lily-string))))
839 (define-display-method RevertProperty (expr)
840 (let* ((symbol (ly:music-property expr 'symbol))
841 (properties (ly:music-property expr 'grob-property-path
842 (list (ly:music-property expr
844 (once (ly:music-property expr 'once #f)))
845 (format #f "~a\\revert ~{~a~^.~}~a"
846 (if once "\\once " "")
847 (if (eqv? (*current-context*) 'Bottom)
848 (cons symbol properties)
849 (cons* (*current-context*) symbol properties))
850 (new-line->lily-string))))
852 (define-display-method TimeSignatureMusic (expr)
853 (let* ((num (ly:music-property expr 'numerator))
854 (den (ly:music-property expr 'denominator))
855 (structure (ly:music-property expr 'beat-structure)))
856 (if (null? structure)
860 (new-line->lily-string))
862 "\\time #'~a ~a/~a~a"
864 (new-line->lily-string)))))
866 ;;; \melisma and \melismaEnd
867 (define-extra-display-method ContextSpeccedMusic (expr)
868 "If expr is a melisma, return \"\\melisma\", otherwise, return #f."
869 (with-music-match (expr (music 'ContextSpeccedMusic
870 element (music 'PropertySet
872 symbol 'melismaBusy)))
875 (define-extra-display-method ContextSpeccedMusic (expr)
876 "If expr is a melisma end, return \"\\melismaEnd\", otherwise, return #f."
877 (with-music-match (expr (music 'ContextSpeccedMusic
878 element (music 'PropertyUnset
879 symbol 'melismaBusy)))
883 (define-extra-display-method SequentialMusic (expr)
884 (with-music-match (expr (music 'SequentialMusic
885 elements ((music 'TempoChangeEvent
888 metronome-count ?count)
889 (music 'ContextSpeccedMusic
890 element (music 'PropertySet
891 symbol 'tempoWholesPerMinute)))))
892 (format #f "\\tempo ~{~a~a~}~a = ~a~a"
894 (list (markup->lily-string ?text) " ")
896 (duration->lily-string ?unit #:force-duration #t)
898 (format #f "~a - ~a" (car ?count) (cdr ?count))
900 (new-line->lily-string))))
902 (define-display-method TempoChangeEvent (expr)
903 (let ((text (ly:music-property expr 'text)))
904 (format #f "\\tempo ~a~a"
905 (markup->lily-string text)
906 (new-line->lily-string))))
909 (define clef-name-alist #f)
910 (define-public (memoize-clef-names clefs)
911 "Initialize @code{clef-name-alist}, if not already set."
912 (if (not clef-name-alist)
913 (set! clef-name-alist
914 (map (lambda (name+vals)
915 (cons (cdr name+vals)
919 (define-extra-display-method ContextSpeccedMusic (expr)
920 "If @var{expr} is a clef change, return \"\\clef ...\".
921 Otherwise, return @code{#f}."
922 (with-music-match (expr (music 'ContextSpeccedMusic
924 element (music 'SequentialMusic
925 elements ((music 'PropertySet
929 symbol 'middleCClefPosition)
932 symbol 'clefPosition)
934 value ?clef-transposition
935 symbol 'clefTransposition)
937 value ?clef-transposition-style
938 symbol 'clefTranspositionStyle)
940 procedure ly:set-middle-C!)))))
941 (let ((clef-name (assoc-get (list ?clef-glyph ?clef-position 0)
944 (format #f "\\clef \"~a~?\"~a"
946 (case ?clef-transposition-style
947 ((parenthesized) "~a(~a)")
948 ((bracketed) "~a[~a]")
950 (cond ((zero? ?clef-transposition)
952 ((positive? ?clef-transposition)
953 (list "^" (1+ ?clef-transposition)))
954 (else (list "_" (- 1 ?clef-transposition))))
955 (new-line->lily-string))))))
958 (define-extra-display-method ContextSpeccedMusic (expr)
959 "If `expr' is a bar, return \"\\bar ...\".
960 Otherwise, return #f."
961 (with-music-match (expr (music 'ContextSpeccedMusic
963 element (music 'PropertySet
966 (format #f "\\bar \"~a\"~a" ?bar-type (new-line->lily-string))))
969 (define-extra-display-method ContextSpeccedMusic (expr)
970 "If `expr' is a partial measure, return \"\\partial ...\".
971 Otherwise, return #f."
972 (with-music-match (expr (music
979 duration ?duration))))
982 (format #f "\\partial ~a"
983 (duration->lily-string ?duration #:force-duration #t)))))
988 (define-display-method ApplyOutputEvent (applyoutput)
989 (let ((proc (ly:music-property applyoutput 'procedure))
990 (ctx (ly:music-property applyoutput 'context-type))
991 (grob (ly:music-property applyoutput 'symbol)))
992 (format #f "\\applyOutput ~a~@[.~a~] #~a"
994 (and (symbol? grob) grob)
995 (or (procedure-name proc)
996 (with-output-to-string
998 (pretty-print (procedure-source proc))))))))
1000 (define-display-method ApplyContext (applycontext)
1001 (let ((proc (ly:music-property applycontext 'procedure)))
1002 (format #f "\\applyContext #~a"
1003 (or (procedure-name proc)
1004 (with-output-to-string
1006 (pretty-print (procedure-source proc))))))))
1009 (define-display-method PartCombineMusic (expr)
1010 (let ((dir (ly:music-property expr 'direction)))
1011 (format #f "\\partcombine~a ~a~a~a"
1012 (cond ((equal? dir UP) "Up")
1013 ((equal? dir DOWN) "Down")
1015 (music->lily-string (car (ly:music-property expr 'elements)))
1016 (new-line->lily-string)
1017 (music->lily-string (cadr (ly:music-property expr 'elements))))))
1019 (define-display-method PartCombinePartMusic (expr)
1020 (with-music-match ((ly:music-property expr 'element)
1021 (music 'ContextSpeccedMusic element ?part))
1022 (format #f "~a" (music->lily-string ?part))))
1024 (define-extra-display-method ContextSpeccedMusic (expr)
1025 "If `expr' is a \\partcombine expression, return \"\\partcombine ...\".
1026 Otherwise, return #f."
1028 (expr (music 'ContextSpeccedMusic
1030 element (music 'SimultaneousMusic
1031 elements ((music 'ContextSpeccedMusic
1033 context-type 'Voice)
1034 (music 'ContextSpeccedMusic
1036 context-type 'Voice)
1037 (music 'ContextSpeccedMusic
1039 context-type 'Voice)
1040 (music 'ContextSpeccedMusic
1042 context-type 'Voice)
1043 (music 'ContextSpeccedMusic
1045 context-type 'NullVoice)
1048 (?pc-music (music 'PartCombineMusic))
1049 (format #f "~a" (music->lily-string ?pc-music)))))
1051 (define-display-method UnrelativableMusic (expr)
1052 (music->lily-string (ly:music-property expr 'element)))
1055 (define-display-method QuoteMusic (expr)
1056 (or (with-music-match (expr (music
1058 quoted-voice-direction ?quoted-voice-direction
1059 quoted-music-name ?quoted-music-name
1060 quoted-context-id "cue"
1061 quoted-context-type 'CueVoice
1063 (format #f "\\cueDuring #~s #~a ~a"
1065 ?quoted-voice-direction
1066 (music->lily-string ?music)))
1067 (format #f "\\quoteDuring #~s ~a"
1068 (ly:music-property expr 'quoted-music-name)
1069 (music->lily-string (ly:music-property expr 'element)))))
1074 (define-display-method LineBreakEvent (expr)
1075 (if (null? (ly:music-property expr 'break-permission))
1079 (define-display-method PageBreakEvent (expr)
1080 (if (null? (ly:music-property expr 'break-permission))
1084 (define-display-method PageTurnEvent (expr)
1085 (if (null? (ly:music-property expr 'break-permission))
1089 (define-extra-display-method EventChord (expr)
1090 (with-music-match (expr (music 'EventChord
1091 elements ((music 'LineBreakEvent
1092 break-permission 'force)
1093 (music 'PageBreakEvent
1094 break-permission 'force))))
1097 (define-extra-display-method EventChord (expr)
1098 (with-music-match (expr (music 'EventChord
1099 elements ((music 'LineBreakEvent
1100 break-permission 'force)
1101 (music 'PageBreakEvent
1102 break-permission 'force)
1103 (music 'PageTurnEvent
1104 break-permission 'force))))
1112 (define-display-method LyricCombineMusic (expr)
1113 (format #f "\\lyricsto ~s ~a"
1114 (ly:music-property expr 'associated-context)
1115 (parameterize ((*explicit-mode* #f)
1116 (*omit-duration* #t))
1117 (music->lily-string (ly:music-property expr 'element)))))
1120 (define-extra-display-method SimultaneousMusic (expr)
1121 (with-music-match (expr (music 'SimultaneousMusic
1122 elements ((music 'ContextSpeccedMusic
1126 (music 'ContextSpeccedMusic
1128 context-type 'Staff)
1129 (music 'ContextSpeccedMusic
1131 context-type 'Staff))))
1132 (with-music-match (?ac-music (music 'AutoChangeMusic))
1134 (music->lily-string ?ac-music)))))
1137 (define-extra-display-method SimultaneousMusic (expr)
1138 (with-music-match (expr (music 'SimultaneousMusic
1139 elements ((music 'ContextSpeccedMusic
1142 element ?note-sequence)
1143 (music 'ContextSpeccedMusic
1144 context-type 'Lyrics
1146 element (music 'LyricCombineMusic
1147 associated-context ?associated-id
1148 element ?lyric-sequence)))))
1149 (if (string=? ?id ?associated-id)
1150 (format #f "~a~a \\addlyrics ~a"
1151 (music->lily-string ?note-sequence)
1152 (new-line->lily-string)
1153 (parameterize ((*explicit-mode* #f)
1154 (*omit-duration* #t))
1155 (music->lily-string ?lyric-sequence)))
1158 ;; Silence internal event sent at end of each lyrics block
1159 (define-display-method CompletizeExtenderEvent (expr)