lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Function to add articulation to all notes


From: David Nalesnik
Subject: Re: Function to add articulation to all notes
Date: Thu, 28 Dec 2017 11:11:56 -0600

Hi,

On Thu, Dec 28, 2017 at 10:23 AM, Caagr98 <address@hidden> wrote:
> Sometimes when having a long section of staccato, it's a bit tedious to add 
> -. to all notes, so then it's useful to have a function which automatically 
> adds an articulation to all notes. I have one such function here:
>
> addArticulation =
> #(define-music-function (event music) (ly:event? ly:music?)
>    (music-map
>     (lambda (mus)
>      (if (music-is-of-type? mus 'note-event)
>       (if (not (memq 'articulations ; Don't add staccato if there already 
> exist an articulation
>                      (map car (ly:music-mutable-properties mus))))
>         (ly:music-set-property! mus 'articulations (list event))))
>      mus)
>     music))
>
> However, this function adds the articulation to all notes in chords (leading 
> to multiple staccato dots), which is not what I want. Is there any better way 
> to do this?
>

This works, but I'm guessing there's a better way:

\version "2.19.65"

addArticulation =
#(define-music-function (event music) (ly:event? ly:music?)
   (define (add mus)
     (if (not (memq 'articulations ; Don't add staccato if there
already exist an articulation
                (map car (ly:music-mutable-properties mus))))
         (ly:music-set-property! mus 'articulations (list event))))
   (for-some-music
    (lambda (mus)
      (cond
       ((music-is-of-type? mus 'event-chord) (add mus))
       ((music-is-of-type? mus 'note-event) (add mus))
       (else #f)))
    music)
   music)

{
  \addArticulation \staccato { c <c e g> d c' }
}

HTH,
David



reply via email to

[Prev in Thread] Current Thread [Next in Thread]