]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/define-music-display-methods.scm
Issue 2525: Fix a number of display-lily shortcomings
[lilypond.git] / scm / define-music-display-methods.scm
index 3e87b4a8a8bab722ac34ac4846fccbaacd3c27ed..6d0449edfc5c5ebd0ef9443bdc17ab086d2c8e5c 100644 (file)
@@ -181,17 +181,22 @@ expression."
                         ""
                         tremolo-type))))
 
-(define-post-event-display-method ArticulationEvent (event parser) #t
-  (let ((articulation  (ly:music-property event 'articulation-type)))
-    (case (string->symbol articulation)
-      ((marcato) "^")
-      ((stopped) "+")
-      ((tenuto)         "-")
-      ((staccatissimo) "|")
-      ((accent) ">")
-      ((staccato) ".")
-      ((portato) "_")
-      (else (format #f "\\~a" articulation)))))
+(define-display-method ArticulationEvent (event parser) #t
+  (let* ((articulation  (ly:music-property event 'articulation-type))
+        (shorthand
+         (case (string->symbol articulation)
+           ((marcato) "^")
+           ((stopped) "+")
+           ((tenuto)    "-")
+           ((staccatissimo) "|")
+           ((accent) ">")
+           ((staccato) ".")
+           ((portato) "_")
+           (else #f))))
+    (format #f "~a~:[\\~;~]~a"
+           (event-direction->lily-string event shorthand)
+           shorthand
+           (or shorthand articulation))))
 
 (define-post-event-display-method FingeringEvent (event parser) #t
   (ly:music-property event 'digit))
@@ -202,16 +207,16 @@ expression."
 (define-post-event-display-method MultiMeasureTextEvent (event parser) #t
   (markup->lily-string (ly:music-property event 'text)))
 
-(define-post-event-display-method BendAfterEvent (event parser) #t
+(define-post-event-display-method BendAfterEvent (event parser) #f
   (format #f "\\bendAfter #~a" (ly:music-property event 'delta-step)))
 
 (define-post-event-display-method HarmonicEvent (event parser) #f "\\harmonic")
-(define-post-event-display-method GlissandoEvent (event parser) #t "\\glissando")
-(define-post-event-display-method ArpeggioEvent (event parser) #t "\\arpeggio")
+(define-post-event-display-method GlissandoEvent (event parser) #f "\\glissando")
+(define-post-event-display-method ArpeggioEvent (event parser) #f "\\arpeggio")
 (define-post-event-display-method AbsoluteDynamicEvent (event parser) #f
   (format #f "\\~a" (ly:music-property event 'text)))
 
-(define-post-event-display-method StrokeFingerEvent (event parser) #t
+(define-post-event-display-method StrokeFingerEvent (event parser) #f
   (format #f "\\rightHandFinger #~a" (ly:music-property event 'digit)))
 
 (define-span-event-display-method BeamEvent (event parser) #f "[" "]")
@@ -426,38 +431,54 @@ Otherwise, return #f."
   ;; post_events : ( post_event | tagged_post_event )*
   ;; tagged_post_event: '-' \tag embedded_scm post_event
 
-  (let* ((elements (ly:music-property chord 'elements))
-        (chord-elements (filter (lambda (m)
-                                   (music-is-of-type? m 'rhythmic-event))
-                                elements))
-        (post-events (filter post-event? elements))
+  (let* ((elements (append (ly:music-property chord 'elements)
+                          (ly:music-property chord 'articulations)))
         (chord-repeat (ly:music-property chord 'duration)))
-    (cond ((ly:duration? chord-repeat)
-          (let ((duration (duration->lily-string chord-repeat #:remember #t)))
-            (format #f "q~a~{~a~^ ~}"
-                    duration
-                    (map-in-order (lambda (music)
-                                    (music->lily-string music parser))
-                                  post-events))))
-         ((pair? chord-elements)
-          ;; note_chord_element : '<' (notepitch | drumpitch)* '>" duration post_events
-          (let ((duration (duration->lily-string (ly:music-property
-                                                  (car chord-elements)
-                                                  'duration) #:remember #t)))
-            ;; Format duration first so that it does not appear on chord elements
-            (format #f "< ~{~a ~}>~a~{~a~^ ~}"
-                    (map-in-order (lambda (music)
-                                    (music->lily-string music parser))
-                                  chord-elements)
-                    duration
-                    (map-in-order (lambda (music)
-                                    (music->lily-string music parser))
-                                  post-events))))
-         (else
-          ;; command_element
-          (format #f "~{~a~^ ~}" (map-in-order (lambda (music)
-                                                 (music->lily-string music parser))
-                                               elements))))))
+    (call-with-values
+       (lambda ()
+         (partition (lambda (m) (music-is-of-type? m 'rhythmic-event))
+                    elements))
+      (lambda (chord-elements other-elements)
+       (cond ((pair? chord-elements)
+              ;; note_chord_element :
+              ;; '<' (notepitch | drumpitch)* '>" duration post_events
+              (let ((duration (duration->lily-string (ly:music-property
+                                                      (car chord-elements)
+                                                      'duration)
+                                                     #:remember #t)))
+                ;; Format duration first so that it does not appear on
+                ;; chord elements
+                (format #f "< ~{~a ~}>~a~:{~:[-~;~]~a~^ ~}"
+                        (map-in-order (lambda (music)
+                                        (music->lily-string music parser))
+                                      chord-elements)
+                        duration
+                        (map-in-order (lambda (music)
+                                        (list
+                                         (post-event? music)
+                                         (music->lily-string music parser)))
+                                      other-elements))))
+             ((ly:duration? chord-repeat)
+              (let ((duration (duration->lily-string chord-repeat
+                                                     #:remember #t)))
+                (format #f "q~a~:{~:[-~;~]~a~^ ~}"
+                        duration
+                        (map-in-order (lambda (music)
+                                        (list
+                                         (post-event? music)
+                                         (music->lily-string music parser)))
+                                      other-elements))))
+
+             ((and (= 1 (length other-elements))
+                   (not (post-event? (car other-elements))))
+              (format #f (music->lily-string (car other-elements) parser)))
+             (else
+              (format #f "< >~:{~:[-~;~]~a~^ ~}"
+                      (map-in-order (lambda (music)
+                                      (list
+                                       (post-event? music)
+                                       (music->lily-string music parser)))
+                                    other-elements))))))))
 
 (define-display-method MultiMeasureRestMusic (mmrest parser)
   (format #f "R~a~{~a~^ ~}"
@@ -478,7 +499,7 @@ Otherwise, return #f."
 ;;;
 
 (define (simple-note->lily-string event parser)
-  (format #f "~a~a~a~a~a~a~{~a~}" ; pitchname octave !? octave-check duration optional_rest articulations
+  (format #f "~a~a~a~a~a~a~:{~:[-~;~]~a~}" ; pitchname octave !? octave-check duration optional_rest articulations
          (note-name->lily-string (ly:music-property event 'pitch) parser)
          (octave->lily-string (ly:music-property event 'pitch))
          (let ((forced (ly:music-property event 'force-accidental))
@@ -503,16 +524,21 @@ Otherwise, return #f."
          (if ((make-music-type-predicate 'RestEvent) event)
              "\\rest" "")
          (map-in-order (lambda (event)
-                         (music->lily-string event parser))
+                         (list
+                          (post-event? event)
+                          (music->lily-string event parser)))
                        (ly:music-property event 'articulations))))
 
 (define-display-method NoteEvent (note parser)
   (cond ((not (null? (ly:music-property note 'pitch))) ;; note
         (simple-note->lily-string note parser))
        ((not (null? (ly:music-property note 'drum-type))) ;; drum
-        (format #f "~a~a" (ly:music-property note 'drum-type)
+        (format #f "~a~a~{~a~}" (ly:music-property note 'drum-type)
                 (duration->lily-string (ly:music-property note 'duration)
-                                       #:remember #t)))
+                                       #:remember #t)
+                (map-in-order (lambda (event)
+                                (music->lily-string event parser))
+                              (ly:music-property note 'articulations))))
        (else ;; unknown?
         "")))
 
@@ -522,16 +548,24 @@ Otherwise, return #f."
 (define-display-method RestEvent (rest parser)
   (if (not (null? (ly:music-property rest 'pitch)))
       (simple-note->lily-string rest parser)
-      (string-append "r" (duration->lily-string (ly:music-property rest 'duration)
-                                               #:remember #t))))
+      (format #f "r~a~{~a~}"
+             (duration->lily-string (ly:music-property rest 'duration)
+                                    #:remember #t)
+             (map-in-order (lambda (event)
+                             (music->lily-string event parser))
+                           (ly:music-property rest 'articulations)))))
 
 (define-display-method MultiMeasureRestEvent (rest parser)
   (string-append "R" (duration->lily-string (ly:music-property rest 'duration)
                                            #:remember #t)))
 
 (define-display-method SkipEvent (rest parser)
-  (string-append "s" (duration->lily-string (ly:music-property rest 'duration)
-                                           #:remember #t)))
+  (format #f "s~a~{~a~}"
+         (duration->lily-string (ly:music-property rest 'duration)
+                                #:remember #t)
+         (map-in-order (lambda (event)
+                         (music->lily-string event parser))
+                       (ly:music-property rest 'articulations))))
 
 (define-display-method RepeatedChord (chord parser)
   (music->lily-string (ly:music-property chord 'element) parser))