lilypond-user
[Top][All Lists]
Advanced

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

Re: how to detect position of note on stave?


From: David Nalesnik
Subject: Re: how to detect position of note on stave?
Date: Thu, 8 Jan 2015 07:31:44 -0600

Hi Graham,

On Wed, Jan 7, 2015 at 7:54 PM, Graham King <address@hidden> wrote:
Many thanks David,
almost there...

On Wed, 2015-01-07 at 18:09 -0600, David Nalesnik wrote:
Hi Graham,

On Wed, Jan 7, 2015 at 4:39 PM, Graham King <address@hidden> wrote:
I'm trying to replace a note with one of two special glyphs, depending on the note's position on the stave:  if on the third line or above, stem down, otherwise stem up.  Is it possible to extend the following code to detect automatically (and independently of clef or transposition) which glyph should be chosen?



Sure--try this:

Merged into my original example, to illustrate a problem:

\version "2.19.5"

#(define ((note-head-musicglyph name) grob)
(grob-interpret-markup grob (make-musicglyph-markup name)))

\score {
    \shiftDurations #-1 #0 {
        \relative c' {
            \time 4/2
            c c c c
            \once \override NoteHead #'stencil =
                #(lambda (grob)
                   (let ((pos (ly:grob-property grob 'staff-position)))
                     (if (>= pos 0)
                         (note-head-musicglyph "noteheads.dM2mensural")
                         (note-head-musicglyph "noteheads.uM2mensural"))))
            c1 }}}

This works beautifully, except when the note is on a ledger line above or below the stave, in which case the ledger line is lost and horizontal spacing goes haywire.

Sure does!  The problem is how the note-head-musicglyph function is called within the stencil override, and I should have caught that.  You need to pass the grob in the function call.

Retaining your definition as it is:


 #(define ((note-head-musicglyph name) grob)
   (grob-interpret-markup grob (make-musicglyph-markup name)))

\score {
  \shiftDurations #-1 #0 {
    \relative c' {
      \time 4/2 
      c c c c
      \once \override NoteHead #'stencil = 
      #(lambda (grob)
         (let ((pos (ly:grob-property grob 'staff-position)))
           (if (>= pos 0)
               ((note-head-musicglyph "noteheads.dM2mensural") grob)
               ((note-head-musicglyph "noteheads.uM2mensural") grob))))
      c1 c' c'' }}}

%%%

You can simplify your definition of note-head-musicglyph:


#(define (note-head-musicglyph name grob)
   (grob-interpret-markup grob (make-musicglyph-markup name)))

\score {
  \shiftDurations #-1 #0 {
    \relative c' {
      \time 4/2 
      c c c c
      \once \override NoteHead #'stencil = 
      #(lambda (grob)
         (let ((pos (ly:grob-property grob 'staff-position)))
           (if (>= pos 0)
               (note-head-musicglyph "noteheads.dM2mensural" grob)
               (note-head-musicglyph "noteheads.uM2mensural" grob))))
      c1 c' c'' }}}


Best,
David


reply via email to

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