2 Translator_group.cc -- implement Translator_group
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "output-def.hh"
10 #include "translator-group.hh"
11 #include "translator.hh"
14 #include "scm-hash.hh"
15 #include "context-def.hh"
21 Translator_group::get_daddy_translator () const
23 return context ()->get_parent_context ()->implementation ();
28 translator_each (SCM list, Translator_method method)
30 for (SCM p = list; scm_is_pair (p); p = scm_cdr (p))
31 (unsmob_translator (scm_car (p))->*method) ();
36 Translator_group::initialize ()
38 SCM tab = scm_make_vector (scm_int2num (19), SCM_BOOL_F);
39 context ()->set_property ("acceptHashTable", tab);
44 translator_accepts_any_of (Translator*tr, SCM ifaces)
46 SCM ack_ifs = scm_assoc (ly_symbol2scm ("events-accepted"),
47 tr->translator_description ());
48 ack_ifs = scm_cdr (ack_ifs);
49 for (SCM s = ifaces; scm_is_pair (s); s = scm_cdr (s))
50 if (scm_c_memq (scm_car (s), ack_ifs) != SCM_BOOL_F)
56 find_accept_translators (SCM gravlist, SCM ifaces)
59 for (SCM s = gravlist; scm_is_pair (s); s = scm_cdr (s))
61 Translator* tr = unsmob_translator (scm_car (s));
62 if (translator_accepts_any_of (tr, ifaces))
63 l = scm_cons (tr->self_scm (), l);
65 l = scm_reverse_x (l, SCM_EOL);
71 Translator_group::try_music (Music* m)
73 SCM tab = get_property ("acceptHashTable");
74 SCM name = scm_sloppy_assq (ly_symbol2scm ("name"),
75 m->get_property_alist (false));
77 if (!scm_is_pair (name))
80 name = scm_cdr (name);
81 SCM accept_list = scm_hashq_ref (tab, name, SCM_UNDEFINED);
82 if (accept_list == SCM_BOOL_F)
84 accept_list = find_accept_translators (get_simple_trans_list (),
85 m->get_property ("types"));
86 scm_hashq_set_x (tab, name, accept_list);
89 for (SCM p = accept_list; scm_is_pair (p); p = scm_cdr (p))
91 Translator * t = unsmob_translator (scm_car (p));
92 if (t && t->try_music (m))
100 Translator_group::get_simple_trans_list ()
102 return simple_trans_list_;
106 recurse_over_translators (Context * c, Translator_method ptr, Direction dir)
108 Translator_group * tg
109 = dynamic_cast<Translator_group*> (c->implementation ());
117 translator_each (tg->get_simple_trans_list (),
123 for (SCM s = c->children_contexts () ; scm_is_pair (s);
126 recurse_over_translators (unsmob_context (scm_car (s)), ptr, dir);
131 translator_each (tg->get_simple_trans_list (),
138 Translator_group::Translator_group()
140 simple_trans_list_ = SCM_EOL;
144 Translator_group::derived_mark () const
146 scm_gc_mark (simple_trans_list_);