Re: slurs anchored at bar lines
Werner LEMBERG <[email protected]>
| Newsgroups | gmane.comp.gnu.lilypond.devel |
|---|---|
| Message-ID | <[email protected]> |
Sorry for the late reply.
> I'm not entirely sure if I understood the problem perfectly, and I
> hope I'm not missing the mark here. However, I have been
> experimenting with layout geometry callbacks, and the attached
> snippet might offer a solution to the issue you described.
Yes! In principle this is exactly what I want, thanks.
I've attached a version that I consider slightly more readable,
together with more examples. IMHO, the code should be adjusted to
consider any prefatory matter that can happen before a bar line as the
(default) end point of the slur. As can be seen, it would be
necessary to modify all control points of the slur to get a decent
looking slur. Similar code would also be necessary at the start of
the slur.
Finally, we would need the same stuff for ties.
Of course, your code is a work-around only. LilyPond more or less
already provides anchors at bar lines together with the start and end
of a staff – it uses this mechanism to align broken slurs and ties...
Werner
Slur-to-bar.ly
(text/plain, 2.8 KB)
\version "2.26.0"
#(define (slur-over-bar rightOffset)
(lambda (slur-grob)
(let* ((system (ly:grob-system slur-grob))
(cps (ly:grob-property slur-grob 'control-points))
(end-cp (cadddr cps))
(end-y (cdr end-cp))
(slur-start-x (ly:grob-relative-coordinate slur-grob system X))
(abs-end-x (+ slur-start-x (car end-cp)))
(all-elts (ly:grob-array->list
(ly:grob-object system 'all-elements)))
(all-bars (filter
(lambda (grob)
(grob::has-interface grob 'bar-line-interface))
all-elts))
(all-next-bars (filter
(lambda (bar)
(> (ly:grob-relative-coordinate bar system X)
abs-end-x))
all-bars)))
(when (not (null? all-next-bars))
(let* ((sorted-bars
(sort all-next-bars
(lambda (bar1 bar2)
(< (ly:grob-relative-coordinate bar1 system X)
(ly:grob-relative-coordinate bar2 system X)))))
(next-bar (car sorted-bars))
(next-bar-x (ly:grob-relative-coordinate next-bar system X))
(new-relative-x (- (+ next-bar-x rightOffset) slur-start-x))
;; Where does the value 0.2 comes from?
(new-end-cp (cons new-relative-x (- end-y 0.2)))
(new-cps (list (car cps)
(cadr cps)
(caddr cps)
new-end-cp)))
(ly:grob-set-property! slur-grob 'control-points new-cps))))))
\layout {
\context {
\Score
\omit BarNumber
}
}
\paper {
ragged-right = ##t
indent = -4
}
#(define-markup-list-command (TableRow layout props arg1 arg2 music)
(number? number? ly:music?)
(interpret-markup-list layout props
#{
\markuplist {
\override #'(baseline-skip . 1.5) {
\score { {
#music } }
\score { {
\override Slur.after-line-breaking = #(slur-over-bar arg1)
#music } }
\score { {
\override Slur.after-line-breaking = #(slur-over-bar arg2)
#music } }
}
}
#}
))
\markuplist {
\override #'(padding . 4)
\override #'(baseline-skip . 6)
\table #'(-1 -1 -1) {
default
\typewriter "#(slur-over-bar 0)"
\typewriter "#(slor-over-bar 1.8)"
\TableRow #0 #1.8 { \relative c'' { c4( a f d) } }
\null \null \null
\TableRow #0 #1.8 { \relative c'' { c4( a f d) \clef "bass" } }
\null \null \null
\TableRow #0 #1.8 { \relative c'' { c4( a f d | \break
c4 d f a) } }
}
}
Slur-to-bar.png
(image/png, 21.3 KB) - not displayed