\version "2.18.0" %% and higher %% http://lsr.di.unimi.it/LSR/Item?id=888 %% [...] #(define space-set (list->char-set (string->list "—.?-;,:“”‘’–— */()[]{}|<>!`~&…"))) #(define (width grob text) (let* ((X-extent (ly:stencil-extent (grob-interpret-markup grob text) X))) (if (interval-empty? X-extent) 0 (cdr X-extent)))) #(define (center-on-word grob) (let* ((text (ly:grob-property-data grob 'text)) (syllable (markup->string text)) (word-position (if (string-skip syllable space-set) (string-skip syllable space-set) 0)) (word-end (if (string-skip-right syllable space-set) (+ (string-skip-right syllable space-set) 1) (string-length syllable))) (preword (substring syllable 0 word-position)) (word (substring syllable word-position word-end)) (preword-width (width grob preword)) (word-width (width grob (if (string-null? syllable) text word))) (note-column (ly:grob-parent grob X)) (note-column-extent (ly:grob-extent note-column note-column X)) (note-column-width (interval-length note-column-extent))) (- (* (/ (- note-column-width word-width) 2) (1+ (ly:grob-property-data grob 'self-alignment-X))) preword-width))) melodies = \relative c'' { \autoBeamOff g8 a b c << { \voiceTwo c } \new Voice { \voiceOne d8 } >> << { \voiceOne c } \new Voice { \voiceTwo d8 } >> << { \voiceTwo c } \new Voice { \voiceOne e8 } >> << { \voiceOne c } \new Voice { \voiceTwo e8 } >> \oneVoice 8.*2/3 } melody = \relative c'' { \autoBeamOff g8 a b c \voiceTwo c \voiceOne c \voiceTwo c \voiceOne c \oneVoice 8.*2/3 } lyr = \lyricmode { \repeat unfold 16 "|" } \score { << \new Staff << \new Voice = "cows" \melodies >> \new Lyrics \with { \override LyricText.X-offset = #center-on-word } \lyricsto "cows" { \set stanza = "cow" \lyr } \new Staff << \new Voice = "ncows" \transpose c c' \melodies >> \new Lyrics \lyricsto "ncows" { \set stanza = "default" \lyr } \new Staff << \new Voice = "cow^8s" \transpose c c' \melodies >> \new Lyrics \with { \override LyricText.X-offset = #center-on-word } \lyricsto "cow^8s" { \set stanza = "cow" \lyr } \new Staff << \new Voice = "cow" \melody >> \new Lyrics \with { \override LyricText.X-offset = #center-on-word } \lyricsto "cow" { \set stanza = "cow" \lyr } \new Staff << \new Voice = "ncow" \transpose c c' \melody >> \new Lyrics \lyricsto "ncow" { \set stanza = "default" \lyr } \new Staff << \new Voice = "cow^8" \transpose c c' \melody >> \new Lyrics \with { \override LyricText.X-offset = #center-on-word } \lyricsto "cow^8" { \set stanza = "cow" \lyr } >> \layout { \context { \Score % just for easier comparison proportionalNotationDuration = #(ly:make-moment 1 16) \override SpacingSpanner.strict-note-spacing = ##t } } }