Thomas Morley <thomasmorle...@gmail.com> writes:

> #(define (make-text-script x)
>    (make-music 'TextScriptEvent
>                'direction DOWN
>                'text x))
>
> #(define (add-text-script m x)
>    (cond ((music-is-of-type? m 'event-chord)
>           (set! (ly:music-property m 'elements)
>                  (cons (make-text-script x)
>                        (ly:music-property m 'elements))))
>          ((music-is-of-type? m 'note-event)
>           (set! (ly:music-property m 'articulations)
>                  (cons (make-text-script x)
>                        (ly:music-property m 'articulations))))
>          (else (let ((es (ly:music-property m 'elements))
>                      (e (ly:music-property m 'element)))
>                  (map (lambda (y) (add-text-script y x)) es)
                   (for-each ...
>                  (if (ly:music? e)
>                      (add-text-script e x))
>                      )))
>    m)

#(define (add-text-script m x)
   (define (append-property! music property element)
     (set! (ly:music-property music property)
           (append! (ly:music-property music property)
                    (list element)))
     music)
   (map-some-music
     (lambda (m)
       (cond ((music-is-of-type m 'event-chord)
              (append-property! m 'elements (make-text-script x)))
             ((music-is-of-type m 'note-event)
              (append-property! m 'articulations (make-text-script x)))
             ;; don't recurse into other rhythmic events
             ((music-is-of-type m 'rhythmic-event) m)
             ;; recurse:
             (else #f)))
     m))

That's the "proper" variant (as opposed to the original, it _returns_
the modified music however).  One has to note that the improper variant
will generally work as well: adding material to 'articulations works for
both 'event-chord as well as 'note-event so one can drop the
distinction.  It's not what LilyPond itself would do, however.

Of course, not recursing into other rhythmic events is just an
optimization that's not particularly important.

-- 
David Kastrup


_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to