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: Thu, 29 Aug 2024 09:49:52 +0200
User-agent: Mozilla Thunderbird

Hi Stefano,

Am 28.08.24 um 16:59 schrieb Stefano Antonelli:
Would it be possible to change the stem direction of a note based on
it's position on the staff?

This is the easiest of your questions, since this can be done using a
callback on Stem.direction:

\version "2.24.0"

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

\relative {
  \override Stem.direction =
  #(grob-transformer
    'direction
    (lambda (stem default-direction)
    (let ((noteheads (ly:grob-array->list (ly:grob-object stem
'note-heads))))
       (when (not (= (length noteheads) 1))
         (ly:warning "Need exactly one notehead per stem.")
         default-direction)
       (assoc-get (ly:grob-property (car noteheads) 'staff-position)
                  notehead-stemdirection-dictionary
                  default-direction))))
  c'4 d e f g a b c d e f g a
}

But this approach doesn't mix well with \voiceOne, polyphony etc. since
these also override Stem.direction, so I don't know if this is good
enough for you.

A more robust solution would involve a (simple) custom engraver that
does the same thing but without the need to override Stem.direction;
would you be interested in that?

The strategies you proposed - if I understand correctly, putting notes
in different voices depending on their pitch / staff position - are
considerably more involved than just setting the Stem direction (whether
in a callback like I did above or in an engraver).

Lukas




reply via email to

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