]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-spanner-engraver.cc
* lily/dynamic-text-spanner.cc (print): new file.
[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       Direction d = to_dir (m->get_property ("span-direction"));
49       req_drul_[d] = m;
50       return true;
51     }
52
53   return false;
54 }
55
56 void
57 Text_spanner_engraver::process_music ()
58 {
59   if (req_drul_[STOP])
60     {
61       if (!span_)
62         {
63           req_drul_[STOP]->origin ()->warning (_ ("can't find start of text spanner"));
64         }
65       else
66         {
67           finished_ = span_;
68           span_ = 0;
69           current_req_ = 0;
70         }
71     }
72
73   if (req_drul_[START])
74     {
75       if (current_req_)
76         {
77           req_drul_[START]->origin ()->warning (_ ("already have a text spanner"));
78         }
79       else
80         {
81           current_req_ = req_drul_[START];
82           span_  = make_spanner ("TextSpanner", req_drul_[START]->self_scm ());
83
84           
85           Side_position_interface::set_axis (span_, Y_AXIS);
86           req_drul_[START] = 0;
87         }
88     }
89 }
90
91 void
92 Text_spanner_engraver::acknowledge_grob (Grob_info info)
93 {
94   Spanner * spans[2] ={span_, finished_};
95   for (int i = 0;  i < 2 ; i++)
96     {
97       if (spans[i] && Note_column::has_interface (info.grob_))
98         {
99           Side_position_interface::add_support (spans[i], info.grob_);
100           add_bound_item (spans[i], dynamic_cast<Item*> (info.grob_));
101         }
102     }
103 }
104
105 void
106 Text_spanner_engraver::typeset_all ()
107 {  
108   if (finished_)
109     {
110       if (!finished_->get_bound (RIGHT))
111         {
112           Grob* e = unsmob_grob (get_property ("currentMusicalColumn"));
113           finished_->set_bound (RIGHT, e);
114         }
115       finished_ = 0;
116     }
117 }
118
119 void
120 Text_spanner_engraver::stop_translation_timestep ()
121 {
122   if (span_ && !span_->get_bound (LEFT))
123     {
124       Grob* e = unsmob_grob (get_property ("currentMusicalColumn"));
125       span_->set_bound (LEFT, e);
126     }
127
128   typeset_all ();
129   req_drul_[START] = 0;
130   req_drul_[STOP] = 0;
131 }
132
133 void
134 Text_spanner_engraver::finalize ()
135 {
136   typeset_all ();
137   if (span_)
138     {
139       current_req_->origin ()->warning (_ ("unterminated text spanner"));
140       span_->suicide ();
141       span_ = 0;
142     }
143 }
144
145 ENTER_DESCRIPTION (Text_spanner_engraver,
146 /* descr */       "Create text spanner from a Music.",
147 /* creats*/       "TextSpanner",
148 /* accepts */     "text-span-event",
149 /* acks  */      "note-column-interface",
150 /* reads */       "",
151 /* write */       "");