From 1cdc9680f2094525103d335d80bc3950f918ed03 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sat, 3 Feb 2007 17:45:22 +0100 Subject: [PATCH] New music function \endSpanners. --- .../regression/music-function-end-spanners.ly | 22 +++++++++++++++ ly/music-functions-init.ly | 28 ++++++++++++++++++- scm/music-functions.scm | 18 ++++++++++-- 3 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 input/regression/music-function-end-spanners.ly diff --git a/input/regression/music-function-end-spanners.ly b/input/regression/music-function-end-spanners.ly new file mode 100644 index 0000000000..c1427a5456 --- /dev/null +++ b/input/regression/music-function-end-spanners.ly @@ -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 + + } + >> + diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly index 2a8af551e9..e6aad14133 100644 --- a/ly/music-functions-init.ly +++ b/ly/music-functions-init.ly @@ -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 diff --git a/scm/music-functions.scm b/scm/music-functions.scm index 681c2c7b08..1a1af41991 100644 --- a/scm/music-functions.scm +++ b/scm/music-functions.scm @@ -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. -- 2.39.2