]> git.donarmstrong.com Git - lilypond.git/commitdiff
New music function \endSpanners.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sat, 3 Feb 2007 16:45:22 +0000 (17:45 +0100)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sat, 3 Feb 2007 16:45:22 +0000 (17:45 +0100)
input/regression/music-function-end-spanners.ly [new file with mode: 0644]
ly/music-functions-init.ly
scm/music-functions.scm

diff --git a/input/regression/music-function-end-spanners.ly b/input/regression/music-function-end-spanners.ly
new file mode 100644 (file)
index 0000000..c1427a5
--- /dev/null
@@ -0,0 +1,22 @@
+
+\header {
+
+  texidoc = "the @code{endSpanners} music function inserts 
+end span events at the end of a note."
+  
+}
+
+\version "2.11.15"
+\paper{
+  ragged-right = ##T
+}
+\relative
+<< {   c'4 c c c }
+   \\
+   {
+     \override TextSpanner #'bound-details #'left #'text = "x" 
+     \endSpanners c,2\<\startTextSpan c2
+
+   }
+ >>
+   
index 2a8af551e98aaacd049907d738126b74c238958e..e6aad14133a0d5d6c8ecb8cfec5ba3c8ad3b1919 100644 (file)
@@ -187,6 +187,32 @@ displayMusic =
    (display-scheme-music music)
    music)
 
+
+endSpanners =
+#(define-music-function (parser location music) (ly:music?)
+   (if (eq? (ly:music-property music 'name) 'EventChord)
+       (let*
+          ((elts (ly:music-property music 'elements))
+           (start-span-evs (filter (lambda (ev)
+                               (and (music-has-type ev 'span-event)
+                                    (equal? (ly:music-property ev 'span-direction)
+                                            START)))
+                             elts))
+           (stop-span-evs
+            (map (lambda (m)
+                   (let* ((c (music-clone m)))
+                     (set! (ly:music-property c 'span-direction) STOP)
+                     c))
+                 start-span-evs))
+           (end-ev-chord (make-music 'EventChord
+                                     'elements stop-span-evs))
+           (total (make-music 'SequentialMusic
+                              'elements (list music
+                                              end-ev-chord))))
+        total)
+       
+       (ly:input-message location (_ "argument endSpanners is not an EventChord: ~a" music))))
+
 featherDurations=
 #(define-music-function (parser location factor argument) (ly:moment? ly:music?)
    (_i "Rearrange durations in ARGUMENT so there is an
@@ -362,7 +388,7 @@ pitchedTrill =
                      (lambda (m) (eq? 'NoteEvent (ly:music-property m 'name)))
                      (ly:music-property ev-chord 'elements))))
        (sec-note-events (get-notes secondary-note))
-       (trill-events (filter (lambda (m) (memq 'trill-span-event (ly:music-property m 'types)))
+       (trill-events (filter (lambda (m) (music-has-type m 'trill-span-event))
                              (ly:music-property main-note 'elements)))
 
        (trill-pitch
index 681c2c7b082bcc6719601d03f054e9f72aeaab50..1a1af41991760e401dbad3c76393cf8d2f05385a 100644 (file)
@@ -573,9 +573,8 @@ of beat groupings "
 
 (define-public (empty-music)
   (ly:export (make-music 'Music)))
-;;;
 
-                                       ; Make a function that checks score element for being of a specific type. 
+;; Make a function that checks score element for being of a specific type. 
 (define-public (make-type-checker symbol)
   (lambda (elt)
     ;;(display symbol)
@@ -625,6 +624,21 @@ SkipEvent. Useful for extracting parts from crowded scores"
    mus))
 
 
+(define-public (music-has-type music type)
+  (memq type (ly:music-property music 'types)))
+
+(define-public (music-clone music)
+  (define (alist->args alist acc)
+    (if (null? alist)
+       acc
+       (alist->args (cdr alist)
+                    (cons (caar alist) (cons (cdar alist) acc)))))
+
+  (apply
+   make-music
+   (ly:music-property music 'name)
+   (alist->args (ly:music-mutable-properties music) '())))
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; warn for bare chords at start.