]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/define-music-display-methods.scm
Don't let lyrics interfere with StaffGrouper.
[lilypond.git] / scm / define-music-display-methods.scm
index 9a3a4c10691cfb1bb14ac43910c2fdf562a42895..53bddaac9359616232bfa2943c4241bec3029b19 100644 (file)
@@ -1,7 +1,7 @@
 ;;; define-music-display-methods.scm -- data for displaying music
 ;;; expressions using LilyPond notation.
 ;;;
-;;; (c) 2005--2009 Nicolas Sceaux  <nicolas.sceaux@free.fr>
+;;; Copyright (C) 2005--2010 Nicolas Sceaux  <nicolas.sceaux@free.fr>
 ;;;
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -81,7 +81,7 @@
     (if (and (car alist) (test item (cdar alist)))
        (set! result (car alist)))))
 
-(define (note-name->lily-string ly-pitch parser)
+(define-public (note-name->lily-string ly-pitch parser)
   ;; here we define a custom pitch= function, since we do not want to
   ;; test whether octaves are also equal. (otherwise, we would be using equal?)
   (define (pitch= pitch1 pitch2)
@@ -92,7 +92,7 @@
        (car result)
        #f)))
 
-(define (octave->lily-string pitch)
+(define-public (octave->lily-string pitch)
   (let ((octave (ly:pitch-octave pitch)))
     (cond ((>= octave 0)
           (make-string (1+ octave) #\'))
 ;;;
 ;;; durations
 ;;;
-(define* (duration->lily-string ly-duration #:key (prev-duration (*previous-duration*))
+(define*-public (duration->lily-string ly-duration #:key (prev-duration (*previous-duration*))
                        (force-duration (*force-duration*))
                        (time-factor-numerator (*time-factor-numerator*))
                        (time-factor-denominator (*time-factor-denominator*)))
 ;;; post events
 ;;;
 
-(define post-event? (make-music-type-predicate
-                    'StringNumberEvent
-                    'ArticulationEvent
-                    'FingeringEvent
-                    'TextScriptEvent
-                    'MultiMeasureTextEvent
-                    'HyphenEvent
-                    'ExtenderEvent
-                    'BeamEvent
-                    'SlurEvent
-                    'TieEvent
-                    'CrescendoEvent
-                    'DecrescendoEvent
-                    'PhrasingSlurEvent
-                    'TremoloEvent
-                    'SustainEvent
-                    'SostenutoEvent
-                    'TextSpanEvent
-                    'HarmonicEvent
-                    'BeamForbidEvent
-                    'AbsoluteDynamicEvent
-                    'TupletSpanEvent
-                    'TrillSpanEvent
-                    'GlissandoEvent
-                    'ArpeggioEvent
-                    'NoteGroupingEvent
-                    'UnaCordaEvent))
+(define post-event?
+  (make-music-type-predicate
+    'AbsoluteDynamicEvent
+    'ArpeggioEvent
+    'ArticulationEvent
+    'BeamEvent
+    'BeamForbidEvent
+    'BendAfterEvent
+    'CrescendoEvent
+    'DecrescendoEvent
+    'EpisemaEvent
+    'ExtenderEvent
+    'FingeringEvent
+    'GlissandoEvent
+    'HarmonicEvent
+    'HyphenEvent
+    'MultiMeasureTextEvent
+    'NoteGroupingEvent
+    'PhrasingSlurEvent
+    'SlurEvent
+    'SostenutoEvent
+    'StringNumberEvent
+    'SustainEvent
+    'TextScriptEvent
+    'TextSpanEvent
+    'TieEvent
+    'TremoloEvent
+    'TrillSpanEvent
+    'TupletSpanEvent
+    'UnaCordaEvent))
 
 (define* (event-direction->lily-string event #:optional (required #t))
   (let ((direction (ly:music-property event 'direction)))
 (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
+  (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-span-event-display-method SlurEvent (event parser) #f "(" ")")
 (define-span-event-display-method CrescendoEvent (event parser) #f "\\<" "\\!")
 (define-span-event-display-method DecrescendoEvent (event parser) #f "\\>" "\\!")
+(define-span-event-display-method EpisemaEvent (event parser) #f "\\episemInitium" "\\episemFinis")
 (define-span-event-display-method PhrasingSlurEvent (event parser) #f "\\(" "\\)")
 (define-span-event-display-method SustainEvent (event parser) #f "\\sustainOn" "\\sustainOff")
 (define-span-event-display-method SostenutoEvent (event parser) #f "\\sostenutoOn" "\\sostenutoOff")
@@ -556,6 +563,9 @@ Otherwise, return #f."
 (define-display-method SkipEvent (rest parser)
   "s")
 
+(define-display-method RepeatedChord (chord parser)
+  (music->lily-string (ly:music-property chord 'element) parser))
+
 (define-display-method MarkEvent (mark parser)
   (let ((label (ly:music-property mark 'label)))
     (if (null? label)
@@ -756,7 +766,7 @@ Otherwise, return #f."
                                         (*indent*)
                                         (first op)
                                         (second op)))
-                              (reverse operations)))
+                              operations))
                        (*indent*)))
            (parameterize ((*current-context* ctype))
              (music->lily-string music parser)))))
@@ -960,11 +970,11 @@ Otherwise, return #f."
                                                                 symbol 'clefOctavation)
                                                          (music 'ApplyContext
                                                                 procedure ly:set-middle-C!)))))
-    (let ((clef-prop+name (assoc (list ?clef-glyph ?clef-position 0)
+    (let ((clef-name (assoc-get (list ?clef-glyph ?clef-position 0)
                                 clef-name-alist)))
-      (if clef-prop+name
+      (if clef-name
          (format #f "\\clef \"~a~{~a~a~}\"~a"
-                 (cdr clef-prop+name)
+                 clef-name
                  (cond ((= 0 ?clef-octavation)
                         (list "" ""))
                        ((> ?clef-octavation 0)
@@ -977,32 +987,37 @@ Otherwise, return #f."
 ;;; \time
 (define-extra-display-method ContextSpeccedMusic (expr parser)
   "If `expr' is a time signature set, return \"\\time ...\".
-Otherwise, return #f."
-  (with-music-match (expr (music
-                          'ContextSpeccedMusic
-                          element (music
-                                   'ContextSpeccedMusic
-                                   context-type 'Timing
-                                   element (music
-                                            'SequentialMusic
-                                            elements ((music
-                                                       'PropertySet
-                                                       value ?num+den
-                                                       symbol 'timeSignatureFraction)
-                                                      (music
-                                                       'PropertySet
-                                                       symbol 'beatLength)
-                                                      (music
-                                                       'PropertySet
-                                                       symbol 'measureLength)
-                                                      (music
-                                                       'PropertySet
-                                                       value ?grouping
-                                                       symbol 'beatGrouping))))))
-    (if (null? ?grouping)
-       (format #f "\\time ~a/~a~a" (car ?num+den) (cdr ?num+den) (new-line->lily-string))
-       (format #f "#(set-time-signature ~a ~a '~s)~a"
-               (car ?num+den) (cdr ?num+den) ?grouping (new-line->lily-string)))))
+Otherwise, return #f.  Note: default grouping is not available."
+  (with-music-match
+   (expr (music
+           'ContextSpeccedMusic
+          element (music
+                   'ContextSpeccedMusic
+                   context-type 'Timing
+                   element (music
+                            'SequentialMusic
+                            elements ?elts))))
+   (and
+    (> (length ?elts) 2)
+    (with-music-match ((cadr ?elts)
+                       (music 'PropertySet
+                              symbol 'beatLength))
+       #t)
+    (with-music-match ((caddr ?elts)
+                       (music 'PropertySet
+                              symbol 'measureLength))
+       #t)
+    (with-music-match ((car ?elts)
+                       (music 'PropertySet
+                              value ?num+den
+                              symbol 'timeSignatureFraction))
+       (if (eq? (length ?elts) 3)
+           (format
+             #f "\\time ~a/~a~a"
+             (car ?num+den) (cdr ?num+den) (new-line->lily-string))
+           (format
+             #f "#(set-time-signature ~a ~a '(<grouping-specifier>))~a"
+             (car ?num+den) (cdr ?num+den)  (new-line->lily-string)))))))
 
 ;;; \bar
 (define-extra-display-method ContextSpeccedMusic (expr parser)
@@ -1027,6 +1042,7 @@ Otherwise, return #f."
             ((= i dots) m)
           (set! m (+ m delta)))
         factor))))
+
 (define moment-duration-alist (map (lambda (duration)
                                     (cons (duration->moment duration)
                                           duration))
@@ -1037,9 +1053,7 @@ Otherwise, return #f."
                                               (list 0 1 2 3 4))))
 
 (define (moment->duration moment)
-  (let ((result (assoc (- moment) moment-duration-alist =)))
-    (and result
-        (cdr result))))
+  (assoc-get (- moment) moment-duration-alist))
 
 (define-extra-display-method ContextSpeccedMusic (expr parser)
   "If `expr' is a partial measure, return \"\\partial ...\".
@@ -1191,4 +1205,6 @@ Otherwise, return #f."
                  (music->lily-string ?lyric-sequence parser)))
        #f)))
 
-
+;; Silence internal event sent at end of each lyrics block
+(define-display-method CompletizeExtenderEvent (expr parser)
+  "")