]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/translator-group.cc
* Documentation/user/refman.itely: bugfix: "Chord namess" ->
[lilypond.git] / lily / translator-group.cc
index 6768de18c70143865e4660a4ca99119159f5d6ee..6dbe4eb65c5037953f79bfc34a8aa0fa8eea633c 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
 #include "music-output-def.hh"
@@ -14,6 +14,7 @@
 #include "scm-hash.hh"
 #include "translator-def.hh"
 #include "main.hh"
+#include "music.hh"
 
 Translator_group::Translator_group (Translator_group const&s)
   : Translator (s)
@@ -121,8 +122,6 @@ Translator_group::find_existing_translator (String n, String id)
 }
 
 
-
-
 Translator_group*
 Translator_group::find_create_translator (String n, String id)
 {
@@ -162,18 +161,6 @@ Translator_group::find_create_translator (String n, String id)
   return ret;
 }
 
-bool
-Translator_group::try_music_on_nongroup_children (Music *m)
-{
-  bool hebbes_b =false;
-  
-  for (SCM p = simple_trans_list_; !hebbes_b && gh_pair_p (p); p = ly_cdr (p))
-    {
-      hebbes_b = unsmob_translator (ly_car (p))->try_music (m);
-    }
-  return hebbes_b;
-}
-
 bool
 Translator_group::try_music (Music* m)
 {
@@ -227,7 +214,6 @@ bool
 Translator_group::is_bottom_translator_b () const
 {
   return !gh_string_p (unsmob_translator_def (definition_)->default_child_context_name ());
-
 }
 
 Translator_group*
@@ -399,6 +385,8 @@ Translator_group::do_announces ()
 void
 Translator_group::initialize ()
 {
+  SCM tab = scm_make_vector (gh_int2scm (19), SCM_BOOL_F);
+  set_property ("acceptHashTable", tab);
   each (&Translator::initialize);
 }
 
@@ -408,31 +396,65 @@ Translator_group::finalize ()
   each (&Translator::removal_processing);
 }
 
-LY_DEFINE(ly_get_context_property,
-         "ly-get-context-property", 2, 0, 0,
-         (SCM context, SCM name),
-         "retrieve the value of @var{sym} from context @var{tr}")
+
+
+bool translator_accepts_any_of (Translator*tr, SCM ifaces)
 {
-  Translator *t = unsmob_translator (context);
-  Translator_group* tr=   dynamic_cast<Translator_group*> (t);
-  SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Translator group");
-  SCM_ASSERT_TYPE(gh_symbol_p (name), name, SCM_ARG2, __FUNCTION__, "symbol");
+  SCM ack_ifs = scm_assoc (ly_symbol2scm ("events-accepted"),
+                          tr->translator_description());
+  ack_ifs = gh_cdr (ack_ifs);
+  for (SCM s = ifaces; ly_pair_p (s); s = ly_cdr (s))
+    if (scm_memq (ly_car (s), ack_ifs) != SCM_BOOL_F)
+      return true;
+  return false;
+}
 
-  return tr->internal_get_property (name);
-  
+SCM
+find_accept_translators (SCM gravlist, SCM ifaces)
+{
+  SCM l = SCM_EOL;
+  for (SCM s = gravlist; ly_pair_p (s);  s = ly_cdr (s))
+    {
+      Translator* tr = unsmob_translator (ly_car (s));
+      if (translator_accepts_any_of (tr, ifaces))
+       l = scm_cons (tr->self_scm (), l); 
+    }
+  l = scm_reverse_x (l, SCM_EOL);
+
+  return l;
 }
 
-LY_DEFINE(ly_set_context_property,
-         "ly-set-context-property", 3, 0, 0,
-         (SCM context, SCM name, SCM val),
-         "set value of property @var{sym} in context @var{tr} to @var{val}.
-")
+bool
+Translator_group::try_music_on_nongroup_children (Music *m )
 {
-  Translator *t = unsmob_translator (context);
-  Translator_group* tr=   dynamic_cast<Translator_group*> (t);
+  SCM tab = get_property ("acceptHashTable");
+  SCM name = scm_sloppy_assq (ly_symbol2scm ("name"),
+                             m->get_property_alist (false));
+
+  if (!gh_pair_p (name))
+    return false;
 
-  SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Context");
-  tr->internal_set_property (name, val);
+  name = gh_cdr (name);
+  SCM accept_list = scm_hashq_ref (tab, name, SCM_UNDEFINED);
+  if (accept_list == SCM_BOOL_F)
+    {
+      accept_list = find_accept_translators (simple_trans_list_,
+                                            m->get_mus_property ("types"));
+      scm_hashq_set_x (tab, name, accept_list);
+    }
 
-  return SCM_UNSPECIFIED;
+  for (SCM p = accept_list; gh_pair_p (p); p = ly_cdr (p))
+    {
+      Translator * t = unsmob_translator (ly_car (p));
+      if (t && t->try_music (m))
+       return true;
+    }
+  return false;
 }
+
+SCM
+Translator_group::properties_as_alist () const
+{
+  return properties_dict()->to_alist();
+}
+