2 context-selector.cc -- implement Context selection.
4 source file of the GNU LilyPond music typesetter
6 (c) 2004 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "context-selector.hh"
11 #include "scm-hash.hh"
13 Scheme_hash_table *Context_selector::contexts_ = 0;
16 Context_selector::register_context (Context *context)
19 if (Context *first = retrieve_context (identify_context (context, 0)))
21 count = robust_scm2int (first->get_property ("tweakCount"), 0);
23 SCM s = scm_int2num (count);
24 first->set_property ("tweakCount", s);
25 context->set_property ("tweakRank", s);
27 /* FIXME: must alway set rank, for get_property () not to segfault. */
28 context->set_property ("tweakRank", scm_int2num (count));
29 store_context (identify_context (context, count), context);
33 Context_selector::identify_context (Context *context, int count)
35 /* TODO: start time, parent-context-at-start */
36 return scm_list_3 (scm_makfrom0str (context->context_name ().to_str0 ()),
37 scm_makfrom0str (context->id_string ().to_str0 ()),
42 Context_selector::identify_context (Context *context)
45 identify_context (context,
46 robust_scm2int (context->get_property ("tweakRank"), 0));
50 Context_selector::store_context (SCM context_id, Context *context)
52 contexts_->set (ly_to_symbol (context_id), context->self_scm ());
56 Context_selector::retrieve_context (SCM context_id)
58 return unsmob_context (contexts_->get (ly_to_symbol (context_id)));
62 Context_selector::set_tweaks (SCM tweaks)
65 contexts_ = new Scheme_hash_table ();