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;
20 Grob_selector::register_grob (Context *context, Grob *grob)
23 grobs_ = new Scheme_hash_table ();
25 if (Grob *first = retrieve_grob (identify_grob (context, grob, 0)))
27 count = robust_scm2int (first->get_property ("max"), 0);
29 SCM s = scm_int2num (count);
30 first->set_property ("max", s);
31 grob->set_property ("count", s);
33 grob->set_property ("context", context->self_scm ());
34 grobs_->set (identify_grob (context, grob, count), grob->self_scm ());
38 Grob_selector::identify_grob (Context *context, Grob *grob, int count)
40 return ly_symbol2scm ((ly_symbol2string (Context_selector::identify_context (context))
43 #if 0 // "when" not defined yet?
45 + Paper_column::when_mom (((Item*)grob)->get_column ()).to_string (),
48 + to_string (count)).to_str0 ());
52 Grob_selector::identify_grob (Grob *grob)
54 return identify_grob (unsmob_context (grob->get_property ("context")),
56 robust_scm2int (grob->get_property ("count"), 0));
60 Grob_selector::retrieve_grob (SCM key)
62 return unsmob_grob (grobs_->get (key));
65 LY_DEFINE (ly_grob_id, "ly:grob-id",
66 1, 0, 0, (SCM grob_scm),
69 Grob *grob = unsmob_grob (grob_scm);
70 SCM_ASSERT_TYPE (grob, grob_scm, SCM_ARG1, __FUNCTION__, "grob");
71 return Grob_selector::identify_grob (grob);