Add arrowed sharp signs
[lilypond.git] / lily / extender-engraver.cc
blobaf1ae8503e7eedaf397c702320004189ca10a67f
1 /*
2 extender-engraver.cc -- implement Extender_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2008 Glen Prideaux <glenprideaux@iname.com>,
7 Han-Wen Nienhuys <hanwen@xs4all.nl>,
8 Jan Nieuwenhuizen <janneke@gnu.org>
9 */
11 #include "context.hh"
12 #include "engraver.hh"
13 #include "international.hh"
14 #include "item.hh"
15 #include "lyric-extender.hh"
16 #include "note-head.hh"
17 #include "pointer-group-interface.hh"
18 #include "stream-event.hh"
19 #include "warn.hh"
20 #include "spanner.hh"
22 #include "translator.icc"
24 void completize_extender (Spanner *sp);
26 class Extender_engraver : public Engraver
28 Stream_event *ev_;
29 Spanner *extender_;
30 Spanner *pending_extender_;
32 public:
33 TRANSLATOR_DECLARATIONS (Extender_engraver);
35 protected:
36 DECLARE_TRANSLATOR_LISTENER (extender);
37 DECLARE_ACKNOWLEDGER (lyric_syllable);
39 virtual void finalize ();
41 void stop_translation_timestep ();
42 void process_music ();
45 Extender_engraver::Extender_engraver ()
47 extender_ = 0;
48 pending_extender_ = 0;
49 ev_ = 0;
52 IMPLEMENT_TRANSLATOR_LISTENER (Extender_engraver, extender);
53 void
54 Extender_engraver::listen_extender (Stream_event *ev)
56 ASSIGN_EVENT_ONCE (ev_, ev);
59 void
60 Extender_engraver::process_music ()
62 if (ev_)
63 extender_ = make_spanner ("LyricExtender", ev_->self_scm ());
66 void
67 Extender_engraver::acknowledge_lyric_syllable (Grob_info i)
69 Item *item = i.item ();
70 if (extender_)
71 extender_->set_bound (LEFT, item);
73 if (pending_extender_)
75 pending_extender_->set_object ("next", item->self_scm ());
76 completize_extender (pending_extender_);
77 pending_extender_ = 0;
81 void
82 Extender_engraver::stop_translation_timestep ()
84 if (extender_ || pending_extender_)
86 Context *voice = get_voice_to_lyrics (context ());
87 Grob *h = voice ? get_current_note_head (voice) : 0;
89 if (h)
91 if (extender_)
93 Pointer_group_interface::add_grob (extender_,
94 ly_symbol2scm ("heads"), h);
97 if (pending_extender_)
99 Pointer_group_interface::add_grob (pending_extender_,
100 ly_symbol2scm ("heads"), h);
103 else
105 if (pending_extender_
106 && !get_property ("extendersOverRests"))
108 completize_extender (pending_extender_);
109 pending_extender_ = 0;
113 if (extender_)
115 pending_extender_ = extender_;
116 extender_ = 0;
120 ev_ = 0;
123 void
124 completize_extender (Spanner *sp)
126 if (!sp->get_bound (RIGHT))
128 extract_item_set (sp, "heads", heads);
129 if (heads.size ())
130 sp->set_bound (RIGHT, heads.back ());
134 void
135 Extender_engraver::finalize ()
137 if (extender_)
139 completize_extender (extender_);
141 if (!extender_->get_bound (RIGHT))
142 extender_->warning (_ ("unterminated extender"));
143 extender_ = 0;
146 if (pending_extender_)
148 completize_extender (pending_extender_);
150 if (!pending_extender_->get_bound (RIGHT))
151 pending_extender_->warning (_ ("unterminated extender"));
152 pending_extender_ = 0;
156 ADD_ACKNOWLEDGER (Extender_engraver, lyric_syllable);
157 ADD_TRANSLATOR (Extender_engraver,
158 /* doc */
159 "Create lyric extenders.",
161 /* create */
162 "LyricExtender ",
164 /* read */
165 "extendersOverRests ",
167 /* write */