]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/define-music-display-methods.scm
Fix #1540: correct display method for single note chords.
[lilypond.git] / scm / define-music-display-methods.scm
index 3b896a245017f6aa463fcb8d412b0dcd495aa617..2440e15bea791191bd9104a06cb589e9852395ad 100644 (file)
@@ -1,7 +1,7 @@
 ;;; define-music-display-methods.scm -- data for displaying music
 ;;; expressions using LilyPond notation.
 ;;;
-;;; Copyright (C) 2005--2010 Nicolas Sceaux  <nicolas.sceaux@free.fr>
+;;; Copyright (C) 2005--2011 Nicolas Sceaux  <nicolas.sceaux@free.fr>
 ;;;
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -37,7 +37,8 @@
 ;;;
 
 (define-public (markup->lily-string markup-expr)
-  "Return a string describing, in LilyPond syntax, the given markup expression."
+  "Return a string describing, in LilyPond syntax, the given markup
+expression."
   (define (proc->command proc)
     (let ((cmd-markup (symbol->string (procedure-name proc))))
       (substring cmd-markup 0 (- (string-length cmd-markup)
                                                         (music
                                                          'SlurEvent
                                                          span-direction START))))))
-                          #t)
+          #t)
          (with-music-match (?stop (music
                                    'SequentialMusic
                                    elements ((music
                                                        grob-property-path '(stroke-style)
                                                        grob-value "grace"
                                                        symbol 'Stem)))))
-                          #t)
+          #t)
         (with-music-match (?stop (music
                                   'SequentialMusic
                                   elements ((music
@@ -456,11 +457,11 @@ Otherwise, return #f."
        (music->lily-string (car elements) parser)
        (if (and (not (null? simple-elements))
                 (null? (cdr simple-elements))
-                ;; special case: if this simple_element has a HarmonicEvent in its
-                ;; 'articulations list, it should be interpreted instead as a
-                ;; note_chord_element, since \harmonic only works inside chords,
-                ;; even for single notes, e.g., < c\harmonic >
-                (null? (filter (make-music-type-predicate 'HarmonicEvent)
+                ;; special case: if this simple_element has any post_events in
+                ;; its 'articulations list, it should be interpreted instead
+                ;; as a note_chord_element to prevent spurious output, e.g.,
+                ;; \displayLilyMusic < c-1\4 >8 -> c-1\48
+                (null? (filter post-event?
                                (ly:music-property (car simple-elements) 'articulations))))
            ;; simple_element : note | figure | rest | mmrest | lyric_element | skip
            (let* ((simple-element (car simple-elements))
@@ -914,53 +915,35 @@ Otherwise, return #f."
     "\\melismaEnd"))
 
 ;;; \tempo
-;;; Check for all three different syntaxes of tempo:
-;;; \tempo string duration=note, \tempo duration=note and \tempo string
-(define-extra-display-method ContextSpeccedMusic (expr parser)
-  "If expr is a tempo, return \"\\tempo x = nnn\", otherwise return #f."
-  (or   (with-music-match (expr (music 'ContextSpeccedMusic
-               element (music 'SequentialMusic
-                             elements ((music 'PropertySet
-                                         value ?unit-text
-                                         symbol 'tempoText)
-                                       (music 'PropertySet
-                                         symbol 'tempoWholesPerMinute)
-                                       (music 'PropertySet
-                                         value ?unit-duration
-                                         symbol 'tempoUnitDuration)
-                                       (music 'PropertySet
-                                         value ?unit-count
-                                         symbol 'tempoUnitCount)))))
-               (format #f "\\tempo ~a ~a = ~a"
-                       (scheme-expr->lily-string ?unit-text)
-                       (duration->lily-string ?unit-duration #:force-duration #t)
-                       ?unit-count))
-       (with-music-match (expr (music 'ContextSpeccedMusic
-                   element (music 'SequentialMusic
-                             elements ((music 'PropertyUnset
-                                         symbol 'tempoText)
-                                       (music 'PropertySet
-                                         symbol 'tempoWholesPerMinute)
-                                       (music 'PropertySet
-                                         value ?unit-duration
-                                         symbol 'tempoUnitDuration)
-                                       (music 'PropertySet
-                                         value ?unit-count
-                                         symbol 'tempoUnitCount)))))
-                       (format #f "\\tempo ~a = ~a"
-                               (duration->lily-string ?unit-duration #:force-duration #t)
-                               ?unit-count))
-       (with-music-match (expr (music 'ContextSpeccedMusic
-                           element (music 'SequentialMusic
-                                     elements ((music 'PropertySet
-                                                 value ?tempo-text
-                                                symbol 'tempoText)))))
-                       (format #f "\\tempo ~a" (scheme-expr->lily-string ?tempo-text)))))
+(define-extra-display-method SequentialMusic (expr parser)
+  (with-music-match (expr (music 'SequentialMusic
+                                elements ((music 'TempoChangeEvent
+                                                 text ?text
+                                                 tempo-unit ?unit
+                                                 metronome-count ?count)
+                                          (music 'ContextSpeccedMusic
+                                                 element (music 'PropertySet
+                                                                symbol 'tempoWholesPerMinute)))))
+    (format #f "\\tempo ~{~a~a~}~a = ~a~a"
+           (if (markup? ?text)
+               (list (markup->lily-string ?text) " ")
+               '())
+           (duration->lily-string ?unit #:force-duration #t)
+           (if (pair? ?count)
+               (format #f "~a ~~ ~a" (car ?count) (cdr ?count))
+               ?count)
+           (new-line->lily-string))))
+
+(define-display-method TempoChangeEvent (expr parser)
+  (let ((text (ly:music-property expr 'text)))
+    (format #f "\\tempo ~a~a"
+           (markup->lily-string text)
+           (new-line->lily-string))))
 
 ;;; \clef
 (define clef-name-alist #f)
 (define-public (memoize-clef-names clefs)
-  "Initialize `clef-name-alist', if not already set."
+  "Initialize @code{clef-name-alist}, if not already set."
   (if (not clef-name-alist)
       (set! clef-name-alist
             (map (lambda (name+vals)
@@ -969,8 +952,8 @@ Otherwise, return #f."
                  clefs))))
 
 (define-extra-display-method ContextSpeccedMusic (expr parser)
-  "If `expr' is a clef change, return \"\\clef ...\"
-Otherwise, return #f."
+  "If @var{expr} is a clef change, return \"\\clef ...\".
+Otherwise, return @code{#f}."
   (with-music-match (expr (music 'ContextSpeccedMusic
                                 context-type 'Staff
                                 element (music 'SequentialMusic
@@ -988,7 +971,7 @@ Otherwise, return #f."
                                                          (music 'ApplyContext
                                                                 procedure ly:set-middle-C!)))))
     (let ((clef-name (assoc-get (list ?clef-glyph ?clef-position 0)
-                                clef-name-alist)))
+                               clef-name-alist)))
       (if clef-name
          (format #f "\\clef \"~a~{~a~a~}\"~a"
                  clef-name
@@ -1010,10 +993,9 @@ Otherwise, return #f."
                                 element (music 'PropertySet
                                                value ?bar-type
                                                symbol 'whichBar)))
-     (format #f "\\bar \"~a\"~a" ?bar-type (new-line->lily-string))))
+    (format #f "\\bar \"~a\"~a" ?bar-type (new-line->lily-string))))
 
 ;;; \partial
-
 (define-extra-display-method ContextSpeccedMusic (expr parser)
   "If `expr' is a partial measure, return \"\\partial ...\".
 Otherwise, return #f."
@@ -1026,9 +1008,9 @@ Otherwise, return #f."
                                             'PartialSet
                                             partial-duration ?duration))))
 
-                   (and ?duration
-                        (format #f "\\partial ~a"
-                                (duration->lily-string ?duration #:force-duration #t)))))
+    (and ?duration
+        (format #f "\\partial ~a"
+                (duration->lily-string ?duration #:force-duration #t)))))
 
 ;;;
 ;;;