Use scalar instead of embedded_scm for context mod overrides.
[lilypond/mpolesky.git] / lily / hyphen-engraver.cc
blob27e85f3f59f880fc9c3d02f905014be9c428551f
1 /*
2 hyphen-engraver.cc -- implement Hyphen_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2009 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_;
28 bool current_lyric_is_skip_;
30 public:
31 TRANSLATOR_DECLARATIONS (Hyphen_engraver);
33 protected:
35 DECLARE_ACKNOWLEDGER (lyric_syllable);
36 DECLARE_TRANSLATOR_LISTENER (hyphen);
38 virtual void finalize ();
40 void stop_translation_timestep ();
41 void process_music ();
44 Hyphen_engraver::Hyphen_engraver ()
46 current_lyric_is_skip_ = false;
47 hyphen_ = 0;
48 finished_hyphen_ = 0;
49 finished_ev_ = 0;
50 ev_ = 0;
53 void
54 Hyphen_engraver::acknowledge_lyric_syllable (Grob_info i)
56 Item *item = i.item ();
57 SCM text = item->get_property ("text");
58 current_lyric_is_skip_ = ly_is_equal (text, scm_from_locale_string (" "));
60 if (!hyphen_ && !current_lyric_is_skip_)
61 hyphen_ = make_spanner ("LyricSpace", item->self_scm ());
63 if (hyphen_)
64 hyphen_->set_bound (LEFT, item);
66 if (finished_hyphen_ && !current_lyric_is_skip_)
67 finished_hyphen_->set_bound (RIGHT, item);
70 IMPLEMENT_TRANSLATOR_LISTENER (Hyphen_engraver, hyphen);
71 void
72 Hyphen_engraver::listen_hyphen (Stream_event *ev)
74 ASSIGN_EVENT_ONCE (ev_, ev);
77 void
78 completize_hyphen (Spanner *sp)
80 if (!sp->get_bound (RIGHT))
82 extract_item_set (sp, "heads", heads);
83 if (heads.size ())
84 sp->set_bound (RIGHT, heads.back ());
88 void
89 Hyphen_engraver::finalize ()
91 if (hyphen_)
93 completize_hyphen (hyphen_);
95 if (!hyphen_->get_bound (RIGHT))
97 hyphen_->warning (_ ("removing unterminated hyphen"));
98 hyphen_->suicide ();
101 hyphen_ = 0;
104 if (finished_hyphen_)
106 completize_hyphen (finished_hyphen_);
108 if (!finished_hyphen_->get_bound (RIGHT))
110 if (finished_ev_)
111 finished_hyphen_->warning (_ ("unterminated hyphen; removing"));
112 finished_hyphen_->suicide ();
114 finished_hyphen_ = 0;
118 void
119 Hyphen_engraver::process_music ()
121 if (ev_)
122 hyphen_ = make_spanner ("LyricHyphen", ev_->self_scm ());
125 void
126 Hyphen_engraver::stop_translation_timestep ()
128 if (finished_hyphen_ && finished_hyphen_->get_bound (RIGHT))
130 finished_hyphen_ = 0;
131 finished_ev_ = 0;
134 if (finished_hyphen_ && hyphen_ && !current_lyric_is_skip_)
136 programming_error ("hyphen not finished yet");
137 finished_hyphen_ = 0;
138 finished_ev_ = 0;
141 if (hyphen_)
143 finished_hyphen_ = hyphen_;
144 finished_ev_ = ev_;
147 hyphen_ = 0;
148 ev_ = 0;
151 ADD_ACKNOWLEDGER (Hyphen_engraver, lyric_syllable);
153 ADD_TRANSLATOR (Hyphen_engraver,
154 /* doc */
155 "Create lyric hyphens and distance constraints between words.",
157 /* create */
158 "LyricHyphen "
159 "LyricSpace ",
161 /* read */
164 /* write */