]> git.donarmstrong.com Git - lilypond.git/blob - lily/grob-selector.cc
* scm/framework-gnome.scm (item-event): Print grob id.
[lilypond.git] / lily / grob-selector.cc
1 /*
2   grob-selector.cc -- implement Grob 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 "grob-selector.hh"
12 #include "grob.hh"
13 #include "paper-column.hh"
14 #include "scm-hash.hh"
15
16 Scheme_hash_table *Grob_selector::grobs_ = 0;
17
18 void
19 Grob_selector::register_grob (Context *context, Grob *grob)
20 {
21   if (!grobs_)
22     grobs_ = new Scheme_hash_table ();
23   int count = 0;
24   if (Grob *first = retrieve_grob (identify_grob (context, grob, 0)))
25     {
26       count = robust_scm2int (first->get_property ("max"), 0);
27       count++;
28       SCM s = scm_int2num (count);
29       first->set_property ("max", s);
30       grob->set_property ("count", s);
31     }
32   grob->set_property ("context", context->self_scm ());
33   grobs_->set (identify_grob (context, grob, count), grob->self_scm ());
34 }
35
36 SCM
37 Grob_selector::identify_grob (Context *context, Grob *grob, int count)
38 {
39   return ly_symbol2scm ((ly_symbol2string (Context_selector::identify_context (context))
40                          + ","
41                          + grob->name ()
42 #if 0   // "when" not defined yet?
43                          + ","
44                          + Paper_column::when_mom (((Item*)grob)->get_column ()).to_string (),
45 #endif                   
46                          + ","
47                          + to_string (count)).to_str0 ());
48 }
49
50 SCM
51 Grob_selector::identify_grob (Grob *grob)
52 {
53   return identify_grob (unsmob_context (grob->get_property ("context")),
54                         grob,
55                         robust_scm2int (grob->get_property ("count"), 0));
56 }
57
58 Grob *
59 Grob_selector::retrieve_grob (SCM key)
60 {
61   return unsmob_grob (grobs_->get (key));
62 }
63
64 LY_DEFINE (ly_grob_id, "ly:grob-id",
65            1, 0, 0, (SCM grob_scm),
66            "Return grob id.")
67 {
68   Grob *grob = unsmob_grob (grob_scm);
69   SCM s = Grob_selector::identify_grob (grob);
70   return s;
71 }