2 grob-selector.cc -- implement Grob 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 "grob-selector.hh"
13 #include "paper-column.hh"
14 #include "scm-hash.hh"
17 Scheme_hash_table *Grob_selector::grobs_ = 0;
18 Protected_scm Grob_selector::tweaks_ = SCM_EOL;
21 Grob_selector::register_grob (Context *context, Grob *grob)
24 Moment m = context->now_mom ();
25 if (Grob *first = retrieve_grob (identify_grob (context, m, grob, 0)))
27 count = robust_scm2int (first->get_property ("tweak-count"), 0);
29 SCM s = scm_int2num (count);
30 first->set_property ("tweak-count", s);
31 grob->set_property ("tweak-rank", s);
33 grob->set_property ("context", context->self_scm ());
34 SCM grob_id = identify_grob (context, m, grob, count);
35 store_grob (grob_id, grob);
36 SCM tweak = ly_assoc_get (grob_id, tweaks_, SCM_BOOL_F);
37 if (tweak != SCM_BOOL_F)
38 grob->set_property (ly_symbol2string (scm_car (tweak)).to_str0 (),
43 Grob_selector::identify_grob (Context *context, Moment m, Grob *grob, int count)
45 return scm_list_4 (Context_selector::identify_context (context),
46 scm_makfrom0str (m.to_string ().to_str0 ()),
47 scm_makfrom0str (grob->name ().to_str0 ()),
52 Grob_selector::identify_grob (Grob *grob)
55 return identify_grob (unsmob_context (grob->get_property ("context")),
56 Paper_column::when_mom (((Item*) grob)->get_column ()),
58 robust_scm2int (grob->get_property ("tweak-rank"), 0));
62 Grob_selector::store_grob (SCM grob_id, Grob *grob)
64 grobs_->set (ly_to_symbol (grob_id), grob->self_scm ());
68 Grob_selector::retrieve_grob (SCM grob_id)
70 return unsmob_grob (grobs_->get (ly_to_symbol (grob_id)));
74 Grob_selector::set_tweaks (SCM tweaks)
76 grobs_ = new Scheme_hash_table ();
80 LY_DEFINE (ly_grob_id, "ly:grob-id",
81 1, 0, 0, (SCM grob_scm),
84 Grob *grob = unsmob_grob (grob_scm);
85 SCM_ASSERT_TYPE (grob, grob_scm, SCM_ARG1, __FUNCTION__, "grob");
86 return Grob_selector::identify_grob (grob);