lilypond-user
[Top][All Lists]
Advanced

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

Re: horizontal alignment of custom stencil


From: David Kastrup
Subject: Re: horizontal alignment of custom stencil
Date: Mon, 23 Jun 2014 11:39:36 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux)

Mark Knoop <address@hidden> writes:

> Hi,
>
> I'm (mis)using the Measure_counter_engraver to indicate numbers of
> repeats, overriding the default stencil with customStencilFromMarkup
> from openlilylib.
>
> Is it possible to adjust the horizontal alignment of the stencil such
> that it is always centered on the barline? The current situation varies
> depending on line breaks and changing time-signatures - see example
> below.
>
> Any suggestions?
>
>
> \version "2.18.2"
>
> customStencilFromMarkup =
> #(define-music-function (parser location name mrkup) (string? markup?)
>    (let* ((name (string-regexp-substitute " " "" name))
>                 ; remove any spaces
>           (name-components (string-split name #\.))
>           (context-name "Voice")
>           (grob-name #f))
>
>      (if (> 2 (length name-components))
>          (set! grob-name (car name-components))
>          (begin
>           (set! grob-name (cadr name-components))
>           (set! context-name (car name-components))))
>      #{
>        \override $context-name . $grob-name #'stencil =
>        #(lambda (grob)
>           (grob-interpret-markup
>            grob mrkup))
>      #}))
>
> repeatBars = #(define-music-function
>     (parser location times music)
>     (number? ly:music?)
>     (_i "make a repeat structure")
>     #{
>     \customStencilFromMarkup "Staff.MeasureCounter"
>       \markup \whiteout \box \concat {
>         \vcenter "×" \vcenter \number #(ly:number->string times)
>       }
>     \startMeasureCount
>     <<
>         \repeat volta #times { $music }
>         { s16 \stopMeasureCount }
>     >>
>     #})

This is not actually an answer to your problem at hand, but all that
name-splitting seems tedious.  You could just do

customStencilFromMarkup =
#(define-music-function (parser location name mrkup) (symbol-list? markup?)
     #{
       \override #name . stencil =
       #(lambda (grob)
          (grob-interpret-markup
           grob mrkup))
     #})

repeatBars = #(define-music-function
    (parser location times music)
    (number? ly:music?)
    (_i "make a repeat structure")
    #{
    \customStencilFromMarkup Staff.MeasureCounter
      \markup \whiteout \box \concat {
        \vcenter "×" \vcenter \number #(ly:number->string times)
      }
    \startMeasureCount
    <<
        \repeat volta #times { $music }
        { s16 \stopMeasureCount }
    >>
    #})

in 2.18.  It might be worth considering to exchange the order of name
and mrkup and turn name into the type symbol-list-or-music? instead,
then use a tweak rather than an override.  That way,
customStencilFromMarkup could be used as either a tweak or an override.
While swapping the argument order is not strictly necessary, combining
multiple tweaks becomes awkward fast if the music argument does not come
last.

-- 
David Kastrup



reply via email to

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