lilypond-user
[Top][All Lists]
Advanced

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

Re: Tweaking notehead direction in chords


From: Paul Morris
Subject: Re: Tweaking notehead direction in chords
Date: Wed, 12 Dec 2012 22:41:32 -0500

Hi Harm,

On Dec 12, 2012, at 9:03 PM, Thomas Morley <address@hidden> wrote:

> I've seen the updated version in the LSR already and tend to approve it as is.
> I doubt it could be possible to create an automatism for 'stem-attachment.

Ok, I went ahead and added examples of manual overrides for fixing stem 
attachment problems.  I used the stem-attachment property for single notes, but 
I couldn't get it to work with chords, so I used the Stem's stem-begin-position 
property instead.  


> I tried to break the code, though.

I found a good way to break it.  If you try it with whole notes the stem's 
X-extent is (+inf.0 . -inf.0) and you get this error: "programming error: 
Infinity or NaN encountered" 

So I tried to work around this with the code below, but when I uploaded it to 
the LSR something went wrong, no error messages or anything but the preview 
page was just blank.[1]  I put the previous version back but it was still 
blank, so I must have broken something.

[1] http://lsr.dsi.unimi.it/LSR/Item?u=1&id=861

#(define ((shift offsets) grob)
(let* ((note-heads (ly:grob-array->list (ly:grob-object grob 'note-heads)))
       (stem (ly:grob-object grob 'stem))
       (stem-ext (ly:grob-property stem 'X-extent))
       (half-stem-ext (if (= -inf.0 (cdr stem-ext)) 0 (cdr stem-ext))))
  (for-each
    (lambda (p q)
      (let ((head-ext (interval-length (ly:grob-property p 'X-extent))))
        (ly:grob-translate-axis! p (* q (- head-ext half-stem-ext)) X)))
    note-heads offsets)))

displaceHeads =
#(define-music-function (parser location offsets) (list?)
#{
  \once \override NoteColumn #'before-line-breaking = #(shift offsets)
#}
)

%%%%%%%% EXAMPLE %%%%%%%%

theMusic = \relative c' {
 e4

 \displaceHeads #'(1) 
 \once \override Staff.NoteHead #'stem-attachment = #'(1.09 . -0.34)
 e

 d'

 \displaceHeads #'(-1) 
 \once \override Staff.NoteHead #'stem-attachment = #'(1.11 . -0.34)
 d

 <c, e>

 \displaceHeads #'(0 1) <c e>

 <e'g>

 \displaceHeads #'(-1 0) <e g>

 <f, a c>

 \displaceHeads #'(1 0 0) 
 \once \override Staff.Stem #'stem-begin-position = #-3.3 
 <f a c>

 <c' e g>

 \displaceHeads #'(-1 -1 0) <c e g>

 <ees f a c>4

 \displaceHeads #'(0 -1 0 0) <ees f a c>4

 <ees, f a c>4

 \displaceHeads #'(1 0 0 0) 
 \once \override Staff.Stem #'stem-begin-position = #-4.3 
 <ees f a c>4
}

\new Staff {
 \theMusic
}


> And noticed that adding Fingering, StringNumber and Script will result
> in some strange not aligned output.

Huh, that's weird.


> Adding a stencil-tweak switches it to funny.
> ->png
> 
> \version "2.16.1"
> 
> % displaceHeads is omitted
> 
> #(define rhomb-note
>  (lambda (grob)
>    (let* ((stencil (ly:note-head::print grob))
>           (new-stil
>             (grob-interpret-markup grob
>               (markup #:rotate -45 #:box #:rotate 45 #:stencil  stencil))))
>    new-stil)))
> 
> \relative c' {
> \displaceHeads #'(1 0 1 1)
> <\tweak #'stencil #rhomb-note b\1 cis-1\2  eis-2\3 gis-3\4 >4-.---|
> }
> 
> It is much easier to break code than to create it.

So true!  

Cheers, 
-Paul


> I should do more review-work.
> :D
> 
> 
> -Harm
> <atest-15.preview.png>




reply via email to

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