lilypond-user
[Top][All Lists]
Advanced

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

Re: Note head on barline


From: Valentin Petzel
Subject: Re: Note head on barline
Date: Wed, 22 Feb 2023 18:17:13 +0100

Hello Immanuel,

The problem here is that the Dots are not placed in the NoteColumn, but in a 
DotsColumn,
so they are not affected by changing the parent of the NoteColumn.

This should solve this (by taking affected Dots and placing them into a new 
DotsColumn:

#(define (Heads_on_bar_lines_engraver context)
   (let ((busy #f))
     (make-engraver
      ((process-music engraver)
       (let ((current (ly:context-current-moment context)))
         (set! busy (filter-map
                     (match-lambda
                      ((end . grob)
                       (and (not (equal? end current))
                            grob)))
                     (ly:context-property context 'busyGrobs '())))))
      ((stop-translation-timestep engraver)
       (let ((bar (ly:context-property context 'currentBarLine #f)))
         (when (and bar (pair? busy))
           (let* ((col (ly:grob-parent (car busy) X))
                  (dots (map (lambda (grob) (ly:grob-object grob 'dot)) busy))
                  (dots (filter ly:grob? dots))
                  (group (ly:grob-parent bar X)))
             (if (not (null? dots))
                 (let ((dcol (ly:engraver-make-grob engraver 'DotColumn '())))
                   (ly:grob-set-object! dcol 'dots (ly:grob-list->grob-array 
dots))
                   (for-each (lambda (dot) (ly:grob-set-parent! dot X dcol)) 
dots)
                   (ly:grob-set-parent! dcol X group)))
             (ly:grob-set-parent! col X group)
             (ly:grob-translate-axis! col -0.6 X))))))))

Note that DotColumns are supposed to be created on Staff level, so in case
you have multiple Voices this engraver should sit at the staff level (this 
should
cause any problems, as Jean’s code does not really make use of any context
specific stuff).

Cheers,
Valentin

Am Mittwoch, 22. Februar 2023, 17:06:50 CET schrieb Immanuel Asmus:
> Thank you, this works like a charm, even with tuplets, multiple voices
> or staves (as far as I tested).
> There is one case that doesn’t work as expected, but I do not (yet) need
> it: Namely, when the note on the barline is dotted, the dot will not be
> moved. Try, e.g.,
> 
> \fixed c' { \time 3/4 d4 g2. fis8 g a4 }
> 
> instead of the original melody, and you see what I mean.
> 
> Regards,
> Immanuel
> 
> Am 22.02.2023 um 15:49 schrieb Jean Abou Samra:
> > Le mercredi 22 février 2023 à 15:05 +0100, Immanuel Asmus a écrit :
> >> |Dear all, I want to typeset the sincopa as it was customary between
> >> 
> >> 1500 and 1700 AD: A note whose duration would exceed the bar should
> >> be placed directly on the barline. (Attached is a scan from a 1739
> >> edition of one of Geminiani’s sonatas.) Some years ago, I found a
> >> snippet that dealt exactly with this problem and used some excessive
> >> scheme coding, so I know it must be possible. However, I’m unable to
> >> relocate this snippet. Any help would be appreciated. |
> > 
> > For me, this works:
> > |\version "2.25.3" #(define (Heads_on_bar_lines_engraver context) (let
> > 
> > ((busy #f)) (make-engraver ((process-music engraver) (let ((current
> > (ly:context-current-moment context))) (set! busy (filter-map
> > (match-lambda ((end . grob) (and (not (equal? end current)) grob)))
> > (ly:context-property context 'busyGrobs '())))))
> > ((stop-translation-timestep engraver) (let ((bar (ly:context-property
> > context 'currentBarLine #f))) (when (and bar (pair? busy)) (let ((col
> > (ly:grob-parent (car busy) X)) (group (ly:grob-parent bar X)))
> > (ly:grob-set-parent! col X group) (ly:grob-translate-axis! col -0.6
> > X)))))))) \layout { \context { \Voice \consists
> > #Heads_on_bar_lines_engraver } } \fixed c' { \time 3/4 r4 d g2 fis8(
> > g) a4 r g b2 a8( b) c'4 r b d' g c'( ees') } |
> > 
> > I am actually pretty surprised that it works, because I would have
> > expected turning note columns into non-musical grobs to wreck all
> > assumptions of the layout engine, but, well, at least on this example,
> > it works. I would not count on it to be super reliable, though.
> > 
> > Best,
> > 
> > Jean

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


reply via email to

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