lilypond-user
[Top][All Lists]
Advanced

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

Re: Position chromatic notes in 1/3 note head size instead of 1/2


From: Valentin Petzel
Subject: Re: Position chromatic notes in 1/3 note head size instead of 1/2
Date: Thu, 03 Mar 2022 19:55:25 +0100

Hello Robert,

the problem is that the Clef properties are not accessible by the grob. These 
are properties of the context. The grob has no access to the context (which 
would also be stupid, as we are are interested in the property during the 
timestep the grob is created, not during the time the callbacks are evaluated.

The position of the NoteHead solves this by having the engraver (which has 
access to the context) determine the staff-position. Now we could create our 
own engraver that acknowledges Note heads and adds Time Signature information 
to them. But rather than that we could as well so it simply like this from a 
grob callback:

By obtaining the pitch from the NoteHead we can detemine a hypothetical staff 
position. By obtaining the staff-position / 2 (or by using ly:staff-symbol-
referencer::callback, which returns exactly that) we get the real staff 
position. The difference between these is then the difference in positioning 
between the actual clef and the hypothetical clef. If e.g. we take the 
hypothetical clef as a standard G-Clef then a standard F-Clef will give us a 
difference 6, so all NoteHeads are 6 Notelines higher than in G-Clef.

This example demonstrates this by calculating and displaying this info during 
stencil-callback. Of course you can use this in any callback.

{
  \override NoteHead.stencil =
  #(lambda (grob)
     (let* ((pitch (ly:event-property (ly:grob-property grob 'cause) 'pitch))
            (oct (ly:pitch-octave pitch))
            (nn (ly:pitch-notename pitch))
            (staffpg (+ (/ (+ nn 1) 2) (* (1- oct) 7/2)))
            (truepos (/ (ly:grob-staff-position grob) 2))
            (clef-offset (- truepos staffpg)))
       (display clef-offset)(newline))
     (ly:note-head::print grob))
  g' \clef bass g
}

Cheers,
Valentin

Am Donnerstag, 3. März 2022, 19:11:15 CET schrieb Robert Mengual:
> Hello Valentin,
> 
> I agree the code ends up being way cleaner with the grob-transformer. I'm
> truly amazed with the amount of flexibility in Lilypond.
> 
> I already managed to implement exactly what I needed, but I now face another
> challenge related with this custom position. Depending on the clef, the
> middle C is in a different position of the staff, so besides the note
> alterations I also need to take into account the clef. So far, I have not
> found any way to know the clef from a grob. Do you know how can I know if a
> note head is being written based on treble clef or bass clef?
> 
> Thank you again,
> Robert
> 
> ________________________________
> De: Valentin Petzel
> Enviado: Jueves, 03 de Marzo de 2022 12:43
> Para: Robert Mengual
> Asunto: Re: Position chromatic notes in 1/3 note head size instead of 1/2
> 
> Hello Robert,
> 
> we do not strictly need grob-transformer. We can also do this manually by
> calculating orig as (staff-symbol-referencer::callback grob) and then still
> do things with the returned value. The merit of using grob-transformer is
> that the code gets cleaner and we do not need to know what the default
> callback is. Although we could do the same as grob-transformer and use
> ly:grob-basic- properties to get the original, but then we’d basically be
> reimplementing the functionality of grob-transformer.
> 
> It is a nice thing to know.
> 
> Valentin
> 
> Am Donnerstag, 3. März 2022, 12:24:08 CET schrieb Robert Mengual:
> > I did not know the existence of the grob-transformer function, even though
> > it is defined in the Scheme Functions docs.
> > 
> > That is exactly what I was looking for. Thanks a lot Valentin.
> > 
> > Robert
> > 
> > ________________________________
> > De: Valentin Petzel
> > Enviado: Miércoles, 02 de Marzo de 2022 20:23
> > Para: lilypond-user@gnu.org; Robert Mengual
> > Asunto: Re: Position chromatic notes in 1/3 note head size instead of 1/2
> > 
> > Have you tried something like this?
> > 
> > \new Staff \with {
> > 
> >   \override NoteHead.Y-offset =
> >   #(grob-transformer 'Y-offset
> >   
> >      (lambda (grob orig)
> >      
> >        (let* ((cause (ly:grob-property grob 'cause))
> >        
> >               (pitch (ly:event-property cause 'pitch))
> >               (st (ly:pitch-alteration pitch))
> >               (offset (* 2/3 st)))
> >          
> >          (+ orig offset))))
> > 
> > }
> > \relative c' {
> > 
> >   c4 cis d dis e eis f fis g gis a ais b bis c
> > 
> > }
> > 
> > Am Mittwoch, 2. März 2022, 19:36:22 CET schrieb Robert Mengual:
> > > Hello Valentin,
> > > 
> > > By increasing the distance between lines it fits, yes, but that is not
> > > how
> > > this music notation was specified. They specify 1/3 notehead size
> > > vertical
> > > distance between chromatic notes.
> > > 
> > > My staff, for example, is defined as follows:
> > > \layout { \context {
> > > 
> > >   \Staff
> > >   \override StaffSymbol.line-positions = #'(-5.67 -2.33 2.33 5.67)
> > > 
> > > }}
> > > So no integer number in staffLineLayoutFunction will allow me to match
> > > my
> > > lines with the noteheads. This is why I think it would make sense to
> > > allow
> > > passing decimal numbers to staffLineLayoutFunction.
> > > 
> > > As an alternative, I tried setting manually NoteHead.Y-offset to
> > > decimals,
> > > but then I have the problem that the note position should be different
> > > depending on the clef...
> > > 
> > > Robert
> > > 
> > > ________________________________
> > > De: Valentin Petzel
> > > Enviado: Miércoles, 02 de Marzo de 2022 19:16
> > > Para: lilypond-user@gnu.org; Robert Mengual
> > > Asunto: Re: Position chromatic notes in 1/3 note head size instead of
> > > 1/2
> > > 
> > > Hello Robert,
> > > 
> > > mathematically 1/3 instead of 1/2 means 50% more, this 3*1.4 = 4.5 notes
> > > should fit.
> > > 
> > > But the same thing should be doable by simply increasing the distance
> > > between lines, like this:
> > > 
> > > <<
> > > \new NoteNames { c d e f g a b c d e f g a }
> > > \new Staff \with {
> > > 
> > >     \override StaffSymbol.line-positions = #'(-6 -3 0 3 6)
> > > 
> > > } \relative c' {
> > > 
> > >   c d e f g a b c d e f g a
> > > 
> > > }
> > > 
> > > Am Mittwoch, 2. März 2022, 19:06:33 CET schrieb Robert Mengual:
> > > > Hello Valentin, thanks for the response.
> > > > 
> > > > That's not really what I want, instead of defining a new Staff (which
> > > > I
> > > > already did btw) I want to position the notes so that more noteheads
> > > > fit
> > > > in
> > > > the same height.
> > > > 
> > > > For example, let's take the height starting from the e bar to the b
> > > > bar
> > > > in
> > > > treble. In the traditional notation, only three noteheads fit between
> > > > this
> > > > height (f g a). In this new notation, 4 noteheads should fit because
> > > > the
> > > > vertical distance between notes is 1/3 instead of 1/2.
> > > > 
> > > > I hope I made things clearer,
> > > > 
> > > > Robert
> > > > 
> > > > ________________________________
> > > > De: Valentin Petzel
> > > > Enviado: Miércoles, 02 de Marzo de 2022 18:49
> > > > Para: lilypond-user@gnu.org
> > > > CC: Robert Mengual
> > > > Asunto: Re: Position chromatic notes in 1/3 note head size instead of
> > > > 1/2
> > > > 
> > > > Hello Robert,
> > > > 
> > > > I’m not exactly sure what you want to do. If you want to achieve the
> > > > results from the screenshot maybe using StaffSymbol.line-positions is
> > > > what you want.
> > > > 
> > > > Cheers,
> > > > Valentin
> > > > 
> > > > Am Mittwoch, 2. März 2022, 18:22:25 CET schrieb Robert Mengual:
> > > > > Hello everyone,
> > > > > 
> > > > > I am trying to position the notes of my custom music notation as in
> > > > > the
> > > > > screenshot.
> > > > > 
> > > > > I tried using a custom callback for staffLineLayoutFunction. I
> > > > > thought
> > > > > it
> > > > > was going to be enough, but it won't allow decimal numbers.
> > > > > 
> > > > > Does anybody have any idea how I can implement this behaviour? Find
> > > > > attached a Tiny.ly as well.
> > > > > 
> > > > > Robert

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

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