lilypond-user
[Top][All Lists]
Advanced

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

Re: Override SystemStartSquare width?


From: Thomas Morley
Subject: Re: Override SystemStartSquare width?
Date: Sat, 19 Nov 2016 10:15:37 +0100

2016-11-19 0:25 GMT+01:00 Thomas Morley <address@hidden>:

> Will have a look at it the upcoming weekend.
>
> Cheers,
>   Harm

Hi Dimitris,

the code below takes the default-stencil for SystemStartSquare and
messes around with it's stencil-expression.
Does it fit your needs?
You will need to manually figure out the needed padding-value, though.
See doc-strings how to use it.

\version "2.19.49"

#(define (lists-map function ls)
"Apply @var{function} to @var{ls} and all of it sublists.
First it recurses over the children, then the function is applied to
@var{ls}."
  (if (list? ls)
      (set! ls (map (lambda (y) (lists-map function y)) ls))
      ls)
  (function ls))

#(define (change-width x y)
"Adds values @var{x} and @var{y} to certain elements of a list, which starts
with @code{'draw-line}."
  (lambda (e)
    (if (and (list? e) (member 'draw-line e))
        `(,@(take e 3)
          ,((if (negative? (fourth e)) + -) (fourth e) y)
          ,(if (not (zero? (fifth e))) (+ x (fifth e)) (fifth e))
          ,((if (negative? (last e)) + -) (last e) y))
        e)))

#(define* (resize-square x #:optional (y #t))
"Applies @code{change-width} to the stencil-expression of a grob, which is
supposed to be SystemStartSquare.

@var{x} will resize the length of the horizontal wings.

The optional @var{y} affects the general size in Y-direction, it's default is
@code{#t}:
- SystemStartSquare is off by half staff-line-thickness compared to the staves,
this default may or may not be intended. The default for @var{y} corrects it.
- If set to a number the size is freely customizable.
- If set to false, the size in Y-direction is not touched.

Using this procedure causes the need to reset the padding of the
SystemStartSquare.
"
  (lambda (grob)
    (let* ((default-stil (ly:system-start-delimiter::print grob))
           (staff-line-thick (ly:staff-symbol-line-thickness grob))
           (y-corr
             (cond ((number? y) (- y))
                   ((eq? #t y) (/ staff-line-thick 2))
                   (else 0))))
      ;; n.b.
      ;; the final stencil has the same x- and y-extent as the original
      (ly:make-stencil
        (lists-map (change-width x y-corr) (ly:stencil-expr default-stil))
        (ly:stencil-extent default-stil X)
        (ly:stencil-extent default-stil Y)))))

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

\new StaffGroup
  \with {
    \override SystemStartBracket.padding = 0.5
    systemStartDelimiter = #'SystemStartBracket
  }
  <<
      \new Staff { c'4 }
    \new StaffGroup
      \with {
        %% next two commands for better visibility only
        %\override SystemStartSquare.color = #cyan
        %\override SystemStartSquare.layer = 2000
        \override SystemStartSquare.stencil = #(resize-square 0.8)
        \override SystemStartSquare.padding = -0.2
        systemStartDelimiter = #'SystemStartSquare
      }
    <<
      \new StaffGroup
        \with {
          %% next command for better visibility only
          %\override SystemStartSquare.color = #red
          \override SystemStartSquare.stencil = #(resize-square 1.6)
          \override SystemStartSquare.padding = -0.2
          systemStartDelimiter = #'SystemStartSquare
        }
       <<
        \new Staff { c'4 }
        \new Staff { c'4^\markup \draw-line #'(0 . 10) }
       >>

      \new Staff { c'4 }
    >>
    \new Staff { c'4 }
  >>

HTH,
  Harm



reply via email to

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