Le 21/11/2022 à 13:43, Jean Faure a écrit :
Hi. The code below is a copy&paste, I do not quite understand what it does. Can I modify it so that an image is chosen according to the following note's duration? Like custom4.eps, custom8.eps?

customHead = {
 \once \override NoteHead  #'stencil = #ly:text-interface::print
 \once \override NoteHead #'text =
   \markup {
     \general-align #Y #CENTER {
       \epsfile #X #2 #"./custom.eps"
     }
   }
 }
{ e'4 f' \customHead g'4 }




Yes, use a callback for that:


\version "2.22.2"

customHead = {
  \once \override NoteHead.stencil = #ly:text-interface::print
  \once \override NoteHead.text =
    #(lambda (grob)
       #{
          \markup \general-align #Y #CENTER
              #(case (ly:duration-log (ly:event-property (event-cause grob) 'duration))
                 ;; whole note:
                 ((0) #{ \markup \epsfile #X #2 "custom1.eps" #})
                 ;; half note:
                 ((1) #{ \markup \epsfile #X #3 "custom2.eps" #})
                 ;; quarter note:
                 ((2) #{ \markup \epsfile #X #4 "custom4.eps" #})
                 ;; eighth note:
                 ((3) #{ \markup \epsfile #X #5 "custom8.eps" #})
                 ;; Add more here if necessary (keeping the "else" line below).
                 (else ""))
       #})
}

{
  \customHead c'1
  \customHead c'2
  \customHead c'4
  \customHead c'8
}




Have a look at these pages:

https://lilypond.org/doc/v2.22/Documentation/extending/callback-functions
https://extending-lilypond.readthedocs.io/en/latest/backend.html#understanding-callbacks

Best,
Jean

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to