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>
11 #include "engraver.hh"
12 #include "international.hh"
14 #include "pointer-group-interface.hh"
16 #include "stream-event.hh"
19 #include "translator.icc"
21 class Hyphen_engraver
: public Engraver
24 Stream_event
*finished_ev_
;
27 Spanner
*finished_hyphen_
;
28 bool current_lyric_is_skip_
;
31 TRANSLATOR_DECLARATIONS (Hyphen_engraver
);
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;
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 ());
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
);
72 Hyphen_engraver::listen_hyphen (Stream_event
*ev
)
74 ASSIGN_EVENT_ONCE (ev_
, ev
);
78 completize_hyphen (Spanner
*sp
)
80 if (!sp
->get_bound (RIGHT
))
82 extract_item_set (sp
, "heads", heads
);
84 sp
->set_bound (RIGHT
, heads
.back ());
89 Hyphen_engraver::finalize ()
93 completize_hyphen (hyphen_
);
95 if (!hyphen_
->get_bound (RIGHT
))
97 hyphen_
->warning (_ ("removing unterminated hyphen"));
104 if (finished_hyphen_
)
106 completize_hyphen (finished_hyphen_
);
108 if (!finished_hyphen_
->get_bound (RIGHT
))
111 finished_hyphen_
->warning (_ ("unterminated hyphen; removing"));
112 finished_hyphen_
->suicide ();
114 finished_hyphen_
= 0;
119 Hyphen_engraver::process_music ()
122 hyphen_
= make_spanner ("LyricHyphen", ev_
->self_scm ());
126 Hyphen_engraver::stop_translation_timestep ()
128 if (finished_hyphen_
&& finished_hyphen_
->get_bound (RIGHT
))
130 finished_hyphen_
= 0;
134 if (finished_hyphen_
&& hyphen_
&& !current_lyric_is_skip_
)
136 programming_error ("hyphen not finished yet");
137 finished_hyphen_
= 0;
143 finished_hyphen_
= hyphen_
;
151 ADD_ACKNOWLEDGER (Hyphen_engraver
, lyric_syllable
);
153 ADD_TRANSLATOR (Hyphen_engraver
,
155 "Create lyric hyphens and distance constraints between words.",