lilypond-user
[Top][All Lists]
Advanced

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

Re: resetting accidentals at word breaks


From: Aaron Hill
Subject: Re: resetting accidentals at word breaks
Date: Thu, 23 Apr 2020 13:23:41 -0700
User-agent: Roundcube Webmail/1.4.2

On 2020-04-23 11:53 am, Fr. Samuel Springuel wrote:
On 14 Apr, 2020, at 3:02 PM, Aaron Hill <address@hidden> wrote: Here is my take that works from events not grobs, plus it allows flexibility in what you want to do between words:

This look useful for me too, but I’m running into some difficulty when
trying to insert regular bars.  It seems the bar inserted by the
betweenLyrics engraver is always used between words, even if the music
specifies a different bar.  Is there some way to adapt around that so
that explicitly \bar commands take precedence?

Ooh, I didn't think of that. Since \bar just sets the whichBar property, it is a case of whichever \bar command is last that wins. So the code just needs to have a variation that checks whether whichBar is already set and only change it if unset:

%%%%
\version "2.20.0"

modifyContextPropertyWhereDefined =
#(define-scheme-function
  (prop value-or-proc) (symbol? scheme?)
  (lambda (context)
    (ly:context-set-property!
      (ly:context-property-where-defined context prop)
      prop
      (if (procedure? value-or-proc)
        (value-or-proc (ly:context-property context prop))
        value-or-proc))))

setContextPropertyWhereDefinedIfUnset =
#(define-scheme-function
  (prop value) (symbol? scheme?)
  (lambda (context)
    (let* ((unspecified (make-symbol "unspecified")))
      (and (eq? unspecified
               (ly:context-property context prop unspecified))
           (ly:context-set-property!
             (ly:context-property-where-defined context prop)
             prop
             value)))))

incrementBarNumber =
  \modifyContextPropertyWhereDefined
  internalBarNumber #1+

insertBar =
  \modifyContextPropertyWhereDefined
  whichBar \etc

insertBarUnlessAlreadySet =
  \setContextPropertyWhereDefinedIfUnset
  whichBar \etc

betweenLyrics = #(define-scheme-function
  (proc) (procedure?)
  (lambda (context)
    (let ((first-lyric? #t) (hyphen? #f))
      (make-engraver
        (listeners
          ((hyphen-event engraver event) (set! hyphen? #t))
          ((lyric-event engraver event)
           (if first-lyric?
             (set! first-lyric? #f)
             (if (not hyphen?) (proc context)))
           (set! hyphen? #f)))))))

doBoth = #(define-scheme-function
  (proc1 proc2) (procedure? procedure?)
  (lambda args (apply proc1 args) (apply proc2 args)))

repetitions = #3
notes = \repeat unfold \repetitions {
  fis'4 4 4 4 4 4 \bar "||" 4( 4) 4( 4 4) 4 4 }
words = \repeat unfold \repetitions \lyricmode {
  a b -- b c -- c -- c d e -- e f }

\paper { indent = 0 }

<< \new Staff { \cadenzaOn \new Voice = melody \notes }
   \new Lyrics \with {
    \consists \betweenLyrics \incrementBarNumber
   } \lyricsto melody \words >>

\markup \vspace #2
<< \new Staff { \cadenzaOn \new Voice = melody \notes }
   \new Lyrics \with {
    \consists \betweenLyrics \insertBar "'"
   } \lyricsto melody \words >>

\markup \vspace #2
<< \new Staff { \cadenzaOn \new Voice = melody \notes }
   \new Lyrics \with {
    \consists \betweenLyrics \doBoth \insertBar "" \incrementBarNumber
   } \lyricsto melody \words >>

\markup \vspace #2
<< \new Staff { \cadenzaOn \new Voice = melody \notes }
   \new Lyrics \with {
    \consists \betweenLyrics
      \doBoth \insertBarUnlessAlreadySet ";"
              \incrementBarNumber
   } \lyricsto melody \words >>
%%%%


-- Aaron Hill

Attachment: reset-accidentals.cropped.png
Description: PNG image


reply via email to

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