]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/define-music-display-methods.scm
Doc-de: updating includes, learning, notation
[lilypond.git] / scm / define-music-display-methods.scm
index 0d7e3c451b80d64913cbdcf57333145a1cd2b36c..ef2b5bd580576a8025487f615052342d9961fcc8 100644 (file)
@@ -16,7 +16,8 @@
 ;;;
 (define (scheme-expr->lily-string scm-arg)
   (cond ((or (number? scm-arg)
-            (string? scm-arg))
+             (string? scm-arg)
+             (boolean? scm-arg))
         (format #f "~s" scm-arg))
        ((or (symbol? scm-arg)
             (list? scm-arg))
@@ -37,7 +38,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)
     'SlurEvent
     'SostenutoEvent
     'StringNumberEvent
+    'StrokeFingerEvent
     'SustainEvent
     'TextScriptEvent
     'TextSpanEvent
 (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
+  (format #f "\\rightHandFinger #~a" (ly:music-property event 'digit)))
+
 (define-span-event-display-method BeamEvent (event parser) #f "[" "]")
 (define-span-event-display-method SlurEvent (event parser) #f "(" ")")
 (define-span-event-display-method CrescendoEvent (event parser) #f "\\<" "\\!")
                                                         (music
                                                          'SlurEvent
                                                          span-direction START))))))
-                          #t)
+          #t)
          (with-music-match (?stop (music
                                    'SequentialMusic
                                    elements ((music
                                                        'OverrideProperty
                                                        grob-property-path '(stroke-style)
                                                        grob-value "grace"
-                                                       symbol 'Stem)))))
-                          #t)
+                                                       symbol 'Flag)))))
+          #t)
         (with-music-match (?stop (music
                                   'SequentialMusic
                                   elements ((music
                                              element (music
                                                       'RevertProperty
                                                       grob-property-path '(stroke-style)
-                                                      symbol 'Stem))
+                                                      symbol 'Flag))
                                             (music
                                              'EventChord
                                              elements ((music
        (chord? (make-music-type-predicate 'EventChord))
        (cluster? (make-music-type-predicate 'ClusterNoteEvent))
        (note? (make-music-type-predicate 'NoteEvent)))
-    (format #f "~a~a{~v%~v_~{~a ~}~v%~v_}"
+    (format #f "~a~a{~v%~v_~{~a~^ ~}~v%~v_}"
            (if (any (lambda (e)
                       (and (chord? e)
                            (any cluster? (ly:music-property e 'elements))))
                                          (music->lily-string music parser))
                                        elements))
            (if force-line-break 1 0)
-           (if force-line-break (*indent*) 0))))
+           (if force-line-break (*indent*) 1))))
 
 (define-display-method SimultaneousMusic (sim parser)
   (parameterize ((*indent* (+ 3 (*indent*))))
@@ -456,16 +462,18 @@ 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)
-                               (ly:music-property (car simple-elements) 'articulations))))
+                ;; 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)))
+                ;; 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 (ly:music-property simple-element 'duration))
-                  (lily-string (format #f "~a~a~a~{~a ~}"
+                  (lily-string (format #f "~a~a~a~{~a~^ ~}"
                                        (music->lily-string simple-element parser)
                                        (duration->lily-string duration)
                                        (if (and ((make-music-type-predicate 'RestEvent) simple-element)
@@ -483,7 +491,7 @@ Otherwise, return #f."
                  (post-events (filter post-event? elements)))
              (if (not (null? chord-elements))
                  ;; note_chord_element : '<' (notepitch | drumpitch)* '>" duration post_events
-                 (let ((lily-string (format #f "< ~{~a ~}>~a~{~a ~}"
+                 (let ((lily-string (format #f "< ~{~a ~}>~a~{~a~^ ~}"
                                             (map-in-order (lambda (music)
                                                             (music->lily-string music parser))
                                                           chord-elements)
@@ -495,13 +503,13 @@ Otherwise, return #f."
                    (*previous-duration* (ly:music-property (car chord-elements) 'duration))
                    lily-string)
                  ;; command_element
-                 (format #f "~{~a ~}" (map-in-order (lambda (music)
+                 (format #f "~{~a~^ ~}" (map-in-order (lambda (music)
                                                       (music->lily-string music parser))
                                                     elements))))))))
 
 (define-display-method MultiMeasureRestMusic (mmrest parser)
   (let* ((dur (ly:music-property mmrest 'duration))
-        (ly (format #f "R~a~{~a ~}"
+        (ly (format #f "R~a~{~a~^ ~}"
                     (duration->lily-string dur)
                     (map-in-order (lambda (music)
                                     (music->lily-string music parser))
@@ -689,6 +697,8 @@ Otherwise, return #f."
 ;;; Repeats
 ;;;
 
+(define-display-method AlternativeEvent (alternative parser) "")
+
 (define (repeat->lily-string expr repeat-type parser)
   (format #f "\\repeat ~a ~a ~a ~a"
          repeat-type
@@ -848,10 +858,8 @@ Otherwise, return #f."
 
 (define-display-method OverrideProperty (expr parser)
   (let* ((symbol         (ly:music-property expr 'symbol))
-        (property-path   (ly:music-property expr 'grob-property-path))
-        (properties      (if (pair? property-path)
-                             property-path
-                             (list (ly:music-property expr 'grob-property))))
+        (properties   (ly:music-property expr 'grob-property-path
+                                             (list (ly:music-property expr 'grob-property))))
         (value   (ly:music-property expr 'grob-value))
         (once    (ly:music-property expr 'once)))
 
@@ -871,8 +879,9 @@ Otherwise, return #f."
            (new-line->lily-string))))
 
 (define-display-method RevertProperty (expr parser)
-  (let ((symbol (ly:music-property expr 'symbol))
-       (properties (ly:music-property expr 'grob-property-path)))
+  (let* ((symbol (ly:music-property expr 'symbol))
+         (properties (ly:music-property expr 'grob-property-path
+                                             (list (ly:music-property expr 'grob-property)))))
     (format #f "\\revert ~a~a #'~a~a"
            (if (eqv? (*current-context*) 'Bottom)
                ""
@@ -893,8 +902,8 @@ Otherwise, return #f."
                 num den
                 (new-line->lily-string))
         (format #f
-                "#(set-time-signature ~a ~a '~a)~a"
-                num den structure
+                "\\time #'~a ~a/~a~a" 
+                structure num den
                 (new-line->lily-string)))))
 
 ;;; \melisma and \melismaEnd
@@ -914,61 +923,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)
-                       (if (number-pair? ?unit-count)
-                           (format #f "~a ~~ ~a"
-                                   (car ?unit-count)
-                                   (cdr ?unit-count))
-                           ?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)
-                               (if (number-pair? ?unit-count)
-                                   (format #f "~a ~~ ~a"
-                                           (car ?unit-count)
-                                           (cdr ?unit-count))
-                                   ?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)
@@ -977,8 +960,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
@@ -996,7 +979,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
@@ -1018,10 +1001,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."
@@ -1034,9 +1016,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)))))
 
 ;;;
 ;;;