]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-spanner-engraver.cc
remove
[lilypond.git] / lily / text-spanner-engraver.cc
1 /*
2   text-spanner-engraver.cc -- implement Text_spanner_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "note-column.hh"
10 #include "item.hh"
11 #include "side-position-interface.hh"
12 #include "engraver.hh"
13
14 class Text_spanner_engraver : public Engraver
15 {
16 public:
17   TRANSLATOR_DECLARATIONS (Text_spanner_engraver);  
18 protected:
19   virtual void finalize ();
20   virtual void acknowledge_grob (Grob_info);
21   virtual bool try_music (Music *);
22   virtual void stop_translation_timestep ();
23   virtual void process_music ();
24
25 private:
26   Spanner *span_;
27   Spanner *finished_;
28   Music *current_req_;
29   Drul_array<Music*> req_drul_;
30   void typeset_all ();
31 };
32
33
34 Text_spanner_engraver::Text_spanner_engraver ()
35 {
36   finished_ = 0;
37   current_req_ = 0;
38   span_ =0;
39   req_drul_[START] = 0;
40   req_drul_[STOP] = 0;
41 }
42
43 bool
44 Text_spanner_engraver::try_music (Music *m)
45 {
46   if (m->is_mus_type ("text-span-event"))
47     {
48
49       Direction d = to_dir (m->get_property ("span-direction"));
50       req_drul_[d] = m;
51       return true;
52     }
53
54   return false;
55 }
56
57 void
58 Text_spanner_engraver::process_music ()
59 {
60   if (req_drul_[STOP])
61     {
62       if (!span_)
63         {
64           req_drul_[STOP]->origin ()->warning
65  (_ ("can't find start of text spanner"));
66         }
67       else
68         {
69           finished_ = span_;
70           span_ = 0;
71           current_req_ = 0;
72         }
73     }
74
75   if (req_drul_[START])
76     {
77       if (current_req_)
78         {
79           req_drul_[START]->origin ()->warning (_ ("already have a text spanner"));
80         }
81       else
82         {
83           current_req_ = req_drul_[START];
84           span_  = make_spanner ("TextSpanner", req_drul_[START]->self_scm ());
85
86           
87           Side_position_interface::set_axis (span_, Y_AXIS);
88           req_drul_[START] = 0;
89         }
90     }
91 }
92
93 void
94 Text_spanner_engraver::acknowledge_grob (Grob_info info)
95 {
96   Spanner * spans[2] ={span_, finished_};
97   for (int i = 0;  i < 2 ; i++)
98     {
99       if (spans[i] && Note_column::has_interface (info.grob_))
100         {
101           Side_position_interface::add_support (spans[i], info.grob_);
102           add_bound_item (spans[i], dynamic_cast<Item*> (info.grob_));
103         }
104     }
105 }
106
107 void
108 Text_spanner_engraver::typeset_all ()
109 {  
110   if (finished_)
111     {
112       if (!finished_->get_bound (RIGHT))
113         {
114           Grob* e = unsmob_grob (get_property ("currentMusicalColumn"));
115           finished_->set_bound (RIGHT, e);
116         }
117       finished_ = 0;
118     }
119 }
120
121 void
122 Text_spanner_engraver::stop_translation_timestep ()
123 {
124   if (span_ && !span_->get_bound (LEFT))
125     {
126       Grob* e = unsmob_grob (get_property ("currentMusicalColumn"));
127       span_->set_bound (LEFT, e);
128     }
129
130   typeset_all ();
131   req_drul_[START] = 0;
132   req_drul_[STOP] = 0;
133 }
134
135 void
136 Text_spanner_engraver::finalize ()
137 {
138   typeset_all ();
139   if (span_)
140     {
141       current_req_->origin ()->warning (_ ("unterminated text spanner"));
142       span_->suicide ();
143       span_ = 0;
144     }
145 }
146
147 ENTER_DESCRIPTION (Text_spanner_engraver,
148 /* descr */       "Create text spanner from a Music.",
149 /* creats*/       "TextSpanner",
150 /* accepts */     "text-span-event",
151 /* acks  */      "note-column-interface",
152 /* reads */       "",
153 /* write */       "");