From: David Kastrup Date: Mon, 8 Sep 2014 09:28:14 +0000 (+0200) Subject: Give \addlyrics the power of christening the associated context X-Git-Tag: release/2.19.14-1~6^2~2 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=eda1a9e297d93e074d10e86dfdeae1226f86b4cd;p=lilypond.git Give \addlyrics the power of christening the associated context With \new Voice \with { \stemDown } { c1 } \addlyrics { Oh } as opposed to \new Voice = "upper" \with { \stemDown } { c1 } \addlyrics { Oh } \addlyrics created its own context (consequently not using \stemDown) since it had no context name for the Lyrics context to attach to. In this case (namely being preceded by an unnamed new Voice context), it will now give a name to the context itself. --- diff --git a/scm/ly-syntax-constructors.scm b/scm/ly-syntax-constructors.scm index 7741914b0f..66f34cfceb 100644 --- a/scm/ly-syntax-constructors.scm +++ b/scm/ly-syntax-constructors.scm @@ -207,14 +207,21 @@ into a @code{MultiMeasureTextEvent}." 'context-type ctx 'origin location))) -(define (get-first-context-id type mus) - "Find the name of a ContextSpeccedMusic with given type" +(define (get-first-context-id! type mus) + "Find the name of a ContextSpeccedMusic with given type, possibly naming it" (let ((id (ly:music-property mus 'context-id))) (if (and (eq? (ly:music-property mus 'name) 'ContextSpeccedMusic) - (eq? (ly:music-property mus 'context-type) type) - (string? id) - (not (string-null? id))) - id + (eq? (ly:music-property mus 'context-type) type)) + (if (and (string? id) + (not (string-null? id))) + id + ;; We may reliably give a new context a unique name, but + ;; not an existing one + (if (ly:music-property mus 'create-new #f) + (let ((id (get-next-unique-voice-name))) + (set! (ly:music-property mus 'context-id) id) + id) + '())) '()))) (define unique-counter -1) @@ -240,7 +247,7 @@ into a @code{MultiMeasureTextEvent}." (lyric-combine-music voice music location)) (define-ly-syntax (add-lyrics parser location music addlyrics-list) - (let* ((existing-voice-name (get-first-context-id 'Voice music)) + (let* ((existing-voice-name (get-first-context-id! 'Voice music)) (voice-name (if (string? existing-voice-name) existing-voice-name (get-next-unique-voice-name)))