lilypond-user
[Top][All Lists]
Advanced

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

Enhancing barre function


From: Nick Payne
Subject: Enhancing barre function
Date: Mon, 16 Feb 2009 18:51:06 +1100

I have a barre function for guitar scores that I would like to enhance by
adding a vertical line indicating how far the barre should extend across the
fretboard. As a test I took the existing barre function and added some
hard-coded Postscript that draws a line of fixed vertical height. I can add
an additional parameter giving the distance in staff units above or below
the centre of the stave where I want this line to terminate, but what I
don't know how to do is to calculate the vertical distance from this point
to where the barre text and horizontal line are going to be drawn, and use
this value in the Postscript code. Can someone point me to where in the LP
installation tree (on Windows) I will find some examples of music functions
that retrieve information in this way. I'm a reasonably competent programmer
in several other languages (going all the way back to Fortran and assembler
in the 1970s) but I've never used Scheme.

Here's the present function with the hard-coded Postscript:

%====================================================
\version "2.12.2"

% more attractive barring indication than the inbuilt one
% Example:
%
%       \barre "CI " #0 #'(-1 . -1) #10 #1
%       <g,-2>\startTextSpan <c-3> <bf'-4>-> <ef,-1> <af-1>-> <c,-3>    
%       g c bf'-> ef, af-> c,\stopTextSpan 
%
barre = #(define-music-function (parser location text vertAdj shorten
adjBreak adjEnd) (string? number? pair? number? number?) #{
        % set vertAdj to 999 if spanner is colliding with another element
        % this will position the spanner outside all other elements
        % can be normally be set to zero
        \once \override TextSpanner #'outside-staff-priority = #$vertAdj
        
        \once \override TextSpanner #'bound-details #'left #'text = \markup
{ \combine $text 
                \postscript #"0.1 setlinewidth 0.5 -0.3 moveto 0 -4 rlineto
stroke 0.5 -4.3 moveto 0.5 0 rlineto stroke" }
        \once \override TextSpanner #'style = #'line
        \once \override TextSpanner #'font-shape = #'upright
        %draw a bracket edge on RHS
        \once \override TextSpanner #'bound-details #'right #'text = \markup
{ \draw-line #'(0 . -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 set by shorten parameter:
normally -ve
        \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
        % optional 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
#})

% test
\relative c' {
        \barre "CVII " #0 #'(-2.2 . -1) #10 #1
        <b d' gis b>4\startTextSpan <b d' gis b> <b d' gis b> <b d' gis
b>\stopTextSpan 
} 
%==================================================

Nick





reply via email to

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