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>
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_
;
30 TRANSLATOR_DECLARATIONS (Hyphen_engraver
);
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 ()
52 Hyphen_engraver::acknowledge_lyric_syllable (Grob_info i
)
54 Item
*item
= i
.item ();
57 hyphen_
= make_spanner ("LyricSpace", item
->self_scm ());
60 hyphen_
->set_bound (LEFT
, item
);
63 finished_hyphen_
->set_bound (RIGHT
, item
);
66 IMPLEMENT_TRANSLATOR_LISTENER (Hyphen_engraver
, hyphen
);
68 Hyphen_engraver::listen_hyphen (Stream_event
*ev
)
70 ASSIGN_EVENT_ONCE (ev_
, ev
);
74 completize_hyphen (Spanner
*sp
)
76 if (!sp
->get_bound (RIGHT
))
78 extract_item_set (sp
, "heads", heads
);
80 sp
->set_bound (RIGHT
, heads
.back ());
85 Hyphen_engraver::finalize ()
89 completize_hyphen (hyphen_
);
91 if (!hyphen_
->get_bound (RIGHT
))
93 hyphen_
->warning (_ ("removing unterminated hyphen"));
100 if (finished_hyphen_
)
102 completize_hyphen (finished_hyphen_
);
104 if (!finished_hyphen_
->get_bound (RIGHT
))
107 finished_hyphen_
->warning (_ ("unterminated hyphen; removing"));
108 finished_hyphen_
->suicide ();
110 finished_hyphen_
= 0;
115 Hyphen_engraver::process_music ()
118 hyphen_
= make_spanner ("LyricHyphen", ev_
->self_scm ());
122 Hyphen_engraver::stop_translation_timestep ()
124 if (finished_hyphen_
&& finished_hyphen_
->get_bound (RIGHT
))
126 finished_hyphen_
= 0;
130 if (finished_hyphen_
&& hyphen_
)
132 programming_error ("hyphen not finished yet");
133 finished_hyphen_
= 0;
139 finished_hyphen_
= hyphen_
;
147 ADD_ACKNOWLEDGER (Hyphen_engraver
, lyric_syllable
);
149 ADD_TRANSLATOR (Hyphen_engraver
,
151 "Create lyric hyphens and distance constraints between words.",