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
>               'NoteEvent
>               'articulations
>               (list (make-music
>                       'SlurEvent
>                       'span-direction
>                       -1))
>               'duration
>               (ly:make-duration 2 0 1/1)
>               'pitch
>               (ly:make-pitch 0 5 0))
>             (make-music
>               'NoteEvent
>               'articulations
>               (list (make-music
>                       'SlurEvent
>                       'span-direction
>                       1))
>               'duration
>               (ly:make-duration 2 0 1/1)
>               'pitch
>               (ly:make-pitch 0 5 0))))

The bad news is that the `SlurEvent` expressions must be added ‘inside’ the note (in its `articulations` property).

Now we examine the input.

>     \displayMusic a'
>     ===>
>     (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 `'articulations` property of each one, and finally make a `SequentialMusic` with the two `NoteEvent` elements. For adding to a property, it is useful to know that an unset property is read out as `'()`, the empty list, so no special checks are required before we put another element at the front of the `articulations` property.

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

#### LilyPond — Extending v2.24.4 (stable-branch).