]> git.donarmstrong.com Git - lilypond.git/blob - lily/grob-info.cc
* lily/*-performer.cc: Converted try_music to listen_*
[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--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "context.hh"
10 #include "grob-info.hh"
11 #include "grob.hh"
12 #include "item.hh"
13 #include "music.hh"
14 #include "spanner.hh"
15 #include "stream-event.hh"
16 #include "translator-group.hh"
17
18 Grob_info::Grob_info (Translator *t, Grob *g)
19 {
20   origin_trans_ = t;
21   grob_ = g;
22   start_end_ = START;
23 }
24
25 Grob_info::Grob_info ()
26 {
27   grob_ = 0;
28   start_end_ = START;
29   origin_trans_ = 0;
30 }
31
32 /* ES TODO: Junk this when no more engravers use try_music */
33 Music *
34 Grob_info::music_cause () const
35 {
36   SCM cause = grob_->get_property ("cause");
37
38   Music *ret = unsmob_music (cause);
39   if (ret)
40     return ret;
41   else
42     {
43       Stream_event *ev = unsmob_stream_event (cause);
44       if (!ev)
45         return 0;
46       return unsmob_music (ev->get_property ("music-cause"));
47     }
48 }
49
50 Stream_event *
51 Grob_info::event_cause () const
52 {
53   SCM cause = grob_->get_property ("cause");
54   return unsmob_stream_event (cause);
55 }
56
57 vector<Context*>
58 Grob_info::origin_contexts (Translator *end) const
59 {
60   Context *t = origin_trans_->context ();
61   vector<Context*> r;
62   do
63     {
64       r.push_back (t);
65       t = t->get_parent_context ();
66     }
67   while (t && t != end->context ());
68
69   return r;
70 }
71
72 Context *
73 Grob_info::context () const
74 {
75   return origin_trans_->context ();
76 }
77
78 Spanner *
79 Grob_info::spanner () const
80 {
81   return dynamic_cast<Spanner *> (grob_);
82 }
83
84 Item *
85 Grob_info::item () const
86 {
87   return dynamic_cast<Item *> (grob_);
88 }
89
90 Stream_event *
91 Grob_info::ultimate_event_cause () const
92 {
93   SCM cause = grob_->self_scm ();
94   while (unsmob_grob (cause))
95     {
96       cause = unsmob_grob (cause)->get_property ("cause");
97     }
98   return unsmob_stream_event (cause);
99 }
100
101 /*
102 ES TODO: Junk this when no more engraver uses try_music
103 */
104 Music *
105 Grob_info::ultimate_music_cause () const
106 {
107   SCM cause = grob_->self_scm ();
108   while (unsmob_grob (cause))
109     {
110       cause = unsmob_grob (cause)->get_property ("cause");
111     }
112
113   Music *ret = unsmob_music (cause);
114   if (ret)
115     return ret;
116   else
117     {
118       Stream_event *ev = unsmob_stream_event (cause);
119       return unsmob_music (ev->get_property ("music-cause"));
120     }
121 }