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 grobs_ = new Scheme_hash_table ();
26 Moment m = context->now_mom ();
27 if (Grob *first = retrieve_grob (identify_grob (context, m, grob, 0)))
29 count = robust_scm2int (first->get_property ("tweak-count"), 0);
31 SCM s = scm_int2num (count);
32 first->set_property ("tweak-count", s);
33 grob->set_property ("tweak-rank", s);
35 grob->set_property ("context", context->self_scm ());
36 SCM grob_id = identify_grob (context, m, grob, count);
37 store_grob (grob_id, grob);
38 SCM tweak = ly_assoc_get (grob_id, tweaks_, SCM_BOOL_F);
39 if (tweak != SCM_BOOL_F)
40 grob->set_property (ly_symbol2string (scm_car (tweak)).to_str0 (),
45 Grob_selector::identify_grob (Context *context, Moment m, Grob *grob, int count)
47 return scm_list_4 (Context_selector::identify_context (context),
48 scm_makfrom0str (m.to_string ().to_str0 ()),
49 scm_makfrom0str (grob->name ().to_str0 ()),
54 Grob_selector::identify_grob (Grob *grob)
57 return identify_grob (unsmob_context (grob->get_property ("context")),
58 Paper_column::when_mom (((Item*) grob)->get_column ()),
60 robust_scm2int (grob->get_property ("tweak-rank"), 0));
64 Grob_selector::store_grob (SCM grob_id, Grob *grob)
66 grobs_->set (ly_to_symbol (grob_id), grob->self_scm ());
70 Grob_selector::retrieve_grob (SCM grob_id)
72 return unsmob_grob (grobs_->get (ly_to_symbol (grob_id)));
76 Grob_selector::set_tweaks (SCM tweaks)
81 LY_DEFINE (ly_grob_id, "ly:grob-id",
82 1, 0, 0, (SCM grob_scm),
85 Grob *grob = unsmob_grob (grob_scm);
86 SCM_ASSERT_TYPE (grob, grob_scm, SCM_ARG1, __FUNCTION__, "grob");
87 return Grob_selector::identify_grob (grob);