]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-spanner-engraver.cc
release: 1.3.109
[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 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "dimensions.hh"
10 #include "musical-request.hh"
11 #include "paper-column.hh"
12 #include "note-column.hh"
13 #include "item.hh"
14 #include "side-position-interface.hh"
15 #include "engraver.hh"
16 #include "group-interface.hh"
17 #include "directional-element-interface.hh"
18 #include "translator-group.hh"
19 #include "axis-group-interface.hh"
20
21
22 class Text_spanner_engraver : public Engraver
23 {
24 public:
25   VIRTUAL_COPY_CONS (Translator);
26   Text_spanner_engraver ();
27   
28 protected:
29   virtual void do_removal_processing ();
30   virtual void acknowledge_grob (Grob_info);
31   virtual bool try_music (Music *);
32   void deprecated_process_music ();
33   virtual void stop_translation_timestep ();
34   virtual void start_translation_timestep ();
35   virtual void create_grobs ();
36
37 private:
38   Spanner *span_;
39   Spanner *finished_;
40   Span_req *current_req_;
41   Drul_array<Span_req*> req_drul_;
42   void typeset_all ();
43 };
44
45 ADD_THIS_TRANSLATOR (Text_spanner_engraver);
46
47
48 Text_spanner_engraver::Text_spanner_engraver ()
49 {
50   finished_ = 0;
51   current_req_ = 0;
52   span_ =0;
53   req_drul_[START] = 0;
54   req_drul_[STOP] = 0;
55 }
56
57 void
58 Text_spanner_engraver::start_translation_timestep ()
59 {
60   req_drul_[START] = 0;
61   req_drul_[STOP] = 0;
62 }
63
64 bool
65 Text_spanner_engraver::try_music (Music *m)
66 {
67   if (Span_req *s =  dynamic_cast <Span_req*> (m))
68     {
69       String t =  ly_scm2string (s->get_mus_property ("span-type"));            
70       if (t == "abort")
71         {
72           req_drul_[LEFT] = 0;
73           req_drul_[RIGHT] = 0;
74           if (span_)
75             span_->suicide ();
76           span_ = 0;
77         }
78       else if (t == "text")
79         {
80           req_drul_[s->get_span_dir()] = s;
81           return true;
82         }
83     }
84   return false;
85 }
86
87 void
88 Text_spanner_engraver::create_grobs ()
89 {
90   deprecated_process_music ();
91 }
92
93 void
94 Text_spanner_engraver::deprecated_process_music ()
95 {
96   /////
97   if (req_drul_[STOP])
98     {
99       if (!span_)
100         {
101           req_drul_[STOP]->origin ()->warning
102             (_ ("can't find start of text spanner"));
103         }
104       else
105         {
106           assert (!finished_);
107           Grob* e = unsmob_element (get_property ("currentMusicalColumn"));
108           span_->set_bound (RIGHT, e);
109
110           finished_ = span_;
111           span_ = 0;
112           current_req_ = 0;
113         }
114     }
115
116   if (req_drul_[START])
117     {
118       if (current_req_)
119         {
120           req_drul_[START]->origin ()->warning
121             (_ ("already have a text spanner"));
122         }
123       else
124         {
125           current_req_ = req_drul_[START];
126           span_  = new Spanner (get_property ("TextSpanner"));
127           Side_position::set_axis (span_, Y_AXIS);
128           Grob *e = unsmob_element (get_property ("currentMusicalColumn"));
129           span_->set_bound (LEFT, e);
130           announce_grob (span_, req_drul_[START]);
131         }
132     }
133 }
134
135 void
136 Text_spanner_engraver::acknowledge_grob (Grob_info info)
137 {
138   if (span_ && Note_column::has_interface (info.elem_l_))
139     {
140       Side_position::add_support (span_, info.elem_l_);
141       add_bound_item (span_, dynamic_cast<Item*> (info.elem_l_));
142     }
143 }
144
145 void
146 Text_spanner_engraver::typeset_all ()
147 {  
148   if (finished_)
149     {
150       Side_position::add_staff_support (finished_);
151       typeset_grob (finished_);
152       finished_ = 0;
153     }
154 }
155
156 void
157 Text_spanner_engraver::stop_translation_timestep ()
158 {
159   typeset_all ();
160 }
161
162 void
163 Text_spanner_engraver::do_removal_processing ()
164 {
165   typeset_all ();
166   if (span_)
167     {
168       current_req_->origin ()->warning (_ ("unterminated text spanner"));
169       span_->suicide ();
170       span_ = 0;
171     }
172 }
173