lilypond-user
[Top][All Lists]
Advanced

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

Re: exchange LyricHyphen with a "proper" hyphen


From: Thomas Morley
Subject: Re: exchange LyricHyphen with a "proper" hyphen
Date: Wed, 7 Dec 2016 23:59:54 +0100

2016-12-07 22:03 GMT+01:00 Simon Albrecht <address@hidden>:
> On 07.12.2016 11:45, Alexander Kobel wrote:
>>
>> I'm not sure whether Harm's proof of concept also involved
>> pre-compile-time modifications.
>
>
> It certainly didn’t; Harm is a Schemer, not a C++ guy :-)

Indeed.

So here a very first shot.
For now I let display the new _and_ the colored default LyricHyphen.
You'll see a drawback already: In tight situations the default gets
shortened until it vanishs. This is not possible or at least not
desirable for characters taken from a font, imho.
Iirc this was already mentioned in the discussion the tracker links to.
Maybe minimum-distance may help here, not tested though.

\version "2.19.52"

#(define (lh-test-stencil arg)
 (lambda (grob)
   (if (ly:stencil? (ly:lyric-hyphen::print grob))
       (let* ((stil (ly:lyric-hyphen::print grob))
              (x-ext (ly:stencil-extent stil X))
              (dash-period (ly:grob-property grob 'dash-period))
              (arg-stil (grob-interpret-markup grob arg))
              (arg-stil-x-ext (ly:stencil-extent arg-stil X))
              (length-to-print (interval-length x-ext))
              (guess (max 0 (truncate (/ length-to-print dash-period))))
              (guessed-args-line-length (* guess dash-period))
              (line-length-diff (- length-to-print guessed-args-line-length))
              (line-length-diff-for-each-arg (/ line-length-diff guess))
              (first-arg-length (+ dash-period line-length-diff-for-each-arg))
              (first-arg-end-coord
                  (/ (* first-arg-length
                        (- (interval-length x-ext)
                           (interval-length arg-stil-x-ext)))
                     length-to-print))
              (list-of-starts
                (map
                  (lambda (n) (* n first-arg-end-coord))
                  (iota (+ 1 guess)))))
         (ly:stencil-translate-axis
           (apply
             ly:stencil-add
             (map
               (lambda (x-val) (ly:stencil-translate-axis arg-stil x-val X))
               list-of-starts))
           (car x-ext) X))
       (ly:grob-suicide! grob))))

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXAMPLES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\paper { ragged-right = ##f }

\layout {
  \context {
    \Score
    \override NonMusicalPaperColumn #'line-break-permission = ##f
  }
}

newLH =
#(define-music-function (mrkp)(markup?)
#{
  \override LyricHyphen.after-line-breaking =
    #(lambda (grob)
      (if (ly:stencil? (ly:lyric-hyphen::print grob))
          (ly:grob-set-property! grob 'stencil
            (ly:stencil-add
              (stencil-with-color (ly:lyric-hyphen::print grob) red)
              ((lh-test-stencil mrkp ) grob)))))
#})


tstI = { c'2. c'4 }
tstII = { c'1 \break c'1 }
tstIII = { c'1 \break r1 c'1 }

lhTest =
#(define-music-function (mkp m i)(markup? ly:music? index?)
#{
<<
  \new Voice \repeat unfold $i $m
  \new Lyrics
    \with { \newLH $mkp }
    \lyricsto "" { \repeat unfold $i { voo -- doo }  }
>>
#})

\lhTest "~" \tstI 1
\lhTest "~" \tstI 2
\lhTest "~" \tstI 3
\lhTest "~" \tstI 4
\lhTest "~" \tstI 5
\lhTest "~" \tstI 6
\lhTest "~" \tstI 7
\lhTest "~" \tstI 8
\lhTest "~" \tstI 9
\lhTest "~" \tstI 10
\lhTest "~" \tstI 11
\lhTest "~" \tstI 12


\lhTest "~" \tstII 1

\lhTest "~" \tstIII 1

Cheers,
  Harm



reply via email to

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