LSR: Update.
[lilypond/mpolesky.git] / lily / hyphen-engraver.cc
blob223fd1f05a94298f53c1bb3d6b188b536fa22fda
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1999--2010 Glen Prideaux <glenprideaux@iname.com>,
5 Han-Wen Nienhuys <hanwen@xs4all.nl>,
6 Jan Nieuwenhuizen <janneke@gnu.org>
8 LilyPond is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 LilyPond is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
22 #include "engraver.hh"
23 #include "international.hh"
24 #include "item.hh"
25 #include "pointer-group-interface.hh"
26 #include "spanner.hh"
27 #include "stream-event.hh"
28 #include "warn.hh"
30 #include "translator.icc"
32 class Hyphen_engraver : public Engraver
34 Stream_event *ev_;
35 Stream_event *finished_ev_;
37 Spanner *hyphen_;
38 Spanner *finished_hyphen_;
40 public:
41 TRANSLATOR_DECLARATIONS (Hyphen_engraver);
43 protected:
45 DECLARE_ACKNOWLEDGER (lyric_syllable);
46 DECLARE_TRANSLATOR_LISTENER (hyphen);
48 virtual void finalize ();
50 void stop_translation_timestep ();
51 void process_music ();
54 Hyphen_engraver::Hyphen_engraver ()
56 hyphen_ = 0;
57 finished_hyphen_ = 0;
58 finished_ev_ = 0;
59 ev_ = 0;
62 void
63 Hyphen_engraver::acknowledge_lyric_syllable (Grob_info i)
65 Item *item = i.item ();
67 if (!hyphen_)
68 hyphen_ = make_spanner ("LyricSpace", item->self_scm ());
70 if (hyphen_)
71 hyphen_->set_bound (LEFT, item);
73 if (finished_hyphen_)
74 finished_hyphen_->set_bound (RIGHT, item);
77 IMPLEMENT_TRANSLATOR_LISTENER (Hyphen_engraver, hyphen);
78 void
79 Hyphen_engraver::listen_hyphen (Stream_event *ev)
81 ASSIGN_EVENT_ONCE (ev_, ev);
84 void
85 completize_hyphen (Spanner *sp)
87 if (!sp->get_bound (RIGHT))
89 extract_item_set (sp, "heads", heads);
90 if (heads.size ())
91 sp->set_bound (RIGHT, heads.back ());
95 void
96 Hyphen_engraver::finalize ()
98 if (hyphen_)
100 completize_hyphen (hyphen_);
102 if (!hyphen_->get_bound (RIGHT))
104 hyphen_->warning (_ ("removing unterminated hyphen"));
105 hyphen_->suicide ();
108 hyphen_ = 0;
111 if (finished_hyphen_)
113 completize_hyphen (finished_hyphen_);
115 if (!finished_hyphen_->get_bound (RIGHT))
117 if (finished_ev_)
118 finished_hyphen_->warning (_ ("unterminated hyphen; removing"));
119 finished_hyphen_->suicide ();
121 finished_hyphen_ = 0;
125 void
126 Hyphen_engraver::process_music ()
128 if (ev_)
129 hyphen_ = make_spanner ("LyricHyphen", ev_->self_scm ());
132 void
133 Hyphen_engraver::stop_translation_timestep ()
135 if (finished_hyphen_ && finished_hyphen_->get_bound (RIGHT))
137 finished_hyphen_ = 0;
138 finished_ev_ = 0;
141 if (finished_hyphen_ && hyphen_)
143 programming_error ("hyphen not finished yet");
144 finished_hyphen_ = 0;
145 finished_ev_ = 0;
148 if (hyphen_)
150 finished_hyphen_ = hyphen_;
151 finished_ev_ = ev_;
154 hyphen_ = 0;
155 ev_ = 0;
158 ADD_ACKNOWLEDGER (Hyphen_engraver, lyric_syllable);
160 ADD_TRANSLATOR (Hyphen_engraver,
161 /* doc */
162 "Create lyric hyphens and distance constraints between words.",
164 /* create */
165 "LyricHyphen "
166 "LyricSpace ",
168 /* read */
171 /* write */