LilyPond and barres

Theory and practice of composition and arranging for classical guitar, discussion of works in progress, etc.
Forum rules
III Our MP3, WMV, MOV, OGG, AVI, Authors' rights

Composers' Workshop
Theory and practice of composition and arranging for classical guitar, discussion of works in progress, etc.

Once you have subscribed to the 002 group, you can attach the following types of files to your messages:
Audio : .mp3 .ogg .wav .flac
Video : .avi .flv .mov .wmv
Score : .pdf .jpg .gif .png
Finale: .mus
User avatar
Paul
Posts: 6531
Joined: Sun Nov 25, 2007 9:18 am
Location: Cape Town, South Africa

LilyPond and barres

Post by Paul » Wed Jul 14, 2010 5:33 pm

I was trying to make a decent set of barres and I got this post by Nick Payne:

http://old.nabble.com/Re%3A-Barres-and- ... 34004.html

The code is a monster, but works extremely well.

I've only made one change to it, which is to remove the fullstop between the "C" and the fret number.

Code: Select all

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% more attractive barring indication than the inbuilt one 
% Parameters 
% 
% "<fretnum>"        % fret number (eg "5") 
% #osp               % outside-staff-priority - normally set to #0 unless barre is colliding with other elements 
% #dirn              % set to #UP for above the staff, #DOWN for below 
% #'(lpad . rpad)    % left and right padding to apply to TextSpanner (shorten or lengthen) 
% #adjBreak          % when barre wraps to following stave, set value to prevent TextSpanner on following stave starting above the clef symbol 
% #adjend            % when barre wraps to following stave, set value to prevent TextSpanner going to the very end of the stave 
% 
% Example: 
%    \barre "5" #0 #UP #'(-0.5 . -1) #8 #1 
% <g,-2>\startTextSpan <c-3> <bf'-4>-> <ef,-1> <af-1>-> <c,-3>\stopTextSpan 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
barre = #(define-music-function (parser location fretnum osp dirn shorten adjBreak adjEnd) (string? number? number? pair? number? number?) 
#{ 
     \once \override TextSpanner #'outside-staff-priority = #$osp 
     \once \override TextSpanner #'bound-details #'left #'text = \markup { \small { \concat { "C" $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 
     % 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 
#}) 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%
%and here's one for half barres that slashes the C and subscripts the 
%number of strings covered: 
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% 
% postscript slash for half barres 
#(define slash "0.18 setlinewidth 0.76 1.53 moveto 0 -1.62 rlineto stroke") 
% 
% Half barre 
% Parameters 
% 
% "<fretnum>"        % fret number (eg "5") 
% "<partial>"        % number of strings to cover - subscripted to the fret number 
% #osp               % outside-staff-priority - normally set to #0 unless barre is colliding with other elements 
% #dirn              % set to #UP for above the staff, #DOWN for below 
% #'(lpad . rpad)    % left and right padding to apply to TextSpanner (shorten or lengthen) 
% #adjBreak          % when barre wraps to following stave, set value to prevent TextSpanner on following stave starting above the clef symbol 
% #adjend            % when barre wraps to following stave, set value to prevent TextSpanner going to the very end of the stave 
% 
% Example: 
%    \hbarre "5" "3" #0 #UP #'(-0.5 . -1) #8 #1 
% <g,-2>\startTextSpan <c-3> <bf'-4>-> <ef,-1> <af-1>-> <c,-3>\stopTextSpan 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hbarre = #(define-music-function (parser location fretnum partial osp dirn shorten adjBreak adjEnd) (string? string? number? number? pair? number? number?) 
#{ 
     \once \override TextSpanner #'outside-staff-priority = #$osp 
     \once \override TextSpanner #'bound-details #'left #'text = \markup { \small { \concat { \postscript #slash "C" $fretnum \raise #0.8 \sub $partial " " } } } 
     \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 
     % 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 
#}) 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
To see the barres in action you can have a look at Lagrima posted here: viewtopic.php?f=12&t=51380

Paul

DanielMcPherson

Re: LilyPond and barres

Post by DanielMcPherson » Wed Jul 14, 2010 7:22 pm

Thanks for this! That is some confusing looking code, but the results are nice.

I've been doing things like this:

Code: Select all

mySetTextSpannerIIIfive =
{
  \override TextSpanner #'(bound-details left text) = \markup { \concat { III \sub {5} } }
}
followed by:

Code: Select all

  \mySetTextSpannerIIIsix
  \mySetTextSpannerRight
  d4.\startTextSpan e8 d4\stopTextSpan

which looks like this:
barre.jpg
I like the solid line much better. Also my version required some tweaking to make the barre line go all the way to the end of the measure.

I found and removed this bit

Code: Select all

 \postscript #slash "C"
from the \hbarre definition to get the partial barres with no slashed "C". Like this:
barre2.jpg
I saved the code to a file called "barres.ly" so I just have to do

Code: Select all

\include "barres.ly"
at the top of any new ly files.

[*Edit: I came to my senses and realized that the correct filename should be "barres.ly" and not "barres.h". The computer programmer in me wanted to see the word "include" and instinctively use C/C++ naming conventions.]

Thanks again for sharing this! I've been struggling with barres in LilyPond for a while. This is a keeper.
You do not have the required permissions to view the files attached to this post.
Last edited by DanielMcPherson on Thu Jul 15, 2010 1:55 am, edited 1 time in total.

John Kotopka

Re: LilyPond and barres

Post by John Kotopka » Wed Jul 14, 2010 7:27 pm

This is excellent Paul!

A couple of other things I noticed: You very cleverly put the LH fingerings on the right side of the notes that have accidentals, except for measure 12. I have been having trouble getting the fingering indications to line up properly when they are on the left and there is an accidental, I hadn't thought of putting them on the right. In measure 12, though, how did you get the spacing correct without overlapping the D# accidental?

Actually I have several other questions about this, could you paste the entire Lilypond in a Code block somewhere in this or the other topic?

User avatar
Paul
Posts: 6531
Joined: Sun Nov 25, 2007 9:18 am
Location: Cape Town, South Africa

Re: LilyPond and barres

Post by Paul » Wed Jul 14, 2010 7:52 pm

No problem. This was actually one of the first things I tried in LilyPond a few years ago and then left it until I tried to re-print the other day and it didn't work, even after doing the convert-ly. It's got some notes to myself as I was (am) learning the stuff. Also there is probably some extraneous code when copying from different scores.

The fingering on the left and right was done using "\set fingeringOrientations = #'(left)" etc.

With all the barre stuff being defined towards the top it's probably easier to read from the bottom. ;)

Code: Select all

\version "2.12.3"                                                               %VERY NB for converting to later versions

\paper{ #(set-paper-size "a4")
top-margin = 15
bottom-margin = 10
left-margin = 15
line-width = 180
indent = 10
% between-system-space = 1.5\cm   %adds space below
between-system-padding = #6  %add space above and below
%   page-count = 3           %not required here
ragged-last-bottom = ##t
}

\header {
    title = "Lágrima"
    composer = \markup \right-column {"Francisco Tárrega" "(1852-1909)" }
    copyright = \markup \center-column { \tiny "Source: The Royal Library of Copenhagen University. http://img.kb.dk/ma/RiBSms/RiBSms-234b.pdf"}
}                                                                               %end of \header block

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% more attractive barring indication than the inbuilt one 
% Parameters 
% 
% "<fretnum>"        % fret number (eg "5") 
% #osp               % outside-staff-priority - normally set to #0 unless barre is colliding with other elements 
% #dirn              % set to #UP for above the staff, #DOWN for below 
% #'(lpad . rpad)    % left and right padding to apply to TextSpanner (shorten or lengthen) 
% #adjBreak          % when barre wraps to following stave, set value to prevent TextSpanner on following stave starting above the clef symbol 
% #adjend            % when barre wraps to following stave, set value to prevent TextSpanner going to the very end of the stave 
% 
% Example: 
%    \barre "5" #0 #UP #'(-0.5 . -1) #8 #1 
% <g,-2>\startTextSpan <c-3> <bf'-4>-> <ef,-1> <af-1>-> <c,-3>\stopTextSpan 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
barre = #(define-music-function (parser location fretnum osp dirn shorten adjBreak adjEnd) (string? number? number? pair? number? number?) 
#{ 
     \once \override TextSpanner #'outside-staff-priority = #$osp 
     \once \override TextSpanner #'bound-details #'left #'text = \markup { \small { \concat { "C" $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 
     % 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 
#}) 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%
%and here's one for half barres that slashes the C and subscripts the 
%number of strings covered: 
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% 
% postscript slash for half barres 
#(define slash "0.18 setlinewidth 0.76 1.53 moveto 0 -1.62 rlineto stroke") 
% 
% Half barre 
% Parameters 
% 
% "<fretnum>"        % fret number (eg "5") 
% "<partial>"        % number of strings to cover - subscripted to the fret number 
% #osp               % outside-staff-priority - normally set to #0 unless barre is colliding with other elements 
% #dirn              % set to #UP for above the staff, #DOWN for below 
% #'(lpad . rpad)    % left and right padding to apply to TextSpanner (shorten or lengthen) 
% #adjBreak          % when barre wraps to following stave, set value to prevent TextSpanner on following stave starting above the clef symbol 
% #adjend            % when barre wraps to following stave, set value to prevent TextSpanner going to the very end of the stave 
% 
% Example: 
%    \hbarre "5" "3" #0 #UP #'(-0.5 . -1) #8 #1 
% <g,-2>\startTextSpan <c-3> <bf'-4>-> <ef,-1> <af-1>-> <c,-3>\stopTextSpan 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hbarre = #(define-music-function (parser location fretnum partial osp dirn shorten adjBreak adjEnd) (string? string? number? number? pair? number? number?) 
#{ 
     \once \override TextSpanner #'outside-staff-priority = #$osp 
     \once \override TextSpanner #'bound-details #'left #'text = \markup { \small { \concat { \postscript #slash "C" $fretnum \raise #0.8 \sub $partial " " } } } 
     \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 
     % 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 
#}) 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

startBarre = \startTextSpan 
stopBarre = \stopTextSpan
fingerL = \set fingeringOrientations = #'(left)  %save some space
fingerR = \set fingeringOrientations = #'(right) %save some more space

\score {                                                                        %start of \score block

{

% \set Staff.midiInstrument = "acoustic guitar (nylon)"                           %set midi instrument
\set Staff.instrumentName = "Guitar"
\set Score.stringNumberOrientations = #'(down)                                  %all string numbers below staff

#(override-auto-beam-setting '(end * * * *) 1 4 'Staff)                         %quaver beams in crotchet pairs
#(override-auto-beam-setting '(end * * * *) 2 4 'Staff)
#(override-auto-beam-setting '(end * * * *) 3 4 'Staff)

\repeat volta 2 {                                                               %section 1 is repeated so we start it here
  
  \clef "G_8" \key e \major \time 3/4                                             %clef with octave indication
  \once \override Score.RehearsalMark #'padding = #3.5
  \mark \markup { \bold "Andante"}

  <<{ \fingerL <gis'-4>4 <a'-4> <b'-4> }\\
    { \fingerL \override Stem #'length-fraction = #(magstep -3) gis'8 <b-0> a' b b' b \revert Stem #'length-fraction }\\
    { \override NoteColumn #'force-hshift = #-1 \stemDown \fingerL  <e-1>4 <fis-2> <gis-2> }>>
  
  <<{ <fis'-4>2. }\\
    { \override Stem #'length-fraction = #(magstep -4) \mergeDifferentlyDottedOn \mergeDifferentlyHeadedOn \fingerL <fis'>8 b \revert Stem #'length-fraction <a-3> b <b,-2> b }\\
    { \stemDown \once \override Dots #'extra-offset = #'(-1.3 . 0) <dis-1>2. }>>

  <<{ gis'4 a' b' }\\
    { \override Stem #'length-fraction = #(magstep -3)gis'8 b a' b b' b \revert Stem #'length-fraction }\\
    { \override NoteColumn #'force-hshift = #-1 \stemDown e4 fis gis }>>
  
  <<{ fis'2. }\\
    { \override Stem #'length-fraction = #(magstep -4) \mergeDifferentlyDottedOn \mergeDifferentlyHeadedOn fis'8 b \revert Stem #'length-fraction a b b, b }\\
    { \stemDown \once \override Dots #'extra-offset = #'(-1.3 . 0) dis2. }>>

  <<{ e''4 dis'' cis''}\\
    { \override StringNumber #'extra-offset = #'(0.0 . -1.5) \hbarre "IX" "4" #0 #UP #'(-0.5 . -1) #8 #1 <e''-4>8\startBarre <e'-1\3> <dis''-4> <e'\3>\stopBarre \hbarre "VII" "4" #0 #UP #'(-0.5 . -1) #8 #1 <cis''-4>\startBarre <fis'-1\2> } \\
    { \override StringNumber #'extra-offset = #'(0.0 . -1.5) \stemDown <cis'-3\4>4  <b-1\4>  <a-1\4> }>>
  
  <<{ \override StringNumber #'extra-offset = #'(0.0 . -1.5) b'4 <cis'-3>8 <e'-1\3> <fis'-4\3> <a'-2\2> }\\
    { \override StringNumber #'extra-offset = #'(0.0 . -1.5) <b'-1>8 <gis'-4\2>\stopBarre <cis'-3\4>2 }\\
    { \override StringNumber #'extra-offset = #'(0.0 . -1.5) \textSpannerDown \override TextSpanner #'extra-offset = #'(0.0 . 0.0) \override TextSpanner #'(bound-details left text) = "rit." \stemDown <b-3\4>4 s4\startTextSpan s4 }>>
  
  <<{ gis'4\fingerR \hbarre "II" "5" #0 #UP #'(-0.5 . -1) #8 #1 <cis'-1>8\startBarre <fis'-1> <b,-1> <a-1 dis'-4>\stopBarre }\\
    { \hbarre "IV" "3" #0 #UP #'(-0.5 . -1) #8 #1 <gis'-1>8\startBarre <e'-2>\stopBarre \fingerR <ais-2>4 b, }\\
    { \stemDown <b-1>4 s2 }>>
  
  <<{ e'2 r4^\markup \halign #-1.0 { "Fine" } }\\
    { \fingerL <gis-1>2 r4 }\\
    { \override NoteColumn #'force-hshift = #0.0 \stemDown <e-2>4\stopTextSpan e,4 s }>>
  
}


\repeat volta 2 {
  
  \key g \major
  
  <<{ \fingerL <g'-2>8\glissando \stemDown \grace <c''-2> \stemUp \slurDown c''( <b'-1>) <e'-0>
      \fingerR \hbarre "II" "5" #0 #UP #'(-0.5 . -1) #8 #1 <a-1 dis'-3 fis'-1>8\startBarre <g'-2>\stopBarre }\\
    { <e, b>2 <b,-1>4 }>>
  
  <<{ e'2. }\\
    { \fingerL e'8 <a-3 c'-1>_\markup { \column {
          \teeny \line { \bold \circle "3" "· · · · · · · · · · · · · · ·"}
          \raise #1.0 \teeny \line { \bold \circle "4" "· · · · · · · · · · · · · · ·"} } }
      <g-2 b-1> <fis-3 a-1> <e-2 g-0> <fis a> }\\
    { \stemDown e,2. }>>
  
  <<{ \fingerL <g-0 b-0>8 <e''-4>  <a-1> <c''-2> <fis-3> <a'-4\2> }\\
     { e,4 <a\4> <fis\5> }>>
   
  <<{ \once \override Voice.Fingering #'padding = #2 <fis'-1 dis'-2>2. }\\
    { \barre "VII" #0 #UP #'(-0.5 . -1) #8 #1 dis'8\startBarre \slurUp <b-3>(_\markup { \teeny { \bold \circle "4" "· · · · · · · ·"} } <c'-4>) <b-3>\stopBarre <b-0> <fis'-2> }\\
    { \fingerL \stemDown \once \override StringNumber #'extra-offset = #'(0.5 . -1.5)
      <b,-1\6>2. }>>
   
  <<{ <g'-3>4 <a'-3> <b'-4> }\\
    { \override Stem #'length-fraction = #(magstep -3)g'8 <b-0> a' b b' b \revert Stem #'length-fraction }\\
    { \override NoteColumn #'force-hshift = #-1 \stemDown <e-1>4 <fis-1> <g-1> }>>
  
  <<{ \slurDown <d''-4>8( <c''-2>) <b'-1> <a'-4>_\markup { \teeny { \bold \circle "2" "· · · · · · · ·"} } <g'-2> <fis'-1> }\\
    { a,2. }>>
   
  <<{ <e'-3>4 <fis'-4> <b-0>8 \fingerR <a-3> }\\
    { \textSpannerDown \override TextSpanner #'(bound-details left text) = "rit." e'8\startTextSpan <g-2 b-1> <fis'\2> <a-3 c'-1> <b,-2> \fingerR <dis-1> }>>
 
  <<{ e'2 r4^\markup \halign #0 { "D.C. al Fine" } }\\
    { g2\stopTextSpan r4 }\\
    { \override NoteColumn #'force-hshift = #0.0 \stemDown \fingerL <e-2>4 e,4 s }>>
 
 }                                                                               %section 2's repeat ends here

 
 
}                                                                               %notation ends here

% \midi {}                                                                        %produce midi file
\layout {}                                                                      %also a score please

}                                                                               %end of \score block
DanielMcPherson wrote:I saved the code to a file called "barres.h" so I just have to do

Code: Select all

\include "barres.h"
at the top of any new ly files.
That's one thing I haven't done. It would definitely tidy up the score's code. It does make me nervous, though, not having all my code for a piece in one place.

Paul

DanielMcPherson

Re: LilyPond and barres

Post by DanielMcPherson » Wed Jul 14, 2010 8:09 pm

Some other tips:

1) When the entire measure is barred, I like my barre lines to extend closer to the end of the measure instead of stopping right over the last note. To do this, increase the rpad parameter to a larger negative value. That is:

Code: Select all

\hbarre "V" "4" #0 #UP #'(-0.5 . -3) #8 #1
                 This number -----^
You'll have to tweak this value on a measure-by-measure basis, but -3 is generally getting the end of the barre line where I want it.

2) To put a barre over a single note,
barre3.jpg
add an invisible rest as a grace note so you have something to attach the \startTextSpan to.

Code: Select all

  \grace s8\startTextSpan <b-4>2. \stopTextSpan
I'm open to suggestions on better ways to accomplish this.
You do not have the required permissions to view the files attached to this post.

User avatar
Paul
Posts: 6531
Joined: Sun Nov 25, 2007 9:18 am
Location: Cape Town, South Africa

Re: LilyPond and barres

Post by Paul » Wed Jul 14, 2010 8:11 pm

That last point is pretty clever. :lol:

wilhelmreich

Re: LilyPond and barres

Post by wilhelmreich » Mon Oct 07, 2013 1:06 pm

Thank you all. This thread is three years old and maybe Lilypond had some major changes in this years, because the bar snippet doesn't work for me. If I try to include and use barre.ly I get error messages (unfortunately in german). Is there a workaround for this?

Code: Select all

D:/files/Backups/tmp/tmp/lp/barre.ly:19:65: Fehler: GUILE signalisierte einen Fehler für den hier beginnenden Ausdruck
         \once \override TextSpanner #'outside-staff-priority = #
                                                                 $osp

D:/files/Backups/tmp/tmp/lp/barre.ly:23:52: Fehler: GUILE signalisierte einen Fehler für den hier beginnenden Ausdruck
         \once \override TextSpanner #'direction = #
                                                    $dirn

D:/files/Backups/tmp/tmp/lp/barre.ly:25:93: Fehler: GUILE signalisierte einen Fehler für den hier beginnenden Ausdruck
         \once \override TextSpanner #'bound-details #'right #'text =  \markup { \draw-line #
                                                                                             (cons 0 (/ $dirn -1)) }

D:/files/Backups/tmp/tmp/lp/barre.ly:25:92: Fehler: falscher Typ für Argument 1; pair of numbers erwartet, #<unspecified> gefunden
         \once \override TextSpanner #'bound-details #'right #'text =  \markup { \draw-line 
                                                                                            #(cons 0 (/ $dirn -1)) }

User avatar
Schneider
Posts: 466
Joined: Tue Jul 26, 2011 9:34 am
Location: Paris, France

Re: LilyPond and barres

Post by Schneider » Tue Oct 08, 2013 4:45 pm

Hi wilhelmreich,

Few remarks :

1) The code that you're using is pretty old ; unfortunately, your error messages do not help to determine which version you are using.
If you have v.2.16, there is a barré code in the documentation :
http://lilypond.org/doc/v2.16/Documenta ... anner_0029

For some reason, the case number stays on the right ; here's the code to put it on the left :

Code: Select all

\version "2.16.2"

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% %%%%%%%  Cut here ----- Start 'bbarred.ly'

%% C with slash -------------------------------
cWithSlash = \markup {
  \combine \roman C \translate #'(0.6 . -0.4) \draw-line #'(0 . 2.0)
}
%% Span -----------------------------------
%% Syntax: \bbarre #"text" { notes } - text = any number of box
bbarre =
#(define-music-function (barre location str music) (string? ly:music?)
   (let ((elts (extract-named-music music '(NoteEvent EventChord))))
     (if (pair? elts)
         (let ((first-element (first elts))
               (last-element (last elts)))
           (set! (ly:music-property first-element 'articulations)
                 (cons (make-music 'TextSpanEvent 'span-direction -1)
                       (ly:music-property first-element 'articulations)))
           (set! (ly:music-property last-element 'articulations)
                 (cons (make-music 'TextSpanEvent 'span-direction 1)
                       (ly:music-property last-element 'articulations))))))
   #{
       \once \override TextSpanner #'font-size = #-2
       \once \override TextSpanner #'font-shape = #'upright
       \once \override TextSpanner #'staff-padding = #3
       \once \override TextSpanner #'style = #'line
       \once \override TextSpanner #'to-barline = ##f
       \once \override TextSpanner #'bound-details =
            #`((right
                (text . ,#{ \markup { \draw-line #'( 0 . -.5) } #})
                (Y . 0)
                (padding . 0.25)
                (attach-dir . 2))
               (left
                (text . ,#{ \markup { \cWithSlash #str } #})
                (Y . 0)
                (padding . 0.25)
                (attach-dir . -2)))
%% uncomment this line for make full barred
       % \once  \override TextSpanner #'bound-details #'left #'text =  \markup { "B" #str }
       $music
   #})

%% %%%%%%%  Cut here ----- End 'bbarred.ly'
%% Copy and change the last line for full barred. Rename in 'fbarred.ly'
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2) If you're using the latest version, here's my personal code (to be also used over rests and skiped notes) :

Code: Select all

\version "2.17.27"

Barre = #(define-music-function (barre location str music) (string? ly:music?)
   (let ((elts (extract-named-music music '(NoteEvent EventChord RestEvent SkipEvent))))
     (if (pair? elts)
         (let ((first-element (first elts))
               (last-element (last elts)))
           (set! (ly:music-property first-element 'articulations)
                 (cons (make-music 'TextSpanEvent 'span-direction -1)
                       (ly:music-property first-element 'articulations)))
           (set! (ly:music-property last-element 'articulations)
                 (cons (make-music 'TextSpanEvent 'span-direction 1)
                       (ly:music-property last-element 'articulations))))))
   #{
       \once \override TextSpanner.font-size = #-2
       \once \override TextSpanner.font-shape = #'upright
       \once \override TextSpanner.staff-padding = #3
       \once \override TextSpanner.style = #'line
       \once \override TextSpanner.to-barline = ##f
       \once \override TextSpanner.bound-details =
            #`((left
                (text . ,#{ \markup { #str } #})
                (Y . 0)
                (padding . 0.25)
                (attach-dir . -2))
               (right
                (text . ,#{ \markup { \draw-line #'( 0 . -.5) } #})
                (Y . 0)
                (padding . 0.25)
                (attach-dir . 2)))
       \once \override TextSpanner.bound-details.left-broken.attach-dir = #-1
       \once \override TextSpanner.bound-details.left-broken.text = ##f 
       \once \override TextSpanner.bound-details.right-broken.text = ##f
       $music
   #})


{ 
  \clef "G_8" 
  s1
  \Barre "CIII " { g4 s s s
  \break	
  s4 s } s s 
}
3) As far as I undestand, you're speaking german arn't you ?
There is an excellent board for the german speaking lilypond users :
http://www.lilypondforum.de/index.php
(I promised to say "hi" if I see you arround :wink: )
with a specific forum for guitar.

4) you can also subscribe to the international users' list :
http://lilypond.org/contact.en.html

Cheers,

wilhelmreich

Re: LilyPond and barres

Post by wilhelmreich » Thu Oct 10, 2013 7:28 am

Thank you Pierre!

Your code works and it looks exactly like I wanted. :bravo: I had to switch to a new Lilypond version and I get some errors now, but it's an another story :)

Thanks for the links. Maybe I will register in the forum, but I more of a reader not a writer.

Return to “Composers' Workshop”