[Top][All Lists]

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

Re: Markup functions and punctuation in lyrics

From: Jean Abou Samra
Subject: Re: Markup functions and punctuation in lyrics
Date: Tue, 2 Nov 2021 18:11:18 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.2

Le 02/11/2021 à 16:23, R. Padraic Springuel a écrit :
On Oct 31, 2021, at 6:02 PM, David Kastrup <> wrote:

If the ugliness of juxtaposition is ok, you may use things like


for concatenating stuff, too.
What about event functions?  Can a command which does the concatenation be 
written as an event function so that the juxtaposition isn’t needed?  (I’ve 
never written an event function and the extending manual doesn’t provide much 
info about their capabilities/limitations.)

The difference between a music function and an
even function is that the return type of an event
function is narrower -- it must return something
suitable as a post-event, such as \p, -., \marcato,
etc. This brings syntax flexibility in the case
where a note is immediately followed by the application
of an event function. The handling of arguments remains
the same. It does not help here.

Since you ask about this again, here is some code that
I wrote when you asked the first time. It post-processes
the lyrics to squash punctuation with the previous lyric
event. I had abandoned it because it was getting complex.
Try it and see how it fares -- it has not been extensively

\version "2.22.1"

#(use-modules (ice-9 regex))

#(define punctuation (make-regexp "^[.,;:?!]+$"))

magneticPunctuation =
#(define-music-function (music) (ly:music?)
     (lambda (m)
       (let ((elts (ly:music-property m 'elements)))
         (if (pair? elts)
             (let loop ((e elts)
                        (last-lyric #f)
                        (acc '()))
               (if (null? e)
                   (ly:music-set-property! m 'elements (reverse! acc))
                   (let ((next (car e)))
                       ((and (music-is-of-type? m 'sequential-music)
                             (music-is-of-type? next 'sequential-music))
                        ; #{ \lyricmode { ... } #} yields sequential music,
                        ; so flatten it.
                        (loop (append (ly:music-property next 'elements)
                                      (cdr e))
                       ((and last-lyric
                             (music-is-of-type? next 'lyric-event))
                        (let ((previous-text (ly:music-property last-lyric 'text))
                              (next-text (ly:music-property next 'text)))
                          (if (and (string? previous-text)
                                   (string? next-text)
                                   (regexp-match? (regexp-exec punctuation next-text)))
                              (let ((new
                                      (make-music 'LyricEvent
                                                  (string-append previous-text
                                (loop (cdr e)
                                      (cons new (delq1! last-lyric acc))))
                              (loop (cdr e)
                                    (cons next acc)))))
                       ((music-is-of-type? next 'lyric-event)
                        (loop (cdr e)
                              (cons next acc)))
                       ((equal? ZERO-MOMENT (ly:music-length next))
                        (loop (cdr e)
                              (cons next acc)))
                        (loop (cdr e)
                              (cons next acc)))))))))

gender = "other"

man =
   ((equal? gender "male") #{ \lyricmode { man } #})
    ;((equal? gender "female")  #{ \lyricmode{ error } #})
   ((equal? gender "plural") #{ \lyricmode { men } #})
       \lyricmode {
         \override Lyrics.LyricText.font-shape = #'italic
         \revert Lyrics.LyricText.font-shape

music = { c' c' c' c' c' c' c' c' c' c' c' }

verseI = \lyricmode {
  In glad re -- mem -- brance of this ho -- ly \man, \skip 4
  Who sought to fol -- low you in faith and love.

\magneticPunctuation \new Staff
    \new Voice = "mel" { \music \music }
    \new Lyrics \lyricsto "mel" { \verseI }


reply via email to

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