Am Sa., 25. Juli 2026 um 11:02 Uhr schrieb Gabriel Ellsworth
<[email protected]>:
>
> I am creating a custom bar line style for Renaissance polyphony (screenshot):
>
>
>
> (The code is attached.)
>
>
> My approach is inspired by Harm’s solution here …
>
> https://www.mail-archive.com/[email protected]/msg101994.html
>
> https://lists.gnu.org/archive/html/lilypond-user/2015-05/msg00416.html
>
>
> … and also by the tick bar line style in
>
> https://github.com/lilypond/lilypond/blob/master/scm/bar-line.scm.
>
>
> I would like to improve this draft in the following ways and need help:
>
> make-down-tick-bar-line — I would like it to mirror make-up-tick-bar-line — 
> i.e., find the lowest staff line and extend down from there. But I haven’t 
> been able to build that in my experimentation.
> Edges — IIUC, LilyPond’s *tick* bar lines are rounded boxes, but *normal* bar 
> lines are squared off to meet the edge of the staff line where they end. My 
> style requires (ideally) a box with one rounded edge (the edge that touches 
> nothing) and one squared-off edge to touch a staff line. But I don’t know how 
> to build that.
>
> Thank you in advance!
>
> Gabriel


Here my take on it, extending/improving my previous coding:

\version "2.27.0"

#(define bar-line::calc-blot
;Redefine the internal `bar-line::calc-blot`.
(@@ (lily) bar-line::calc-blot))

#(define (staff-lines-extent grob)
"Return a number-pair representing the position of bottom/top staff-lines.
If no staff-lines are present '(0 . 0) is returned."
;; The provided default extent is for normal bar lines, which do not
;; necessarily end at the top staff line: they are expected to be
;; extended if the staff is vertically short, and it is always
;; possible for BarLine.bar-extent to be overridden.
  (let* ((staff-symbol (ly:grob-object grob 'staff-symbol))
         (line-pos (ly:grob-property staff-symbol 'line-positions))
         (half-staff (* 1/2 (ly:staff-symbol-staff-space grob)))
         (max-pos
           (if (pair? line-pos) (apply min line-pos) 0))
         (min-pos
           (if (pair? line-pos) (apply max line-pos) 0)))
    (ordered-cons (* half-staff min-pos) (* half-staff max-pos))))

#(define (make-up-tick-bar-line is-span grob extent)
  (let* ((line-thickness (layout-line-thickness grob))
         (thickness (* (ly:grob-property grob 'hair-thickness 1)
                       line-thickness))
         (staff-space (ly:staff-symbol-staff-space grob))
         (height (interval-end (staff-lines-extent grob))))
    ;; Bypass bar-line::draw-filled-box to ignore the 'roundness property.
    (ly:round-filled-box (cons 0 thickness)
                         (cons height (+ height (* 0.5 staff-space)))
                         (bar-line::calc-blot thickness extent grob))))

#(define (make-down-tick-bar-line is-span grob extent)
  (let* ((line-thickness (layout-line-thickness grob))
         (thickness (* (ly:grob-property grob 'hair-thickness 1)
                       line-thickness))
         (staff-space (ly:staff-symbol-staff-space grob))
         (bottom (interval-start (staff-lines-extent grob))))
    ;; Bypass bar-line::draw-filled-box to ignore the 'roundness property.
    (ly:round-filled-box (cons 0 thickness)
                         (ordered-cons bottom (- bottom (* 0.5 staff-space)))
                         (bar-line::calc-blot thickness extent grob))))

#(define (make-both-tick-bar-line is-span grob extent)
  (ly:stencil-add
    (make-up-tick-bar-line is-span grob extent)
    (make-down-tick-bar-line is-span grob extent)))

#(add-bar-glyph-print-procedure "u" make-up-tick-bar-line)
#(define-bar-line "u" "u" #f #f)

#(add-bar-glyph-print-procedure "d" make-down-tick-bar-line)
#(define-bar-line "d" "d" #f #f)

#(add-bar-glyph-print-procedure "b" make-both-tick-bar-line)
#(define-bar-line "b" "b" #f #f)

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

\layout {
  %\override Staff.StaffSymbol.line-count = #2
  %\override Staff.StaffSymbol.line-positions = #'(-8 -2)
}

{
  r1 \bar "u" r \bar "u" \break
  r \bar "d" r \bar "d" \break
  r \bar "b" r \bar "b" \break
}

Cheers,
  Harm

Reply via email to