Jump to content

Adding extra fingering with Scheme: Difference between revisions

From LilyPond wiki
m New category
Tags: Mobile edit Mobile web edit
mNo edit summary
 
Line 1: Line 1:
You can add additional elements to notes using <code>map-some-music</code>. In this example, an extra script is attached to a note.
You can add additional elements to notes using <code>map-some-music</code>. In this example, an extra script is attached to a note (or a chord).


In general, first do a <code>\displayMusic</code> of the music you want to create, then write a function that will work on the appropriate parts of the music for you.
In general, you should first apply <code>\displayMusic</code> to music similar to what you want to create so that you can see its structure.  This can be then used as template for your Scheme code.


<lilypond version="2.24">
<lilypond version="2.24">
addScript =
addScript =
#(define-music-function (script music)
#(define-music-function (script music) (ly:event? ly:music?)
  (ly:event? ly:music?)
   (map-some-music
   (map-some-music
     (lambda (mus)
     (lambda (mus)
Line 14: Line 13:
                       (list (ly:music-deep-copy script))))
                       (list (ly:music-deep-copy script))))
         mus)
         mus)
       (case (ly:music-property mus 'name)
       (case (ly:music-property mus 'name)
         ((EventChord)
         ((EventChord)
Line 22: Line 22:
     music))
     music))


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


[[Category:Scheme]]
[[Category:Scheme]]
[[Category:Scheme]]
[[Category:Included in the official documentation]]
[[Category:Included in the official documentation]]
[[Category:Snippet]]
[[Category:Snippet]]

Latest revision as of 08:28, 28 December 2025

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

In general, you should first apply \displayMusic to music similar to what you want to create so that you can see its structure. This can be then used as template for your Scheme code.

\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))

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