* lily/ledger-line-engraver.cc: new file.
[lilypond.git] / lily / text-spanner-engraver.cc
blobb7bd32b9e1ffc07d7f6804bc2b4c5767e3c20ed2
1 /*
2 text-spanner-engraver.cc -- implement Text_spanner_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
9 #include "note-column.hh"
10 #include "item.hh"
11 #include "side-position-interface.hh"
12 #include "engraver.hh"
14 class Text_spanner_engraver : public Engraver
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 ();
25 private:
26 Spanner *span_;
27 Spanner *finished_;
28 Music *current_req_;
29 Drul_array<Music*> req_drul_;
30 void typeset_all ();
34 Text_spanner_engraver::Text_spanner_engraver ()
36 finished_ = 0;
37 current_req_ = 0;
38 span_ =0;
39 req_drul_[START] = 0;
40 req_drul_[STOP] = 0;
43 bool
44 Text_spanner_engraver::try_music (Music *m)
46 if (m->is_mus_type ("text-span-event"))
49 Direction d = to_dir (m->get_property ("span-direction"));
50 req_drul_[d] = m;
51 return true;
54 return false;
57 void
58 Text_spanner_engraver::process_music ()
60 if (req_drul_[STOP])
62 if (!span_)
64 req_drul_[STOP]->origin ()->warning
65 (_ ("can't find start of text spanner"));
67 else
69 finished_ = span_;
70 span_ = 0;
71 current_req_ = 0;
75 if (req_drul_[START])
77 if (current_req_)
79 req_drul_[START]->origin ()->warning (_ ("already have a text spanner"));
81 else
83 current_req_ = req_drul_[START];
84 span_ = make_spanner ("TextSpanner", req_drul_[START]->self_scm ());
87 Side_position_interface::set_axis (span_, Y_AXIS);
88 req_drul_[START] = 0;
93 void
94 Text_spanner_engraver::acknowledge_grob (Grob_info info)
96 Spanner * spans[2] ={span_, finished_};
97 for (int i = 0; i < 2 ; i++)
99 if (spans[i] && Note_column::has_interface (info.grob_))
101 Side_position_interface::add_support (spans[i], info.grob_);
102 add_bound_item (spans[i], dynamic_cast<Item*> (info.grob_));
107 void
108 Text_spanner_engraver::typeset_all ()
110 if (finished_)
112 if (!finished_->get_bound (RIGHT))
114 Grob* e = unsmob_grob (get_property ("currentMusicalColumn"));
115 finished_->set_bound (RIGHT, e);
117 finished_ = 0;
121 void
122 Text_spanner_engraver::stop_translation_timestep ()
124 if (span_ && !span_->get_bound (LEFT))
126 Grob* e = unsmob_grob (get_property ("currentMusicalColumn"));
127 span_->set_bound (LEFT, e);
130 typeset_all ();
131 req_drul_[START] = 0;
132 req_drul_[STOP] = 0;
135 void
136 Text_spanner_engraver::finalize ()
138 typeset_all ();
139 if (span_)
141 current_req_->origin ()->warning (_ ("unterminated text spanner"));
142 span_->suicide ();
143 span_ = 0;
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 */ "");