]> git.donarmstrong.com Git - lilypond.git/blob - lily/context-selector.cc
* lily/lookup.cc (triangle): rewrite, obviating symmetric_x_triangle().
[lilypond.git] / lily / context-selector.cc
1 /*
2   context-selector.cc -- implement Context selection.
3
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2004 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "context-selector.hh"
10 #include "context.hh"
11 #include "scm-hash.hh"
12
13 Scheme_hash_table *Context_selector::contexts_ = 0;
14
15 void
16 Context_selector::register_context (Context *context)
17 {
18   int count = 0;
19   if (Context *first = retrieve_context (identify_context (context, 0)))
20     {
21       count = robust_scm2int (first->get_property ("tweakCount"), 0);
22       count++;
23       SCM s = scm_int2num (count);
24       first->set_property ("tweakCount", s);
25       context->set_property ("tweakRank", s);
26   }
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);
30 }
31
32 SCM
33 Context_selector::identify_context (Context *context, int count)
34 {
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 ()),
38                      scm_int2num (count));
39 }
40
41 SCM
42 Context_selector::identify_context (Context *context)
43 {
44   return
45     identify_context (context,
46                       robust_scm2int (context->get_property ("tweakRank"), 0));
47 }
48
49 void
50 Context_selector::store_context (SCM context_id, Context *context)
51 {
52   contexts_->set (ly_to_symbol (context_id), context->self_scm ());
53 }
54
55 Context *
56 Context_selector::retrieve_context (SCM context_id)
57 {
58   return unsmob_context (contexts_->get (ly_to_symbol (context_id)));
59 }
60
61 void
62 Context_selector::set_tweaks (SCM tweaks)
63 {
64   (void) tweaks;
65   contexts_ = new Scheme_hash_table ();
66   //tweaks_ = tweaks;
67 }
68