Here's a new function that's a little better than the previous one.
\version "2.17.21"
%% A markup-command for better viewing and the possibility
%% to read out some values
#(define-markup-command (rectangle layout props x) (number?)
" returns a rectangle "
(let ((osc (ly:output-def-lookup layout 'output-scale))
(pt (ly:output-def-lookup layout 'pt)))
;; (display "\n\t'output-scale \t")(write osc)
;; (display "\n\tpt from layout \t")(write pt)
;; (display "\n\t(* osc pt) \t")(write (* osc pt))
;; (newline)
(interpret-markup layout props
(markup #:stencil (make-filled-box-stencil `(0 . ,x) '(0 . 3))))))
\paper {
indent = 30
%% #(display "\n\tpt from within \\paper \t")
%% #(write pt)
}
\layout {
% Better viewing:
\override Score.RehearsalMark #'color = #red
\override Score.RehearsalMark #'layer = #10
\override Score.RehearsalMark #'extra-offset = #'(0 . -2.5)
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Test here with different values:
#(define staff-size 16)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#(set-global-staff-size staff-size)
%%%%%%% here's the function :
#(define (adjust-kern x-lngth)
(*(* 19.33 (- 1.004 (exp (* -0.03604 staff-size)))) x-lngth))
show =
#(define-music-function (parser location x-length)(number?)
"
returns some test-music, with the rectangle and tweaked BarLine.kern
"
#{
\set Staff.instrumentName =
\markup \fontsize #-1 \center-column {
"stencil/kern-length?"
#(number->string x-length)
}
R1
\mark \markup
\rectangle #x-length
\override Staff.BarLine.kern = #(adjust-kern x-length)
\bar "||"
R1
#})
\header {
title = "Adjust BarLine 'kern to stencil-extent"
subtitle = #(format #f "Used global-staff-size: ~a" staff-size)
subsubtitle = \markup \vspace #2
}
\show #1
\show #2
\show #10
\show #20
See herewith the comparaison between the measured figures (blue curve) and the calculated ones (orange curve).
I'm still very curious about what you'll do with it...