]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/define-music-display-methods.scm
Let display-music work more consistently with command events and empty chords
[lilypond.git] / scm / define-music-display-methods.scm
index ac9930e1381ae24b9b36ee57a21382e990f2df43..6089e2539255c85f509b608d6ec87b94e25517d3 100644 (file)
@@ -419,72 +419,69 @@ Otherwise, return #f."
 ;;;
 
 (define-display-method EventChord (chord parser)
-  ;; event_chord : simple_element post_events
-  ;;              | command_element
+  ;; event_chord : command_element
   ;;              | note_chord_element
 
   ;; TODO : tagged post_events
   ;; post_events : ( post_event | tagged_post_event )*
   ;; tagged_post_event: '-' \tag embedded_scm post_event
 
-  (let* ((elements (ly:music-property chord 'elements))
-        (simple-elements (filter (make-music-type-predicate
-                                  'NoteEvent 'ClusterNoteEvent 'RestEvent
-                                  'SkipEvent 'LyricEvent)
-                                 elements)))
-    (if ((make-music-type-predicate 'StaffSpanEvent 'BreathingEvent) (car elements))
-       ;; first, a special case: StaffSpanEvent (\startStaff, \stopStaff)
-       ;; and BreathingEvent (\breathe)
-       (music->lily-string (car elements) parser)
-       (if (and (not (null? simple-elements))
-                (null? (cdr simple-elements))
-                ;; a non-empty articulation list is only possible with
-                ;; chord entry.
-                (null? (ly:music-property (car simple-elements) 'articulations))
-                ;; same for simple_element with \tweak
-                (null? (ly:music-property (car simple-elements) 'tweaks)))
-           ;; simple_element : note | figure | rest | mmrest | lyric_element | skip
-           (let* ((simple-element (car simple-elements))
-                  (duration (duration->lily-string
-                             (ly:music-property simple-element 'duration)
-                             #:remember #t)))
-             (format #f "~a~a~{~a~^ ~}"
-                     (music->lily-string simple-element parser)
-                     duration
-                     (map-in-order (lambda (music)
-                                     (music->lily-string music parser))
-                                   (filter post-event? elements))))
-           (let ((chord-elements (filter (make-music-type-predicate
-                                          'NoteEvent 'ClusterNoteEvent 'BassFigureEvent)
-                                         elements))
-                 (post-events (filter post-event? elements)))
-             (if (not (null? 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 #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)))
-                 ;; command_element
-                 (format #f "~{~a~^ ~}" (map-in-order (lambda (music)
-                                                      (music->lily-string music parser))
-                                                    elements))))))))
+  (let* ((elements (append (ly:music-property chord 'elements)
+                          (ly:music-property chord 'articulations)))
+        (chord-repeat (ly:music-property chord 'duration)))
+    (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)
-  (let* ((dur (ly:music-property mmrest 'duration))
-        (ly (format #f "R~a~{~a~^ ~}"
-                    (duration->lily-string dur)
-                    (map-in-order (lambda (music)
-                                    (music->lily-string music parser))
-                                  (ly:music-property mmrest 'articulations)))))
-    (*previous-duration* dur)
-    ly))
+  (format #f "R~a~{~a~^ ~}"
+         (duration->lily-string (ly:music-property mmrest 'duration)
+                                #:remember #t)
+         (map-in-order (lambda (music)
+                         (music->lily-string music parser))
+                       (ly:music-property mmrest 'articulations))))
 
 (define-display-method SkipMusic (skip parser)
   (format #f "\\skip ~a" (duration->lily-string (ly:music-property skip 'duration) #:force-duration #t)))