Hallo kil,
heute vormittag habe ich kaum Zeit, deshalb nur in aller Kürze: Meine Anfrage auf der englischen Liste führte tatsächlich zu einer wertvollen Erkenntnis.
In der Folge habe ich die notwendigen Variablen reduzieren können, y-offset konnte ich eliminieren (corr-y und slope-1 auch), deshalb gehe ich nicht weiter darauf ein.
Ich hatte noch keine Gelegenheit mich darum zu kümmern, ob es möglich ist die Definition für die zusätzlichen Balken auch noch zu verbessern. Genau dort liegt nämlich das Problem welches Du schilderst.
Nichtsdestotrotz kann man mit der Definition auf ihrem derzeitigen Stand zu einem befriedigenden Ergebnis kommen. (Die dazu nötigen Werte legen aber ebenfalls die Vermutung nahe, daß irgenwas noch nicht ganz in Ordnung ist.) Dein Beispiel ist bei Buchstabe "J".
Ein Wort zu 'layer. Das layer-property bestimmt in welcher Reihenfolge "gedruckt" wird. Wenn ich \override Beam #'layer = #-4 einstelle, dann wird der Balken (normalerweise) zuerst gedruckt. Sichtbar ist ein Effekt nur dann, wenn man den Balken einfärbt. Ich benutze es, um zu kontrollieren wie tief die Stems in den Beam hineinragen. Im Code unten habe ich per layout die Balkenfarbe (für den langen Balken) gelb eingestellt, sodaß Du den Effekt sehen können müßtest. Das kannst Du natürlich problemlos wieder rückgämgig machen. Die zusätzlichen Balken kann man auch einzeln einfärben (wenn auch an anderer Stelle im Code). Wie schon gesagt das Ganze dient der Kontrolle, nicht der Konstruktion.
\version "2.14.2"
#(set-global-staff-size 20)
\layout {
\context {
\Staff
\override Beam #'layer = #-4
\override Beam #'color = #yellow
}
}
\markup \column { \bold \fill-line { "EXAMPLE" } \vspace #2 }
#(define ((grow-dir-var top slope-2 slope-3) grob)
(cond ((= top 1) (and (display "\n ______________No Top wanted?________________________") #f))
((< top 1) (and (display "\n ______________No reachable Top!_____________________") #f))
((> top 1)
(if (ly:stencil? (ly:beam::print grob))
(let* ((beam (ly:beam::print grob))
(dir (ly:beam::calc-direction grob))
(beam-extent-X (ly:stencil-extent beam X))
(beam-length-x (interval-length beam-extent-X))
(beam-extent-Y (ly:stencil-extent beam Y))
(beam-length-y (interval-length beam-extent-Y))
(line-thickness (ly:output-def-lookup (ly:grob-layout grob) 'line-thickness))
(half-stem-thickness (/ (* 1.3 line-thickness) 2))
(beam-thickness (ly:grob-property grob 'beam-thickness))
(beam-positions (ly:grob-property grob 'positions))
(beam-slant (if (>= (car beam-positions) (cdr beam-positions)) -1 1))
(orig-slope (* beam-slant (/ (- beam-length-y (+ (* 3 beam-thickness) 0.6)) beam-length-x)))
(alpha (atan orig-slope))
(h-max (/ (+ (* 3 beam-thickness) 0.35) (cos alpha)))
;; markup-a is the longest beam
(markup-a (markup #:beam (- beam-length-x (* half-stem-thickness 1.25)) ;; length
orig-slope ;; slope
beam-thickness)) ;; thickness
;; markup-b is begin of the first additional beam
(y1 (- (/ (- beam-length-y (+ (* 3 beam-thickness) 0.6)) top) (/ h-max 2)))
(x1 (/ (- beam-length-x (* half-stem-thickness 1.25)) top))
(part-beam-1
(if (not (equal? (car slope-2) #f))
(markup #:beam (- (/ beam-length-x top) (* half-stem-thickness 0.8)) ;; length
;(if (and (> dir 0) (> beam-slant 0))
;(/ y1 x1)
(* (car slope-2) dir (/ y1 x1))
;) ;; slope
beam-thickness) ;; thickness
(markup #:null)))
(markup-b (markup part-beam-1))
(first-part-beam-1 (grob-interpret-markup grob markup-b))
(first-part-beam-1-ext-y (ly:stencil-extent first-part-beam-1 Y))
(length-first-part-beam-1-y (interval-length first-part-beam-1-ext-y))
;; markup-bb is the end of the first additional beam
(y11 (- (- beam-length-y (+ (* 3 beam-thickness) 0.6)) y1 ))
(x11 (- beam-length-x x1))
(part-beam-11
(if (not (equal? (cdr slope-2) #f))
(markup #:beam (- (- beam-length-x (/ beam-length-x top)) (* half-stem-thickness 0.8)) ;; length
(* (cdr slope-2) dir (/ y11 x11)) ;; slope
beam-thickness) ;; thickness
(markup #:null)))
(markup-bb (markup part-beam-11))
;; markup-c is the begin of the second additional beam
(y2 (- (/ (- beam-length-y (+ (* 3 beam-thickness) 0.6)) top) h-max))
(x2 x1)
(part-beam-2
(if (not (equal? (car slope-3) #f))
(markup #:beam (- (/ beam-length-x top) (* half-stem-thickness 0.8)) ;; length
(* (car slope-3) dir (/ y2 x2)) ;; slope
beam-thickness) ;; thickness
(markup #:null)))
(markup-c (markup part-beam-2))
(first-part-beam-2 (grob-interpret-markup grob markup-c))
(first-part-beam-2-ext-y (ly:stencil-extent first-part-beam-2 Y))
(length-first-part-beam-2-y (interval-length first-part-beam-2-ext-y))
;; markup-cc is the end of the second additional beam
(y22 (- (- beam-length-y (+ (* 3 beam-thickness) 0.6)) y2 ))
(x22 x11)
(part-beam-22
(if (not (equal? (cdr slope-3) #f))
(markup #:beam (- (- beam-length-x (/ beam-length-x top)) (* half-stem-thickness 0.8)) ;;length
(* (cdr slope-3) dir (/ y22 x22)) ;;slope
beam-thickness) ;; thickness
(markup #:null)))
(markup-cc (markup part-beam-22))
) ;; end of defs in let*
(ly:stencil-translate-axis
(ly:stencil-add
;; first (long beam)
(ly:stencil-translate-axis
(grob-interpret-markup grob markup-a)
(/ half-stem-thickness -2.5)
X)
;; parts of second beam
(ly:stencil-in-color
(ly:stencil-combine-at-edge
(ly:stencil-translate-axis
(grob-interpret-markup grob markup-b)
(/ half-stem-thickness -2.5) X)
X RIGHT
(ly:stencil-translate-axis
(grob-interpret-markup grob markup-bb)
(cond ((> dir 0)
(* beam-slant (- length-first-part-beam-1-y beam-thickness)))
((and (< dir 0) (> beam-slant 0))
(* beam-slant (- length-first-part-beam-1-y beam-thickness)))
((and (< dir 0) (< beam-slant 0))
(- length-first-part-beam-1-y beam-thickness)))
Y)
0)
0 0 0) ;; <-- coloring
;; parts of third beam
(ly:stencil-in-color
(ly:stencil-combine-at-edge
(grob-interpret-markup grob markup-c)
X RIGHT
(ly:stencil-translate-axis
(grob-interpret-markup grob markup-cc)
(cond ((> dir 0)
(* -1 (- length-first-part-beam-2-y beam-thickness)))
((and (< dir 0) (> beam-slant 0))
(* beam-slant (* beam-slant (- length-first-part-beam-2-y beam-thickness))))
((and (< dir 0) (< beam-slant 0))
(* beam-slant (* beam-slant (- length-first-part-beam-2-y beam-thickness)))))
Y)
0)
0 0 0) ;; <-- coloring
) ;; end of stencil-add
(car beam-positions)
Y)
) ;; end of let*
#f))))
%--------------------- Test ----------------------------------------------------
\relative c' {
\mark\markup { \with-color #red "A" }
\once \override Beam #'stencil = #(grow-dir-var 2 ; where to print the turn (2 is half-beam)
'(1 . 1) ; slope '(<first part of the first added beam>
; .
; <second part of the first added beam>)
'(1 . 1)) % slope '(<first part of the second added beam>
% .
% <second part of the second added beam>)
% to delete the first or second additional
% beam use '(#f . #f)
c32[ d e f g a b c]
\mark\markup { \with-color #red "B" }
\once \override Beam #'stencil = #(grow-dir-var 1.4 ; where to print the turn (2 is half-beam)
'(1 . 1) ; slope '(<first part of the first added beam>
; .
; <second part of the first added beam>)
'(1 . 1)) % slope '(<first part of the second added beam>
% .
% <second part of the second added beam>)
% to delete the first or second additional
% beam use '(#f . #f)
c,32[ d e f g a b c]
\mark\markup { \with-color #red "C" }
\once \override Beam #'stencil = #(grow-dir-var 2 '(8 . 0.17) '(2.5 . 0.55))
a32[ g f e d c b a]
\mark\markup { \with-color #red "D" }
\once\override Beam #'stencil = #(grow-dir-var 3.5 '(1 . 1) '(1 . 1))
c,32 [c c c c c c c c c c c c c c c
]
\bar "" \break
\mark\markup { \with-color #red "E" }
\once \override Beam #'stencil = #(grow-dir-var 3 ; where to print the turn (2 is half-beam)
'(1 . 0.85) ; slope '(<first part of the first added beam>
; .
; <second part of the first added beam>)
'(1 . 0.9)) % slope '(<first part of the second added beam>
% .
% <second part of the second added beam>)
% to delete the first or second additional
% beam use '(#f . #f)
c''32 [d' e, f g a b, c d'' e f g, a b c d
]
\mark\markup { \with-color #red "F" }
\once \override Beam #'stencil = #(grow-dir-var 3 '(2.5 . 0.1) '(1.6 . 0.45))
c,,32 [d e f g a b c d e f g a b c d
]
\bar ""\break
\mark\markup { \with-color #red "G" }
\once \override Beam #'stencil = #(grow-dir-var 3 '(1.2 . 1.03) '(1 . 1))
c32 [b a g f e d c b a g f e d c b
]
\mark\markup { \with-color #red "H" }
\once\override Beam #'stencil = #(grow-dir-var 1.3 '(1 . 1) '(1 . 1))
c,32 [c' c' c,, c d e f g c e b' c'
]
}
\relative c' {
\mark\markup { \with-color #red "J" }
\once \override Beam #'stencil = #(grow-dir-var 2
'(-3.2 . -0.33) ; slope '(<first part of the first added beam>
; .
; <second part of the first added beam>)
'(42 . 0.05)) % slope '(<first part of the second added beam>
% .
% <second part of the second added beam>)
% to delete the first or second additional
% beam use '(#f . #f)
c32[ e g b d f a c]
}
Gruß,
Harm