Hi,

On Sun, Aug 30, 2015 at 1:40 PM, David Nalesnik <david.nales...@gmail.com>
wrote:
>
>
> On Sun, Aug 30, 2015 at 11:08 AM, Andrew Bernard <andrew.bern...@gmail.com
> > wrote:
>
>> Greetings All,
>>
>> Not that it is relevant to the OP’s question in any way, but I can’t help
>> noticing out that this didactic example makes copious use of horizontal
>> bracket spanners with centred text on every note - the very thing that I am
>> currently working on. They’re everywhere. :-)
>>
>>
> LilyPond already has the ability to make analysis brackets, which are
> attached to note columns and can nest as in the link (HorizontalBracket).
> I have an old patch for adding text to these that I will finish up and
> post.  (I have code for doing this in Scheme, but my approach now is an
> enhancement of the C++ engraver.)
>

The attached file is what I used to use when making form handouts.

David
\version "2.19.25"


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% A function to add labels to analysis brackets.  Allows for different text
%% if broken between staves.
%%
%% Use with \tweak.  For example: -\tweak #'stencil #(label "antecedent" "ant." "")
%% This will add "antecedent" to the bracket if unbroken (or to the first piece, if
%% broken), "ant." to the first broken piece, and an empty string to the next piece
%% (if there is one).  If no "" were specified, all pieces after the first would be
%% labelled "ant."
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


#(define (add-label grob text)
   ;; adapted from LSR snippet, "Center text below hairpin dynamics"
   (ly:stencil-aligned-to
    (ly:stencil-combine-at-edge
     (ly:stencil-aligned-to (ly:horizontal-bracket::print grob) X CENTER)
     Y (ly:grob-property grob 'direction)
     (ly:stencil-aligned-to (grob-interpret-markup grob (markup text)) X CENTER)
     0.2)
    X LEFT))

#(define ((label . text) grob)
   (let* ((orig (ly:grob-original grob))
          (siblings (if (ly:grob? orig)
                        (ly:spanner-broken-into orig)
                        '())))

     (define (helper text siblings)
       ;; step through the pieces to find the current one, and modify its stencil
       (if (eq? (car siblings) grob)
           (add-label grob (car text))
           (if (or (null? (cdr siblings))
                   (null? (cdr text)))
               (add-label grob (car text)) ;; if not enough text for pieces, use last given
               (helper (cdr text) (cdr siblings)))))

     (if (pair? siblings)
         (helper text siblings)
         (add-label grob (car text)))))

gluck = \relative c'' {
  \time 3/4
  \key f \major
  \override HorizontalBracket.direction = #UP
  c4-\tweak stencil #(label "contrasting period" "contrasting period")\startGroup
  -\tweak stencil #(label "a" "a" )\startGroup
  a8( bes c f)
  f4( e d)
  c d8( c bes c)
  \appoggiatura bes4 a2 g4 \stopGroup
  f'8-\tweak stencil #(label "b" "b")\startGroup r a, r d r
  c4( e, f)
  g8( bes) a4 g8( f)
  f2 \stopGroup \stopGroup r4
  \bar "||"
}

\score {
  \new Staff \gluck
  \layout {
    \context {
      \Voice
      \consists "Horizontal_bracket_engraver"
    }
  }
}
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to