Next: Adding articulation to notes (example), Previous: Music properties, Up: Building complicated functions
Suppose we want to create a function which translates input like ‘`a'’ into ‘`a( a)'’. We begin by examining the internal representation of the music we want to end up with.
\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 SlurEvents
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))))
Next: Adding articulation to notes (example), Previous: Music properties, Up: Building complicated functions
This page is for LilyPond-2.10.33 (stable-branch).