lilypond-user
[Top][All Lists]
Advanced

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

Re: Change stem direction based on position of note in staff?


From: Lukas-Fabian Moser
Subject: Re: Change stem direction based on position of note in staff?
Date: Fri, 30 Aug 2024 07:07:51 +0200
User-agent: Mozilla Thunderbird

Hi Stefano,

Am 30.08.24 um 04:10 schrieb Stefano Antonelli:
Firstly, thanks very much for the help.  This approach does not work
well with polyphony as you suggest.  I did give it a try.

This new version implemented as an engraver does:

\version "2.24.0"

notehead-stemdirection-dictionary =
#`(
    (0 . ,UP)
    (-2 . ,DOWN)
    (-5 . ,DOWN)
    (1 . ,UP)
    (3 . ,UP)
    )

Staffposition_Stemdirection_engraver =
#(lambda (context)
   (make-engraver
    (acknowledgers
     ((stem-interface this-engraver stem source-engraver)
      (let
       ((noteheads
         (ly:grob-array->list (ly:grob-object stem 'note-heads))))
       (if (and (not (null? noteheads))
                (null? (cdr noteheads))) ; i.e. if noteheads has length 1
           (let
            ((new-direction
              (assoc-get (ly:grob-property (car noteheads) 'staff-position)
                         notehead-stemdirection-dictionary
                         #f)))
            (if new-direction
                (ly:grob-set-property! stem 'direction new-direction)))
           (ly:warning "Need exactly one notehead per stem.")))))))

\new Staff \with { \consists #Staffposition_Stemdirection_engraver } \relative {
  \voiceOne
  c'4 d e f g a b c
  \bar "."
  \voiceTwo
  d e f g a <e a>
}

The approach of moving notes to different voices doesn't solve the core
problem either.  Now that I've thought about it.

The core problem is that I can't just move notes.

To be honest, I still do not understand what it is you want to achieve in the end - and I suspect the core problem from the second sentence is different from the core problem mentioned in the first :-).

Lukas


reply via email to

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