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"
16 Scheme_hash_table *Grob_selector::grobs_ = 0;
19 Grob_selector::register_grob (Context *context, Grob *grob)
22 grobs_ = new Scheme_hash_table ();
24 if (Grob *first = retrieve_grob (identify_grob (context, grob, 0)))
26 count = robust_scm2int (first->get_property ("max"), 0);
28 SCM s = scm_int2num (count);
29 first->set_property ("max", s);
30 grob->set_property ("count", s);
32 grob->set_property ("context", context->self_scm ());
33 grobs_->set (identify_grob (context, grob, count), grob->self_scm ());
37 Grob_selector::identify_grob (Context *context, Grob *grob, int count)
39 return ly_symbol2scm ((ly_symbol2string (Context_selector::identify_context (context))
42 #if 0 // "when" not defined yet?
44 + Paper_column::when_mom (((Item*)grob)->get_column ()).to_string (),
47 + to_string (count)).to_str0 ());
51 Grob_selector::identify_grob (Grob *grob)
53 return identify_grob (unsmob_context (grob->get_property ("context")),
55 robust_scm2int (grob->get_property ("count"), 0));
59 Grob_selector::retrieve_grob (SCM key)
61 return unsmob_grob (grobs_->get (key));
64 LY_DEFINE (ly_grob_id, "ly:grob-id",
65 1, 0, 0, (SCM grob_scm),
68 Grob *grob = unsmob_grob (grob_scm);
69 SCM s = Grob_selector::identify_grob (grob);