Re: Custom Bar Line for Renaissance Polyphony

Thomas Morley <[email protected]> Mon, 27 Jul 2026 16:21:33 +0200
Newsgroups gmane.comp.gnu.lilypond.general
Message-ID <CABsfGyVx6U-Du9Ze7gdTeKyYcUvZko4SoEAi+vTB_sbMCbq8XA@mail.gmail.com>
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 (screensh=
ot):
>
>
>
> (The code is attached.)
>
>
> My approach is inspired by Harm=E2=80=99s solution here =E2=80=A6
>
> https://www.mail-archive.com/[email protected]/msg101994.html
>
> https://lists.gnu.org/archive/html/lilypond-user/2015-05/msg00416.html
>
>
> =E2=80=A6 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 =E2=80=94 I would like it to mirror make-up-tick-=
bar-line =E2=80=94 i.e., find the lowest staff line and extend down from th=
ere. But I haven=E2=80=99t been able to build that in my experimentation.
> Edges =E2=80=94 IIUC, LilyPond=E2=80=99s *tick* bar lines are rounded box=
es, but *normal* bar lines are squared off to meet the edge of the staff li=
ne 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 l=
ine. But I don=E2=80=99t 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 =3D #2
  %\override Staff.StaffSymbol.line-positions =3D #'(-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