]> git.donarmstrong.com Git - lilypond.git/blob - lily/grob-info.cc
45bacb9bb907285b6061817ff74606c0b9e35b2a
[lilypond.git] / lily / grob-info.cc
1 /*
2   grob-info.cc -- implement Grob_info
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "context.hh"
10 #include "grob-info.hh"
11 #include "item.hh"
12 #include "music.hh"
13 #include "spanner.hh"
14 #include "stream-event.hh"
15 #include "translator-group.hh"
16
17 Grob_info::Grob_info (Translator *t, Grob *g)
18 {
19   origin_trans_ = t;
20   grob_ = g;
21   start_end_ = START;
22
23   /*
24     assert here, because this is easier to debug.
25   */
26   assert (g);
27 }
28
29 Grob_info::Grob_info ()
30 {
31   grob_ = 0;
32   start_end_ = START;
33   origin_trans_ = 0;
34 }
35
36 Stream_event *
37 Grob_info::event_cause () const
38 {
39   SCM cause = grob_->get_property ("cause");
40   return unsmob_stream_event (cause);
41 }
42
43 vector<Context*>
44 Grob_info::origin_contexts (Translator *end) const
45 {
46   Context *t = origin_trans_->context ();
47   vector<Context*> r;
48   do
49     {
50       r.push_back (t);
51       t = t->get_parent_context ();
52     }
53   while (t && t != end->context ());
54
55   return r;
56 }
57
58 Context *
59 Grob_info::context () const
60 {
61   return origin_trans_->context ();
62 }
63
64 Spanner *
65 Grob_info::spanner () const
66 {
67   return dynamic_cast<Spanner *> (grob_);
68 }
69
70 Item *
71 Grob_info::item () const
72 {
73   return dynamic_cast<Item *> (grob_);
74 }
75
76 Stream_event *
77 Grob_info::ultimate_event_cause () const
78 {
79   SCM cause = grob_->self_scm ();
80   while (unsmob_grob (cause))
81     {
82       cause = unsmob_grob (cause)->get_property ("cause");
83     }
84   return unsmob_stream_event (cause);
85 }