lilypond-user
[Top][All Lists]
Advanced

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

Centering a slur/tie over a syllable


From: Benjamin Bloomfield
Subject: Centering a slur/tie over a syllable
Date: Wed, 4 Mar 2020 14:26:22 -0500

I am trying to figure out a way to change the way centering a slur or tied note above a syllable so that if the noteheads all fit within the width of the syllable that they would be centered above it, and otherwise left aligned.

I have changed the centering behavior before by putting
\override LyricText #'X-offset = #center-on-word
inside a Lyrics context, and defining center-on-word in scheme so that it would measure the width of the syllable without any surrounding punctuation.  However, for what I'm asking about right now, I will need to also know the location of the final notehead attached to the syllable.  I don't think there should be any cases of this, but if the final notehead for the current syllable is on a different system, I would only want to consider the last notehead on the current system.

Here is what I had for center-on-word:
#(define (center-on-word grob)
  (let* (
      (text (ly:grob-property-data grob 'text))
      (syllable (if (string? text) text ""))
      (word-position (if (integer? (string-skip syllable space-set)) (string-skip syllable space-set) 0))
      (word-end (if (integer? (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 (if (string? text) (width grob preword) 0))
      (word-width (if (string? text) (width grob word) (width grob text)))
      (notehead (ly:grob-parent grob X))
      (refp (ly:grob-common-refpoint notehead grob X))
      (note-extent (ly:grob-extent notehead refp X))
      (note-width (- (cdr note-extent) (car note-extent)))
    )
    (if (= -1 (ly:grob-property-data grob 'self-alignment-X))
      (- 0 preword-width)
      (- (/ (- note-width word-width) 2) preword-width)
    )
  )
)

Any help is greatly appreciated.

Thanks,

Benjamin Bloomfield

reply via email to

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