*/
-#include "object-key.hh"
-#include "context-def.hh"
-#include "context-selector.hh"
#include "context.hh"
+
+#include "context-def.hh"
#include "ly-smobs.icc"
#include "main.hh"
#include "output-def.hh"
if (!t->init_)
{
t->init_ = true;
-#ifdef TWEAK
- Context_selector::register_context (t);
-#endif
+
scm_gc_unprotect_object (ts);
Context_def *td = unsmob_context_def (t->definition_);
definition_ = SCM_EOL;
smobify_self ();
-
properties_scm_ = (new Scheme_hash_table)->self_scm ();
scm_gc_unprotect_object (properties_scm_);
+ scm_gc_unprotect_object (key_->self_scm ());
}
+/*
+ TODO: this shares code with find_create_context().
+ */
+Context*
+Context::create_unique_context (SCM n, SCM operations)
+{
+ /*
+ Don't create multiple score contexts.
+ */
+ if (dynamic_cast<Global_context*> (this)
+ && dynamic_cast<Global_context*> (this)->get_score_context ())
+ return get_score_context ()->create_unique_context (n, operations);
+
+ /*
+ TODO: use accepts_list_.
+ */
+ Link_array<Context_def> path
+ = unsmob_context_def (definition_)->path_to_acceptable_context (n, get_output_def ());
+
+ if (path.size ())
+ {
+ Context * current = this;
+
+ // start at 1. The first one (index 0) will be us.
+ for (int i = 0; i < path.size (); i++)
+ {
+ SCM ops = (i == path.size () -1) ? operations : SCM_EOL;
+
+ current = current->create_context (path[i],
+ "\\new",
+ ops);
+ }
+
+ return current;
+ }
+
+ /*
+ Don't go up to Global_context, because global goes down to
+ Score_context
+ */
+ Context *ret = 0;
+ if (daddy_context_ && !dynamic_cast<Global_context*> (daddy_context_))
+ ret = daddy_context_->create_unique_context (n, operations);
+ else
+ {
+ warning (_f ("Cannot find or create new `%s'",
+ ly_symbol2string (n).to_str0 ()));
+ ret = 0;
+ }
+ return ret;
+}
Context *
if (n == ly_symbol2scm ("Bottom"))
{
Context* tg = get_default_interpreter ();
- tg->id_string_ = id;
return tg;
}
Context * current = this;
// start at 1. The first one (index 0) will be us.
- for (int i=0; i < path.size (); i++)
+ for (int i = 0; i < path.size (); i++)
{
SCM ops = (i == path.size () -1) ? operations : SCM_EOL;
}
- current = create_context (path[i],
- this_id,
- ops);
+ current = current->create_context (path[i],
+ this_id,
+ ops);
}
return current;
{
warning (_f ("Cannot find or create `%s' called `%s'",
ly_symbol2string (n).to_str0 (), id));
- ret =0;
+ ret = 0;
}
return ret;
}
Object_key const *key = get_context_key (type, id);
Context * new_group
= cdef->instantiate (ops, key);
- scm_gc_unprotect_object (key->self_scm ());
new_group->id_string_ = id;
add_context (new_group);
return new_group;
}
+
+
Object_key const*
Context::get_context_key (String type, String id)
{
scm_display (d->get_context_name (), port);
}
- if (Context *td=dynamic_cast<Context *> (sc))
+ if (Context *td = dynamic_cast<Context *> (sc))
{
scm_puts ("=", port);
scm_puts (td->id_string_.to_str0 (), port);