]> git.donarmstrong.com Git - lilypond.git/commitdiff
Give \addlyrics the power of christening the associated context
authorDavid Kastrup <dak@gnu.org>
Mon, 8 Sep 2014 09:28:14 +0000 (11:28 +0200)
committerDavid Kastrup <dak@gnu.org>
Sun, 14 Sep 2014 05:44:55 +0000 (07:44 +0200)
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.

scm/ly-syntax-constructors.scm

index 7741914b0f8fa50125ec2d5275c97224c4b62287..66f34cfceb7c8819659ed0dfd3f68effb1c86d71 100644 (file)
@@ -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)))