Hi Marc,

Some observations:

the main problem seems to be the storing of the new stencils in an
alist and how to call them. Directly in bar-line::compound-bar-line
works.
Also, I created bar-line-stencil-alist-demo containing new stencils,
which are defined before. Calling them in bar-line::compound-bar-line
works too.
But I didn't manage to make it work with the original alist.

In addition I changed a line in bar-line::simple-bar-line otherwise
the barlines are printed misplaced in Y-direction.

HTH,
  Harm
\version "2.15.33"

#(define (new-stil-1 grob)
  (grob-interpret-markup grob (markup "1")))
  
#(define (new-stil-2 grob)
  (grob-interpret-markup grob (markup "2")))
  
#(define (new-stil-3 grob)
  (grob-interpret-markup grob (markup "3")))
  
#(define bar-line-stencil-alist-demo
  `(("|" . ,new-stil-1)
    ("." . ,new-stil-2)
    ("" . ,new-stil-3)
    ))

#(define (bar-line::calc-bar-extent grob)
  (let ((staff-symbol (ly:grob-object grob 'staff-symbol))
        (staff-extent (cons 0 0)))
       
       (if (ly:grob? staff-symbol)
           (let* ((bar-line-color (ly:grob-property grob 'color))
                  (staff-color (ly:grob-property staff-symbol 'color))
                  (radius (ly:staff-symbol-staff-radius grob))
                  (line-thickness (ly:staff-symbol-line-thickness grob)))

                 (set! staff-extent (ly:staff-symbol::height staff-symbol))
                 (if (and (eq? bar-line-color staff-color)
                          radius)
                     (interval-widen staff-extent
                       (- 1 (* 1/2 (/ line-thickness radius)))))))
       staff-extent))

#(define-public (bar-line::print grob)
   (let* ((glyph (ly:grob-property grob 'glyph-name))
          (bar-extent (ly:grob-property grob 'bar-extent '(0 . 0)))
          (extent (interval-length bar-extent))
          (stencil (if (and (not (eq? glyph '()))
                       (> extent 0))
                       (bar-line::compound-bar-line grob glyph extent #f))))
   stencil))
   
#(define (bar-line::simple-bar-line grob width extent rounded)
  (let ((blot (if rounded
                  (ly:output-def-lookup layout 'blot-diameter)
                  0)))
        (ly:round-filled-box (cons 0 width)
                             (cons (* -0.5 extent) (* 0.5 extent))
                             blot)))
%%{
#(define (bar-line::tick-bar-line grob height rounded)
  (let* ((half-staff (* 1/2 (ly:staff-symbol-staff-space grob)))
        (stafflinethick (ly:staff-symbol-line-thickness grob))
        (blot (if rounded
                  (ly:output-def-lookup layout 'blot-diameter)
                  0)))
        (ly:round-filled-box (cons 0 stafflinethick)
                            (cons (- height half-staff) (+ height half-staff))
                            blot)))
%} 

#(define bar-line-stencil-alist
  `(("|" . thin-stil)
    ("." . thick-stil)
    ("" . empty-stil)
    ))

#(define (bar-line::compound-bar-line grob glyph extent rounded)
   (let* ((staff-symbol (ly:grob-object grob 'staff-symbol))
          (line-count (if (ly:grob? staff-symbol)
                          (ly:grob-property staff-symbol 'line-count)
                          0))
          (staff-space (ly:staff-symbol-staff-space grob))
          (stafflinethick (ly:staff-symbol-line-thickness grob))
          (dist (if (or (odd? line-count)
                        (zero? line-count))
                    1
                    (* staff-space (if (< staff-space 2)
                                       2
                                       1/2))))
          (font (ly:grob-default-font grob))
          (dot (ly:font-get-glyph font "dots.dot"))
          (segno (ly:font-get-glyph font "scripts.varsegno"))
          (kievan (ly:font-get-glyph font "scripts.barline.kievan"))
          (kern (* (ly:grob-property grob 'kern 1)
                   stafflinethick))
          (thinkern (* (ly:grob-property grob 'thinkern 1)
                       stafflinethick))
          (hair (* (ly:grob-property grob 'hair-thickness 1)
                   stafflinethick))
          (fatline (* (ly:grob-property grob 'thick-thickness 1)
                      stafflinethick))
          (thin-stil (bar-line::simple-bar-line grob hair extent rounded))
          (thick-stil (bar-line::simple-bar-line grob fatline extent rounded))
          (empty-stil (make-filled-box-stencil (cons 0 0) (cons 0 extent)))
          (stencil (assoc-get glyph bar-line-stencil-alist-demo))
          (stencil (cond ((equal? glyph "|") thin-stil)
          	         ((equal? glyph ".") thick-stil)
          	         (else empty-stil))))
         stencil))              

music = \relative f {
  c'4 d e f | f f f f \bar "" | g g g g \bar "." g a b c \bar "||" 
  c c c c \bar "'" c b a g \bar "|:" f e d c \bar "|."
}

\score {
  \new Staff {
     \new Voice { \music }
  }
}

\score {
  \new Staff {
     \new Voice { 
       \override Staff.BarLine #'bar-extent = #bar-line::calc-bar-extent
       \override Staff.BarLine #'stencil = #bar-line::print
       \music
     }
  }
}
_______________________________________________
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel

Reply via email to