lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Programming Question


From: David Nalesnik
Subject: Re: Programming Question
Date: Thu, 18 Sep 2014 07:01:35 -0500

Hi Jay,

On Thu, Sep 18, 2014 at 4:43 AM, Jay Vara <address@hidden> wrote:
> I'm not top posting.

I am using NoteNames context to print the note names automatically for
scales of half notes, quarter notes and eighth notes. I have redefined
the NoteNames using override NoteName.Stencil.

I need different font sizes for the note names of half, quarter and
eighth notes. Currently I have got this working by using three different
versions of the myNoteNames function. The only change between them is
the fontsize of text. Is there a way to combine the three functions -
perhaps have two arguments. I tried this and since the syntax of
defining the function and of using it were not clear, I was not able to
get it to work.


Here's how you could add an argument for 'font-size to your function:

 \version "2.18.2"

music =  \relative c' {c2 d e f g a b c c b a g f e d c}


newnames =
#`(("c" . "S")
   ("d" . "R")
   ("e" . "G")
   ("f" . "M")
   ("g" . "P")
   ("a" . "D")
   ("b" . "N")
   )

myNoteNames =
#(lambda (size)
   (lambda (grob)
   
     (let* (
             ;; bindings
             (default-name (ly:grob-property grob 'text))
             (new-name (assoc-get default-name newnames))
             )
       ;; body
       (ly:grob-set-property! grob 'text new-name)
       (ly:grob-set-property! grob 'font-size size)
       (ly:text-interface::print grob)
       )
     ))

#(define (myNoteNames size)
   (lambda (grob)
   
     (let* (
             ;; bindings
             (default-name (ly:grob-property grob 'text))
             (new-name (assoc-get default-name newnames))
             )
       ;; body
       (ly:grob-set-property! grob 'text new-name)
       (ly:grob-set-property! grob 'font-size size)
       (ly:text-interface::print grob)
       )
     ))


\new Staff {
  <<
    \new Voice {
      \music
      \shiftDurations #1 #0 {\music }
      \shiftDurations #2 #0 {\music \music }
    }
    \context NoteNames {

      \override NoteName.stencil = #(myNoteNames 1)
      \music

      \override NoteName.stencil = #(myNoteNames -2)
      \shiftDurations #1 #0 {\music }

      \override NoteName.stencil = #(myNoteNames -4)
      \shiftDurations #2 #0 {\music \music }

    }
  >>
}

%%%%%%%%%%%%%%
Notice that I've given two versions of myNoteNames.  They are equivalent.  (I find the second easier to use, but maybe that's just me.)

Now, if you want to have LilyPond detect the note durations and make the fontsize decisions for you, I don't believe you'll be able to use the NoteNames grob as it stands.  It would be nice if a NoteNames object had a pointer to a NoteHead, from which information like duration could be gleaned, but it doesn't. 

Hope this helps.
David 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]