bug-lilypond
[Top][All Lists]
Advanced

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

Re: vowel aligned lyrics - want to improve it


From: Wolf Alight
Subject: Re: vowel aligned lyrics - want to improve it
Date: Mon, 27 May 2013 22:55:09 +0200

Hello

Here are some improvements that I did awhile ago. Maybe it's useful.

Best regards
Torulf

\version "2.14.1"

%
% Definitions for vowel alignment
% This code snippet have been sponsored by the Vadstena Sisters in Sweden
%

#(define vowel-set (list->char-set (string->list "AEIOUYÅÄÖaeiouyåäö")))


#(define (width grob text-string)
(let* ((layout (ly:grob-layout grob))
       (props (ly:grob-alist-chain grob (ly:output-def-lookup layout
'text-font-defaults))))
      (cdr (ly:stencil-extent (ly:text-interface::interpret-markup layout
props (markup text-string)) X))))

#(define (center-on-vowel grob)
         (let* ((syllable (ly:grob-property-data grob 'text))
          (letter-count (string-length syllable))
        (vowel-count (string-count syllable vowel-set))
(note-width (interval-length (ly:grob-property (ly:grob-parent grob X)
'X-extent))))
               (if (or (= letter-count 1) (= letter-count 0) (= vowel-count
0))
          (let* ((syllable-width (width grob syllable)))
                (/ (- note-width syllable-width) 2))
         (let* ((vowel-position (string-index syllable vowel-set))
         (prevowel (substring syllable 0 vowel-position))
         (vowel (if (= (char->integer (string-ref syllable vowel-position))
195) ; swedish letters take up two characters!
            (substring syllable vowel-position (+ vowel-position 2))
                    (substring syllable vowel-position (+ vowel-position
1))))
         (prevowel-width (width grob prevowel))
         (vowel-width (width grob vowel)))
               (- (/ (- note-width vowel-width) 2) prevowel-width)))))



%
% Example
%

chant = {

  \relative c'' {

    g4 a4( c4) c4 c4( b4) a4 b4 c4 d2

  }
}

words = \lyricmode {

I di -- na hän -- der, Her -- re Gud,
}


\score {
  \new Staff

  <<
    \new Voice = "melody" \chant
    \new Lyrics \lyricsto "melody" \words
  >>

  \layout {
    \context { \Lyrics
      \override LyricText #'X-offset = #center-on-vowel
    }
  }
}



2013/4/4 Janek Warchoł <address@hidden>

> Hi all,
>
> On Thu, Apr 4, 2013 at 1:20 AM, Kieren MacMillan
> <address@hidden> wrote:
> > Ultimately, it would be great to have two settings:
> > 1. glyphs which "don't count" for width calculations
> > (e.g., the LyricText "amazing—" should be centred
> > as if it were just "amazing")
>
> http://code.google.com/p/lilypond/issues/detail?id=2451
>
> > 2. glyphs which "don't count" for left-edge determination
> > (e.g., all consonants, if you want vowel-aligned lyrics).
>
> http://code.google.com/p/lilypond/issues/detail?id=2452
>
> I know that i'm horribly late with those, but the work has been
> restarted already.  I have mostly working code for these two issues;
> now i only need to finish
> http://code.google.com/p/lilypond/issues/detail?id=3239 - as the code
> for the above issues touches alignment interface, it makes sense to
> first cleanup the current messy state of alignment, and then add new
> features.
> I'm sorry that this is taking so long :(
>
> best,
> Janek
>


reply via email to

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