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 12:33:26 -0600

On Thu, Dec 28, 2017 at 12:25 PM, David Nalesnik
<address@hidden> wrote:
> Hi Kieren,
>
> On Thu, Dec 28, 2017 at 11:29 AM, Kieren MacMillan
> <address@hidden> wrote:
>> Hi David,
>>
>>>> This works, but I'm guessing there's a better way:
>>
>> This is nice! Any way that it could take two (or more) articulations like
>>
>>   \addArticulation \tenuto \staccato { c <c e g> d c' }
>>
>> to avoid nesting or chaining like
>>
>>   \addArticulation \tenuto \addArticulation \staccato { c <c e g> d c' }
>>
>> which doesn't even work (of course, since the function won't add 
>> articulations if they already exist)?
>>
>
> Something like this?
>
> \version "2.19.65"
>
> addArticulation =
> #(define-music-function (scripts music) (list? ly:music?)
>    (define (add mus)
>      (let* ((art (ly:music-property mus 'articulations))
>             (types
>              (if (pair? art)
>                  (map (lambda (a) (ly:music-property a 'articulation-type))
>                    art)
>                  '()))
>             (types (lset-union string=? types scripts)))
>        (ly:music-set-property!
>         mus 'articulations (map make-articulation types))))
>    (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" "accent") { c-. <c e g>-> d c'-! }
> }
>
> it doesn't maintain direction of the specified articulations if they
> are already there, but I suppose something could be done about that.
>
> David

Replying to the list with removal of some redundant code:

\version "2.19.65"

addArticulation =
#(define-music-function (scripts music) (list? ly:music?)
   (define (add mus)
     (let* ((art (ly:music-property mus 'articulations))
            (types (map (lambda (a) (ly:music-property a 'articulation-type))
                     art))
            (types (lset-union string=? types scripts)))
       (ly:music-set-property!
        mus 'articulations (map make-articulation types))))
   (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" "accent") { c <c e g>-> d c'-! }
}

HTH,
David



reply via email to

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