Jump to content

Adding extra fingering with Scheme: Difference between revisions

From LilyPond wiki
m Replace version="2.24.0" with version="2.24" now that the LilyWiki extension supports auto-selecting the latest release in a stable series
No edit summary
Line 31: Line 31:
[[Category:Scheme]]
[[Category:Scheme]]
[[Category:Scheme]]
[[Category:Scheme]]
[[Category:Included in the official documentation]]
[[Category:Included in the official documentation]][[Category:Snippet]]

Revision as of 22:46, 21 November 2025

You can add additional elements to notes using map-some-music. In this example, an extra script is attached to a note.

In general, first do a \displayMusic of the music you want to create, then write a function that will work on the appropriate parts of the music for you.

\version "2.24"

addScript =
#(define-music-function (script music)
   (ly:event? ly:music?)
   (map-some-music
    (lambda (mus)
      (define (append-script-at! prop)
        (set! (ly:music-property mus prop)
              (append (ly:music-property mus prop)
                      (list (ly:music-deep-copy script))))
        mus)
      (case (ly:music-property mus 'name)
        ((EventChord)
         (append-script-at! 'elements))
        ((NoteEvent)
         (append-script-at! 'articulations))
        (else #f)))
    music))

\score {
  {
    \addScript _6 { c'4-3 <c' e' g'> }
  }
}