+Context *
+Context::create_context (Context_def *cdef,
+ string id,
+ SCM ops)
+{
+ int unique = get_global_context()->new_unique();
+
+ // TODO: The following should be carried out by a listener.
+ string type = ly_symbol2string (cdef->get_context_name ());
+ Object_key const *key = key_manager_.get_context_key (now_mom(), type, id);
+ Context *new_context
+ = cdef->instantiate (ops, key);
+
+ new_context->id_string_ = id;
+ new_context->unique_ = unique;
+
+ new_context->events_below_->register_as_listener (new_context->event_source_);
+
+ add_context (new_context);
+ apply_property_operations (new_context, ops);
+ events_below_->register_as_listener (new_context->events_below_);
+
+ // TODO: The above operations should be performed by a listener to the following event.
+ send_stream_event (this, "CreateContext",
+ ly_symbol2scm ("unique"), scm_int2num (unique),
+ ly_symbol2scm ("ops"), ops,
+ ly_symbol2scm ("type"), cdef->get_context_name (),
+ ly_symbol2scm ("id"), scm_makfrom0str (id.c_str ()));
+
+ return new_context;
+}
+