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* ((pitches (ly:parser-lookup 'pitchnames))
93 (result (rassoc ly-pitch pitches pitch=)))
94 (and result (car result))))
96 (define-public (octave->lily-string pitch)
97 (let ((octave (ly:pitch-octave pitch)))
99 (make-string (1+ octave) #\'))
101 (make-string (1- (* -1 octave)) #\,))
107 (define*-public (duration->lily-string ly-duration #:key
109 (time-scale (*time-scale*)))
110 (let ((log2 (ly:duration-log ly-duration))
111 (dots (ly:duration-dot-count ly-duration))
112 (scale (ly:duration-scale ly-duration)))
113 (if (or force-duration (not (*omit-duration*)))
114 (string-append (case log2
118 (else (number->string (expt 2 log2))))
119 (make-string dots #\.)
120 (let ((end-scale (/ scale time-scale)))
121 (if (= end-scale 1) ""
122 (format #f "*~a" end-scale))))
129 (define post-event? (music-type-predicate 'post-event))
131 (define* (event-direction->lily-string event #:optional (required #t))
132 (let ((direction (ly:music-property event 'direction)))
133 (cond ((or (not direction) (null? direction) (= CENTER direction))
134 (if required "-" ""))
135 ((= UP direction) "^")
136 ((= DOWN direction) "_")
139 (define-macro (define-post-event-display-method type vars direction-required str)
140 `(define-display-method ,type ,vars
142 (event-direction->lily-string ,(car vars) ,direction-required)
145 (define-macro (define-span-event-display-method type vars direction-required str-start str-stop)
146 `(define-display-method ,type ,vars
148 (event-direction->lily-string ,(car vars) ,direction-required)
149 (if (= START (ly:music-property ,(car vars) 'span-direction))
153 (define-display-method HyphenEvent (event)
155 (define-display-method ExtenderEvent (event)
157 (define-display-method TieEvent (event)
159 (define-display-method BeamForbidEvent (event)
161 (define-display-method StringNumberEvent (event)
162 (format #f "\\~a" (ly:music-property event 'string-number)))
165 (define-display-method TremoloEvent (event)
166 (let ((tremolo-type (ly:music-property event 'tremolo-type 8)))
167 (format #f ":~a" tremolo-type)))
169 (define-display-method ArticulationEvent (event) #t
170 (let* ((articulation (ly:music-property event 'articulation-type))
172 (case (string->symbol articulation)
176 ((staccatissimo) "!")
181 (format #f "~a~:[\\~;~]~a"
182 (event-direction->lily-string event shorthand)
184 (or shorthand articulation))))
186 (define-post-event-display-method FingeringEvent (event) #t
187 (ly:music-property event 'digit))
189 (define-post-event-display-method TextScriptEvent (event) #t
190 (markup->lily-string (ly:music-property event 'text)))
192 (define-post-event-display-method MultiMeasureTextEvent (event) #t
193 (markup->lily-string (ly:music-property event 'text)))
195 (define-post-event-display-method BendAfterEvent (event) #f
196 (format #f "\\bendAfter #~a " (ly:music-property event 'delta-step)))
198 (define-post-event-display-method HarmonicEvent (event) #f "\\harmonic")
199 (define-post-event-display-method GlissandoEvent (event) #f "\\glissando")
200 (define-post-event-display-method ArpeggioEvent (event) #f "\\arpeggio")
201 (define-post-event-display-method AbsoluteDynamicEvent (event) #f
202 (format #f "\\~a" (ly:music-property event 'text)))
204 (define-post-event-display-method StrokeFingerEvent (event) #f
205 (format #f "\\rightHandFinger #~a " (ly:music-property event 'digit)))
207 (define-span-event-display-method BeamEvent (event) #f "[" "]")
208 (define-span-event-display-method SlurEvent (event) #f "(" ")")
209 (define-span-event-display-method CrescendoEvent (event) #f "\\<" "\\!")
210 (define-span-event-display-method DecrescendoEvent (event) #f "\\>" "\\!")
211 (define-span-event-display-method EpisemaEvent (event) #f "\\episemInitium" "\\episemFinis")
212 (define-span-event-display-method PhrasingSlurEvent (event) #f "\\(" "\\)")
213 (define-span-event-display-method SustainEvent (event) #f "\\sustainOn" "\\sustainOff")
214 (define-span-event-display-method SostenutoEvent (event) #f "\\sostenutoOn" "\\sostenutoOff")
215 (define-span-event-display-method TextSpanEvent (event) #f "\\startTextSpan" "\\stopTextSpan")
216 (define-span-event-display-method TrillSpanEvent (event) #f "\\startTrillSpan" "\\stopTrillSpan")
217 (define-span-event-display-method StaffSpanEvent (event) #f "\\startStaff" "\\stopStaff")
218 (define-span-event-display-method NoteGroupingEvent (event) #f "\\startGroup" "\\stopGroup")
219 (define-span-event-display-method UnaCordaEvent (event) #f "\\unaCorda" "\\treCorde")
225 (define-display-method GraceMusic (expr)
226 (format #f "\\grace ~a"
227 (music->lily-string (ly:music-property expr 'element))))
229 ;; \acciaccatura \appoggiatura \grace
230 ;; TODO: it would be better to compare ?start and ?stop
231 ;; with startAppoggiaturaMusic and stopAppoggiaturaMusic,
232 ;; using a custom music equality predicate.
233 (define-extra-display-method GraceMusic (expr)
234 "Display method for appoggiatura."
235 (with-music-match (expr (music
242 ;; we check whether ?start and ?stop look like
243 ;; startAppoggiaturaMusic stopAppoggiaturaMusic
244 (and (with-music-match (?start (music
251 span-direction START))))))
253 (with-music-match (?stop (music
260 span-direction STOP))))))
261 (format #f "\\appoggiatura ~a" (music->lily-string ?music))))))
264 (define-extra-display-method GraceMusic (expr)
265 "Display method for acciaccatura."
266 (with-music-match (expr (music
273 ;; we check whether ?start and ?stop look like
274 ;; startAcciaccaturaMusic stopAcciaccaturaMusic
275 (and (with-music-match (?start (music
282 span-direction START)))
287 grob-property-path '(stroke-style)
291 (with-music-match (?stop (music
297 grob-property-path '(stroke-style)
305 span-direction STOP))))))
306 (format #f "\\acciaccatura ~a" (music->lily-string ?music))))))
308 (define-extra-display-method GraceMusic (expr)
309 "Display method for grace."
310 (with-music-match (expr (music
317 ;; we check whether ?start and ?stop look like
318 ;; startGraceMusic stopGraceMusic
319 (and (null? (ly:music-property ?start 'elements))
320 (null? (ly:music-property ?stop 'elements))
321 (format #f "\\grace ~a" (music->lily-string ?music)))))
327 (define-display-method SequentialMusic (seq)
328 (let ((force-line-break (and (*force-line-break*)
330 (> (length (ly:music-property seq 'elements))
331 (*max-element-number-before-break*))))
332 (elements (ly:music-property seq 'elements))
333 (chord? (make-music-type-predicate 'EventChord))
334 (note-or-chord? (make-music-type-predicate 'EventChord 'NoteEvent
335 'LyricEvent 'RestEvent
337 (cluster? (make-music-type-predicate 'ClusterNoteEvent))
338 (note? (make-music-type-predicate 'NoteEvent)))
339 (format #f "~a~a{~v%~v_~{~a~^ ~}~v%~v_}"
343 (any cluster? (ly:music-property e 'elements)))))
347 (if (*explicit-mode*)
348 ;; if the sequence contains EventChord which contains figures ==> figuremode
349 ;; if the sequence contains EventChord which contains lyrics ==> lyricmode
350 ;; if the sequence contains EventChord which contains drum notes ==> drummode
351 (cond ((any (lambda (chord)
352 (any (make-music-type-predicate 'BassFigureEvent)
353 (ly:music-property chord 'elements)))
354 (filter chord? elements))
356 ((any (lambda (chord)
357 (any (make-music-type-predicate 'LyricEvent)
359 (ly:music-property chord 'elements))))
360 (filter note-or-chord? elements))
362 ((any (lambda (chord)
365 (not (null? (ly:music-property event 'drum-type)))))
367 (ly:music-property chord 'elements))))
368 (filter note-or-chord? elements))
370 (else ;; TODO: other modes?
373 (if force-line-break 1 0)
374 (if force-line-break (+ 2 (*indent*)) 1)
375 (parameterize ((*indent* (+ 2 (*indent*))))
376 (map-in-order (lambda (music)
377 (music->lily-string music))
379 (if force-line-break 1 0)
380 (if force-line-break (*indent*) 1))))
382 (define-display-method SimultaneousMusic (sim)
383 (parameterize ((*indent* (+ 3 (*indent*))))
384 (format #f "<< ~{~a ~}>>"
385 (map-in-order (lambda (music)
386 (music->lily-string music))
387 (ly:music-property sim 'elements)))))
389 (define-extra-display-method SimultaneousMusic (expr)
390 "If `sim' is an \afterGrace expression, return \"\\afterGrace ...\".
391 Otherwise, return #f."
392 ;; TODO: do something with afterGraceFraction?
393 (with-music-match (expr (music 'SimultaneousMusic
394 elements (?before-grace
395 (music 'SequentialMusic
396 elements ((music 'SkipMusic)
399 (format #f "\\afterGrace ~a ~a"
400 (music->lily-string ?before-grace)
401 (music->lily-string ?grace))))
407 (define-display-method EventChord (chord)
408 ;; event_chord : command_element
409 ;; | note_chord_element
411 ;; TODO : tagged post_events
412 ;; post_events : ( post_event | tagged_post_event )*
413 ;; tagged_post_event: '-' \tag embedded_scm post_event
415 (let* ((elements (append (ly:music-property chord 'elements)
416 (ly:music-property chord 'articulations)))
417 (chord-repeat (ly:music-property chord 'duration)))
420 (partition (music-type-predicate 'rhythmic-event)
422 (lambda (chord-elements other-elements)
423 (cond ((pair? chord-elements)
424 ;; note_chord_element :
425 ;; '<' (notepitch | drumpitch)* '>" duration post_events
426 (let ((duration (duration->lily-string (ly:music-property
429 ;; Format duration first so that it does not appear on
431 (format #f "< ~{~a ~}>~a~:{~:[-~;~]~a~^ ~}"
432 (parameterize ((*omit-duration* #t))
435 (music->lily-string music))
438 (map-in-order (lambda (music)
441 (music->lily-string music)))
443 ((ly:duration? chord-repeat)
444 (let ((duration (duration->lily-string chord-repeat)))
445 (format #f "q~a~:{~:[-~;~]~a~^ ~}"
447 (map-in-order (lambda (music)
450 (music->lily-string music)))
453 ((and (= 1 (length other-elements))
454 (not (post-event? (car other-elements))))
455 (format #f (music->lily-string (car other-elements))))
457 (format #f "< >~:{~:[-~;~]~a~^ ~}"
458 (map-in-order (lambda (music)
461 (music->lily-string music)))
462 other-elements))))))))
464 (define-display-method MultiMeasureRestMusic (mmrest)
465 (format #f "R~a~{~a~^ ~}"
466 (duration->lily-string (ly:music-property mmrest 'duration))
467 (map-in-order (lambda (music)
468 (music->lily-string music))
469 (ly:music-property mmrest 'articulations))))
471 (define-display-method SkipMusic (skip)
472 (format #f "\\skip ~a" (duration->lily-string (ly:music-property skip 'duration) #:force-duration #t)))
474 (define-display-method OttavaMusic (ottava)
475 (format #f "\\ottava #~a" (ly:music-property ottava 'ottava-number)))
478 ;;; Notes, rests, skips...
481 (define (simple-note->lily-string event)
482 (format #f "~a~a~a~a~a~a~:{~:[-~;~]~a~}" ; pitchname octave !? octave-check duration optional_rest articulations
483 (note-name->lily-string (ly:music-property event 'pitch))
484 (octave->lily-string (ly:music-property event 'pitch))
485 (let ((forced (ly:music-property event 'force-accidental))
486 (cautionary (ly:music-property event 'cautionary)))
487 (cond ((and (not (null? forced))
489 (not (null? cautionary))
492 ((and (not (null? forced)) forced) "!")
494 (let ((octave-check (ly:music-property event 'absolute-octave)))
495 (if (not (null? octave-check))
496 (format #f "=~a" (cond ((>= octave-check 0)
497 (make-string (1+ octave-check) #\'))
499 (make-string (1- (* -1 octave-check)) #\,))
502 (duration->lily-string (ly:music-property event 'duration))
503 (if ((make-music-type-predicate 'RestEvent) event)
505 (map-in-order (lambda (event)
508 (music->lily-string event)))
509 (ly:music-property event 'articulations))))
511 (define-display-method NoteEvent (note)
512 (cond ((not (null? (ly:music-property note 'pitch))) ;; note
513 (simple-note->lily-string note))
514 ((not (null? (ly:music-property note 'drum-type))) ;; drum
515 (format #f "~a~a~{~a~}" (ly:music-property note 'drum-type)
516 (duration->lily-string (ly:music-property note 'duration))
517 (map-in-order (lambda (event)
518 (music->lily-string event))
519 (ly:music-property note 'articulations))))
522 (format #f "~a~{~a~}"
523 (duration->lily-string (ly:music-property note 'duration)
525 (map-in-order (lambda (event)
526 (music->lily-string event))
527 (ly:music-property note 'articulations))))))
529 (define-display-method ClusterNoteEvent (note)
530 (simple-note->lily-string note))
532 (define-display-method RestEvent (rest)
533 (if (not (null? (ly:music-property rest 'pitch)))
534 (simple-note->lily-string rest)
535 (format #f "r~a~{~a~}"
536 (duration->lily-string (ly:music-property rest 'duration))
537 (map-in-order (lambda (event)
538 (music->lily-string event))
539 (ly:music-property rest 'articulations)))))
541 (define-display-method MultiMeasureRestEvent (rest)
542 (string-append "R" (duration->lily-string (ly:music-property rest 'duration))))
544 (define-display-method SkipEvent (rest)
545 (format #f "s~a~{~a~}"
546 (duration->lily-string (ly:music-property rest 'duration))
547 (map-in-order (lambda (event)
548 (music->lily-string event))
549 (ly:music-property rest 'articulations))))
551 (define-display-method RepeatedChord (chord)
552 (music->lily-string (ly:music-property chord 'element)))
554 (define-display-method MarkEvent (mark)
555 (let ((label (ly:music-property mark 'label)))
558 (format #f "\\mark ~a" (markup->lily-string label)))))
560 (define-display-method KeyChangeEvent (key)
561 (let ((pitch-alist (ly:music-property key 'pitch-alist))
562 (tonic (ly:music-property key 'tonic)))
563 (if (or (null? pitch-alist)
566 (let ((c-pitch-alist (ly:transpose-key-alist pitch-alist
567 (ly:pitch-diff (ly:make-pitch 0 0 0) tonic))))
568 (format #f "\\key ~a \\~a~a"
569 (note-name->lily-string (ly:music-property key 'tonic))
571 (and (equal? (ly:parser-lookup mode) c-pitch-alist)
572 (symbol->string mode)))
573 '(major minor ionian locrian aeolian mixolydian lydian phrygian dorian))
574 (new-line->lily-string))))))
576 (define-display-method RelativeOctaveCheck (octave)
577 (let ((pitch (ly:music-property octave 'pitch)))
578 (format #f "\\octaveCheck ~a~a"
579 (note-name->lily-string pitch)
580 (octave->lily-string pitch))))
582 (define-display-method VoiceSeparator (sep)
585 (define-display-method LigatureEvent (ligature)
586 (if (= START (ly:music-property ligature 'span-direction))
590 (define-display-method BarCheck (check)
591 (format #f "|~a" (new-line->lily-string)))
593 (define-display-method PesOrFlexaEvent (expr)
596 (define-display-method BassFigureEvent (figure)
597 (let ((alteration (ly:music-property figure 'alteration))
598 (fig (ly:music-property figure 'figure))
599 (bracket-start (ly:music-property figure 'bracket-start))
600 (bracket-stop (ly:music-property figure 'bracket-stop)))
602 (format #f "~a~a~a~a"
603 (if (null? bracket-start) "" "[")
604 (cond ((null? fig) "_")
605 ((markup? fig) (second fig)) ;; fig: (<number-markup> "number")
607 (if (null? alteration)
610 ((= alteration DOUBLE-FLAT) "--")
611 ((= alteration FLAT) "-")
612 ((= alteration NATURAL) "!")
613 ((= alteration SHARP) "+")
614 ((= alteration DOUBLE-SHARP) "++")
616 (if (null? bracket-stop) "" "]"))))
618 (define-display-method LyricEvent (lyric)
619 (format #f "~a~{~a~^ ~}"
620 (let ((text (ly:music-property lyric 'text)))
621 (if (or (string? text)
622 (eqv? (first text) simple-markup))
623 ;; a string or a simple markup
624 (let ((string (if (string? text)
627 (if (string-match "(\"| |[0-9])" string)
628 ;; TODO check exactly in which cases double quotes should be used
629 (format #f "~s" string)
631 (markup->lily-string text)))
632 (map-in-order (lambda (m) (music->lily-string m))
633 (ly:music-property lyric 'articulations))))
635 (define-display-method BreathingEvent (event)
642 (define-display-method AutoChangeMusic (m)
643 (format #f "\\autochange ~a"
645 (ly:music-property (ly:music-property m 'element) 'element))))
647 (define-display-method ContextChange (m)
648 (format #f "\\change ~a = \"~a\""
649 (ly:music-property m 'change-to-type)
650 (ly:music-property m 'change-to-id)))
654 (define-display-method TimeScaledMusic (times)
655 (let* ((num (ly:music-property times 'numerator))
656 (den (ly:music-property times 'denominator))
657 (span (ly:music-property times 'duration #f))
658 ;; need to format before changing time scale
660 (and span (duration->lily-string span #:force-duration #t)))
662 (time-scale (*time-scale*)))
664 (parameterize ((*force-line-break* #f)
665 (*time-scale* (* time-scale scale)))
666 (format #f "\\tuplet ~a/~a ~@[~a ~]~a"
670 (music->lily-string (ly:music-property times 'element))))))
673 (define-display-method RelativeOctaveMusic (m)
674 (music->lily-string (ly:music-property m 'element)))
676 (define-display-method TransposedMusic (m)
677 (music->lily-string (ly:music-property m 'element)))
683 (define-display-method AlternativeEvent (alternative) "")
685 (define (repeat->lily-string expr repeat-type)
686 (let* ((main (music->lily-string (ly:music-property expr 'element))))
687 (format #f "\\repeat ~a ~a ~a ~a"
689 (ly:music-property expr 'repeat-count)
691 (let ((alternatives (ly:music-property expr 'elements)))
692 (if (null? alternatives)
694 (format #f "\\alternative { ~{~a ~}}"
695 (map-in-order (lambda (music)
696 (music->lily-string music))
699 (define-display-method VoltaRepeatedMusic (expr)
700 (repeat->lily-string expr "volta"))
702 (define-display-method UnfoldedRepeatedMusic (expr)
703 (repeat->lily-string expr "unfold"))
705 (define-display-method PercentRepeatedMusic (expr)
706 (repeat->lily-string expr "percent"))
708 (define-display-method TremoloRepeatedMusic (expr)
709 (repeat->lily-string expr "tremolo"))
715 (define-display-method ContextSpeccedMusic (expr)
716 (let ((id (ly:music-property expr 'context-id))
717 (create-new (ly:music-property expr 'create-new))
718 (music (ly:music-property expr 'element))
719 (operations (ly:music-property expr 'property-operations))
720 (ctype (ly:music-property expr 'context-type)))
721 (format #f "~a ~a~a~a ~a"
722 (if (and (not (null? create-new)) create-new)
728 (format #f " = ~s" id))
729 (if (null? operations)
731 (format #f " \\with {~{~a~}~%~v_}"
732 (parameterize ((*indent* (+ (*indent*) 2)))
734 (format #f "~%~v_\\~a ~s"
740 (parameterize ((*current-context* ctype))
741 (music->lily-string music)))))
743 ;; special cases: \figures \lyrics \drums
744 (define-extra-display-method ContextSpeccedMusic (expr)
745 (with-music-match (expr (music 'ContextSpeccedMusic
747 property-operations ?op
748 context-type ?context-type
751 (parameterize ((*explicit-mode* #f))
754 (format #f "\\figures ~a" (music->lily-string ?sequence)))
756 (format #f "\\lyrics ~a" (music->lily-string ?sequence)))
758 (format #f "\\drums ~a" (music->lily-string ?sequence)))
763 ;;; Context properties
765 (define-extra-display-method ContextSpeccedMusic (expr)
766 (let ((element (ly:music-property expr 'element))
767 (property-tuning? (make-music-type-predicate 'PropertySet
771 (sequence? (make-music-type-predicate 'SequentialMusic)))
772 (if (and (ly:music? element)
773 (or (property-tuning? element)
774 (and (sequence? element)
775 (every property-tuning? (ly:music-property element 'elements)))))
776 (parameterize ((*current-context* (ly:music-property expr 'context-type)))
777 (music->lily-string element))
780 (define-public (value->lily-string arg)
781 (cond ((ly:music? arg)
782 (music->lily-string arg))
784 (format #f "#~s" arg))
786 (markup->lily-string arg))
788 (format #f "##{ ~a #}" (duration->lily-string arg #:force-duration #t)))
791 (note-name->lily-string arg)
792 (octave->lily-string arg)))
794 (format #f "#~a" (scheme-expr->lily-string arg)))))
796 (define-display-method PropertySet (expr)
797 (let ((property (ly:music-property expr 'symbol))
798 (value (ly:music-property expr 'value))
799 (once (ly:music-property expr 'once)))
800 (format #f "~a\\set ~a~a = ~a~a"
801 (if (and (not (null? once)))
804 (if (eqv? (*current-context*) 'Bottom)
806 (format #f "~a . " (*current-context*)))
808 (value->lily-string value)
809 (new-line->lily-string))))
811 (define-display-method PropertyUnset (expr)
812 (format #f "\\unset ~a~a~a"
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 'grob-property)))))
843 (format #f "\\revert ~{~a~^.~}~a"
844 (if (eqv? (*current-context*) 'Bottom)
845 (cons symbol properties)
846 (cons* (*current-context*) symbol properties))
847 (new-line->lily-string))))
849 (define-display-method TimeSignatureMusic (expr)
850 (let* ((num (ly:music-property expr 'numerator))
851 (den (ly:music-property expr 'denominator))
852 (structure (ly:music-property expr 'beat-structure)))
853 (if (null? structure)
857 (new-line->lily-string))
859 "\\time #'~a ~a/~a~a"
861 (new-line->lily-string)))))
863 ;;; \melisma and \melismaEnd
864 (define-extra-display-method ContextSpeccedMusic (expr)
865 "If expr is a melisma, return \"\\melisma\", otherwise, return #f."
866 (with-music-match (expr (music 'ContextSpeccedMusic
867 element (music 'PropertySet
869 symbol 'melismaBusy)))
872 (define-extra-display-method ContextSpeccedMusic (expr)
873 "If expr is a melisma end, return \"\\melismaEnd\", otherwise, return #f."
874 (with-music-match (expr (music 'ContextSpeccedMusic
875 element (music 'PropertyUnset
876 symbol 'melismaBusy)))
880 (define-extra-display-method SequentialMusic (expr)
881 (with-music-match (expr (music 'SequentialMusic
882 elements ((music 'TempoChangeEvent
885 metronome-count ?count)
886 (music 'ContextSpeccedMusic
887 element (music 'PropertySet
888 symbol 'tempoWholesPerMinute)))))
889 (format #f "\\tempo ~{~a~a~}~a = ~a~a"
891 (list (markup->lily-string ?text) " ")
893 (duration->lily-string ?unit #:force-duration #t)
895 (format #f "~a - ~a" (car ?count) (cdr ?count))
897 (new-line->lily-string))))
899 (define-display-method TempoChangeEvent (expr)
900 (let ((text (ly:music-property expr 'text)))
901 (format #f "\\tempo ~a~a"
902 (markup->lily-string text)
903 (new-line->lily-string))))
906 (define clef-name-alist #f)
907 (define-public (memoize-clef-names clefs)
908 "Initialize @code{clef-name-alist}, if not already set."
909 (if (not clef-name-alist)
910 (set! clef-name-alist
911 (map (lambda (name+vals)
912 (cons (cdr name+vals)
916 (define-extra-display-method ContextSpeccedMusic (expr)
917 "If @var{expr} is a clef change, return \"\\clef ...\".
918 Otherwise, return @code{#f}."
919 (with-music-match (expr (music 'ContextSpeccedMusic
921 element (music 'SequentialMusic
922 elements ((music 'PropertySet
926 symbol 'middleCClefPosition)
929 symbol 'clefPosition)
931 value ?clef-transposition
932 symbol 'clefTransposition)
934 value ?clef-transposition-style
935 symbol 'clefTranspositionStyle)
937 procedure ly:set-middle-C!)))))
938 (let ((clef-name (assoc-get (list ?clef-glyph ?clef-position 0)
941 (format #f "\\clef \"~a~?\"~a"
943 (case ?clef-transposition-style
944 ((parenthesized) "~a(~a)")
945 ((bracketed) "~a[~a]")
947 (cond ((zero? ?clef-transposition)
949 ((positive? ?clef-transposition)
950 (list "^" (1+ ?clef-transposition)))
951 (else (list "_" (- 1 ?clef-transposition))))
952 (new-line->lily-string))))))
955 (define-extra-display-method ContextSpeccedMusic (expr)
956 "If `expr' is a bar, return \"\\bar ...\".
957 Otherwise, return #f."
958 (with-music-match (expr (music 'ContextSpeccedMusic
960 element (music 'PropertySet
963 (format #f "\\bar \"~a\"~a" ?bar-type (new-line->lily-string))))
966 (define-extra-display-method ContextSpeccedMusic (expr)
967 "If `expr' is a partial measure, return \"\\partial ...\".
968 Otherwise, return #f."
969 (with-music-match (expr (music
976 duration ?duration))))
979 (format #f "\\partial ~a"
980 (duration->lily-string ?duration #:force-duration #t)))))
985 (define-display-method ApplyOutputEvent (applyoutput)
986 (let ((proc (ly:music-property applyoutput 'procedure))
987 (ctx (ly:music-property applyoutput 'context-type))
988 (grob (ly:music-property applyoutput 'symbol)))
989 (format #f "\\applyOutput ~a~@[.~a~] #~a"
991 (and (symbol? grob) grob)
992 (or (procedure-name proc)
993 (with-output-to-string
995 (pretty-print (procedure-source proc))))))))
997 (define-display-method ApplyContext (applycontext)
998 (let ((proc (ly:music-property applycontext 'procedure)))
999 (format #f "\\applyContext #~a"
1000 (or (procedure-name proc)
1001 (with-output-to-string
1003 (pretty-print (procedure-source proc))))))))
1006 (define-display-method PartCombineMusic (expr)
1007 (let ((dir (ly:music-property expr 'direction)))
1008 (format #f "\\partcombine~a ~a~a~a"
1009 (cond ((equal? dir UP) "Up")
1010 ((equal? dir DOWN) "Down")
1012 (music->lily-string (car (ly:music-property expr 'elements)))
1013 (new-line->lily-string)
1014 (music->lily-string (cadr (ly:music-property expr 'elements))))))
1016 (define-display-method PartCombinePartMusic (expr)
1017 (with-music-match ((ly:music-property expr 'element)
1018 (music 'ContextSpeccedMusic element ?part))
1019 (format #f "~a" (music->lily-string ?part))))
1021 (define-extra-display-method ContextSpeccedMusic (expr)
1022 "If `expr' is a \\partcombine expression, return \"\\partcombine ...\".
1023 Otherwise, return #f."
1025 (expr (music 'ContextSpeccedMusic
1027 element (music 'SimultaneousMusic
1028 elements ((music 'ContextSpeccedMusic
1030 context-type 'Voice)
1031 (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 'NullVoice)
1045 (?pc-music (music 'PartCombineMusic))
1046 (format #f "~a" (music->lily-string ?pc-music)))))
1048 (define-display-method UnrelativableMusic (expr)
1049 (music->lily-string (ly:music-property expr 'element)))
1052 (define-display-method QuoteMusic (expr)
1053 (or (with-music-match (expr (music
1055 quoted-voice-direction ?quoted-voice-direction
1056 quoted-music-name ?quoted-music-name
1057 quoted-context-id "cue"
1058 quoted-context-type 'CueVoice
1060 (format #f "\\cueDuring #~s #~a ~a"
1062 ?quoted-voice-direction
1063 (music->lily-string ?music)))
1064 (format #f "\\quoteDuring #~s ~a"
1065 (ly:music-property expr 'quoted-music-name)
1066 (music->lily-string (ly:music-property expr 'element)))))
1071 (define-display-method LineBreakEvent (expr)
1072 (if (null? (ly:music-property expr 'break-permission))
1076 (define-display-method PageBreakEvent (expr)
1077 (if (null? (ly:music-property expr 'break-permission))
1081 (define-display-method PageTurnEvent (expr)
1082 (if (null? (ly:music-property expr 'break-permission))
1086 (define-extra-display-method EventChord (expr)
1087 (with-music-match (expr (music 'EventChord
1088 elements ((music 'LineBreakEvent
1089 break-permission 'force)
1090 (music 'PageBreakEvent
1091 break-permission 'force))))
1094 (define-extra-display-method EventChord (expr)
1095 (with-music-match (expr (music 'EventChord
1096 elements ((music 'LineBreakEvent
1097 break-permission 'force)
1098 (music 'PageBreakEvent
1099 break-permission 'force)
1100 (music 'PageTurnEvent
1101 break-permission 'force))))
1109 (define-display-method LyricCombineMusic (expr)
1110 (format #f "\\lyricsto ~s ~a"
1111 (ly:music-property expr 'associated-context)
1112 (parameterize ((*explicit-mode* #f)
1113 (*omit-duration* #t))
1114 (music->lily-string (ly:music-property expr 'element)))))
1117 (define-extra-display-method SimultaneousMusic (expr)
1118 (with-music-match (expr (music 'SimultaneousMusic
1119 elements ((music 'ContextSpeccedMusic
1123 (music 'ContextSpeccedMusic
1125 context-type 'Staff)
1126 (music 'ContextSpeccedMusic
1128 context-type 'Staff))))
1129 (with-music-match (?ac-music (music 'AutoChangeMusic))
1131 (music->lily-string ?ac-music)))))
1134 (define-extra-display-method SimultaneousMusic (expr)
1135 (with-music-match (expr (music 'SimultaneousMusic
1136 elements ((music 'ContextSpeccedMusic
1139 element ?note-sequence)
1140 (music 'ContextSpeccedMusic
1141 context-type 'Lyrics
1143 element (music 'LyricCombineMusic
1144 associated-context ?associated-id
1145 element ?lyric-sequence)))))
1146 (if (string=? ?id ?associated-id)
1147 (format #f "~a~a \\addlyrics ~a"
1148 (music->lily-string ?note-sequence)
1149 (new-line->lily-string)
1150 (parameterize ((*explicit-mode* #f)
1151 (*omit-duration* #t))
1152 (music->lily-string ?lyric-sequence)))
1155 ;; Silence internal event sent at end of each lyrics block
1156 (define-display-method CompletizeExtenderEvent (expr)