lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: LyricText center-on-word breaks lyricMelismaAlignment


From: Thomas Morley
Subject: Re: LyricText center-on-word breaks lyricMelismaAlignment
Date: Thu, 3 Dec 2015 17:32:03 +0100

2015-11-12 6:11 GMT+01:00 Kieren MacMillan <address@hidden>:
> Hi all,
>
> It seems that, when using the very useful center-on-word function 
> (<http://lsr.di.unimi.it/LSR/Snippet?id=888>), setting lyricMelimsaAlignment 
> to anything other than integer values (including #LEFT, etc.) fails.
>
> Fixing the snippet is definitely beyond my Scheme-fu…
> Any help would be appreciated.
>
> Thanks,
> Kieren.
> ________________________________



Hi Kieren,

below an improved and extended version of the snippet.
Should be possible to use override/set for self-alignment-X and
lyricMelimsaAlignment as you like now.
If no drawbacks happened, I'll put it in LSR soon, replacing the older one.

Btw, this snippet has the same problems as the engraver in this thread:
http://lilypond.1069038.n5.nabble.com/aligning-melisma-and-non-melisma-lyrics-across-staves-in-the-same-system-td184122.html
- multiple stencils are created and thrown away
- how to compare strings and markups


\version "2.18.2" %% and higher

#(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)))

%% For general use take this this layout-setting
%% In the example below the override is applied to selected Lyrics only
%%
%\layout {
%  \context {
%    \Lyrics
%    \override LyricText #'X-offset = #center-on-word
%  }
%}

melody = \relative c' {
  c4
  d e f |
  c d
  e( f)
  g1 \bar"|."
}

lyr = \lyricmode {
  \set stanza = "1. "
  Do, ““Re, Mi, Fa, Do, Re,
  %\once \set Score.lyricMelismaAlignment = #4.5
  "...mimifa,"
  \markup \bold Sol—
}

lyrA = \lyricmode {
  \set stanza = "2. "
  “Do Re, Mi, Fa, Do, Re,
  mimifa...
  Sol!”
}

lyrControl = \lyricmode{
  \set stanza = "Control: "
  \revert LyricText.X-offset
  Do Re Mi Fa Do Re mimifa Sol
}

\score {
  \new Staff <<
    \new Voice = "voice" \melody
    \new Lyrics = "testI"
      \with { \override LyricText.X-offset = #center-on-word }
      \lyricsto "voice" \lyr
    \new Lyrics = "testII"
      \with { \override LyricText.X-offset = #center-on-word }
      \lyricsto "voice" \lyrA
    %% The control-voice omits the override
    \new Lyrics = "control"
      \lyricsto "voice" \lyrControl
  >>
  \layout {
    \context {
      \Score
      lyricMelismaAlignment = #-0.6
    }
  }
}


HTH,
  Harm



reply via email to

[Prev in Thread] Current Thread [Next in Thread]