Bump version.
[lilypond.git] / lily / hyphen-engraver.cc
bloba9ea53054e7e4b96f356bdc95a8b9c3f411dd97e
1 /*
2 hyphen-engraver.cc -- implement Hyphen_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2007 Glen Prideaux <glenprideaux@iname.com>,
7 Han-Wen Nienhuys <hanwen@xs4all.nl>,
8 Jan Nieuwenhuizen <janneke@gnu.org>
9 */
11 #include "engraver.hh"
12 #include "international.hh"
13 #include "item.hh"
14 #include "pointer-group-interface.hh"
15 #include "spanner.hh"
16 #include "stream-event.hh"
17 #include "warn.hh"
19 #include "translator.icc"
21 class Hyphen_engraver : public Engraver
23 Stream_event *ev_;
24 Stream_event *finished_ev_;
26 Spanner *hyphen_;
27 Spanner *finished_hyphen_;
29 public:
30 TRANSLATOR_DECLARATIONS (Hyphen_engraver);
32 protected:
34 DECLARE_ACKNOWLEDGER (lyric_syllable);
35 DECLARE_TRANSLATOR_LISTENER (hyphen);
37 virtual void finalize ();
39 void stop_translation_timestep ();
40 void process_music ();
43 Hyphen_engraver::Hyphen_engraver ()
45 hyphen_ = 0;
46 finished_hyphen_ = 0;
47 finished_ev_ = 0;
48 ev_ = 0;
51 void
52 Hyphen_engraver::acknowledge_lyric_syllable (Grob_info i)
54 Item *item = i.item ();
56 if (!hyphen_)
57 hyphen_ = make_spanner ("LyricSpace", item->self_scm ());
59 if (hyphen_)
60 hyphen_->set_bound (LEFT, item);
62 if (finished_hyphen_)
63 finished_hyphen_->set_bound (RIGHT, item);
66 IMPLEMENT_TRANSLATOR_LISTENER (Hyphen_engraver, hyphen);
67 void
68 Hyphen_engraver::listen_hyphen (Stream_event *ev)
70 ASSIGN_EVENT_ONCE (ev_, ev);
73 void
74 completize_hyphen (Spanner *sp)
76 if (!sp->get_bound (RIGHT))
78 extract_item_set (sp, "heads", heads);
79 if (heads.size ())
80 sp->set_bound (RIGHT, heads.back ());
84 void
85 Hyphen_engraver::finalize ()
87 if (hyphen_)
89 completize_hyphen (hyphen_);
91 if (!hyphen_->get_bound (RIGHT))
93 hyphen_->warning (_ ("removing unterminated hyphen"));
94 hyphen_->suicide ();
97 hyphen_ = 0;
100 if (finished_hyphen_)
102 completize_hyphen (finished_hyphen_);
104 if (!finished_hyphen_->get_bound (RIGHT))
106 if (finished_ev_)
107 finished_hyphen_->warning (_ ("unterminated hyphen; removing"));
108 finished_hyphen_->suicide ();
110 finished_hyphen_ = 0;
114 void
115 Hyphen_engraver::process_music ()
117 if (ev_)
118 hyphen_ = make_spanner ("LyricHyphen", ev_->self_scm ());
121 void
122 Hyphen_engraver::stop_translation_timestep ()
124 if (finished_hyphen_ && finished_hyphen_->get_bound (RIGHT))
126 finished_hyphen_ = 0;
127 finished_ev_ = 0;
130 if (finished_hyphen_ && hyphen_)
132 programming_error ("hyphen not finished yet");
133 finished_hyphen_ = 0;
134 finished_ev_ = 0;
137 if (hyphen_)
139 finished_hyphen_ = hyphen_;
140 finished_ev_ = ev_;
143 hyphen_ = 0;
144 ev_ = 0;
147 ADD_ACKNOWLEDGER (Hyphen_engraver, lyric_syllable);
149 ADD_TRANSLATOR (Hyphen_engraver,
150 /* doc */
151 "Create lyric hyphens and distance constraints between words.",
153 /* create */
154 "LyricHyphen "
155 "LyricSpace ",
157 /* read */
160 /* write */