1 #include "translator-group.hh"
2 #include "context-def.hh"
4 #include "music-output-def.hh"
9 Translator_group::is_removable () const
11 return trans_group_list_ == SCM_EOL && ! iterator_count_;
15 Translator_group::find_existing_translator (SCM n, String id)
17 if ((is_alias (n) && (id_string_ == id || id.is_empty ())) || n == ly_symbol2scm ("Current"))
20 Translator_group* r = 0;
21 for (SCM p = trans_group_list_; !r && gh_pair_p (p); p = ly_cdr (p))
23 Translator * t = unsmob_translator (ly_car (p));
25 r = dynamic_cast<Translator_group*> (t)->find_existing_translator (n, id);
33 Translator_group::find_create_translator (SCM n, String id, SCM operations)
35 Translator_group * existing = find_existing_translator (n,id);
39 if (n == ly_symbol2scm ("Bottom"))
41 Translator_group* tg = get_default_interpreter ();
47 TODO: use accepts_list_.
49 Link_array<Context_def> path
50 = unsmob_context_def (definition_)->path_to_acceptable_translator (n, get_output_def ());
54 Translator_group * current = this;
56 // start at 1. The first one (index 0) will be us.
57 for (int i=0; i < path.size (); i++)
59 SCM ops = (i == path.size () -1) ? operations : SCM_EOL;
61 Translator_group * new_group
62 = path[i]->instantiate (ops);
64 if (i == path.size () -1)
66 new_group->id_string_ = id;
69 current->add_fresh_group_translator (new_group);
70 apply_property_operations (new_group, ops);
78 Translator_group *ret = 0;
80 ret = daddy_trans_->find_create_translator (n, id, operations);
83 warning (_f ("Cannot find or create `%s' called `%s'",
84 ly_symbol2string (n).to_str0 (), id));
91 Default child context as a SCM string, or something else if there is
95 default_child_context_name (Translator_group const *tg)
97 return gh_pair_p (tg->accepts_list_)
98 ? ly_car (scm_last_pair (tg->accepts_list_))
104 Translator_group::is_bottom_context () const
106 return !gh_symbol_p (default_child_context_name (this));
110 Translator_group::get_default_interpreter ()
112 if (!is_bottom_context ())
114 SCM nm = default_child_context_name (this);
115 SCM st = get_output_def ()->find_translator (nm);
117 Context_def *t = unsmob_context_def (st);
120 warning (_f ("can't find or create: `%s'", ly_symbol2string (nm).to_str0 ()));
121 t = unsmob_context_def (this->definition_);
123 Translator_group *tg = t->instantiate (SCM_EOL);
124 add_fresh_group_translator (tg);
125 if (!tg->is_bottom_context ())
126 return tg->get_default_interpreter ();
137 Translator_group::where_defined (SCM sym) const
139 if (properties_dict ()->contains (sym))
141 return (Translator_group*)this;
144 return (daddy_trans_) ? daddy_trans_->where_defined (sym) : 0;
148 return SCM_EOL when not found.
151 Translator_group::internal_get_property (SCM sym) const
154 if (properties_dict ()->try_retrieve (sym, &val))
158 return daddy_trans_->internal_get_property (sym);
164 Translator_group::is_alias (SCM sym) const
166 if (sym == ly_symbol2scm ("Bottom")
167 && !gh_pair_p (accepts_list_))
169 return unsmob_context_def (definition_)->is_alias (sym);
173 Translator_group::internal_set_property (SCM sym, SCM val)
176 if (internal_type_checking_global_b)
177 assert (type_check_assignment (sym, val, ly_symbol2scm ("translation-type?")));
180 properties_dict ()->set (sym, val);
184 TODO: look up to check whether we have inherited var?
187 Translator_group::unset_property (SCM sym)
189 properties_dict ()->remove (sym);