Extending LilyPond: 1.3.3 Doubling a note with slurs (example)

### 1.3.3 Doubling a note with slurs (example)

Suppose we want to create a function that translates input like `a` into `a( a)`. We begin by examining the internal representation of the desired result.

>     \displayMusic{ a'( a') }
>     ===>
>     (make-music
>       'SequentialMusic
>       'elements
>       (list (make-music
>               'EventChord
>               'elements
>               (list (make-music
>                       'NoteEvent
>                       'duration
>                       (ly:make-duration 2 0 1 1)
>                       'pitch
>                       (ly:make-pitch 0 5 0))
>                     (make-music
>                       'SlurEvent
>                       'span-direction
>                       -1)))
>             (make-music
>               'EventChord
>               'elements
>               (list (make-music
>                       'NoteEvent
>                       'duration
>                       (ly:make-duration 2 0 1 1)
>                       'pitch
>                       (ly:make-pitch 0 5 0))
>                     (make-music
>                       'SlurEvent
>                       'span-direction
>                       1)))))

The bad news is that the `SlurEvent` expressions must be added ‘inside’ the note (or more precisely, inside the `EventChord` expression).

Now we examine the input,

>     (make-music
>       'SequentialMusic
>       'elements
>       (list (make-music
>               'EventChord
>               'elements
>               (list (make-music
>                       'NoteEvent
>                       'duration
>                       (ly:make-duration 2 0 1 1)
>                       'pitch
>                       (ly:make-pitch 0 5 0))))))

So in our function, we need to clone this expression (so that we have two notes to build the sequence), add a `SlurEvent` to the `'elements` property of each one, and finally make a `SequentialMusic` with the two `EventChords`.

>     doubleSlur = #(define-music-function (parser location note) (ly:music?)
>              "Return: { note ( note ) }.
>              `note' is supposed to be an EventChord."
>              (let ((note2 (ly:music-deep-copy note)))
>                (set! (ly:music-property note 'elements)
>                      (cons (make-music 'SlurEvent 'span-direction -1)
>                            (ly:music-property note 'elements)))
>                (set! (ly:music-property note2 'elements)
>                      (cons (make-music 'SlurEvent 'span-direction 1)
>                            (ly:music-property note2 'elements)))
>                (make-music 'SequentialMusic 'elements (list note note2))))

Jiné jazyky: deutsch, español.

#### LilyPond — Extending