Hi Benjamin,
On Thu, Sep 19, 2013 at 9:31 AM, Benjamin Bloomfield <[email protected]>wrote:
> I'm still struggling to figure out how to override the markup of the first
> syllable in each system. I have figured out a callback that can add the
> underscore to the syllable, but I need to figure out how to know if the
> syllable is the first in its system. Does anyone know how to do this?
>
I'm not aware of a direct way to tell if a particular grob is the first one
in a system, but it's possible to determine this information by comparing
horizontal positions.
This is what I come up with:
(BTW, I assume this will work on 2.16, as you're using.)
\version "2.17.25"
#(define (my-callback grob)
(let* ((text (ly:grob-property-data grob 'text))
(refp (ly:grob-system grob))
; This returns all grobs in a line.
(all-cols (ly:grob-array->list
(ly:grob-object refp 'all-elements)))
; We're only interested in NoteColumn grobs, because LyricText
grobs
; are attached to NoteHead (whose X-parent is NoteColumn).
(just-note-cols
(filter
(lambda (x) (grob::has-interface x 'note-column-interface))
all-cols))
; We want the first NoteColumn in the system. We must locate this
; by position, since grobs don't seem to be listed in order in the
; 'all-elements grob array. How is it possible to access
_ranking_ in
; Scheme? If possible, this would probably be more efficient.
(first-note-col
(fold
(lambda (elem prev)
(if (< (ly:grob-relative-coordinate elem refp X)
(ly:grob-relative-coordinate prev refp X))
elem
prev))
(car just-note-cols)
just-note-cols))
; the NoteColumn associated with our LyricText grob
(our-note-col (ly:grob-parent (ly:grob-parent grob X) X)))
; If our NoteColumn is the first on the line, override its stencil.
(if (eq? our-note-col first-note-col)
(begin
(ly:grob-set-property! grob 'text
#{ \markup \combine #text \translate #'(1.6 . -0.5) \draw-line
#'(-4 . 0) #})
(ly:grob-set-property! grob 'stencil (lyric-text::print
grob))))))
melody = \repeat unfold 16 g'4
lyr = \lyricmode {
\repeat unfold 16 sol
}
\score {
\new Staff <<
\new Voice = "voice" {
\melody
}
\new Lyrics \with {
\override LyricText #'after-line-breaking = #my-callback
} \lyricsto "voice" \lyr
>>
}
\paper {
indent = 0
line-width = 5.5\cm
}
%%%%%%%%%%%%%%
Hope this helps,
David
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user