]> git.donarmstrong.com Git - lilypond.git/commitdiff
Set context-id for implicit voices in polyphony shorthand.
authorNeil Puttock <n.puttock@gmail.com>
Wed, 27 Jan 2010 01:41:04 +0000 (01:41 +0000)
committerNeil Puttock <n.puttock@gmail.com>
Wed, 27 Jan 2010 01:41:04 +0000 (01:41 +0000)
Since voicify-music now uses the context alias `Bottom' to create the
appropriate voice-level contexts in a << { } \\ { } >> construct, the
context-id sent via context-spec-music is ignored.

* add context-id as arg to Global_context/Context::get_default_interpreter (),
  with empty string as default

* pass context-id to Context::get_default_interpreter () so it can
  be used in call to create_context () instead of empty string

* add regtest, which will fail to compile if context-id is invalid

input/regression/automatic-polyphony-context-id.ly [new file with mode: 0644]
lily/context.cc
lily/global-context.cc
lily/include/context.hh
lily/include/global-context.hh

diff --git a/input/regression/automatic-polyphony-context-id.ly b/input/regression/automatic-polyphony-context-id.ly
new file mode 100644 (file)
index 0000000..31b42a3
--- /dev/null
@@ -0,0 +1,36 @@
+\version "2.13.12"
+
+\header {
+  texidoc = "The bottom-level contexts in polyphony shorthand are
+allocated a context id in order of creation, starting with
+@code{\"1\"}.
+This snippet will fail to compile if either voice has an invalid
+@code{context-id} string.
+"
+}
+
+assertContextId =
+#(define-music-function (parser location id) (string?)
+   (let ((music (make-music 'ApplyContext
+                            'procedure
+                            (lambda (ctx)
+                              (and
+                               (not (string=? (ly:context-id ctx) id))
+                               (ly:error "context-id mismatch found: expecting ~s, got ~s"
+                                         id
+                                         (ly:context-id ctx)))))))
+     music))
+
+\relative c'' {
+  <<
+    {
+      \assertContextId "1"
+      c4 d e2
+    }
+    \\
+    {
+      \assertContextId "2"
+      a,4 b c2
+    }
+  >>
+}
index fedaeae5b065582b59f35e43ba592db653d796d6..8328205214f0fb358908f60e44f549fe5508ee76 100644 (file)
@@ -114,7 +114,7 @@ Context::create_unique_context (SCM name, string id, SCM operations)
   if (gthis && gthis->get_score_context ())
     return gthis->get_score_context ()->create_unique_context (name, id, operations);
 
-  vector<Context_def*> path = path_to_acceptable_context (name);
+  vector<Context_def *> path = path_to_acceptable_context (name);
   if (path.size ())
     {
       Context *current = this;
@@ -168,7 +168,7 @@ Context::find_create_context (SCM n, string id, SCM operations)
 
   if (n == ly_symbol2scm ("Bottom"))
     {
-      Context *tg = get_default_interpreter ();
+      Context *tg = get_default_interpreter (id);
       return tg;
     }
 
@@ -386,7 +386,7 @@ Context::is_bottom_context () const
 }
 
 Context *
-Context::get_default_interpreter ()
+Context::get_default_interpreter (string context_id)
 {
   if (!is_bottom_context ())
     {
@@ -401,8 +401,8 @@ Context::get_default_interpreter ()
          t = unsmob_context_def (this->definition_);
        }
 
-      Context *tg = create_context (t, "", SCM_EOL);
-      return tg->get_default_interpreter ();
+      Context *tg = create_context (t, context_id, SCM_EOL);
+      return tg->get_default_interpreter (context_id);
     }
   return this;
 }
index 3a29a6f24a27ef7fbc28d489214afcbba3947002..160b7b62788cb5c46e11a5a62f3e5c20d4bcc753 100644 (file)
@@ -200,7 +200,7 @@ Global_context::previous_moment () const
 }
 
 Context *
-Global_context::get_default_interpreter ()
+Global_context::get_default_interpreter (string /* context_id */)
 {
   if (get_score_context ())
     return get_score_context ()->get_default_interpreter ();
index b0601bde7ec8e3c3523b45e0a90617e868401a7e..45e94ab9e5593f78861dff6dc48e27080eceab63 100644 (file)
@@ -114,7 +114,7 @@ public:
   virtual Context *get_score_context () const;
   virtual Output_def *get_output_def () const;
   virtual Moment now_mom () const;
-  virtual Context *get_default_interpreter ();
+  virtual Context *get_default_interpreter (string context_id = "");
 
   bool is_alias (SCM) const;
   void add_alias (SCM);
index d69bb598ab42b13c313164e62dbb5959becd74c7..561cd6e49cc7012ea8d3dc66bbc988c59395a202 100644 (file)
@@ -46,7 +46,7 @@ public:
   virtual SCM get_output ();
   virtual Output_def *get_output_def () const;
   virtual Moment now_mom () const;
-  virtual Context *get_default_interpreter ();
+  virtual Context *get_default_interpreter (string context_id = "");
 
   Moment previous_moment () const;
 protected: