Hi Aaron.
Many thanks for this. I can now write functions like this:
mock = #(define-music-function
   ( punct)
   ( markup?)
   #{ \addPunct \lyricmode { He mock -- eth at us } $punct #})
and
sopranoVerse = \lyricmode { \mock ; \mock ! }
Ace!

On Tue, 11 Aug 2020 at 10:03, Aaron Hill <lilyp...@hillvisions.com> wrote:

> On 2020-08-11 1:57 am, Aaron Hill wrote:
> > On 2020-08-11 1:48 am, Aaron Hill wrote:
> >>          (last (car (take-right elts 1)))
> >
> > And in my haste to reply, I overlooked simplifying the car/take-right
> > 1 to being just a call to the SRFI-1 "last" procedure:
> >
> >>          (last (last elts))
> >
> > Though, I probably should pick a better local variable name than
> > "last".  Even though the compiler does the right thing, such usage
> > could be prone to misunderstanding.
>
> Minimally improved version here that also demonstrates that lyric
> hyphens work:
>
> %%%%
> \version "2.20.0"
>
> #(define (lyrics? x)
>    (and (ly:music? x)
>         (music-is-of-type? x 'sequential-music)
>         (every (music-type-predicate '(lyric-event))
>                (ly:prob-property x 'elements))))
>
> addPunct = #(define-music-function
>    (lyrics punct)
>    (lyrics? markup?)
>    (let* ((elts (ly:prob-property lyrics 'elements))
>           (last-elt (last elts))
>           (text (ly:prob-property last-elt 'text)))
>      (ly:prob-set-property! last-elt 'text
>        #{ \markup \concat { $text $punct } #})
>      lyrics))
>
> foobarbaz = \lyricmode { foo -- bar baz }
>
> \new Voice \fixed c' { g8 fis g4 a4. b8 | c'1 }
> \addlyrics { \addPunct \foobarbaz "," \addPunct \foobarbaz "!" }
> %%%%
>
>
> -- Aaron Hill

Reply via email to