3

I have the following markup which gives the output below:

\version "2.22.2"
\language "english"

global = {
  \key df \major
  \numericTimeSignature
  \time 2/4
}

right = \fixed c'' {
  \global
  <af, c ef af>8. <bf, c ef af>16~ 16 <c ef> bf, <af, c ef af>~ |
  8. <bf, c ef af>16~ 16 <c ef> bf, <c ef> |
}

left = \fixed c {
  \global
  \clef bass
  <ef, ef>16 <gf, gf> <af c' gf'>8 <gf, gf> <af c' gf'> |
  <f, f> <af c' gf'> <ef, ef>16 <df, df> <c, c>8 |
}

pedal = {
  \set Dynamics.pedalSustainStyle = #'bracket
  8\sustainOn 4\sustainOff 16 16\sustainOn | 16 16\sustainOff 8 8\sustainOn 8\sustainOff |
}

\score {
  \new PianoStaff <<
    \new Staff = "right" \right 
    \new Staff = "left" \left
    \new Dynamics \pedal
  >>
}

Current output

I'd like to add a number to the left of each sustain bracket to indicate a variation on the 2nd time the passage is palyed:

Desired output

The closest I got is by using 8^"1."\sustainOn or 8_"1."\sustainOn, however this places the number above/below the bracket rather than directly before it.

1 Answer 1

2

Fret not! Lilypond does allow us to take a lot of control of what to print, easily enabling us to do such annotations:

\version "2.24"
\language "english"

% Return a stencil function that annotates the default stencil with some text.
% If text-from-details is false grob.text is used for text, else grob.details.text
% is used. The staff-dir parameter specifies the direction of the grob relative to
% the staff. This is only used to place indications away from the staff, so it can
% also be interpreted in which direction to move the annotation. If set to #f we
% will attempt to use grob.direction and default to UP.
%
% This function will also make use of grob.details.direction for the X-direction placement
% and grob.details.padding for padding between grob and annotation. Also a manual offset
% can be specified using grob.details.offset
#(define (text-annotate-transformer staff-dir text-from-details)
   (grob-transformer 'stencil
                     (lambda (grob orig)
                       (let* ((det (ly:grob-property grob 'details))
                              (staff-dir (or staff-dir (ly:grob-property grob 'direction UP)))
                              (pad (assoc-get 'padding det 0.3))
                              (dir (assoc-get 'direction det LEFT))
                              (offset (assoc-get 'offset det '(0 . 0)))
                              (text (if text-from-details
                                        (assoc-get 'text det #f)
                                        (ly:grob-property grob 'text #f)))
                              (text-c (or text ""))
                              (m (grob-interpret-markup grob text-c))
                              (m (ly:stencil-aligned-to m X (- dir)))
                              (orig-ext-x (ly:stencil-extent orig X))
                              (ndir (/ (+ dir 1) 2))
                              (orig-refpoint (+ (* ndir (cdr orig-ext-x)) (* (- 1 ndir) (car orig-ext-x))))
                              (m (ly:stencil-translate-axis m orig-refpoint X))
                              (orig-ext-y (ly:stencil-extent orig Y))
                              (orig-refpoint-y (if (< (abs dir) 1)
                                                   (if (< staff-dir 0) (car orig-ext-y) (cdr orig-ext-y))
                                                   (interval-center orig-ext-y)))
                              (m (ly:stencil-aligned-to m Y (if (< (abs dir) 1) (- staff-dir) CENTER)))
                              (m (ly:stencil-translate-axis m orig-refpoint-y Y))
                              (m (ly:stencil-translate m offset))
                              (m (if (< (abs dir) 1)
                                     (ly:stencil-translate-axis m (if (< staff-dir 0) (- pad) pad) Y)
                                     (ly:stencil-translate-axis m (if (< dir 0) (- pad) pad) X))))
                         (if text
                             (ly:stencil-add orig m)
                             orig)))))


\layout {
  \context {
    \Dynamics
    \override PianoPedalBracket.stencil = #(text-annotate-transformer DOWN #f)
    pedalSustainStyle = #'bracket
    \override PianoPedalBracket.font-size = #-2
    \override PianoPedalBracket.font-series = #'bold
  }
}

global = {
  \key df \major
  \numericTimeSignature
  \time 2/4
}

right = \fixed c'' {
  \global
  <af, c ef af>8. <bf, c ef af>16~ 16 <c ef> bf, <af, c ef af>~ |
  8. <bf, c ef af>16~ 16 <c ef> bf, <c ef> |
}

left = \fixed c {
  \global
  \clef bass
  <ef, ef>16 <gf, gf> <af c' gf'>8 <gf, gf> <af c' gf'> |
  <f, f> <af c' gf'> <ef, ef>16 <df, df> <c, c>8 |
}

pedal = {
  8\tweak text "2." \sustainOn 4\sustainOff 16 16\tweak text "1." \sustainOn |
  16 16\sustainOff 8 8\tweak text "2." \sustainOn 8\sustainOff |
}

\score {
  \new PianoStaff <<
    \new Staff = "right" \right 
    \new Staff = "left" \left
    \new Dynamics \pedal
  >>
}


%%% demonstrating details.direction and details.padding parameters
\score {
  \new PianoStaff <<
    \new Staff = "right" \right 
    \new Staff = "left" \left
    \new Dynamics { \override PianoPedalBracket.details.direction = #RIGHT \pedal }
  >>
}

\score {
  \new PianoStaff <<
    \new Staff = "right" \right 
    \new Staff = "left" \left
    \new Dynamics { \override PianoPedalBracket.details.direction = #CENTER \pedal }
  >>
}

\score {
  \new PianoStaff <<
    \new Staff = "right" \right 
    \new Staff = "left" \left
    \new Dynamics { \override PianoPedalBracket.details.direction = #0.3 \pedal }
  >>
}

\score {
  \new PianoStaff <<
    \new Staff = "right" \right 
    \new Staff = "left" \left
    \new Dynamics { \override PianoPedalBracket.details.direction = #CENTER
                    \override PianoPedalBracket.details.padding = #1
                    \pedal }
  >>
}


%%% Use with other grobs:
{
  \override Slur.stencil = #(text-annotate-transformer #f #f)
  \override Slur.details.direction = #CENTER
  c'8\tweak text "(a)" _( d' e' g') c'\tweak text "(b)" ^( d' e' g')
  c'8
  \tweak text "(c)"
  \tweak details.direction #LEFT
  \tweak details.padding #1
  \tweak details.offset #'(0 . -1.5) (
  d' e' f' g' a' b' c'')
}

{
  \override TextScript.stencil = #(text-annotate-transformer #f #t)
  \override TextScript.details.direction = #CENTER
  c
  -\tweak details.text \markup\tiny "(annot)"
  ^"some text"
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.