lilypond-user
[Top][All Lists]
Advanced

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

Re: Repeat signs / bar lines in markup


From: Thomas Morley
Subject: Re: Repeat signs / bar lines in markup
Date: Fri, 8 Feb 2013 00:24:02 +0100

Hi,

below a markup-command to print bar-lines.
For now it is limited to bar-lines containing thick-bar-line,
thin-bar-line and/or colon-bar-line.
Every additional bar-line (dashed, dotted etc) would need an
additional construction-procedure.

\bar-line follows the procedures in bar-line.scm, heavily simplified.
Some comments are included, where I'm not sure about the used values.

Please note: it is a first sketch, maybe there are some undetected issues.

Works with "2.16.1" and "2.17.10"

%%%%%%%%%%%%%%%%%%%%%%%%%

\version "2.16.1"

#(define-markup-command (bar-line layout props strg)(string?)
#:properties ((font-size 0))

  (define (string->string-list str)
    "Convert a string into a list of strings with length 1.
  @code{"aBc"} will be converted to @code{("a" "B" "c")}.
  An empty string will be converted to a list containing @code{""}."
    (if (and (string? str)
             (not (zero? (string-length str))))
        (map (lambda (s)
                     (string s))
             (string->list str))
        (list "")))

  (define (make-bar-line thickness height fontsize blot-diameter)
    "Draw a simple bar line."
    (ly:round-filled-box (cons 0 (* (magstep font-size) thickness))
                         (interval-widen (cons 0 height) (magstep font-size))
                         blot-diameter))

  (define (make-colon-bar-line height fontsize)
    "Draw repeat dots."
    (let* ((font
             (ly:paper-get-font layout
               (cons '((font-encoding . fetaMusic)) props)))
           (dot (ly:font-get-glyph font "dots.dot")))
       (ly:stencil-add
           dot
           (ly:stencil-translate-axis
             dot
             (magstep font-size)
             Y))))

    (let* ((line-thickness (ly:output-def-lookup layout 'line-thickness))
           (size (ly:output-def-lookup layout 'text-font-size 12))
           ;; Numerical values taken from the IR
           (thin-thickness (* line-thickness 1.9))
           (kern (* line-thickness 3.0))
           (thick-thickness (* line-thickness 6.0))
           (blot (ly:output-def-lookup layout 'blot-diameter))
           ;; Not sure about the numerical value, found it by try and error.
           (thin-bar-line
             (ly:stencil-aligned-to
               (make-bar-line thin-thickness (/ size 9) font-size blot)
               Y CENTER))
           (thick-bar-line
             (ly:stencil-aligned-to
               (make-bar-line thick-thickness (/ size 9) font-size blot)
               Y CENTER))
           (colon-bar-line
             (ly:stencil-aligned-to
               (make-colon-bar-line (/ size 9) font-size)
               Y CENTER))
           (strg-list (string->string-list strg))
           (find-bar-line-proc
              (lambda (x) (cond ((string=? ":" x) colon-bar-line)
                                ((string=? "|" x) thin-bar-line)
                                ((string=? "." x) thick-bar-line)
                                (else empty-stencil))))
           (bar-line-stils
             (remove ly:stencil-empty? (map find-bar-line-proc strg-list)))
           (stil
             (stack-stencils X
                             RIGHT
                             (* (magstep font-size) kern)
                             bar-line-stils))
           (stil-y-length (interval-length (ly:stencil-extent stil Y))))

      ;; Hm, hould the stencil-translate be hard-coded?
      (ly:stencil-translate-axis
        stil
        (/ stil-y-length 4)
        Y)
        ))

\markup
  \fontsize #2
  \column
  \override #'(box-padding . 0.5)
  {
    \line {
            "This is a starting-repeat-bar:"
            \hspace #1
              %\box
              \fontsize #-4
              \bar-line #".|:"
          }
    \line {
            "This is a ending-repeat-bar."
            \hspace #1
            %\box
              \fontsize #-4
                \bar-line #":|."
    }
    \line {
            "These are simple bar-lines."
            \tiny "(colon, thin, thick)"
            \hspace #1
            %\box
              \fontsize #-4
              \bar-line #":"
            \hspace #1
            %\box
              \fontsize #-4
              \bar-line #"|"
            \hspace #1
            %\box
              \fontsize #-4
              \bar-line #"."
    }

    \line {
            "Others."
            \hspace #1
            %\box
              \fontsize #-4
              \bar-line #":..:"
            \hspace #1
            %\box
              \fontsize #-4
              \bar-line #":|.|:"
            \hspace #1
            %\box
              \fontsize #-4
              \bar-line #":|..|:"
    }
  }

%%%%%%%%%%%%%%%%%%%%%%%%%

HTH,
  Harm

Attachment: bar-line.png
Description: PNG image


reply via email to

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