Fix \deadNotesOff.
[lilypond/mpolesky.git] / lily / hyphen-engraver.cc
blob24b8665e80d111ffd9d401af5e474d083ddfceef
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_;
39 bool current_lyric_is_skip_;
41 public:
42 TRANSLATOR_DECLARATIONS (Hyphen_engraver);
44 protected:
46 DECLARE_ACKNOWLEDGER (lyric_syllable);
47 DECLARE_TRANSLATOR_LISTENER (hyphen);
49 virtual void finalize ();
51 void stop_translation_timestep ();
52 void process_music ();
55 Hyphen_engraver::Hyphen_engraver ()
57 current_lyric_is_skip_ = false;
58 hyphen_ = 0;
59 finished_hyphen_ = 0;
60 finished_ev_ = 0;
61 ev_ = 0;
64 void
65 Hyphen_engraver::acknowledge_lyric_syllable (Grob_info i)
67 Item *item = i.item ();
68 SCM text = item->get_property ("text");
69 current_lyric_is_skip_ = ly_is_equal (text, scm_from_locale_string (" "));
71 if (!hyphen_ && !current_lyric_is_skip_)
72 hyphen_ = make_spanner ("LyricSpace", item->self_scm ());
74 if (hyphen_)
75 hyphen_->set_bound (LEFT, item);
77 if (finished_hyphen_ && !current_lyric_is_skip_)
78 finished_hyphen_->set_bound (RIGHT, item);
81 IMPLEMENT_TRANSLATOR_LISTENER (Hyphen_engraver, hyphen);
82 void
83 Hyphen_engraver::listen_hyphen (Stream_event *ev)
85 ASSIGN_EVENT_ONCE (ev_, ev);
88 void
89 completize_hyphen (Spanner *sp)
91 if (!sp->get_bound (RIGHT))
93 extract_item_set (sp, "heads", heads);
94 if (heads.size ())
95 sp->set_bound (RIGHT, heads.back ());
99 void
100 Hyphen_engraver::finalize ()
102 if (hyphen_)
104 completize_hyphen (hyphen_);
106 if (!hyphen_->get_bound (RIGHT))
108 hyphen_->warning (_ ("removing unterminated hyphen"));
109 hyphen_->suicide ();
112 hyphen_ = 0;
115 if (finished_hyphen_)
117 completize_hyphen (finished_hyphen_);
119 if (!finished_hyphen_->get_bound (RIGHT))
121 if (finished_ev_)
122 finished_hyphen_->warning (_ ("unterminated hyphen; removing"));
123 finished_hyphen_->suicide ();
125 finished_hyphen_ = 0;
129 void
130 Hyphen_engraver::process_music ()
132 if (ev_)
133 hyphen_ = make_spanner ("LyricHyphen", ev_->self_scm ());
136 void
137 Hyphen_engraver::stop_translation_timestep ()
139 if (finished_hyphen_ && finished_hyphen_->get_bound (RIGHT))
141 finished_hyphen_ = 0;
142 finished_ev_ = 0;
145 if (finished_hyphen_ && hyphen_ && !current_lyric_is_skip_)
147 programming_error ("hyphen not finished yet");
148 finished_hyphen_ = 0;
149 finished_ev_ = 0;
152 if (hyphen_)
154 finished_hyphen_ = hyphen_;
155 finished_ev_ = ev_;
158 hyphen_ = 0;
159 ev_ = 0;
162 ADD_ACKNOWLEDGER (Hyphen_engraver, lyric_syllable);
164 ADD_TRANSLATOR (Hyphen_engraver,
165 /* doc */
166 "Create lyric hyphens and distance constraints between words.",
168 /* create */
169 "LyricHyphen "
170 "LyricSpace ",
172 /* read */
175 /* write */