2 slur-engraver.cc -- implement Slur_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
12 #include "directional-element-interface.hh"
13 #include "international.hh"
14 #include "note-column.hh"
17 #include "stream-event.hh"
20 #include "translator.icc"
26 This is largely similar to Phrasing_slur_engraver. Check if fixes
29 (on principle, engravers don't use inheritance for code sharing)
34 It is possible that a slur starts and ends on the same note. At
35 least, it is for phrasing slurs: a note can be both beginning and
38 class Slur_engraver : public Engraver
40 Drul_array<Stream_event *> events_;
41 Stream_event *running_slur_start_;
43 vector<Grob*> end_slurs_;
45 void set_melisma (bool);
48 DECLARE_TRANSLATOR_LISTENER (slur);
49 DECLARE_ACKNOWLEDGER (accidental);
50 DECLARE_ACKNOWLEDGER (dynamic_line_spanner);
51 DECLARE_ACKNOWLEDGER (fingering);
52 DECLARE_ACKNOWLEDGER (note_column);
53 DECLARE_ACKNOWLEDGER (script);
54 DECLARE_ACKNOWLEDGER (text_script);
55 DECLARE_ACKNOWLEDGER (tie);
56 DECLARE_ACKNOWLEDGER (tuplet_number);
58 void acknowledge_extra_object (Grob_info);
59 void stop_translation_timestep ();
60 void process_music ();
62 virtual void finalize ();
66 TRANSLATOR_DECLARATIONS (Slur_engraver);
69 Slur_engraver::Slur_engraver ()
71 events_[START] = events_[STOP] = 0;
74 IMPLEMENT_TRANSLATOR_LISTENER (Slur_engraver, slur);
76 Slur_engraver::listen_slur (Stream_event *ev)
78 Direction d = to_dir (ev->get_property ("span-direction"));
80 ASSIGN_EVENT_ONCE (events_[START], ev);
82 ASSIGN_EVENT_ONCE (events_[STOP], ev);
83 else ev->origin ()->warning (_f ("direction of %s invalid: %d",
84 "slur-event", int (d)));
88 Slur_engraver::set_melisma (bool m)
90 context ()->set_property ("slurMelismaBusy", m ? SCM_BOOL_T : SCM_BOOL_F);
94 Slur_engraver::acknowledge_note_column (Grob_info info)
96 Grob *e = info.grob ();
97 for (vsize i = slurs_.size (); i--;)
98 Slur::add_column (slurs_[i], e);
99 for (vsize i = end_slurs_.size (); i--;)
100 Slur::add_column (end_slurs_[i], e);
104 Slur_engraver::acknowledge_extra_object (Grob_info info)
106 Slur::auxiliary_acknowledge_extra_object (info, slurs_, end_slurs_);
110 Slur_engraver::acknowledge_accidental (Grob_info info)
112 acknowledge_extra_object (info);
116 Slur_engraver::acknowledge_dynamic_line_spanner (Grob_info info)
118 acknowledge_extra_object (info);
122 Slur_engraver::acknowledge_fingering (Grob_info info)
124 acknowledge_extra_object (info);
128 Slur_engraver::acknowledge_tuplet_number (Grob_info info)
130 acknowledge_extra_object (info);
135 Slur_engraver::acknowledge_script (Grob_info info)
137 if (!info.grob ()->internal_has_interface (ly_symbol2scm ("dynamic-interface")))
138 acknowledge_extra_object (info);
142 Slur_engraver::acknowledge_text_script (Grob_info info)
144 acknowledge_extra_object (info);
148 Slur_engraver::acknowledge_tie (Grob_info info)
150 acknowledge_extra_object (info);
154 Slur_engraver::finalize ()
157 slurs_[0]->warning (_ ("unterminated slur"));
161 Slur_engraver::process_music ()
165 if (slurs_.size () == 0)
166 events_[STOP]->origin ()->warning (_ ("cannot end slur"));
173 if (events_[START] && slurs_.empty ())
175 Stream_event *ev = events_[START];
177 bool double_slurs = to_boolean (get_property ("doubleSlurs"));
179 Grob *slur = make_spanner ("Slur", events_[START]->self_scm ());
180 Direction updown = to_dir (ev->get_property ("direction"));
181 if (updown && !double_slurs)
182 set_grob_direction (slur, updown);
184 slurs_.push_back (slur);
188 set_grob_direction (slur, DOWN);
189 slur = make_spanner ("Slur", events_[START]->self_scm ());
190 set_grob_direction (slur, UP);
191 slurs_.push_back (slur);
194 set_melisma (slurs_.size ());
198 Slur_engraver::stop_translation_timestep ()
200 if (Grob *g = unsmob_grob (get_property ("breakableSeparationItem")))
202 for (vsize i = 0; i < end_slurs_.size (); i++)
203 Slur::add_extra_encompass (end_slurs_[i], g);
206 for (vsize i = 0; i < slurs_.size (); i++)
207 Slur::add_extra_encompass (slurs_[i], g);
211 for (vsize i = 0; i < end_slurs_.size (); i++)
212 announce_end_grob (end_slurs_[i], SCM_EOL);
214 events_[START] = events_[STOP] = 0;
217 ADD_ACKNOWLEDGER (Slur_engraver, accidental);
218 ADD_ACKNOWLEDGER (Slur_engraver, dynamic_line_spanner);
219 ADD_ACKNOWLEDGER (Slur_engraver, fingering);
220 ADD_ACKNOWLEDGER (Slur_engraver, note_column);
221 ADD_ACKNOWLEDGER (Slur_engraver, script);
222 ADD_ACKNOWLEDGER (Slur_engraver, text_script);
223 ADD_ACKNOWLEDGER (Slur_engraver, tie);
224 ADD_ACKNOWLEDGER (Slur_engraver, tuplet_number);
225 ADD_TRANSLATOR (Slur_engraver,
226 /* doc */ "Build slur grobs from slur events",