lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Combining custom bar line with standard elements


From: Thomas Morley
Subject: Re: Combining custom bar line with standard elements
Date: Sun, 6 Dec 2020 19:47:02 +0100

Am So., 6. Dez. 2020 um 17:53 Uhr schrieb Fr. Samuel Springuel
<rpspringuel@gmail.com>:
>
> > On 6 Dec, 2020, at 6:39 AM, Thomas Morley <thomasmorley65@gmail.com> wrote:
> >
> > \layout {
> >  \context {
> >    \Staff
> >    \override BarLine.before-line-breaking =
> >    #(lambda (grob)
> >      (let ((glyph (ly:grob-property grob 'glyph)))
> >        (if (and (string? glyph)
> >                 (or (string-contains glyph "[")
> >                     (string-contains glyph "]")))
> >            (begin
> >             (ly:grob-set-property! grob 'thick-thickness 2)
> >             (ly:grob-set-property! grob 'font-size -4)))))
> >  }
> > }
> >
> > \defineBarLine "[" #'("" "[" "")
> > \defineBarLine "]" #'("]" "" "")
> > \defineBarLine "]." #'("]." "" "")
> >
> > global = { \key f \major }
> >
> > music = {
> >  g' f' e' d' \bar "["
> >  f' g' a' g' \bar "|"
> >  f' e' c' d' \bar "]."
> > }
> >
> > \new Staff
> > <<
> >    \new Voice = "mel" { \global \music }
> >>>
> >
>
> The problem there is that the final bar line (the “.” Element) is also 
> thinned.  I want only the “]” element to be thinned.  All other elements of 
> the bar line should retain their default thickness.


Ok, then my initial understanding
> Iiuc, you want to change thick-thickness and font-size for barlines 
> containing "[" or "]".
was wrong. You rather want a different thick-thickness for the thick
line in bracket-barlines and for the thick-barline.
Since the same procedure, make-thick-bar-line, is per default used for
both, we need to define own bar-line-printing-procedures, reassigning
them the relevant glyphes.
For this purpose I look at (new invented)
BarLine.details.bracket-thick-thickness to distuingish it from default
thick-thickness.
This will cause a programming error _if_ compiled with -dcheck-internal-types:
programming error: Grob `BarLine' has no interface for property `details'
For now you can ignore it, imho.

Leading to (slightly modified copies from bar-line.scm):

#(define (make-my-thick-bar-line grob extent)
  "Draw a thick bar line."
  (let* ((line-thickness (layout-line-thickness grob))
         (thick (ly:grob-property grob 'thick-thickness 1))
         (details (ly:grob-property grob 'details))
         (bracket-thick
           (assoc-get 'bracket-thick-thickness details thick))
         (thickness (* bracket-thick line-thickness))
         (extent (bar-line::widen-bar-extent-on-span grob extent)))
    (bar-line::draw-filled-box
     (cons 0 thickness)
     extent
     thickness
     extent
     grob)))

#(define ((make-my-bracket-bar-line dir) grob extent)
  "Draw a bracket-style bar line. If @var{dir} is set to @code{LEFT}, the
opening bracket will be drawn, for @code{RIGHT} we get the closing bracket."
  (let* ((thick-stil (make-my-thick-bar-line grob extent))
         (brackettips-up (ly:font-get-glyph (ly:grob-default-font grob)
                                            "brackettips.up"))
         (brackettips-down (ly:font-get-glyph (ly:grob-default-font grob)
                                              "brackettips.down"))
         ;; the x-extent of the brackettips must not be taken into account
         ;; for bar line constructs like "[|:", so we set new bounds:
         (tip-up-stil
           (ly:make-stencil (ly:stencil-expr brackettips-up)
                            (cons 0 0)
                            (ly:stencil-extent brackettips-up Y)))
         (tip-down-stil
           (ly:make-stencil (ly:stencil-expr brackettips-down)
                            (cons 0 0)
                            (ly:stencil-extent brackettips-down Y)))
         (stencil (ly:stencil-add
                   thick-stil
                   (ly:stencil-translate-axis tip-up-stil
                                              (interval-end extent)
                                              Y)
                   (ly:stencil-translate-axis tip-down-stil
                                              (interval-start extent)
                                              Y))))

    (if (eqv? dir LEFT)
        stencil
        (flip-stencil X stencil))))

#(add-bar-glyph-print-procedure "[" (make-my-bracket-bar-line LEFT))
#(add-bar-glyph-print-procedure "]" (make-my-bracket-bar-line RIGHT))


#(define (set-bracket-bar-line-thick-thickness value)
  (lambda (grob)
    (let ((glyph (ly:grob-property grob 'glyph)))
      (if (and (string? glyph)
               (or (string-contains glyph "[")
                   (string-contains glyph "]")))
          (begin
           (ly:grob-set-nested-property!
             grob '(details bracket-thick-thickness) value)
           (ly:grob-set-property! grob 'font-size -4))))))

\layout {
  \context {
    \Staff
    \override BarLine.before-line-breaking =
    #(set-bracket-bar-line-thick-thickness 2)
  }
}

\defineBarLine "[" #'("" "[" "")
\defineBarLine "]" #'("]" "" "")
\defineBarLine "]." #'("]." "" "")

global = { \key f \major }

music = {
  g' f' e' d' \bar "["
  f' g' a' g' \bar "|"
  f' e' c' d' \bar "]."
}

\new Staff
<<
    \new Voice = "mel" { \global \music }
>>

Cheers,
  Harm



reply via email to

[Prev in Thread] Current Thread [Next in Thread]