]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/context.cc
Merge branch 'master' of /home/jcharles/GIT/Lily/. into translation
[lilypond.git] / lily / context.cc
index 392077861828ea7683644662eb3ff1974afeca38..d2c93155a578964e5cf439400fe626236b611ca3 100644 (file)
@@ -91,6 +91,7 @@ Context::Context ()
   definition_mods_ = SCM_EOL;
   event_source_ = 0;
   events_below_ = 0;
+  ancestor_lookup_ = SCM_UNDEFINED;
 
   smobify_self ();
 
@@ -159,8 +160,29 @@ Context::find_create_context (SCM n, string id, SCM operations)
     Don't create multiple score contexts.
   */
   Global_context *gthis = dynamic_cast<Global_context *> (this);
-  if (gthis && gthis->get_score_context ())
-    return gthis->get_score_context ()->find_create_context (n, id, operations);
+  if (gthis)
+    {
+      if (gthis->get_score_context ())
+        return gthis->get_score_context ()->find_create_context (n, id, operations);
+
+      // Special case: If we use \set Timing.xxx = whatever before
+      // Score is established, the alias of Score to Timing will not
+      // be taken into account.  We check for this particular case
+      // here.  Aliases apart from Score-level ones don't warrant
+      // context creation as they could create unwanted contexts, like
+      // RhythmicVoice instead of Voice.  Creating a Score context,
+      // however, can't really do anything wrong.
+
+      SCM score_name = default_child_context_name ();
+      SCM score_def = find_context_def (get_output_def (), score_name);
+
+      if (Context_def *cd = unsmob_context_def (score_def))
+        {
+          if (cd->is_alias (n))
+            return create_context (cd, id, operations);
+        }
+    }
+
 
   if (Context *existing = find_context_below (this, n, id))
     return existing;
@@ -227,6 +249,12 @@ Context::set_property_from_event (SCM sev)
   if (scm_is_symbol (sym))
     {
       SCM val = ev->get_property ("value");
+
+      if (SCM_UNBNDP (val)) {
+        unset_property (sym);
+        return;
+      }
+          
       bool ok = true;
       if (val != SCM_EOL)
         ok = type_check_assignment (sym, val, ly_symbol2scm ("translation-type?"));
@@ -327,7 +355,7 @@ Context::path_to_acceptable_context (SCM name) const
 
   return unsmob_context_def (definition_)->path_to_acceptable_context (name,
          get_output_def (),
-        scm_reverse_x (accepts, SCM_EOL));
+         scm_reverse_x (accepts, SCM_EOL));
 
 }
 
@@ -452,7 +480,7 @@ be called from any other place than the send_stream_event macro.
 void
 Context::internal_send_stream_event (SCM type, Input *origin, SCM props[])
 {
-  Stream_event *e = new Stream_event (type, origin);
+  Stream_event *e = new Stream_event (make_event_class (type), origin);
   for (int i = 0; props[i]; i += 2)
     {
       e->set_property (props[i], props[i + 1]);
@@ -593,6 +621,14 @@ Context::get_score_context () const
     return 0;
 }
 
+SCM
+Context::make_event_class (SCM event_type)
+{
+  if (SCM_UNBNDP (ancestor_lookup_))
+    ancestor_lookup_ = get_global_context ()->ancestor_lookup_;
+  return scm_hashq_ref (ancestor_lookup_, event_type, SCM_EOL);
+}
+
 Output_def *
 Context::get_output_def () const
 {
@@ -661,6 +697,8 @@ Context::mark_smob (SCM sm)
   if (me->events_below_)
     scm_gc_mark (me->events_below_->self_scm ());
 
+  scm_gc_mark (me->ancestor_lookup_);
+
   return me->properties_scm_;
 }