lilypond-user
[Top][All Lists]
Advanced

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

Retrieving Y-offset value in a music function how?


From: Nick Payne
Subject: Retrieving Y-offset value in a music function how?
Date: Mon, 24 Oct 2011 14:45:55 +1100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1

I have a barre function that, as well as the horizontal line indicating the duration of the barre, also has a vertical line at the LH end indicating the lowest note that the barre covers. However, it's a bit unsatisfactory in that I have to initially enter a guess for the length of the vertical line in staff units, and then produce the output and see if my guess needs altering. If I could find the distance that the TextSpanner is above the centre of the staff, then I should be able to change that parameter to be the position on the staff of the end of the line, and calculate it's length from those two values. From the internals reference it looks like the value I need is in the Y-offset setting, but how do I retrieve this value into a variable?

\version "2.15.14"

% Parameters:
% fretnum: the fret number for the barre - eg "VII"
% osp: outside staff priority, in case this needs altering from the default
% dirn: #UP or #DOWN
% vdrop: height of vertical line at LH end
% shorten: pair indicating left & right padding of TextSpanner
% adjBreak: adjust LH end of TextSpanner line when it has wrapped to following stave
% adjEnd: adjustment of line end when it wraps to following stave
barre = #(define-music-function (parser location fretnum osp dirn vdrop shorten adjBreak adjEnd)
    (string? number? number? number? pair? number? number?)
#{
    \once \override TextSpanner #'outside-staff-priority = #$osp
    \once \override TextSpanner #'bound-details #'left #'text =
    \markup\small\bold { \concat {
        \postscript #(string-append
            "0.1 setlinewidth 0.7 -0.5 moveto 0 -"
            (number->string $vdrop)
            " rlineto 0.5 0 rlineto stroke")
        $fretnum " "
    } }
    \once \override TextSpanner #'style = #'line
    \once \override TextSpanner #'font-shape = #'upright
    \once \override TextSpanner #'direction = #$dirn
    %draw a bracket edge on RHS
\once \override TextSpanner #'bound-details #'right #'text = \markup { \draw-line #(cons 0 (/ $dirn -1)) }
    % set alignment of line with reference to left text
\once \override TextSpanner #'bound-details #'left #'stencil-align-dir-y = #CENTER
    % change X pos of LH and RH end as desired
\once \override TextSpanner #'bound-details #'left #'padding = #(car $shorten) \once \override TextSpanner #'bound-details #'right #'padding = #(cdr $shorten)
    % allow adjustment of line end when it wraps to following stave
\once \override TextSpanner #'bound-details #'right-broken #'padding = #$adjEnd % adjust LH end of line when it wraps to following stave so that it doesn't
    % extend to the left of the notes on the stave
\once \override TextSpanner #'bound-details #'left-broken #'X = #$adjBreak
    % override to remove text and bracket edge at line breaks
    \once \override TextSpanner #'bound-details #'left-broken #'text = ##f
    \once \override TextSpanner #'bound-details #'right-broken #'text = ##f
#})

\relative c'' {
\barre "III" #0 #UP #4 #'(-1.5 . -1) #10 #0.5 f4.\startTextSpan f8 b4. d8\stopTextSpan
}

Attachment: barre.png
Description: PNG image


reply via email to

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